You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

38 lines
819 B

  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. package transform_test
  5. import (
  6. "fmt"
  7. "unicode"
  8. "golang.org/x/text/transform"
  9. "golang.org/x/text/unicode/norm"
  10. )
  11. func ExampleRemoveFunc() {
  12. input := []byte(`tschüß; до свидания`)
  13. b := make([]byte, len(input))
  14. t := transform.RemoveFunc(unicode.IsSpace)
  15. n, _, _ := t.Transform(b, input, true)
  16. fmt.Println(string(b[:n]))
  17. t = transform.RemoveFunc(func(r rune) bool {
  18. return !unicode.Is(unicode.Latin, r)
  19. })
  20. n, _, _ = t.Transform(b, input, true)
  21. fmt.Println(string(b[:n]))
  22. n, _, _ = t.Transform(b, norm.NFD.Bytes(input), true)
  23. fmt.Println(string(b[:n]))
  24. // Output:
  25. // tschüß;досвидания
  26. // tschüß
  27. // tschuß
  28. }