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
700
701
#![warn(clippy::pedantic, clippy::nursery)]
#![allow(clippy::non_ascii_literal)]

#[cfg(test)]
mod tests;
use unicode_segmentation::UnicodeSegmentation;

#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub enum Strictness {
    Strict,
    StrictAndSeparateApostropheFromCurlyQuote,
    Loose,
}

impl Strictness {
    #[must_use]
    pub fn is_strict(self) -> bool {
        self == Self::Strict || self == Self::StrictAndSeparateApostropheFromCurlyQuote
    }
}

#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
#[allow(clippy::struct_excessive_bools)]
pub struct PinyinParser {
    p_strict: Strictness,
    p_preserve_punctuations: bool,
    p_preserve_spaces: bool,
    p_preserve_miscellaneous: bool,
}

impl Default for PinyinParser {
    fn default() -> Self {
        Self::new()
    }
}

impl PinyinParser {
    #[must_use]
    pub const fn new() -> Self {
        Self {
            p_strict: Strictness::Loose,
            p_preserve_spaces: false,
            p_preserve_punctuations: false,
            p_preserve_miscellaneous: false,
        }
    }

    #[must_use]
    #[deprecated = "Use `with_strictness(Strictness::Strict)` or `with_strictness(Strictness::Loose)`"]
    pub const fn is_strict(self, b: bool) -> Self {
        Self {
            p_strict: if b {
                Strictness::Strict
            } else {
                Strictness::Loose
            },
            ..self
        }
    }

    #[must_use]
    pub const fn with_strictness(self, strictness: Strictness) -> Self {
        Self {
            p_strict: strictness,
            ..self
        }
    }

    #[must_use]
    pub const fn preserve_spaces(self, b: bool) -> Self {
        Self {
            p_preserve_spaces: b,
            ..self
        }
    }

    #[must_use]
    pub const fn preserve_punctuations(self, b: bool) -> Self {
        Self {
            p_preserve_punctuations: b,
            ..self
        }
    }

    /// ```
    /// use pinyin_parser::PinyinParser;
    /// let parser = PinyinParser::new()
    ///     .is_strict(true)
    ///     .preserve_miscellaneous(true);
    /// assert_eq!(
    ///     parser
    ///         .parse("你Nǐ 好hǎo")
    ///         .into_iter()
    ///         .collect::<Vec<_>>(),
    ///     vec!["你", "nǐ", "好", "hǎo"]
    /// )
    /// ```
    #[must_use]
    pub const fn preserve_miscellaneous(self, b: bool) -> Self {
        Self {
            p_preserve_miscellaneous: b,
            ..self
        }
    }

    /// ```
    /// use pinyin_parser::PinyinParser;
    /// let parser = PinyinParser::new()
    ///     .is_strict(true)
    ///     .preserve_punctuations(true)
    ///     .preserve_spaces(true);
    /// assert_eq!(
    ///     parser
    ///         .parse("Nǐ zuò shénme?")
    ///         .into_iter()
    ///         .collect::<Vec<_>>(),
    ///     vec!["nǐ", " ", "zuò", " ", "shén", "me", "?"]
    /// )
    /// ```
    #[must_use]
    pub fn parse(self, s: &str) -> PinyinParserIter {
        PinyinParserIter {
            configs: self,
            it: VecAndIndex {
                vec: UnicodeSegmentation::graphemes(s, true)
                    .map(|c| pinyin_token::to_token(c, self.p_strict))
                    .collect::<Vec<_>>(),
                next_pos: 0,
            },
            state: ParserState::BeforeWordInitial,
        }
    }

    /// Strict mode:
    /// * forbids the use of breve instead of hacek to represent the third tone
    /// * forbids the use of IPA `ɡ` (U+0261) instead of `g`, and other such lookalike characters
    /// * allows apostrophes only before an `a`, an `e` or an `o`
    /// ```
    /// use pinyin_parser::PinyinParser;
    /// assert_eq!(
    ///     PinyinParser::strict("jīntiān")
    ///         .into_iter()
    ///         .collect::<Vec<_>>(),
    ///     vec!["jīn", "tiān"]
    /// );
    /// ```

    /// ```should_panic
    /// use pinyin_parser::PinyinParser;
    /// assert_eq!(
    ///     PinyinParser::strict("zǒnɡshì") // this `ɡ` is not the `g` from ASCII
    ///         .into_iter()
    ///         .collect::<Vec<_>>(),
    ///     vec!["zǒng", "shì"]
    /// );
    /// ```

