OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / text / transform / examples_test.go
1 // Copyright 2013 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.
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         // Output:
34         // tschüß;досвидания
35         // tschüß
36         // tschuß
37 }