11use ib_pinyin:: { matcher:: PinyinMatcher , pinyin:: PinyinNotation } ;
2+ use std:: env;
23use std:: io:: { BufRead , BufReader } ;
34
5+ fn parse_pinyin_notation_env ( ) -> PinyinNotation {
6+ let env_val = env:: var ( "PINYIN_COMP_MODE" ) . unwrap_or_default ( ) ;
7+ let mut notation = PinyinNotation :: empty ( ) ;
8+ let mut shuangpin = Option :: < PinyinNotation > :: None ;
9+
10+ for mode in env_val. split ( ',' ) {
11+ let mode = mode. trim ( ) ;
12+ match mode {
13+ "Quanpin" => {
14+ notation |= PinyinNotation :: Ascii ;
15+ }
16+ "ShuangpinAbc" => {
17+ shuangpin. get_or_insert ( PinyinNotation :: DiletterAbc ) ;
18+ }
19+ "ShuangpinJiajia" => {
20+ shuangpin. get_or_insert ( PinyinNotation :: DiletterJiajia ) ;
21+ }
22+ "ShuangpinMicrosoft" => {
23+ shuangpin. get_or_insert ( PinyinNotation :: DiletterMicrosoft ) ;
24+ }
25+ "ShuangpinThunisoft" => {
26+ shuangpin. get_or_insert ( PinyinNotation :: DiletterThunisoft ) ;
27+ }
28+ "ShuangpinXiaohe" => {
29+ shuangpin. get_or_insert ( PinyinNotation :: DiletterXiaohe ) ;
30+ }
31+ "ShuangpinZrm" => {
32+ shuangpin. get_or_insert ( PinyinNotation :: DiletterZrm ) ;
33+ }
34+ _ => { }
35+ }
36+ }
37+
38+ notation |= shuangpin. unwrap_or ( PinyinNotation :: empty ( ) ) ;
39+
40+ if notation. is_empty ( ) {
41+ notation = PinyinNotation :: Ascii ;
42+ }
43+
44+ if notation == PinyinNotation :: Ascii {
45+ notation |= PinyinNotation :: AsciiFirstLetter ;
46+ }
47+
48+ notation
49+ }
50+
451fn main ( ) {
552 let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
653 // Print usage
@@ -12,8 +59,9 @@ fn main() {
1259
1360 let input: & str = & args[ 1 ] ;
1461 if han_re. is_match ( input) { return } ;
62+ let notation = parse_pinyin_notation_env ( ) ;
1563 let matcher = PinyinMatcher :: builder ( input)
16- . pinyin_notations ( PinyinNotation :: Ascii | PinyinNotation :: AsciiFirstLetter )
64+ . pinyin_notations ( notation )
1765 . build ( ) ;
1866
1967 let stdin = std:: io:: stdin ( ) ;
0 commit comments