    /// ```should_panic
    /// use pinyin_parser::PinyinParser;
    /// assert_eq!(
    ///     // An apostrophe can come only before an `a`, an `e` or an `o` in strict mode    
    ///     PinyinParser::strict("Yīng'guó")
    ///         .into_iter()
    ///         .collect::<Vec<_>>(),
    ///     vec!["yīng", "guó"]
    /// );
    /// ```

    /// This parser supports the use of `ẑ`, `ĉ`, `ŝ` and `ŋ`, though I have never seen anyone use it.
    /// ```
    /// use pinyin_parser::PinyinParser;
    /// assert_eq!(
    ///     PinyinParser::strict("Ẑāŋ").into_iter().collect::<Vec<_>>(),
    ///     vec!["zhāng"]
    /// )
    /// ```

    #[must_use]
    pub fn strict(s: &str) -> PinyinParserIter {
        Self::new().with_strictness(Strictness::Strict).parse(s)
    }

    /// ```
    /// use pinyin_parser::PinyinParser;
    /// assert_eq!(
    ///     // 'ă' is LATIN SMALL LETTER A WITH BREVE and is not accepted in strict mode.  
    ///     // The correct alphabet to use is 'ǎ'.  
    ///     PinyinParser::loose("mián'ăo")
    ///         .into_iter()
    ///         .collect::<Vec<_>>(),
    ///     vec!["mián", "ǎo"]
    /// );
    /// ```

    /// ```
    /// use pinyin_parser::PinyinParser;
    /// assert_eq!(
    ///     // An apostrophe can come only before an `a`, an `e` or an `o` in strict mode,
    ///     // but allowed here because it's loose    
    ///     PinyinParser::loose("Yīng'guó")
    ///         .into_iter()
    ///         .collect::<Vec<_>>(),
    ///     vec!["yīng", "guó"]
    /// );
    /// ```
    #[must_use]
    pub fn loose(s: &str) -> PinyinParserIter {
        Self::new().parse(s)
    }
}

mod pinyin_token;

struct VecAndIndex<T> {
    vec: std::vec::Vec<T>,
    next_pos: usize,
}

pub struct PinyinParserIter {
    configs: PinyinParser,
    it: VecAndIndex<pinyin_token::PinyinToken>,
    state: ParserState,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum ParserState {
    BeforeWordInitial,
    InitialParsed(SpellingInitial),
    ZCSParsed(ZCS),
    AfterSyllablePossiblyConsumingApostrophe,
}

impl<T> VecAndIndex<T> {
    fn next(&mut self) -> Option<&T> {
        let ans = self.vec.get(self.next_pos);
        self.next_pos += 1;
        ans
    }

    fn peek(&self, n: usize) -> Option<&T> {
        self.vec.get(self.next_pos + n)
    }

    fn rewind(&mut self, n: usize) {
        assert!(self.next_pos >= n, "too much rewind");
        self.next_pos -= n;
    }

    fn advance(&mut self, n: usize) {
        self.next_pos += n;
    }
}

pub struct PinyinParserIterWithSplitR {
    iter: PinyinParserIter,
    next_is_r: bool,
}

impl Iterator for PinyinParserIterWithSplitR {
    type Item = String;

    fn next(&mut self) -> Option<Self::Item> {
        if self.next_is_r {
            self.next_is_r = false;
            return Some("r".to_owned());
        }

        let ans = self.iter.next()?;

        // r should be split off from ans, unless they are "er", "ēr", "ér", "ěr", or "èr"
        if matches!(&ans[..], "er" | "ēr" | "ér" | "ěr" | "èr") {
            return Some(ans);
        }

        if let Some(rest) = ans.strip_suffix('r') {
            self.next_is_r = true;
            return Some(rest.to_owned());
        }

        Some(ans)
    }
}

impl PinyinParserIter {
    #[must_use]
    pub const fn split_erhua(self) -> PinyinParserIterWithSplitR {
        PinyinParserIterWithSplitR {
            iter: self,
            next_is_r: false,
        }
    }
}

impl Iterator for PinyinParserIter {
    type Item = String;

