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
/// A number of constants to give a name to all characters in this block.
mod constants {
    /// \u{a900}: '꤀'
    pub const DIGIT_ZERO: char = '꤀';
    /// \u{a901}: '꤁'
    pub const DIGIT_ONE: char = '꤁';
    /// \u{a902}: '꤂'
    pub const DIGIT_TWO: char = '꤂';
    /// \u{a903}: '꤃'
    pub const DIGIT_THREE: char = '꤃';
    /// \u{a904}: '꤄'
    pub const DIGIT_FOUR: char = '꤄';
    /// \u{a905}: '꤅'
    pub const DIGIT_FIVE: char = '꤅';
    /// \u{a906}: '꤆'
    pub const DIGIT_SIX: char = '꤆';
    /// \u{a907}: '꤇'
    pub const DIGIT_SEVEN: char = '꤇';
    /// \u{a908}: '꤈'
    pub const DIGIT_EIGHT: char = '꤈';
    /// \u{a909}: '꤉'
    pub const DIGIT_NINE: char = '꤉';
    /// \u{a90a}: 'ꤊ'
    pub const LETTER_KA: char = 'ꤊ';
    /// \u{a90b}: 'ꤋ'
    pub const LETTER_KHA: char = 'ꤋ';
    /// \u{a90c}: 'ꤌ'
    pub const LETTER_GA: char = 'ꤌ';
    /// \u{a90d}: 'ꤍ'
    pub const LETTER_NGA: char = 'ꤍ';
    /// \u{a90e}: 'ꤎ'
    pub const LETTER_SA: char = 'ꤎ';
    /// \u{a90f}: 'ꤏ'
    pub const LETTER_SHA: char = 'ꤏ';
    /// \u{a910}: 'ꤐ'
    pub const LETTER_ZA: char = 'ꤐ';
    /// \u{a911}: 'ꤑ'
    pub const LETTER_NYA: char = 'ꤑ';
    /// \u{a912}: 'ꤒ'
    pub const LETTER_TA: char = 'ꤒ';
    /// \u{a913}: 'ꤓ'
    pub const LETTER_HTA: char = 'ꤓ';
    /// \u{a914}: 'ꤔ'
    pub const LETTER_NA: char = 'ꤔ';
    /// \u{a915}: 'ꤕ'
    pub const LETTER_PA: char = 'ꤕ';
    /// \u{a916}: 'ꤖ'
    pub const LETTER_PHA: char = 'ꤖ';
    /// \u{a917}: 'ꤗ'
    pub const LETTER_MA: char = 'ꤗ';
    /// \u{a918}: 'ꤘ'
    pub const LETTER_DA: char = 'ꤘ';
    /// \u{a919}: 'ꤙ'
    pub const LETTER_BA: char = 'ꤙ';
    /// \u{a91a}: 'ꤚ'
    pub const LETTER_RA: char = 'ꤚ';
    /// \u{a91b}: 'ꤛ'
    pub const LETTER_YA: char = 'ꤛ';
    /// \u{a91c}: 'ꤜ'
    pub const LETTER_LA: char = 'ꤜ';
    /// \u{a91d}: 'ꤝ'
    pub const LETTER_WA: char = 'ꤝ';
    /// \u{a91e}: 'ꤞ'
    pub const LETTER_THA: char = 'ꤞ';
    /// \u{a91f}: 'ꤟ'
    pub const LETTER_HA: char = 'ꤟ';
    /// \u{a920}: 'ꤠ'
    pub const LETTER_VA: char = 'ꤠ';
    /// \u{a921}: 'ꤡ'
    pub const LETTER_CA: char = 'ꤡ';
    /// \u{a922}: 'ꤢ'
    pub const LETTER_A: char = 'ꤢ';
    /// \u{a923}: 'ꤣ'
    pub const LETTER_OE: char = 'ꤣ';
    /// \u{a924}: 'ꤤ'
    pub const LETTER_I: char = 'ꤤ';
    /// \u{a925}: 'ꤥ'
    pub const LETTER_OO: char = 'ꤥ';
    /// \u{a926}: 'ꤦ'
    pub const VOWEL_UE: char = 'ꤦ';
    /// \u{a927}: 'ꤧ'
    pub const VOWEL_E: char = 'ꤧ';
    /// \u{a928}: 'ꤨ'
    pub const VOWEL_U: char = 'ꤨ';
    /// \u{a929}: 'ꤩ'
    pub const VOWEL_EE: char = 'ꤩ';
    /// \u{a92a}: 'ꤪ'
    pub const VOWEL_O: char = 'ꤪ';
    /// \u{a92b}: '꤫'
    pub const TONE_PLOPHU: char = '꤫';
    /// \u{a92c}: '꤬'
    pub const TONE_CALYA: char = '꤬';
    /// \u{a92d}: '꤭'
    pub const TONE_CALYA_PLOPHU: char = '꤭';
    /// \u{a92e}: '꤮'
    pub const SIGN_CWI: char = '꤮';
}

