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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
#![warn(missing_docs)]
extern crate phf;
use std::str;
use std::string::String;
use std::vec::Vec;
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
static PINYIN_TONES: [[char; 5]; 6] =
[['a', 'ā', 'á', 'ǎ', 'à'],
['o', 'ō', 'ó', 'ǒ', 'ò'],
['e', 'ē', 'é', 'ě', 'è'],
['i', 'ī', 'í', 'ǐ', 'ì'],
['u', 'ū', 'ú', 'ǔ', 'ù'],
['ü', 'ǖ', 'ǘ', 'ǚ', 'ǜ']];
static ZHUYIN_TONES: [&str; 5] =
["˙", "", "ˊ", "ˇ", "ˋ"];
fn get_tonal_mark<C>(c: C, tone: u8) -> char
where C: Into<char>
{
let mut c = c.into();
if c == 'v' {
c = 'ü';
}
for t in PINYIN_TONES.iter() {
if c == t[0] {
return t[tone as usize]
}
}
unreachable!();
}
fn tone_rhyme(s: &[u8], tone: u8) -> String {
let mut ret = String::with_capacity(3);
if s.len() == 1 {
ret.push(get_tonal_mark(s[0], tone));
return ret
}
let (c1, c2) = (s[0], s[1]);
if c1 == b'a' || ((c1 == b'o' || c1 == b'e') && c2 != b'a') || !is_rhyme(c2) {
ret.push(get_tonal_mark(c1, tone));
ret.push_str(unsafe { str::from_utf8_unchecked(&s[1..]) });
return ret
}
ret.push(c1 as char);
ret.push(get_tonal_mark(c2, tone));
ret.push_str(unsafe { str::from_utf8_unchecked(&s[2..]) });
return ret
}
fn is_rhyme(c: u8) -> bool {
return c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u' || c == b'v'
}
fn is_consonant(c: u8) -> bool {
return c >= b'a' && c <= b'z' && !is_rhyme(c)
}
fn decode_rhyme(s: &str) -> Option<(String, u8)> {
let mut rhyme = String::with_capacity(4);
let mut tone = 0;
for mut c in s.chars() {
for t in PINYIN_TONES.iter() {
for i in 1..t.len() {
if c == t[i] {
c = t[0];
if tone != 0 {
return None
}
tone = i as u8;
}
}
}
if c == 'ü' {
c = 'v';
}
rhyme.push(c);
}
if tone == 0 {
tone = 5;
}
Some((rhyme, tone))
}
pub fn split(s: &str) -> Option<(&str, &str, u8)> {
if s == "r5" {
return Some(("", "r", 5))
}
_split(s)
}
fn _split(s: &str) -> Option<(&str, &str, u8)> {
let s = s.as_bytes();
let mut pos = 0;
for &b in s.iter() {
if !is_consonant(b) {
break
}
pos += 1;
}
let consonant = unsafe { str::from_utf8_unchecked(&s[0..pos]) };
for &b in s.iter().skip(pos) {
if b < b'a' || b > b'z' {
break;
}
pos += 1;
}
let rhyme = unsafe { str::from_utf8_unchecked(&s[consonant.len()..pos]) };
if rhyme.len() == 0 || s.len() - pos > 2 {
return None
}
let tone;
if pos < s.len() {
tone = s[pos] - b'0';
if tone > 5 || tone < 1 {
return None
}
} else {
return None
}
Some((consonant, rhyme, tone))
}
pub fn encode_pinyin<S>(s: S) -> Option<String>
where S: AsRef<str>
{
let s = s.as_ref();
if s == "e5" {
return Some("ê".to_owned())
} else if s == "r" || s == "r5" {
return Some("r".to_owned())
}
let (consonant, rhyme, tone) = _split(s)?;
encode_pinyin_from_parts(consonant, rhyme, tone)
}
fn encode_pinyin_from_parts(consonant: &str, rhyme: &str, tone: u8) -> Option<String> {
let consonant = consonant.as_bytes();
let mut rhyme = rhyme.as_bytes().to_vec();
if consonant.len() > 0 {
if MAP_P2Z.get(unsafe { str::from_utf8_unchecked(consonant) }) == None {
return None
}
if rhyme[0] == b'v' {
let c = consonant[0];
if c == b'j' || c == b'q' || c == b'x' || c == b'y' {
rhyme[0] = b'u';
}
}
}
if MAP_P2Z.get(unsafe { str::from_utf8_unchecked(&rhyme) }) == None {
return None
}
let mut tone = tone;
if tone == 5 {
tone = 0;
}
let mut rhyme: String = tone_rhyme(&rhyme, tone);
if rhyme.as_bytes()[0] == b'v' {
rhyme = "ü".to_owned() + &rhyme[1..];
}
return Some(unsafe { str::from_utf8_unchecked(&consonant).to_owned() } + &rhyme)
}
pub fn decode_pinyin<S>(s: S) -> Option<String>
where S: AsRef<str>
{
let s = s.as_ref();
if s == "ê" {
return Some("e5".to_owned())
} else if s == "r" {
return Some("r5".to_owned())
}
let (consonant, rhyme, tone) = decode_pinyin_to_parts(s)?;
let mut ret = Vec::with_capacity(7);
ret.extend_from_slice(&consonant.as_bytes());
ret.extend_from_slice(&rhyme.as_bytes());
ret.push(tone + b'0');
Some(unsafe { String::from_utf8_unchecked(ret) })
}
fn decode_pinyin_to_parts(s: &str) -> Option<(&str, String, u8)> {
let s = s.as_bytes();
let mut consonant: &[u8] = &[];
let mut rhyme: &[u8] = &[];
for (i, &b) in s.iter().enumerate() {
if !is_consonant(b) {
consonant = &s[..i];
rhyme = &s[i..];
break;
}
}
if consonant.len() > 0 {
if MAP_P2Z.get(unsafe { str::from_utf8_unchecked(consonant) }) == None {
return None
}
}
let (mut untoned_rhyme, tone) = decode_rhyme(unsafe { str::from_utf8_unchecked(rhyme) })?;
{
let rhyme_bytes = unsafe { untoned_rhyme.as_bytes_mut() };
if consonant.len() > 0 && rhyme_bytes[0] == b'u' {
let c = consonant[0];
if c == b'j' || c == b'q' || c == b'x' || c == b'y' {
rhyme_bytes[0] = b'v';
}
}
}
if MAP_P2Z.get(&*untoned_rhyme) == None {
return None
}
let consonant = unsafe { str::from_utf8_unchecked(consonant) };
Some((consonant, untoned_rhyme, tone))
}
pub fn encode_zhuyin<S>(s: S) -> Option<String>
where S: AsRef<str>
{
let s = s.as_ref();
if s == "e5" {
return Some("ㄝ".to_owned())
} else if s == "r5" {
return Some("ㄦ˙".to_owned())
}
let (consonant, rhyme, mut tone) = _split(s)?;
if tone == 5 {
tone = 0;
}
encode_zhuyin_from_parts(consonant, rhyme, tone)
}
fn encode_zhuyin_from_parts(consonant: &str, rhyme: &str, tone: u8) -> Option<String> {
let mut ret_vec = Vec::with_capacity(11);
ret_vec.extend_from_slice(consonant.as_bytes());
let mut consonant = ret_vec;
let mut rhyme = rhyme.as_bytes().to_vec();
if rhyme[0] == b'u' && consonant.len() > 0 {
let c = consonant[0];
if c == b'j' || c == b'q' || c == b'x' || c == b'y' {
rhyme[0] = b'v';
}
}
if rhyme == b"i" {
if consonant == b"zh" || consonant == b"ch" || consonant == b"sh" ||
consonant == b"r" || consonant == b"z" || consonant == b"c" ||
consonant == b"s" || consonant == b"y" {
rhyme.clear();
}
} else if consonant == b"w" {
if rhyme == b"u" {
consonant.clear();
}
} else if consonant == b"y" {
if rhyme == b"v" || rhyme == b"e" || rhyme == b"ve" || rhyme == b"in" ||
rhyme == b"van" || rhyme == b"ing" || rhyme == b"vn" {
consonant.clear();
}
}
if consonant.len() > 0 {
if let Some(zhuyin) = MAP_P2Z.get(unsafe { str::from_utf8_unchecked(&consonant) }) {
consonant.clear();
consonant.extend_from_slice(zhuyin.as_bytes());
} else {
return None
}
}
if rhyme.len() > 0 {
if let Some(zhuyin) = MAP_P2Z.get(unsafe { str::from_utf8_unchecked(&rhyme) }) {
rhyme.clear();
rhyme.extend_from_slice(zhuyin.as_bytes());
} else {
return None
}
}
consonant.extend_from_slice(&rhyme);
let mut ret = unsafe { String::from_utf8_unchecked(consonant) };
ret.push_str(ZHUYIN_TONES[tone as usize]);
Some(ret)
}
pub fn decode_zhuyin<S>(s: S) -> Option<String>
where S: AsRef<str>
{
let s = s.as_ref();
if s == "ㄝ" {
return Some("e5".to_owned())
} else if s == "ㄦ˙" {
return Some("r5".to_owned())
}
let (consonant, rhyme, tone) = decode_zhuyin_to_parts(s)?;
if rhyme.len() == 0 {
return None
}
let mut ret = Vec::with_capacity(7);
ret.extend_from_slice(&consonant.as_bytes());
ret.extend_from_slice(&rhyme.as_bytes());
ret.push(tone + b'0');
Some(unsafe { String::from_utf8_unchecked(ret) })
}
fn decode_zhuyin_to_parts(s: &str) -> Option<(String, String, u8)> {
let mut consonant = Vec::with_capacity(2);
let mut rhyme = Vec::with_capacity(4);
let mut tone: u8 = 1;
let mut useless_char_buf = [0; 4];
'split_input: for (i, c) in s.char_indices() {
let c = c.encode_utf8(&mut useless_char_buf);
if let Some(decoded) = MAP_Z2P.get(c) {
let decoded = decoded.as_bytes();
match i == 0 && is_consonant(decoded[0]) {
true => consonant.extend_from_slice(decoded),
false => rhyme.extend_from_slice(c.as_bytes()),
}
continue
}
let tone_slice = &s[i..];
for (j, t) in ZHUYIN_TONES.into_iter().enumerate() {
if &tone_slice == t {
if j == 0 {
tone = 5;
} else {
tone = j as u8;
}
break 'split_input;
}
}
return None
}
if rhyme.len() == 0 {
match consonant.as_slice() {
b"zh" | b"ch" | b"sh" | b"r" |
b"z" | b"c" | b"s" => {
rhyme.push(b'i');
return Some(unsafe {
(String::from_utf8_unchecked(consonant),
String::from_utf8_unchecked(rhyme),
tone)
})
},
_ => return None
}
}
match MAP_Z2P.get(unsafe { str::from_utf8_unchecked(&rhyme) }) {
Some(decoded) if is_rhyme(decoded.as_bytes()[0]) => {
rhyme.clear();
rhyme.extend_from_slice(decoded.as_bytes());
},
_ => return None,
};
if consonant.len() == 0 {
if rhyme == b"i" || rhyme == b"v" || rhyme == b"e" ||
rhyme == b"ve" || rhyme == b"in" || rhyme == b"van" ||
rhyme == b"ing" || rhyme == b"vn" {
consonant.clear();
consonant.push(b'y');
} else if rhyme == b"u" {
consonant.clear();
consonant.push(b'w');
} else if rhyme[0] == b'u' {
consonant.clear();
consonant.push(b'w');
rhyme.drain(0..1);
} else if rhyme[0] == b'i' {
consonant.clear();
consonant.push(b'y');
rhyme.drain(0..1);
} else if rhyme == b"ong" {
consonant.clear();
consonant.push(b'w');
rhyme.clear();
rhyme.extend_from_slice(b"eng");
}
}
Some(unsafe {
(String::from_utf8_unchecked(consonant),
String::from_utf8_unchecked(rhyme),
tone)
})
}
pub fn pinyin_to_zhuyin<S>(s: S) -> Option<String>
where S: AsRef<str>
{
let s = s.as_ref();
if s == "ê" {
return Some("ㄝ".to_owned())
}
encode_zhuyin(decode_pinyin(s)?)
}
pub fn zhuyin_to_pinyin<S>(s: S) -> Option<String>
where S: AsRef<str>
{
let s = s.as_ref();
if s == "ㄝ" {
return Some("ê".to_owned())
}
encode_pinyin(decode_zhuyin(s)?)
}
mod tests {
#[allow(unused_imports)]
use super::*;
#[allow(unused_macros)]
macro_rules! s(
($i:expr) => (Some($i.to_owned()));
);
#[test]
fn encode_pinyin_test() {
assert_eq!(encode_pinyin("e5"), s!("ê"));
assert_eq!(encode_pinyin("ju3"), s!("jǔ"));
assert_eq!(encode_pinyin("jv3"), s!("jǔ"));
assert_eq!(encode_pinyin("lvan4"), s!("lüàn"));
assert_eq!(encode_pinyin("zhuan4"), s!("zhuàn"));
assert_eq!(encode_pinyin("zhao2"), s!("zháo"));
assert_eq!(encode_pinyin("leng1"), s!("lēng"));
assert_eq!(encode_pinyin("shui3"), s!("shuǐ"));
assert_eq!(encode_pinyin("liu2"), s!("liú"));
assert_eq!(encode_pinyin("an3"), s!("ǎn"));
assert_eq!(encode_pinyin("yi2"), s!("yí"));
assert_eq!(encode_pinyin("yuan2"), s!("yuán"));
assert_eq!(encode_pinyin("yvan2"), s!("yuán"));
assert_eq!(encode_pinyin("min2"), s!("mín"));
assert_eq!(encode_pinyin("er2"), s!("ér"));
assert_eq!(encode_pinyin("r5"), s!("r"));
assert_eq!(encode_pinyin("a"), None);
assert_eq!(encode_pinyin("a0"), None);
assert_eq!(encode_pinyin("zh3"), None);
assert_eq!(encode_pinyin("zhaang4"), None);
assert_eq!(encode_pinyin("啊"), None);
assert_eq!(encode_pinyin("a5啊"), None);
assert_eq!(encode_pinyin("啊a5"), None);
assert_eq!(encode_pinyin(""), None);
}
#[test]
fn encode_zhuyin_test() {
assert_eq!(encode_zhuyin("e5"), s!("ㄝ"));
assert_eq!(encode_zhuyin("ju3"), s!("ㄐㄩˇ"));
assert_eq!(encode_zhuyin("jv3"), s!("ㄐㄩˇ"));
assert_eq!(encode_zhuyin("lvan4"), s!("ㄌㄩㄢˋ"));
assert_eq!(encode_zhuyin("zhuan4"), s!("ㄓㄨㄢˋ"));
assert_eq!(encode_zhuyin("zhao2"), s!("ㄓㄠˊ"));
assert_eq!(encode_zhuyin("leng1"), s!("ㄌㄥ"));
assert_eq!(encode_zhuyin("shui3"), s!("ㄕㄨㄟˇ"));
assert_eq!(encode_zhuyin("liu2"), s!("ㄌㄧㄡˊ"));
assert_eq!(encode_zhuyin("an3"), s!("ㄢˇ"));
assert_eq!(encode_zhuyin("yi2"), s!("ㄧˊ"));
assert_eq!(encode_zhuyin("yuan2"), s!("ㄩㄢˊ"));
assert_eq!(encode_zhuyin("yvan2"), s!("ㄩㄢˊ"));
assert_eq!(encode_zhuyin("min2"), s!("ㄇㄧㄣˊ"));
assert_eq!(encode_zhuyin("er2"), s!("ㄦˊ"));
assert_eq!(encode_zhuyin("r5"), s!("ㄦ˙"));
assert_eq!(encode_zhuyin("yu1"), s!("ㄩ"));
assert_eq!(encode_zhuyin("wu2"), s!("ㄨˊ"));
assert_eq!(encode_zhuyin("yve3"), s!("ㄩㄝˇ"));
assert_eq!(encode_zhuyin("yue4"), s!("ㄩㄝˋ"));
assert_eq!(encode_zhuyin("zhi4"), s!("ㄓˋ"));
assert_eq!(encode_zhuyin("a"), None);
assert_eq!(encode_zhuyin("a0"), None);
assert_eq!(encode_zhuyin("zh3"), None);
assert_eq!(encode_zhuyin("zhaang4"), None);
assert_eq!(encode_zhuyin("啊"), None);
assert_eq!(encode_zhuyin("a5啊"), None);
assert_eq!(encode_zhuyin("啊a5"), None);
assert_eq!(encode_zhuyin(""), None);
}
#[test]
fn decode_pinyin_test() {
assert_eq!(decode_pinyin("ê"), s!("e5"));
assert_eq!(decode_pinyin("ju"), s!("jv5"));
assert_eq!(decode_pinyin("lǚ"), s!("lv3"));
assert_eq!(decode_pinyin("lüàn"), s!("lvan4"));
assert_eq!(decode_pinyin("zhuàn"), s!("zhuan4"));
assert_eq!(decode_pinyin("zháo"), s!("zhao2"));
assert_eq!(decode_pinyin("lēng"), s!("leng1"));
assert_eq!(decode_pinyin("shuǐ"), s!("shui3"));
assert_eq!(decode_pinyin("liú"), s!("liu2"));
assert_eq!(decode_pinyin("ǎn"), s!("an3"));
assert_eq!(decode_pinyin("yí"), s!("yi2"));
assert_eq!(decode_pinyin("yuán"), s!("yvan2"));
assert_eq!(decode_pinyin("mín"), s!("min2"));
assert_eq!(decode_pinyin("ér"), s!("er2"));
assert_eq!(decode_pinyin("r"), s!("r5"));
assert_eq!(decode_pinyin("a5"), None);
assert_eq!(decode_pinyin("zhāāng"), None);
assert_eq!(decode_pinyin("啊"), None);
assert_eq!(decode_pinyin("a啊"), None);
assert_eq!(decode_pinyin("啊a"), None);
assert_eq!(decode_pinyin(""), None);
}
#[test]
fn decode_zhuyin_test() {
assert_eq!(decode_zhuyin("ㄝ"), s!("e5"));
assert_eq!(decode_zhuyin("ㄐㄩ˙"), s!("jv5"));
assert_eq!(decode_zhuyin("ㄌㄩˇ"), s!("lv3"));
assert_eq!(decode_zhuyin("ㄌㄩㄢˋ"), s!("lvan4"));
assert_eq!(decode_zhuyin("ㄓㄨㄢˋ"), s!("zhuan4"));
assert_eq!(decode_zhuyin("ㄓㄠˊ"), s!("zhao2"));
assert_eq!(decode_zhuyin("ㄓˋ"), s!("zhi4"));
assert_eq!(decode_zhuyin("ㄌㄥ"), s!("leng1"));
assert_eq!(decode_zhuyin("ㄕㄨㄟˇ"), s!("shui3"));
assert_eq!(decode_zhuyin("ㄌㄧㄡˊ"), s!("liu2"));
assert_eq!(decode_zhuyin("ㄢˇ"), s!("an3"));
assert_eq!(decode_zhuyin("ㄩ"), s!("yv1"));
assert_eq!(decode_zhuyin("ㄨˊ"), s!("wu2"));
assert_eq!(decode_zhuyin("ㄩㄝˇ"), s!("yve3"));
assert_eq!(decode_zhuyin("ㄩㄝˋ"), s!("yve4"));
assert_eq!(decode_zhuyin("ㄧˊ"), s!("yi2"));
assert_eq!(decode_zhuyin("ㄩㄢˊ"), s!("yvan2"));
assert_eq!(decode_zhuyin("ㄇㄧㄣˊ"), s!("min2"));
assert_eq!(decode_zhuyin("ㄦˊ"), s!("er2"));
assert_eq!(decode_zhuyin("ㄦ˙"), s!("r5"));
assert_eq!(decode_zhuyin("ㄨㄥˊ"), s!("weng2"));
assert_eq!(decode_zhuyin("a5"), None);
assert_eq!(decode_zhuyin("ㄩㄝㄝ"), None);
assert_eq!(decode_zhuyin("ㄐˇ"), None);
assert_eq!(decode_zhuyin("ㄨㄕ"), None);
assert_eq!(decode_zhuyin("ㄕㄨㄕㄨ"), None);
assert_eq!(decode_zhuyin("啊"), None);
assert_eq!(decode_zhuyin("ㄚ啊"), None);
assert_eq!(decode_zhuyin("啊ㄚ"), None);
assert_eq!(decode_zhuyin(""), None);
}
#[test]
fn pinyin_to_zhuyin_test() {
assert_eq!(pinyin_to_zhuyin("mín"), s!("ㄇㄧㄣˊ"));
assert_eq!(pinyin_to_zhuyin("zhāng"), s!("ㄓㄤ"));
assert_eq!(pinyin_to_zhuyin("wéng"), s!("ㄨㄥˊ"));
assert_eq!(pinyin_to_zhuyin("ér"), s!("ㄦˊ"));
assert_eq!(pinyin_to_zhuyin("r"), s!("ㄦ˙"));
assert_eq!(pinyin_to_zhuyin("wengg"), None);
assert_eq!(pinyin_to_zhuyin("啊"), None);
assert_eq!(pinyin_to_zhuyin(""), None);
}
#[test]
fn zhuyin_to_pinyin_test() {
assert_eq!(zhuyin_to_pinyin("ㄇㄧㄣˊ"), s!("mín"));
assert_eq!(zhuyin_to_pinyin("ㄓㄤ"), s!("zhāng"));
assert_eq!(zhuyin_to_pinyin("ㄨㄥˊ"), s!("wéng"));
assert_eq!(zhuyin_to_pinyin("ㄦˊ"), s!("ér"));
assert_eq!(zhuyin_to_pinyin("ㄦ˙"), s!("r"));
assert_eq!(zhuyin_to_pinyin("ㄥㄥ"), None);
assert_eq!(zhuyin_to_pinyin("啊"), None);
assert_eq!(zhuyin_to_pinyin(""), None);
}
}