github.com/go-xe2/third@v1.0.3/golang.org/x/text/internal/ucd/example_test.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ucd_test 6 7 import ( 8 "fmt" 9 "strings" 10 11 "github.com/go-xe2/third/golang.org/x/text/internal/ucd" 12 ) 13 14 func Example() { 15 // Read rune-by-rune from UnicodeData. 16 var count int 17 p := ucd.New(strings.NewReader(unicodeData)) 18 for p.Next() { 19 count++ 20 if lower := p.Runes(ucd.SimpleLowercaseMapping); lower != nil { 21 fmt.Printf("lower(%U) -> %U\n", p.Rune(0), lower[0]) 22 } 23 } 24 if err := p.Err(); err != nil { 25 fmt.Println(err) 26 } 27 fmt.Println("Number of runes visited:", count) 28 29 // Read raw ranges from Scripts. 30 p = ucd.New(strings.NewReader(scripts), ucd.KeepRanges) 31 for p.Next() { 32 start, end := p.Range(0) 33 fmt.Printf("%04X..%04X: %s\n", start, end, p.String(1)) 34 } 35 if err := p.Err(); err != nil { 36 fmt.Println(err) 37 } 38 39 // Output: 40 // lower(U+00C0) -> U+00E0 41 // lower(U+00C1) -> U+00E1 42 // lower(U+00C2) -> U+00E2 43 // lower(U+00C3) -> U+00E3 44 // lower(U+00C4) -> U+00E4 45 // Number of runes visited: 6594 46 // 0000..001F: Common 47 // 0020..0020: Common 48 // 0021..0023: Common 49 // 0024..0024: Common 50 } 51 52 // Excerpt from UnicodeData.txt 53 const unicodeData = ` 54 00B9;SUPERSCRIPT ONE;No;0;EN;<super> 0031;;1;1;N;SUPERSCRIPT DIGIT ONE;;;; 55 00BA;MASCULINE ORDINAL INDICATOR;Lo;0;L;<super> 006F;;;;N;;;;; 56 00BB;RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK;Pf;0;ON;;;;;Y;RIGHT POINTING GUILLEMET;;;; 57 00BC;VULGAR FRACTION ONE QUARTER;No;0;ON;<fraction> 0031 2044 0034;;;1/4;N;FRACTION ONE QUARTER;;;; 58 00BD;VULGAR FRACTION ONE HALF;No;0;ON;<fraction> 0031 2044 0032;;;1/2;N;FRACTION ONE HALF;;;; 59 00BE;VULGAR FRACTION THREE QUARTERS;No;0;ON;<fraction> 0033 2044 0034;;;3/4;N;FRACTION THREE QUARTERS;;;; 60 00BF;INVERTED QUESTION MARK;Po;0;ON;;;;;N;;;;; 61 00C0;LATIN CAPITAL LETTER A WITH GRAVE;Lu;0;L;0041 0300;;;;N;LATIN CAPITAL LETTER A GRAVE;;;00E0; 62 00C1;LATIN CAPITAL LETTER A WITH ACUTE;Lu;0;L;0041 0301;;;;N;LATIN CAPITAL LETTER A ACUTE;;;00E1; 63 00C2;LATIN CAPITAL LETTER A WITH CIRCUMFLEX;Lu;0;L;0041 0302;;;;N;LATIN CAPITAL LETTER A CIRCUMFLEX;;;00E2; 64 00C3;LATIN CAPITAL LETTER A WITH TILDE;Lu;0;L;0041 0303;;;;N;LATIN CAPITAL LETTER A TILDE;;;00E3; 65 00C4;LATIN CAPITAL LETTER A WITH DIAERESIS;Lu;0;L;0041 0308;;;;N;LATIN CAPITAL LETTER A DIAERESIS;;;00E4; 66 67 # A legacy rune range. 68 3400;<CJK Ideograph Extension A, First>;Lo;0;L;;;;;N;;;;; 69 4DB5;<CJK Ideograph Extension A, Last>;Lo;0;L;;;;;N;;;;; 70 ` 71 72 // Excerpt from Scripts.txt 73 const scripts = ` 74 # Property: Script 75 # ================================================ 76 77 0000..001F ; Common # Cc [32] <control-0000>..<control-001F> 78 0020 ; Common # Zs SPACE 79 0021..0023 ; Common # Po [3] EXCLAMATION MARK..NUMBER SIGN 80 0024 ; Common # Sc DOLLAR SIGN 81 `