/// An enum to represent all characters in the KayahLi block.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum KayahLi {
    /// \u{a900}: '꤀'
    DigitZero,
    /// \u{a901}: '꤁'
    DigitOne,
    /// \u{a902}: '꤂'
    DigitTwo,
    /// \u{a903}: '꤃'
    DigitThree,
    /// \u{a904}: '꤄'
    DigitFour,
    /// \u{a905}: '꤅'
    DigitFive,
    /// \u{a906}: '꤆'
    DigitSix,
    /// \u{a907}: '꤇'
    DigitSeven,
    /// \u{a908}: '꤈'
    DigitEight,
    /// \u{a909}: '꤉'
    DigitNine,
    /// \u{a90a}: 'ꤊ'
    LetterKa,
    /// \u{a90b}: 'ꤋ'
    LetterKha,
    /// \u{a90c}: 'ꤌ'
    LetterGa,
    /// \u{a90d}: 'ꤍ'
    LetterNga,
    /// \u{a90e}: 'ꤎ'
    LetterSa,
    /// \u{a90f}: 'ꤏ'
    LetterSha,
    /// \u{a910}: 'ꤐ'
    LetterZa,
    /// \u{a911}: 'ꤑ'
    LetterNya,
    /// \u{a912}: 'ꤒ'
    LetterTa,
    /// \u{a913}: 'ꤓ'
    LetterHta,
    /// \u{a914}: 'ꤔ'
    LetterNa,
    /// \u{a915}: 'ꤕ'
    LetterPa,
    /// \u{a916}: 'ꤖ'
    LetterPha,
    /// \u{a917}: 'ꤗ'
    LetterMa,
    /// \u{a918}: 'ꤘ'
    LetterDa,
    /// \u{a919}: 'ꤙ'
    LetterBa,
    /// \u{a91a}: 'ꤚ'
    LetterRa,
    /// \u{a91b}: 'ꤛ'
    LetterYa,
    /// \u{a91c}: 'ꤜ'
    LetterLa,
    /// \u{a91d}: 'ꤝ'
    LetterWa,
    /// \u{a91e}: 'ꤞ'
    LetterTha,
    /// \u{a91f}: 'ꤟ'
    LetterHa,
    /// \u{a920}: 'ꤠ'
    LetterVa,
    /// \u{a921}: 'ꤡ'
    LetterCa,
    /// \u{a922}: 'ꤢ'
    LetterA,
    /// \u{a923}: 'ꤣ'
    LetterOe,
    /// \u{a924}: 'ꤤ'
    LetterI,
    /// \u{a925}: 'ꤥ'
    LetterOo,
    /// \u{a926}: 'ꤦ'
    VowelUe,
    /// \u{a927}: 'ꤧ'
    VowelE,
    /// \u{a928}: 'ꤨ'
    VowelU,
    /// \u{a929}: 'ꤩ'
    VowelEe,
    /// \u{a92a}: 'ꤪ'
    VowelO,
    /// \u{a92b}: '꤫'
    TonePlophu,
    /// \u{a92c}: '꤬'
    ToneCalya,
    /// \u{a92d}: '꤭'
    ToneCalyaPlophu,
    /// \u{a92e}: '꤮'
    SignCwi,
}

