-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
example_test.go
137 lines (120 loc) · 2.92 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package pinyin_test
import (
"fmt"
"github.com/mozillazg/go-pinyin"
)
func ExampleConvert() {
hans := "中国人"
fmt.Println("default:", pinyin.Convert(hans, nil))
// Output: default: [[zhong] [guo] [ren]]
}
func ExamplePinyin_default() {
hans := "中国人"
a := pinyin.NewArgs()
fmt.Println("default:", pinyin.Pinyin(hans, a))
// Output: default: [[zhong] [guo] [ren]]
}
func ExamplePinyin_normal() {
hans := "中国人"
a := pinyin.NewArgs()
a.Style = pinyin.Normal
fmt.Println("Normal:", pinyin.Pinyin(hans, a))
// Output: Normal: [[zhong] [guo] [ren]]
}
func ExamplePinyin_tone() {
hans := "中国人"
a := pinyin.NewArgs()
a.Style = pinyin.Tone
fmt.Println("Tone:", pinyin.Pinyin(hans, a))
// Output: Tone: [[zhōng] [guó] [rén]]
}
func ExamplePinyin_tone2() {
hans := "中国人"
a := pinyin.NewArgs()
a.Style = pinyin.Tone2
fmt.Println("Tone2:", pinyin.Pinyin(hans, a))
// Output: Tone2: [[zho1ng] [guo2] [re2n]]
}
func ExamplePinyin_initials() {
hans := "中国人"
a := pinyin.NewArgs()
a.Style = pinyin.Initials
fmt.Println("Initials:", pinyin.Pinyin(hans, a))
// Output: Initials: [[zh] [g] [r]]
}
func ExamplePinyin_firstLetter() {
hans := "中国人"
a := pinyin.NewArgs()
a.Style = pinyin.FirstLetter
fmt.Println(pinyin.Pinyin(hans, a))
// Output: [[z] [g] [r]]
}
func ExamplePinyin_finals() {
hans := "中国人"
a := pinyin.NewArgs()
a.Style = pinyin.Finals
fmt.Println(pinyin.Pinyin(hans, a))
// Output: [[ong] [uo] [en]]
}
func ExamplePinyin_finalsTone() {
hans := "中国人"
a := pinyin.NewArgs()
a.Style = pinyin.FinalsTone
fmt.Println(pinyin.Pinyin(hans, a))
// Output: [[ōng] [uó] [én]]
}
func ExamplePinyin_finalsTone2() {
hans := "中国人"
a := pinyin.NewArgs()
a.Style = pinyin.FinalsTone2
fmt.Println(pinyin.Pinyin(hans, a))
// Output: [[o1ng] [uo2] [e2n]]
}
func ExamplePinyin_heteronym() {
hans := "中国人"
a := pinyin.NewArgs()
a.Heteronym = true
a.Style = pinyin.Tone2
fmt.Println(pinyin.Pinyin(hans, a))
// Output: [[zho1ng zho4ng] [guo2] [re2n]]
}
func ExamplePinyin_fallbackCustom1() {
hans := "中国人abc"
a := pinyin.NewArgs()
a.Fallback = func(r rune, a pinyin.Args) []string {
return []string{string(r)}
}
fmt.Println(pinyin.Pinyin(hans, a))
// Output: [[zhong] [guo] [ren] [a] [b] [c]]
}
func ExamplePinyin_fallbackCustom2() {
hans := "中国人アイウ"
a := pinyin.NewArgs()
a.Fallback = func(r rune, a pinyin.Args) []string {
data := map[rune][]string{
'ア': {"a"},
'イ': {"i"},
'ウ': {"u"},
}
s, ok := data[r]
if ok {
return s
} else {
return []string{}
}
}
fmt.Println(pinyin.Pinyin(hans, a))
// Output: [[zhong] [guo] [ren] [a] [i] [u]]
}
func ExampleLazyPinyin() {
hans := "中国人"
a := pinyin.NewArgs()
fmt.Println(pinyin.LazyPinyin(hans, a))
// Output: [zhong guo ren]
}
func ExampleSlug() {
hans := "中国人"
a := pinyin.NewArgs()
fmt.Println(pinyin.Slug(hans, a))
// Output: zhong-guo-ren
}