Marcel van Lohuizen | 191b11a | 2013-11-26 08:29:24 +0100 | [diff] [blame] | 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 | |
Andrew Gerrand | d541d34 | 2014-11-10 08:48:25 +1100 | [diff] [blame] | 11 | "golang.org/x/text/transform" |
| 12 | "golang.org/x/text/unicode/norm" |
Marcel van Lohuizen | 191b11a | 2013-11-26 08:29:24 +0100 | [diff] [blame] | 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 | } |