Skip to content

Commit e1b7587

Browse files
committed
Auto merge of #15 - mozillazg:develop, r=mozillazg
v0.9.0
2 parents fa0d319 + 0354817 commit e1b7587

File tree

6 files changed

+82
-1
lines changed

6 files changed

+82
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go:
55
- 1.4
66
- 1.5
77
- 1.6
8+
- 1.7
89
- tip
910

1011
sudo: false

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Changelog
22

33

4+
## 0.9.0 (2016-09-04):
5+
6+
* **NEW** 新增 `func Convert(s string, a *Args) [][]string`
7+
* **NEW** 新增 `func LazyConvert(s string, a *Args) []string`
8+
9+
之所以增加这两个函数是希望 `a` 参数支持 `nil`
10+
11+
12+
413
## 0.8.0 (2016-08-19)
514

615
* **Changed** use [pinyin-data](https://github.com/mozillazg/pinyin-data) v0.3.0

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545

4646
func main() {
4747
hans := "中国人"
48+
4849
// 默认
4950
a := pinyin.NewArgs()
5051
fmt.Println(pinyin.Pinyin(hans, a))
@@ -68,6 +69,15 @@ func main() {
6869
a.Style = pinyin.Tone2
6970
fmt.Println(pinyin.Pinyin(hans, a))
7071
// [[zho1ng zho4ng] [guo2] [re2n]]
72+
73+
fmt.Println(pinyin.LazyPinyin(hans, pinyin.NewArgs()))
74+
// [zhong guo ren]
75+
76+
fmt.Println(pinyin.Convert(hans, nil))
77+
// [[zhong] [guo] [ren]]
78+
79+
fmt.Println(pinyin.LazyConvert(hans, nil))
80+
// [zhong guo ren]
7181
}
7282
```
7383

@@ -78,3 +88,9 @@ Related Projects
7888
* [hotoo/pinyin](https://github.com/hotoo/pinyin): 汉语拼音转换工具 Node.js/JavaScript 版。
7989
* [mozillazg/python-pinyin](https://github.com/mozillazg/python-pinyin): 汉语拼音转换工具 Python 版。
8090
* [mozillazg/rust-pinyin](https://github.com/mozillazg/rust-pinyin): 汉语拼音转换工具 Rust 版。
91+
92+
93+
License
94+
---------
95+
96+
Under the MIT License.

example_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import (
66
"github.com/mozillazg/go-pinyin"
77
)
88

9+
func ExampleConvert() {
10+
hans := "中国人"
11+
fmt.Println("default:", pinyin.Convert(hans, nil))
12+
// Output: default: [[zhong] [guo] [ren]]
13+
}
14+
915
func ExamplePinyin_default() {
1016
hans := "中国人"
1117
a := pinyin.NewArgs()

pinyin.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
// Meta
99
const (
10-
Version = "0.8.0"
10+
Version = "0.9.0"
1111
Author = "mozillazg, 闲耘"
1212
License = "MIT"
1313
Copyright = "Copyright (c) 2016 mozillazg, 闲耘"
@@ -240,7 +240,26 @@ func LazyPinyin(s string, a Args) []string {
240240
}
241241

242242
// Slug join `LazyPinyin` 的返回值.
243+
// 建议改用 https://github.com/mozillazg/go-slugify
243244
func Slug(s string, a Args) string {
244245
separator := a.Separator
245246
return strings.Join(LazyPinyin(s, a), separator)
246247
}
248+
249+
// Convert 跟 Pinyin 的唯一区别就是 a 参数可以是 nil
250+
func Convert(s string, a *Args) [][]string {
251+
if a == nil {
252+
args := NewArgs()
253+
a = &args
254+
}
255+
return Pinyin(s, *a)
256+
}
257+
258+
// LazyConvert 跟 LazyPinyin 的唯一区别就是 a 参数可以是 nil
259+
func LazyConvert(s string, a *Args) []string {
260+
if a == nil {
261+
args := NewArgs()
262+
a = &args
263+
}
264+
return LazyPinyin(s, *a)
265+
}

pinyin_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,33 @@ func TestUpdated(t *testing.T) {
322322
}
323323
testPinyinUpdate(t, testData, Pinyin)
324324
}
325+
326+
func TestConvert(t *testing.T) {
327+
s := "中国人"
328+
v := Convert(s, nil)
329+
value := [][]string{{"zhong"}, {"guo"}, {"ren"}}
330+
if !reflect.DeepEqual(v, value) {
331+
t.Errorf("Expected %s, got %s", value, v)
332+
}
333+
334+
a := NewArgs()
335+
v = Convert(s, &a)
336+
if !reflect.DeepEqual(v, value) {
337+
t.Errorf("Expected %s, got %s", value, v)
338+
}
339+
}
340+
341+
func TestLazyConvert(t *testing.T) {
342+
s := "中国人"
343+
v := LazyConvert(s, nil)
344+
value := []string{"zhong", "guo", "ren"}
345+
if !reflect.DeepEqual(v, value) {
346+
t.Errorf("Expected %s, got %s", value, v)
347+
}
348+
349+
a := NewArgs()
350+
v = LazyConvert(s, &a)
351+
if !reflect.DeepEqual(v, value) {
352+
t.Errorf("Expected %s, got %s", value, v)
353+
}
354+
}

0 commit comments

Comments
 (0)