...
1
2
3
4
5 package runes_test
6
7 import (
8 "fmt"
9 "unicode"
10
11 "golang.org/x/text/runes"
12 "golang.org/x/text/transform"
13 "golang.org/x/text/unicode/norm"
14 "golang.org/x/text/width"
15 )
16
17 func ExampleRemove() {
18 t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
19 s, _, _ := transform.String(t, "résumé")
20 fmt.Println(s)
21
22
23
24 }
25
26 func ExampleMap() {
27 replaceHyphens := runes.Map(func(r rune) rune {
28 if unicode.Is(unicode.Hyphen, r) {
29 return '|'
30 }
31 return r
32 })
33 s, _, _ := transform.String(replaceHyphens, "a-b‐c⸗d﹣e")
34 fmt.Println(s)
35
36
37
38 }
39
40 func ExampleIn() {
41
42
43 t := runes.If(runes.In(unicode.Latin), width.Fold, nil)
44 s, _, _ := transform.String(t, "アルアノリウ tech / アルアノリウ tech")
45 fmt.Println(s)
46
47
48
49 }
50
51 func ExampleIf() {
52
53 isASCII := func(r rune) bool { return r <= unicode.MaxASCII }
54 t := runes.If(runes.Predicate(isASCII), nil, width.Widen)
55 s, _, _ := transform.String(t, "アルアノリウ tech / 中國 / 5₩")
56 fmt.Println(s)
57
58
59
60 }
61
View as plain text