impl Into<char> for KayahLi {
    fn into(self) -> char {
        use constants::*;
        match self {
            KayahLi::DigitZero => DIGIT_ZERO,
            KayahLi::DigitOne => DIGIT_ONE,
            KayahLi::DigitTwo => DIGIT_TWO,
            KayahLi::DigitThree => DIGIT_THREE,
            KayahLi::DigitFour => DIGIT_FOUR,
            KayahLi::DigitFive => DIGIT_FIVE,
            KayahLi::DigitSix => DIGIT_SIX,
            KayahLi::DigitSeven => DIGIT_SEVEN,
            KayahLi::DigitEight => DIGIT_EIGHT,
            KayahLi::DigitNine => DIGIT_NINE,
            KayahLi::LetterKa => LETTER_KA,
            KayahLi::LetterKha => LETTER_KHA,
            KayahLi::LetterGa => LETTER_GA,
            KayahLi::LetterNga => LETTER_NGA,
            KayahLi::LetterSa => LETTER_SA,
            KayahLi::LetterSha => LETTER_SHA,
            KayahLi::LetterZa => LETTER_ZA,
            KayahLi::LetterNya => LETTER_NYA,
            KayahLi::LetterTa => LETTER_TA,
            KayahLi::LetterHta => LETTER_HTA,
            KayahLi::LetterNa => LETTER_NA,
            KayahLi::LetterPa => LETTER_PA,
            KayahLi::LetterPha => LETTER_PHA,
            KayahLi::LetterMa => LETTER_MA,
            KayahLi::LetterDa => LETTER_DA,
            KayahLi::LetterBa => LETTER_BA,
            KayahLi::LetterRa => LETTER_RA,
            KayahLi::LetterYa => LETTER_YA,
            KayahLi::LetterLa => LETTER_LA,
            KayahLi::LetterWa => LETTER_WA,
            KayahLi::LetterTha => LETTER_THA,
            KayahLi::LetterHa => LETTER_HA,
            KayahLi::LetterVa => LETTER_VA,
            KayahLi::LetterCa => LETTER_CA,
            KayahLi::LetterA => LETTER_A,
            KayahLi::LetterOe => LETTER_OE,
            KayahLi::LetterI => LETTER_I,
            KayahLi::LetterOo => LETTER_OO,
            KayahLi::VowelUe => VOWEL_UE,
            KayahLi::VowelE => VOWEL_E,
            KayahLi::VowelU => VOWEL_U,
            KayahLi::VowelEe => VOWEL_EE,
            KayahLi::VowelO => VOWEL_O,
            KayahLi::TonePlophu => TONE_PLOPHU,
            KayahLi::ToneCalya => TONE_CALYA,
            KayahLi::ToneCalyaPlophu => TONE_CALYA_PLOPHU,
            KayahLi::SignCwi => SIGN_CWI,
        }
    }
}

impl std::convert::TryFrom<char> for KayahLi {
    type Error = ();
    fn try_from(c: char) -> Result<Self, Self::Error> {
        use constants::*;
        match c {
            DIGIT_ZERO => Ok(KayahLi::DigitZero),
            DIGIT_ONE => Ok(KayahLi::DigitOne),
            DIGIT_TWO => Ok(KayahLi::DigitTwo),
            DIGIT_THREE => Ok(KayahLi::DigitThree),
            DIGIT_FOUR => Ok(KayahLi::DigitFour),
            DIGIT_FIVE => Ok(KayahLi::DigitFive),
            DIGIT_SIX => Ok(KayahLi::DigitSix),
            DIGIT_SEVEN => Ok(KayahLi::DigitSeven),
            DIGIT_EIGHT => Ok(KayahLi::DigitEight),
            DIGIT_NINE => Ok(KayahLi::DigitNine),
            LETTER_KA => Ok(KayahLi::LetterKa),
            LETTER_KHA => Ok(KayahLi::LetterKha),
            LETTER_GA => Ok(KayahLi::LetterGa),
            LETTER_NGA => Ok(KayahLi::LetterNga),
            LETTER_SA => Ok(KayahLi::LetterSa),
            LETTER_SHA => Ok(KayahLi::LetterSha),
            LETTER_ZA => Ok(KayahLi::LetterZa),
            LETTER_NYA => Ok(KayahLi::LetterNya),
            LETTER_TA => Ok(KayahLi::LetterTa),
            LETTER_HTA => Ok(KayahLi::LetterHta),
            LETTER_NA => Ok(KayahLi::LetterNa),
            LETTER_PA => Ok(KayahLi::LetterPa),
            LETTER_PHA => Ok(KayahLi::LetterPha),
            LETTER_MA => Ok(KayahLi::LetterMa),
            LETTER_DA => Ok(KayahLi::LetterDa),
            LETTER_BA => Ok(KayahLi::LetterBa),
            LETTER_RA => Ok(KayahLi::LetterRa),
            LETTER_YA => Ok(KayahLi::LetterYa),
            LETTER_LA => Ok(KayahLi::LetterLa),
            LETTER_WA => Ok(KayahLi::LetterWa),
            LETTER_THA => Ok(KayahLi::LetterTha),
            LETTER_HA => Ok(KayahLi::LetterHa),
            LETTER_VA => Ok(KayahLi::LetterVa),
            LETTER_CA => Ok(KayahLi::LetterCa),
            LETTER_A => Ok(KayahLi::LetterA),
            LETTER_OE => Ok(KayahLi::LetterOe),
            LETTER_I => Ok(KayahLi::LetterI),
            LETTER_OO => Ok(KayahLi::LetterOo),
            VOWEL_UE => Ok(KayahLi::VowelUe),
            VOWEL_E => Ok(KayahLi::VowelE),
            VOWEL_U => Ok(KayahLi::VowelU),
            VOWEL_EE => Ok(KayahLi::VowelEe),
            VOWEL_O => Ok(KayahLi::VowelO),
            TONE_PLOPHU => Ok(KayahLi::TonePlophu),
            TONE_CALYA => Ok(KayahLi::ToneCalya),
            TONE_CALYA_PLOPHU => Ok(KayahLi::ToneCalyaPlophu),
            SIGN_CWI => Ok(KayahLi::SignCwi),
            _ => Err(()),
        }
    }
}

