1
0
Fork 0
mirror of https://github.com/Luzifer/ansible-role-version.git synced 2024-12-23 11:01:20 +00:00
ansible-role-version/vendor/golang.org/x/text/runes/example_test.go
Knut Ahlers 209b813c5b
Update dependencies
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-03-19 18:16:10 +01:00

60 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runes_test
import (
"fmt"
"unicode"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"golang.org/x/text/width"
)
func ExampleRemove() {
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
s, _, _ := transform.String(t, "résumé")
fmt.Println(s)
// Output:
// resume
}
func ExampleMap() {
replaceHyphens := runes.Map(func(r rune) rune {
if unicode.Is(unicode.Hyphen, r) {
return '|'
}
return r
})
s, _, _ := transform.String(replaceHyphens, "a-bc⸗d﹣e")
fmt.Println(s)
// Output:
// a|b|c|d|e
}
func ExampleIn() {
// Convert Latin characters to their canonical form, while keeping other
// width distinctions.
t := runes.If(runes.In(unicode.Latin), width.Fold, nil)
s, _, _ := transform.String(t, "アルアノリウ tech / アルアノリウ ")
fmt.Println(s)
// Output:
// アルアノリウ tech / アルアノリウ tech
}
func ExampleIf() {
// Widen everything but ASCII.
isASCII := func(r rune) bool { return r <= unicode.MaxASCII }
t := runes.If(runes.Predicate(isASCII), nil, width.Widen)
s, _, _ := transform.String(t, "アルアノリウ tech / 中國 / 5₩")
fmt.Println(s)
// Output:
// アルアノリウ tech / 中國 / 5₩
}