-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
14 changed files
with
349 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "tools/pinyin-data"] | ||
path = tools/pinyin-data | ||
[submodule "_tools/pinyin-data"] | ||
path = _tools/pinyin-data | ||
url = https://github.com/mozillazg/pinyin-data.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Submodule pinyin-data
added at
0b3d00
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
|
||
"github.com/mattn/go-isatty" | ||
"github.com/mozillazg/go-pinyin" | ||
) | ||
|
||
func main() { | ||
heteronym := flag.Bool("e", false, "启用多音字模式") | ||
style := flag.String("s", "zh4ao", "指定拼音风格。可选值:zhao, zh4ao, zha4o, zhao4, zh, z, ao, 4ao, a4o, ao4") | ||
flag.Parse() | ||
hans := flag.Args() | ||
stdin := []byte{} | ||
if !isatty.IsTerminal(os.Stdin.Fd()) { | ||
stdin, _ = ioutil.ReadAll(os.Stdin) | ||
} | ||
if len(stdin) > 0 { | ||
hans = append(hans, string(stdin)) | ||
} | ||
|
||
if len(hans) == 0 { | ||
fmt.Fprintln(os.Stderr, "请至少输入一个汉字: pinyin [-e] [-s STYLE] HANS [HANS ...]") | ||
os.Exit(1) | ||
} | ||
|
||
args := pinyin.NewArgs() | ||
if *heteronym { | ||
args.Heteronym = true | ||
} | ||
|
||
styleValues := map[string]int{ | ||
"zhao": pinyin.Normal, | ||
"zh4ao": pinyin.Tone, | ||
"zha4o": pinyin.Tone2, | ||
"zhao4": pinyin.Tone3, | ||
"zh": pinyin.Initials, | ||
"z": pinyin.FirstLetter, | ||
"ao": pinyin.Finals, | ||
"4ao": pinyin.FinalsTone, | ||
"a4o": pinyin.FinalsTone2, | ||
"ao4": pinyin.FinalsTone3, | ||
} | ||
if value, ok := styleValues[*style]; !ok { | ||
fmt.Fprintf(os.Stderr, "无效的拼音风格:%s\n", *style) | ||
os.Exit(1) | ||
} else { | ||
args.Style = value | ||
} | ||
|
||
pys := pinyin.Pinyin(strings.Join(hans, ""), args) | ||
for _, s := range pys { | ||
fmt.Print(strings.Join(s, ","), " ") | ||
} | ||
if len(pys) > 0 { | ||
fmt.Println() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.