impl Into<u32> for KayahLi {
    fn into(self) -> u32 {
        let c: char = self.into();
        let hex = c
            .escape_unicode()
            .to_string()
            .replace("\\u{", "")
            .replace("}", "");
        u32::from_str_radix(&hex, 16).unwrap()
    }
}

impl std::convert::TryFrom<u32> for KayahLi {
    type Error = ();
    fn try_from(u: u32) -> Result<Self, Self::Error> {
        if let Ok(c) = char::try_from(u) {
            Self::try_from(c)
        } else {
            Err(())
        }
    }
}

impl Iterator for KayahLi {
    type Item = Self;
    fn next(&mut self) -> Option<Self> {
        let index: u32 = (*self).into();
        use std::convert::TryFrom;
        Self::try_from(index + 1).ok()
    }
}

impl KayahLi {
    /// The character with the lowest index in this unicode block
    pub fn new() -> Self {
        KayahLi::DigitZero
    }

    /// The character's name, all lowercase and space-separated
    pub fn name(&self) -> &str {
        match self {
            KayahLi::DigitZero => "kayah li digit zero",
            KayahLi::DigitOne => "kayah li digit one",
            KayahLi::DigitTwo => "kayah li digit two",
            KayahLi::DigitThree => "kayah li digit three",
            KayahLi::DigitFour => "kayah li digit four",
            KayahLi::DigitFive => "kayah li digit five",
            KayahLi::DigitSix => "kayah li digit six",
            KayahLi::DigitSeven => "kayah li digit seven",
            KayahLi::DigitEight => "kayah li digit eight",
            KayahLi::DigitNine => "kayah li digit nine",
            KayahLi::LetterKa => "kayah li letter ka",
            KayahLi::LetterKha => "kayah li letter kha",
            KayahLi::LetterGa => "kayah li letter ga",
            KayahLi::LetterNga => "kayah li letter nga",
            KayahLi::LetterSa => "kayah li letter sa",
            KayahLi::LetterSha => "kayah li letter sha",
            KayahLi::LetterZa => "kayah li letter za",
            KayahLi::LetterNya => "kayah li letter nya",
            KayahLi::LetterTa => "kayah li letter ta",
            KayahLi::LetterHta => "kayah li letter hta",
            KayahLi::LetterNa => "kayah li letter na",
            KayahLi::LetterPa => "kayah li letter pa",
            KayahLi::LetterPha => "kayah li letter pha",
            KayahLi::LetterMa => "kayah li letter ma",
            KayahLi::LetterDa => "kayah li letter da",
            KayahLi::LetterBa => "kayah li letter ba",
            KayahLi::LetterRa => "kayah li letter ra",
            KayahLi::LetterYa => "kayah li letter ya",
            KayahLi::LetterLa => "kayah li letter la",
            KayahLi::LetterWa => "kayah li letter wa",
            KayahLi::LetterTha => "kayah li letter tha",
            KayahLi::LetterHa => "kayah li letter ha",
            KayahLi::LetterVa => "kayah li letter va",
            KayahLi::LetterCa => "kayah li letter ca",
            KayahLi::LetterA => "kayah li letter a",
            KayahLi::LetterOe => "kayah li letter oe",
            KayahLi::LetterI => "kayah li letter i",
            KayahLi::LetterOo => "kayah li letter oo",
            KayahLi::VowelUe => "kayah li vowel ue",
            KayahLi::VowelE => "kayah li vowel e",
            KayahLi::VowelU => "kayah li vowel u",
            KayahLi::VowelEe => "kayah li vowel ee",
            KayahLi::VowelO => "kayah li vowel o",
            KayahLi::TonePlophu => "kayah li tone plophu",
            KayahLi::ToneCalya => "kayah li tone calya",
            KayahLi::ToneCalyaPlophu => "kayah li tone calya plophu",
            KayahLi::SignCwi => "kayah li sign cwi",
        }
    }
}