Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
example_test.go257 linesDownload Raw Back to unicode
1// Copyright 2015 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4 5package unicode_test6 7import (8	"fmt"9	"unicode"10)11 12// Functions starting with "Is" can be used to inspect which table of range a13// rune belongs to. Note that runes may fit into more than one range.14func Example_is() {15 16	// constant with mixed type runes17	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	// Output:65	// For '\b':66	// 	is control rune67	// 	is not printable rune68	// For '5':69	// 	is digit rune70	// 	is graphic rune71	// 	is number rune72	// 	is printable rune73	// For 'Ὂ':74	// 	is graphic rune75	// 	is letter rune76	// 	is printable rune77	// 	is upper case rune78	// For 'g':79	// 	is graphic rune80	// 	is letter rune81	// 	is lower case rune82	// 	is printable rune83	// For '̀':84	// 	is graphic rune85	// 	is mark rune86	// 	is printable rune87	// For '9':88	// 	is digit rune89	// 	is graphic rune90	// 	is number rune91	// 	is printable rune92	// For '!':93	// 	is graphic rune94	// 	is printable rune95	// 	is punct rune96	// For ' ':97	// 	is graphic rune98	// 	is printable rune99	// 	is space rune100	// For '℃':101	// 	is graphic rune102	// 	is printable rune103	// 	is symbol rune104	// For 'ᾭ':105	// 	is graphic rune106	// 	is letter rune107	// 	is printable rune108	// 	is title case rune109	// For 'G':110	// 	is graphic rune111	// 	is letter rune112	// 	is printable rune113	// 	is upper case rune114}115 116func 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'123 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'131}132 133func 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	// 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'151}152 153func ExampleToLower() {154	const ucG = 'G'155	fmt.Printf("%#U\n", unicode.ToLower(ucG))156 157	// Output:158	// U+0067 'g'159}160func ExampleToTitle() {161	const ucG = 'g'162	fmt.Printf("%#U\n", unicode.ToTitle(ucG))163 164	// Output:165	// U+0047 'G'166}167 168func ExampleToUpper() {169	const ucG = 'g'170	fmt.Printf("%#U\n", unicode.ToUpper(ucG))171 172	// Output:173	// U+0047 'G'174}175 176func ExampleSpecialCase() {177	t := unicode.TurkishCase178 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	// Output:190	// U+0069 'i'191	// U+0130 'İ'192	// U+0130 'İ'193	// U+0069 'i'194	// U+0130 'İ'195	// U+0130 'İ'196}197 198func ExampleIsDigit() {199	fmt.Printf("%t\n", unicode.IsDigit('৩'))200	fmt.Printf("%t\n", unicode.IsDigit('A'))201	// Output:202	// true203	// false204}205 206func ExampleIsNumber() {207	fmt.Printf("%t\n", unicode.IsNumber('Ⅷ'))208	fmt.Printf("%t\n", unicode.IsNumber('A'))209	// Output:210	// true211	// false212}213 214func ExampleIsLetter() {215	fmt.Printf("%t\n", unicode.IsLetter('A'))216	fmt.Printf("%t\n", unicode.IsLetter('7'))217	// Output:218	// true219	// false220}221 222func ExampleIsLower() {223	fmt.Printf("%t\n", unicode.IsLower('a'))224	fmt.Printf("%t\n", unicode.IsLower('A'))225	// Output:226	// true227	// false228}229 230func ExampleIsUpper() {231	fmt.Printf("%t\n", unicode.IsUpper('A'))232	fmt.Printf("%t\n", unicode.IsUpper('a'))233	// Output:234	// true235	// false236}237 238func ExampleIsTitle() {239	fmt.Printf("%t\n", unicode.IsTitle('Dž'))240	fmt.Printf("%t\n", unicode.IsTitle('a'))241	// Output:242	// true243	// false244}245 246func ExampleIsSpace() {247	fmt.Printf("%t\n", unicode.IsSpace(' '))248	fmt.Printf("%t\n", unicode.IsSpace('\n'))249	fmt.Printf("%t\n", unicode.IsSpace('\t'))250	fmt.Printf("%t\n", unicode.IsSpace('a'))251	// Output:252	// true253	// true254	// true255	// false256}257 
codekingpro/portable-devtools · Team Ai