sync/atomic, runtime/internal/atomic: don't assume reads from 0 fail
[official-gcc.git] / libgo / go / unicode / example_test.go
blob50c5b18a48e63d8269996a21e810fbface9e6acf
1 // Copyright 2015 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.
5 package unicode_test
7 import (
8 "fmt"
9 "unicode"
12 // Functions starting with "Is" can be used to inspect which table of range a
13 // rune belongs to. Note that runes may fit into more than one range.
14 func Example_is() {
16 // constant with mixed type runes
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")
23 if unicode.IsDigit(c) {
24 fmt.Println("\tis digit rune")
26 if unicode.IsGraphic(c) {
27 fmt.Println("\tis graphic rune")
29 if unicode.IsLetter(c) {
30 fmt.Println("\tis letter rune")
32 if unicode.IsLower(c) {
33 fmt.Println("\tis lower case rune")
35 if unicode.IsMark(c) {
36 fmt.Println("\tis mark rune")
38 if unicode.IsNumber(c) {
39 fmt.Println("\tis number rune")
41 if unicode.IsPrint(c) {
42 fmt.Println("\tis printable rune")
44 if !unicode.IsPrint(c) {
45 fmt.Println("\tis not printable rune")
47 if unicode.IsPunct(c) {
48 fmt.Println("\tis punct rune")
50 if unicode.IsSpace(c) {
51 fmt.Println("\tis space rune")
53 if unicode.IsSymbol(c) {
54 fmt.Println("\tis symbol rune")
56 if unicode.IsTitle(c) {
57 fmt.Println("\tis title case rune")
59 if unicode.IsUpper(c) {
60 fmt.Println("\tis upper case rune")
64 // Output:
65 // For '\b':
66 // is control rune
67 // is not printable rune
68 // For '5':
69 // is digit rune
70 // is graphic rune
71 // is number rune
72 // is printable rune
73 // For 'Ὂ':
74 // is graphic rune
75 // is letter rune
76 // is printable rune
77 // is upper case rune
78 // For 'g':
79 // is graphic rune
80 // is letter rune
81 // is lower case rune
82 // is printable rune
83 // For '̀':
84 // is graphic rune
85 // is mark rune
86 // is printable rune
87 // For '9':
88 // is digit rune
89 // is graphic rune
90 // is number rune
91 // is printable rune
92 // For '!':
93 // is graphic rune
94 // is printable rune
95 // is punct rune
96 // For ' ':
97 // is graphic rune
98 // is printable rune
99 // is space rune
100 // For '℃':
101 // is graphic rune
102 // is printable rune
103 // is symbol rune
104 // For 'ᾭ':
105 // is graphic rune
106 // is letter rune
107 // is printable rune
108 // is title case rune
109 // For 'G':
110 // is graphic rune
111 // is letter rune
112 // is printable rune
113 // is upper case rune
116 func ExampleSimpleFold() {
117 fmt.Printf("%#U\n", unicode.SimpleFold('A')) // 'a'
118 fmt.Printf("%#U\n", unicode.SimpleFold('a')) // 'A'
119 fmt.Printf("%#U\n", unicode.SimpleFold('K')) // 'k'
120 fmt.Printf("%#U\n", unicode.SimpleFold('k')) // '\u212A' (Kelvin symbol, K)
121 fmt.Printf("%#U\n", unicode.SimpleFold('\u212A')) // 'K'
122 fmt.Printf("%#U\n", unicode.SimpleFold('1')) // '1'
124 // Output:
125 // U+0061 'a'
126 // U+0041 'A'
127 // U+006B 'k'
128 // U+212A 'K'
129 // U+004B 'K'
130 // U+0031 '1'
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))
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))
144 // Output:
145 // U+0047 'G'
146 // U+0067 'g'
147 // U+0047 'G'
148 // U+0047 'G'
149 // U+0067 'g'
150 // U+0047 'G'
153 func ExampleToLower() {
154 const ucG = 'G'
155 fmt.Printf("%#U\n", unicode.ToLower(ucG))
157 // Output:
158 // U+0067 'g'
160 func ExampleToTitle() {
161 const ucG = 'g'
162 fmt.Printf("%#U\n", unicode.ToTitle(ucG))
164 // Output:
165 // U+0047 'G'
168 func ExampleToUpper() {
169 const ucG = 'g'
170 fmt.Printf("%#U\n", unicode.ToUpper(ucG))
172 // Output:
173 // U+0047 'G'
176 func ExampleSpecialCase() {
177 t := unicode.TurkishCase
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))
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))
189 // Output:
190 // U+0069 'i'
191 // U+0130 'İ'
192 // U+0130 'İ'
193 // U+0069 'i'
194 // U+0130 'İ'
195 // U+0130 'İ'