...
Source file
src/unicode/example_test.go
Documentation: unicode
1
2
3
4
5 package unicode_test
6
7 import (
8 "fmt"
9 "unicode"
10 )
11
12
13
14 func Example_is() {
15
16
17 const mixed = "\b5Ὂg̀9! ℃ᾭG"
18 for _, c := range mixed {
19 fmt.Printf("For %q:\n", c)
20 if unicode.IsControl(c) {
21 fmt.Println("\tis control rune")
22 }
23 if unicode.IsDigit(c) {
24 fmt.Println("\tis digit rune")
25 }
26 if unicode.IsGraphic(c) {
27 fmt.Println("\tis graphic rune")
28 }
29 if unicode.IsLetter(c) {
30 fmt.Println("\tis letter rune")
31 }
32 if unicode.IsLower(c) {
33 fmt.Println("\tis lower case rune")
34 }
35 if unicode.IsMark(c) {
36 fmt.Println("\tis mark rune")
37 }
38 if unicode.IsNumber(c) {
39 fmt.Println("\tis number rune")
40 }
41 if unicode.IsPrint(c) {
42 fmt.Println("\tis printable rune")
43 }
44 if !unicode.IsPrint(c) {
45 fmt.Println("\tis not printable rune")
46 }
47 if unicode.IsPunct(c) {
48 fmt.Println("\tis punct rune")
49 }
50 if unicode.IsSpace(c) {
51 fmt.Println("\tis space rune")
52 }
53 if unicode.IsSymbol(c) {
54 fmt.Println("\tis symbol rune")
55 }
56 if unicode.IsTitle(c) {
57 fmt.Println("\tis title case rune")
58 }
59 if unicode.IsUpper(c) {
60 fmt.Println("\tis upper case rune")
61 }
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 }
115
116 func ExampleSimpleFold() {
117 fmt.Printf("%#U\n", unicode.SimpleFold('A'))
118 fmt.Printf("%#U\n", unicode.SimpleFold('a'))
119 fmt.Printf("%#U\n", unicode.SimpleFold('K'))
120 fmt.Printf("%#U\n", unicode.SimpleFold('k'))
121 fmt.Printf("%#U\n", unicode.SimpleFold('\u212A'))
122 fmt.Printf("%#U\n", unicode.SimpleFold('1'))
123
124
125
126
127
128
129
130
131 }
132
133 func ExampleTo() {
134 const lcG = 'g'
135 fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, lcG))
136 fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, lcG))
137 fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, lcG))
138
139 const ucG = 'G'
140 fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, ucG))
141 fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, ucG))
142 fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, ucG))
143
144
145
146
147
148
149
150
151 }
152
153 func ExampleToLower() {
154 const ucG = 'G'
155 fmt.Printf("%#U\n", unicode.ToLower(ucG))
156
157
158
159 }
160 func ExampleToTitle() {
161 const ucG = 'g'
162 fmt.Printf("%#U\n", unicode.ToTitle(ucG))
163
164
165
166 }
167
168 func ExampleToUpper() {
169 const ucG = 'g'
170 fmt.Printf("%#U\n", unicode.ToUpper(ucG))
171
172
173
174 }
175
176 func ExampleSpecialCase() {
177 t := unicode.TurkishCase
178
179 const lci = 'i'
180 fmt.Printf("%#U\n", t.ToLower(lci))
181 fmt.Printf("%#U\n", t.ToTitle(lci))
182 fmt.Printf("%#U\n", t.ToUpper(lci))
183
184 const uci = 'İ'
185 fmt.Printf("%#U\n", t.ToLower(uci))
186 fmt.Printf("%#U\n", t.ToTitle(uci))
187 fmt.Printf("%#U\n", t.ToUpper(uci))
188
189
190
191
192
193
194
195
196 }
197
View as plain text