| 1 |
// Copyright 2015 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 width_test |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
|
| 10 |
"golang.org/x/text/width" |
| 11 |
) |
| 12 |
|
| 13 |
func ExampleTransformer_fold() { |
| 14 |
s := "abヲ₩○¥A" |
| 15 |
f := width.Fold.String(s) |
| 16 |
fmt.Printf("%U: %s\n", []rune(s), s) |
| 17 |
fmt.Printf("%U: %s\n", []rune(f), f) |
| 18 |
|
| 19 |
// Output: |
| 20 |
// [U+0061 U+0062 U+FF66 U+FFE6 U+FFEE U+FFE5 U+FF21]: abヲ₩○¥A |
| 21 |
// [U+0061 U+0062 U+30F2 U+20A9 U+25CB U+00A5 U+0041]: abヲ₩○¥A |
| 22 |
} |
| 23 |
|
| 24 |
func ExampleTransformer_widen() { |
| 25 |
s := "ab¥ヲ₩○" |
| 26 |
w := width.Widen.String(s) |
| 27 |
fmt.Printf("%U: %s\n", []rune(s), s) |
| 28 |
fmt.Printf("%U: %s\n", []rune(w), w) |
| 29 |
|
| 30 |
// Output: |
| 31 |
// [U+0061 U+0062 U+00A5 U+FF66 U+20A9 U+FFEE]: ab¥ヲ₩○ |
| 32 |
// [U+FF41 U+FF42 U+FFE5 U+30F2 U+FFE6 U+25CB]: ab¥ヲ₩○ |
| 33 |
} |
| 34 |
|
| 35 |
func ExampleTransformer_narrow() { |
| 36 |
s := "abヲ₩○¥A" |
| 37 |
n := width.Narrow.String(s) |
| 38 |
fmt.Printf("%U: %s\n", []rune(s), s) |
| 39 |
fmt.Printf("%U: %s\n", []rune(n), n) |
| 40 |
|
| 41 |
// Ambiguous characters with a halfwidth equivalent get mapped as well. |
| 42 |
s = "←" |
| 43 |
n = width.Narrow.String(s) |
| 44 |
fmt.Printf("%U: %s\n", []rune(s), s) |
| 45 |
fmt.Printf("%U: %s\n", []rune(n), n) |
| 46 |
|
| 47 |
// Output: |
| 48 |
// [U+0061 U+0062 U+30F2 U+FFE6 U+25CB U+FFE5 U+FF21]: abヲ₩○¥A |
| 49 |
// [U+0061 U+0062 U+FF66 U+20A9 U+FFEE U+00A5 U+0041]: abヲ₩○¥A |
| 50 |
// [U+2190]: ← |
| 51 |
// [U+FFE9]: ← |
| 52 |
} |