    #[allow(clippy::too_many_lines)]
    #[allow(clippy::cognitive_complexity)]
    fn next(&mut self) -> Option<Self::Item> {
        use pinyin_token::Alphabet;
        use pinyin_token::PinyinToken::{
            Alph, Apostrophe, LightToneMarker, Others, Punctuation, Space,
        };
        use ParserState::{
            AfterSyllablePossiblyConsumingApostrophe, BeforeWordInitial, InitialParsed, ZCSParsed,
        };
        loop {
            match (self.it.next(), self.state) {
                (
                    b @ Some(LightToneMarker | Punctuation(_) | Apostrophe | Space(_) | Others(_)),
                    a @ (InitialParsed(_) | ZCSParsed(_)),
                ) => panic!("unexpected {b:?} found after parsing initial {a:?}"),
                (
                    Some(LightToneMarker),
                    AfterSyllablePossiblyConsumingApostrophe | BeforeWordInitial,
                ) => continue, // just ignore it

                (
                    Some(Apostrophe),
                    AfterSyllablePossiblyConsumingApostrophe | BeforeWordInitial,
                ) => panic!("unexpected apostrophe found at the beginning of a word"),
                (None, AfterSyllablePossiblyConsumingApostrophe | BeforeWordInitial) => {
                    return None
                }
                (None, InitialParsed(initial)) => {
                    panic!("unexpected end of string found after {initial:?}");
                }
                (None, ZCSParsed(zcs)) => panic!("unexpected end of string found after {zcs:?}"),
                (
                    Some(Punctuation(s)),
                    BeforeWordInitial | AfterSyllablePossiblyConsumingApostrophe,
                ) => {
                    if self.configs.p_preserve_punctuations {
                        self.state = BeforeWordInitial;
                        return Some((*s).clone());
                    }
                    continue;
                }
                (Some(Space(s)), BeforeWordInitial | AfterSyllablePossiblyConsumingApostrophe) => {
                    if self.configs.p_preserve_spaces {
                        self.state = BeforeWordInitial;
                        return Some((*s).clone());
                    }
                    continue;
                }

                (Some(Others(s)), BeforeWordInitial | AfterSyllablePossiblyConsumingApostrophe) => {
                    if self.configs.p_preserve_miscellaneous {
                        self.state = BeforeWordInitial;
                        return Some((*s).clone());
                    }
                    continue;
                }

                (
                    Some(Alph(alph)),
                    BeforeWordInitial | AfterSyllablePossiblyConsumingApostrophe,
                ) => match alph.alphabet {
                    Alphabet::B => self.state = InitialParsed(SpellingInitial::B),
                    Alphabet::P => self.state = InitialParsed(SpellingInitial::P),
                    Alphabet::M => {
                        if alph.diacritics.is_empty() {
                            self.state = InitialParsed(SpellingInitial::M);
                        } else {
                            return Some(alph.to_str(self.configs.p_strict));
                        }
                    }
                    Alphabet::F => self.state = InitialParsed(SpellingInitial::F),
                    Alphabet::D => self.state = InitialParsed(SpellingInitial::D),
                    Alphabet::T => self.state = InitialParsed(SpellingInitial::T),
                    Alphabet::N => {
                        if alph.diacritics.is_empty() {
                            self.state = InitialParsed(SpellingInitial::N);
                        } else {
                            return Some(alph.to_str(self.configs.p_strict));
                        }
                    }
                    Alphabet::L => self.state = InitialParsed(SpellingInitial::L),
                    Alphabet::G => self.state = InitialParsed(SpellingInitial::G),
                    Alphabet::K => self.state = InitialParsed(SpellingInitial::K),
                    Alphabet::H => self.state = InitialParsed(SpellingInitial::H),
                    Alphabet::J => self.state = InitialParsed(SpellingInitial::J),
                    Alphabet::Q => self.state = InitialParsed(SpellingInitial::Q),
                    Alphabet::X => self.state = InitialParsed(SpellingInitial::X),
                    Alphabet::R => self.state = InitialParsed(SpellingInitial::R),
                    Alphabet::Y => self.state = InitialParsed(SpellingInitial::Y),
                    Alphabet::W => self.state = InitialParsed(SpellingInitial::W),
                    Alphabet::Z => {
                        if alph.diacritics.is_empty() {
                            self.state = ZCSParsed(ZCS::Z);
                        } else if matches!(
                            &alph.diacritics[..],
                            &[pinyin_token::Diacritic::Circumflex]
                        ) {
                            self.state = InitialParsed(SpellingInitial::ZH);
                        } else {
                            return Some(alph.to_str(self.configs.p_strict));
                        }
                    }
                    Alphabet::C => {
                        if alph.diacritics.is_empty() {
                            self.state = ZCSParsed(ZCS::C);
                        } else if matches!(
                            &alph.diacritics[..],
                            &[pinyin_token::Diacritic::Circumflex]
                        ) {
                            self.state = InitialParsed(SpellingInitial::CH);
                        } else {
                            return Some(alph.to_str(self.configs.p_strict));
                        }
                    }
                    Alphabet::S => {
                        if alph.diacritics.is_empty() {
                            self.state = ZCSParsed(ZCS::S);
                        } else if matches!(
                            &alph.diacritics[..],
                            &[pinyin_token::Diacritic::Circumflex]
                        ) {
                            self.state = InitialParsed(SpellingInitial::SH);
                        } else {
                            return Some(alph.to_str(self.configs.p_strict));
                        }
                    }
                    Alphabet::A | Alphabet::E | Alphabet::O => {
                        self.it.rewind(1);
                        self.state = InitialParsed(SpellingInitial::ZeroAEO);
                    }

                    Alphabet::I | Alphabet::U | Alphabet::Ŋ => panic!(
                        "unexpected alphabet {:?} found at the beginning of a word",
                        alph.alphabet,
                    ),
                },

                (Some(Alph(alph)), ZCSParsed(zcs)) => {
                    if alph.alphabet == Alphabet::H {
                        self.state = match zcs {
                            ZCS::Z => InitialParsed(SpellingInitial::ZH),
                            ZCS::C => InitialParsed(SpellingInitial::CH),
                            ZCS::S => InitialParsed(SpellingInitial::SH),
                        }
                    } else {
                        self.it.rewind(1);
                        self.state = match zcs {
                            ZCS::Z => InitialParsed(SpellingInitial::Z),
                            ZCS::C => InitialParsed(SpellingInitial::C),
                            ZCS::S => InitialParsed(SpellingInitial::S),
                        }
                    }
                }

                (Some(Alph(_)), InitialParsed(initial)) => {
                    use finals::Candidate;
                    self.it.rewind(1);
                    let candidates = self.it.get_candidates_without_rhotic(self.configs.p_strict);

                    assert!(!candidates.is_empty(),
                            "no adequate candidate for finals (-an, -ian, ...) is found, after the initial {initial:?}"
                        );

                    for Candidate { ŋ, fin, tone } in candidates.clone() {
                        let fin_len = fin.len() - usize::from(ŋ); // ŋ accounts for ng, hence the len is shorter by 1
                        self.it.advance(fin_len);

                        // ITERATOR IS TEMPORARILY ADVANCED HERE
                        match self.it.peek(0) {
                            None => {
                                self.it.advance(1);
                                self.state = AfterSyllablePossiblyConsumingApostrophe;
                                return Some(format!(
                                    "{}{}",
                                    initial,
                                    finals::FinalWithTone { fin, tone }
                                ));
                            }

                            Some(Apostrophe) => {
                                self.it.advance(1);

                                // In the strict mode, `a`, `e` or `o` must follow the apostrophe
                                if self.configs.p_strict.is_strict() {
                                    let a_e_o = match self.it.peek(0) {
                                        Some(Alph(a)) => matches!(
                                            a.alphabet,
                                            Alphabet::A | Alphabet::E | Alphabet::O
                                        ),
                                        _ => false,
                                    };

                                    assert!(a_e_o, "In strict mode, an apostrophe must be followed by either 'a', 'e' or 'o'");
                                }

                                self.state = AfterSyllablePossiblyConsumingApostrophe;
                                return Some(format!(
                                    "{}{}",
                                    initial,
                                    finals::FinalWithTone { fin, tone }
                                ));
                            }

                            Some(Punctuation(_) | LightToneMarker | Space(_) | Others(_)) => {
                                self.state = AfterSyllablePossiblyConsumingApostrophe;
                                return Some(format!(
                                    "{}{}",
                                    initial,
                                    finals::FinalWithTone { fin, tone }
                                ));
                            }

                            Some(Alph(alph)) => match alph.alphabet {
                                Alphabet::A
                                | Alphabet::E
                                | Alphabet::I
                                | Alphabet::O
                                | Alphabet::U
                                | Alphabet::Ŋ => {
                                    /* we have read too much or too little; this candidate is not good; ignore. */
                                    self.it.rewind(fin_len);
                                    continue;
                                }

                                Alphabet::R =>
                                /* possibly rhotic */
                                {
                                    let vowel_follows = match self.it.peek(1) {
                                        Some(Alph(a)) => matches!(
                                            a.alphabet,
                                            Alphabet::A
                                                | Alphabet::E
                                                | Alphabet::I
                                                | Alphabet::O
                                                | Alphabet::U
                                        ),
                                        _ => false,
                                    };
                                    if vowel_follows {
                                        // cannot be rhotic
                                        // peeking `r` was not needed
                                        // hence simply return
                                        self.state = AfterSyllablePossiblyConsumingApostrophe;
                                        return Some(format!(
                                            "{}{}",
                                            initial,
                                            finals::FinalWithTone { fin, tone }
                                        ));
                                    }
                                    // this is rhotic
                                    self.it.advance(1);
                                    self.state = AfterSyllablePossiblyConsumingApostrophe;
                                    return Some(format!(
                                        "{}{}r",
                                        initial,
                                        finals::FinalWithTone { fin, tone }
                                    ));
                                }

                                Alphabet::G =>
                                /* possibly g */
                                {
                                    let vowel_follows = match self.it.peek(1) {
                                        Some(Alph(a)) => matches!(
                                            a.alphabet,
                                            Alphabet::A
                                                | Alphabet::E
                                                | Alphabet::I
                                                | Alphabet::O
                                                | Alphabet::U
                                        ),
                                        _ => false,
                                    };
                                    if vowel_follows {
                                        // cannot be an additiona g
                                        // peeking `g` was not needed
                                        // hence simply return
                                        self.state = AfterSyllablePossiblyConsumingApostrophe;
                                        return Some(format!(
                                            "{}{}",
                                            initial,
                                            finals::FinalWithTone { fin, tone }
                                        ));
                                    }
                                    // this candidate is wrong
                                    self.it.rewind(fin_len);
                                    continue;
                                }

                                Alphabet::N => {
                                    let vowel_follows = match self.it.peek(1) {
                                        Some(Alph(a)) => matches!(
                                            a.alphabet,
                                            Alphabet::A
                                                | Alphabet::E
                                                | Alphabet::I
                                                | Alphabet::O
                                                | Alphabet::U
                                        ),
                                        _ => false,
                                    };
                                    if vowel_follows {
                                        // peeking `n` was not needed
                                        // hence simply return
                                        self.state = AfterSyllablePossiblyConsumingApostrophe;
                                        return Some(format!(
                                            "{}{}",
                                            initial,
                                            finals::FinalWithTone { fin, tone }
                                        ));
                                    }
                                    // this candidate is not good
                                    self.it.rewind(fin_len);
                                    continue;
                                }

                                _ => {
                                    self.state = AfterSyllablePossiblyConsumingApostrophe;
                                    return Some(format!(
                                        "{}{}",
                                        initial,
                                        finals::FinalWithTone { fin, tone }
                                    ));
                                }
                            },
                        }
                    }
                    panic!(
                        "no adequate candidate for finals (-an, -ian, ...) found, among possible candidates {candidates:?}"
                    );
                }
            }
        }
    }
}

mod finals;

#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
enum ZCS {
    Z,
    C,
    S,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
enum SpellingInitial {
    B,
    P,
    M,
    F,
    D,
    T,
    N,
    L,
    G,
    K,
    H,
    J,
    Q,
    X,
    ZH,
    CH,
    SH,
    R,
    Z,
    C,
    S,
    Y,
    W,
    ZeroAEO,
}

impl std::fmt::Display for SpellingInitial {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::B => write!(f, "b"),
            Self::P => write!(f, "p"),
            Self::M => write!(f, "m"),
            Self::F => write!(f, "f"),
            Self::D => write!(f, "d"),
            Self::T => write!(f, "t"),
            Self::N => write!(f, "n"),
            Self::L => write!(f, "l"),
            Self::G => write!(f, "g"),
            Self::K => write!(f, "k"),
            Self::H => write!(f, "h"),
            Self::J => write!(f, "j"),
            Self::Q => write!(f, "q"),
            Self::X => write!(f, "x"),
            Self::ZH => write!(f, "zh"),
            Self::CH => write!(f, "ch"),
            Self::SH => write!(f, "sh"),
            Self::R => write!(f, "r"),
            Self::Z => write!(f, "z"),
            Self::C => write!(f, "c"),
            Self::S => write!(f, "s"),
            Self::Y => write!(f, "y"),
            Self::W => write!(f, "w"),
            Self::ZeroAEO => write!(f, ""),
        }
    }
}