1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package unicode_test
import (
"fmt"
"unicode"
)
// Functions starting with "Is" can be used to inspect which table of range a
// rune belongs to. Note that runes may fit into more than one range.
func Example_is() {
// constant with mixed type runes
const mixed = "\b5Ὂg̀9! ℃ᾭG"
for _, c := range mixed {
fmt.Printf("For %q:\n", c)
if unicode.IsControl(c) {
fmt.Println("\tis control rune")
}
if unicode.IsDigit(c) {
fmt.Println("\tis digit rune")
}
if unicode.IsGraphic(c) {
fmt.Println("\tis graphic rune")
}
if unicode.IsLetter(c) {
fmt.Println("\tis letter rune")
}
if unicode.IsLower(c) {
fmt.Println("\tis lower case rune")
}
if unicode.IsMark(c) {
fmt.Println("\tis mark rune")
}
if unicode.IsNumber(c) {
fmt.Println("\tis number rune")
}
if unicode.IsPrint(c) {
fmt.Println("\tis printable rune")
}
if !unicode.IsPrint(c) {
fmt.Println("\tis not printable rune")
}
if unicode.IsPunct(c) {
fmt.Println("\tis punct rune")
}
if unicode.IsSpace(c) {
fmt.Println("\tis space rune")
}
if unicode.IsSymbol(c) {
fmt.Println("\tis symbol rune")
}
if unicode.IsTitle(c) {
fmt.Println("\tis title case rune")
}
if unicode.IsUpper(c) {
fmt.Println("\tis upper case rune")
}
}
// Output:
// For '\b':
// is control rune
// is not printable rune
// For '5':
// is digit rune
// is graphic rune
// is number rune
// is printable rune
// For 'Ὂ':
// is graphic rune
// is letter rune
// is printable rune
// is upper case rune
// For 'g':
// is graphic rune
// is letter rune
// is lower case rune
// is printable rune
// For '̀':
// is graphic rune
// is mark rune
// is printable rune
// For '9':
// is digit rune
// is graphic rune
// is number rune
// is printable rune
// For '!':
// is graphic rune
// is printable rune
// is punct rune
// For ' ':
// is graphic rune
// is printable rune
// is space rune
// For '℃':
// is graphic rune
// is printable rune
// is symbol rune
// For 'ᾭ':
// is graphic rune
// is letter rune
// is printable rune
// is title case rune
// For 'G':
// is graphic rune
// is letter rune
// is printable rune
// is upper case rune
}
func ExampleSimpleFold() {
fmt.Printf("%#U\n", unicode.SimpleFold('A')) // 'a'
fmt.Printf("%#U\n", unicode.SimpleFold('a')) // 'A'
fmt.Printf("%#U\n", unicode.SimpleFold('K')) // 'k'
fmt.Printf("%#U\n", unicode.SimpleFold('k')) // '\u212A' (Kelvin symbol, K)
fmt.Printf("%#U\n", unicode.SimpleFold('\u212A')) // 'K'
fmt.Printf("%#U\n", unicode.SimpleFold('1')) // '1'
// Output:
// U+0061 'a'
// U+0041 'A'
// U+006B 'k'
// U+212A 'K'
// U+004B 'K'
// U+0031 '1'
}
func ExampleTo() {
const lcG = 'g'
fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, lcG))
fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, lcG))
fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, lcG))
const ucG = 'G'
fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, ucG))
fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, ucG))
fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, ucG))
// Output:
// U+0047 'G'
// U+0067 'g'
// U+0047 'G'
// U+0047 'G'
// U+0067 'g'
// U+0047 'G'
}
func ExampleToLower() {
const ucG = 'G'
fmt.Printf("%#U\n", unicode.ToLower(ucG))
// Output:
// U+0067 'g'
}
func ExampleToTitle() {
const ucG = 'g'
fmt.Printf("%#U\n", unicode.ToTitle(ucG))
// Output:
// U+0047 'G'
}
func ExampleToUpper() {
const ucG = 'g'
fmt.Printf("%#U\n", unicode.ToUpper(ucG))
// Output:
// U+0047 'G'
}
func ExampleSpecialCase() {
t := unicode.TurkishCase
const lci = 'i'
fmt.Printf("%#U\n", t.ToLower(lci))
fmt.Printf("%#U\n", t.ToTitle(lci))
fmt.Printf("%#U\n", t.ToUpper(lci))
const uci = 'İ'
fmt.Printf("%#U\n", t.ToLower(uci))
fmt.Printf("%#U\n", t.ToTitle(uci))
fmt.Printf("%#U\n", t.ToUpper(uci))
// Output:
// U+0069 'i'
// U+0130 'İ'
// U+0130 'İ'
// U+0069 'i'
// U+0130 'İ'
// U+0130 'İ'
}
|