...
1
2
3
4
5 package transform_test
6
7 import (
8 "fmt"
9 "unicode"
10
11 "golang.org/x/text/transform"
12 "golang.org/x/text/unicode/norm"
13 )
14
15 func ExampleRemoveFunc() {
16 input := []byte(`tschüß; до свидания`)
17
18 b := make([]byte, len(input))
19
20 t := transform.RemoveFunc(unicode.IsSpace)
21 n, _, _ := t.Transform(b, input, true)
22 fmt.Println(string(b[:n]))
23
24 t = transform.RemoveFunc(func(r rune) bool {
25 return !unicode.Is(unicode.Latin, r)
26 })
27 n, _, _ = t.Transform(b, input, true)
28 fmt.Println(string(b[:n]))
29
30 n, _, _ = t.Transform(b, norm.NFD.Bytes(input), true)
31 fmt.Println(string(b[:n]))
32
33
34
35
36
37 }
38
View as plain text