blob: f2e284dba52b19696bcc0afb7f1cf256a4c4e0d8 [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001// 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
5package transform_test
6
7import (
8 "fmt"
9 "unicode"
10
11 "golang.org/x/text/transform"
12 "golang.org/x/text/unicode/norm"
13)
14
15func 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}