...
1
2
3
4
5 package ucd_test
6
7 import (
8 "fmt"
9 "strings"
10
11 "golang.org/x/text/internal/ucd"
12 )
13
14 func Example() {
15
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
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
40
41
42
43
44
45
46
47
48
49
50 }
51
52
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
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 `
82
View as plain text