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
/// A number of constants to give a name to all characters in this block.
mod constants {
    /// \u{10a60}: '𐩠'
    pub const LETTER_HE: char = '𐩠';
    /// \u{10a61}: '𐩡'
    pub const LETTER_LAMEDH: char = '𐩡';
    /// \u{10a62}: '𐩢'
    pub const LETTER_HETH: char = '𐩢';
    /// \u{10a63}: '𐩣'
    pub const LETTER_MEM: char = '𐩣';
    /// \u{10a64}: '𐩤'
    pub const LETTER_QOPH: char = '𐩤';
    /// \u{10a65}: '𐩥'
    pub const LETTER_WAW: char = '𐩥';
    /// \u{10a66}: '𐩦'
    pub const LETTER_SHIN: char = '𐩦';
    /// \u{10a67}: '𐩧'
    pub const LETTER_RESH: char = '𐩧';
    /// \u{10a68}: '𐩨'
    pub const LETTER_BETH: char = '𐩨';
    /// \u{10a69}: '𐩩'
    pub const LETTER_TAW: char = '𐩩';
    /// \u{10a6a}: '𐩪'
    pub const LETTER_SAT: char = '𐩪';
    /// \u{10a6b}: '𐩫'
    pub const LETTER_KAPH: char = '𐩫';
    /// \u{10a6c}: '𐩬'
    pub const LETTER_NUN: char = '𐩬';
    /// \u{10a6d}: '𐩭'
    pub const LETTER_KHETH: char = '𐩭';
    /// \u{10a6e}: '𐩮'
    pub const LETTER_SADHE: char = '𐩮';
    /// \u{10a6f}: '𐩯'
    pub const LETTER_SAMEKH: char = '𐩯';
    /// \u{10a70}: '𐩰'
    pub const LETTER_FE: char = '𐩰';
    /// \u{10a71}: '𐩱'
    pub const LETTER_ALEF: char = '𐩱';
    /// \u{10a72}: '𐩲'
    pub const LETTER_AYN: char = '𐩲';
    /// \u{10a73}: '𐩳'
    pub const LETTER_DHADHE: char = '𐩳';
    /// \u{10a74}: '𐩴'
    pub const LETTER_GIMEL: char = '𐩴';
    /// \u{10a75}: '𐩵'
    pub const LETTER_DALETH: char = '𐩵';
    /// \u{10a76}: '𐩶'
    pub const LETTER_GHAYN: char = '𐩶';
    /// \u{10a77}: '𐩷'
    pub const LETTER_TETH: char = '𐩷';
    /// \u{10a78}: '𐩸'
    pub const LETTER_ZAYN: char = '𐩸';
    /// \u{10a79}: '𐩹'
    pub const LETTER_DHALETH: char = '𐩹';
    /// \u{10a7a}: '𐩺'
    pub const LETTER_YODH: char = '𐩺';
    /// \u{10a7b}: '𐩻'
    pub const LETTER_THAW: char = '𐩻';
    /// \u{10a7c}: '𐩼'
    pub const LETTER_THETH: char = '𐩼';
    /// \u{10a7d}: '𐩽'
    pub const NUMBER_ONE: char = '𐩽';
    /// \u{10a7e}: '𐩾'
    pub const NUMBER_FIFTY: char = '𐩾';
}

/// An enum to represent all characters in the OldSouthArabian block.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum OldSouthArabian {
    /// \u{10a60}: '𐩠'
    LetterHe,
    /// \u{10a61}: '𐩡'
    LetterLamedh,
    /// \u{10a62}: '𐩢'
    LetterHeth,
    /// \u{10a63}: '𐩣'
    LetterMem,
    /// \u{10a64}: '𐩤'
    LetterQoph,
    /// \u{10a65}: '𐩥'
    LetterWaw,
    /// \u{10a66}: '𐩦'
    LetterShin,
    /// \u{10a67}: '𐩧'
    LetterResh,
    /// \u{10a68}: '𐩨'
    LetterBeth,
    /// \u{10a69}: '𐩩'
    LetterTaw,
    /// \u{10a6a}: '𐩪'
    LetterSat,
    /// \u{10a6b}: '𐩫'
    LetterKaph,
    /// \u{10a6c}: '𐩬'
    LetterNun,
    /// \u{10a6d}: '𐩭'
    LetterKheth,
    /// \u{10a6e}: '𐩮'
    LetterSadhe,
    /// \u{10a6f}: '𐩯'
    LetterSamekh,
    /// \u{10a70}: '𐩰'
    LetterFe,
    /// \u{10a71}: '𐩱'
    LetterAlef,
    /// \u{10a72}: '𐩲'
    LetterAyn,
    /// \u{10a73}: '𐩳'
    LetterDhadhe,
    /// \u{10a74}: '𐩴'
    LetterGimel,
    /// \u{10a75}: '𐩵'
    LetterDaleth,
    /// \u{10a76}: '𐩶'
    LetterGhayn,
    /// \u{10a77}: '𐩷'
    LetterTeth,
    /// \u{10a78}: '𐩸'
    LetterZayn,
    /// \u{10a79}: '𐩹'
    LetterDhaleth,
    /// \u{10a7a}: '𐩺'
    LetterYodh,
    /// \u{10a7b}: '𐩻'
    LetterThaw,
    /// \u{10a7c}: '𐩼'
    LetterTheth,
    /// \u{10a7d}: '𐩽'
    NumberOne,
    /// \u{10a7e}: '𐩾'
    NumberFifty,
}

impl Into<char> for OldSouthArabian {
    fn into(self) -> char {
        use constants::*;
        match self {
            OldSouthArabian::LetterHe => LETTER_HE,
            OldSouthArabian::LetterLamedh => LETTER_LAMEDH,
            OldSouthArabian::LetterHeth => LETTER_HETH,
            OldSouthArabian::LetterMem => LETTER_MEM,
            OldSouthArabian::LetterQoph => LETTER_QOPH,
            OldSouthArabian::LetterWaw => LETTER_WAW,
            OldSouthArabian::LetterShin => LETTER_SHIN,
            OldSouthArabian::LetterResh => LETTER_RESH,
            OldSouthArabian::LetterBeth => LETTER_BETH,
            OldSouthArabian::LetterTaw => LETTER_TAW,
            OldSouthArabian::LetterSat => LETTER_SAT,
            OldSouthArabian::LetterKaph => LETTER_KAPH,
            OldSouthArabian::LetterNun => LETTER_NUN,
            OldSouthArabian::LetterKheth => LETTER_KHETH,
            OldSouthArabian::LetterSadhe => LETTER_SADHE,
            OldSouthArabian::LetterSamekh => LETTER_SAMEKH,
            OldSouthArabian::LetterFe => LETTER_FE,
            OldSouthArabian::LetterAlef => LETTER_ALEF,
            OldSouthArabian::LetterAyn => LETTER_AYN,
            OldSouthArabian::LetterDhadhe => LETTER_DHADHE,
            OldSouthArabian::LetterGimel => LETTER_GIMEL,
            OldSouthArabian::LetterDaleth => LETTER_DALETH,
            OldSouthArabian::LetterGhayn => LETTER_GHAYN,
            OldSouthArabian::LetterTeth => LETTER_TETH,
            OldSouthArabian::LetterZayn => LETTER_ZAYN,
            OldSouthArabian::LetterDhaleth => LETTER_DHALETH,
            OldSouthArabian::LetterYodh => LETTER_YODH,
            OldSouthArabian::LetterThaw => LETTER_THAW,
            OldSouthArabian::LetterTheth => LETTER_THETH,
            OldSouthArabian::NumberOne => NUMBER_ONE,
            OldSouthArabian::NumberFifty => NUMBER_FIFTY,
        }
    }
}

impl std::convert::TryFrom<char> for OldSouthArabian {
    type Error = ();
    fn try_from(c: char) -> Result<Self, Self::Error> {
        use constants::*;
        match c {
            LETTER_HE => Ok(OldSouthArabian::LetterHe),
            LETTER_LAMEDH => Ok(OldSouthArabian::LetterLamedh),
            LETTER_HETH => Ok(OldSouthArabian::LetterHeth),
            LETTER_MEM => Ok(OldSouthArabian::LetterMem),
            LETTER_QOPH => Ok(OldSouthArabian::LetterQoph),
            LETTER_WAW => Ok(OldSouthArabian::LetterWaw),
            LETTER_SHIN => Ok(OldSouthArabian::LetterShin),
            LETTER_RESH => Ok(OldSouthArabian::LetterResh),
            LETTER_BETH => Ok(OldSouthArabian::LetterBeth),
            LETTER_TAW => Ok(OldSouthArabian::LetterTaw),
            LETTER_SAT => Ok(OldSouthArabian::LetterSat),
            LETTER_KAPH => Ok(OldSouthArabian::LetterKaph),
            LETTER_NUN => Ok(OldSouthArabian::LetterNun),
            LETTER_KHETH => Ok(OldSouthArabian::LetterKheth),
            LETTER_SADHE => Ok(OldSouthArabian::LetterSadhe),
            LETTER_SAMEKH => Ok(OldSouthArabian::LetterSamekh),
            LETTER_FE => Ok(OldSouthArabian::LetterFe),
            LETTER_ALEF => Ok(OldSouthArabian::LetterAlef),
            LETTER_AYN => Ok(OldSouthArabian::LetterAyn),
            LETTER_DHADHE => Ok(OldSouthArabian::LetterDhadhe),
            LETTER_GIMEL => Ok(OldSouthArabian::LetterGimel),
            LETTER_DALETH => Ok(OldSouthArabian::LetterDaleth),
            LETTER_GHAYN => Ok(OldSouthArabian::LetterGhayn),
            LETTER_TETH => Ok(OldSouthArabian::LetterTeth),
            LETTER_ZAYN => Ok(OldSouthArabian::LetterZayn),
            LETTER_DHALETH => Ok(OldSouthArabian::LetterDhaleth),
            LETTER_YODH => Ok(OldSouthArabian::LetterYodh),
            LETTER_THAW => Ok(OldSouthArabian::LetterThaw),
            LETTER_THETH => Ok(OldSouthArabian::LetterTheth),
            NUMBER_ONE => Ok(OldSouthArabian::NumberOne),
            NUMBER_FIFTY => Ok(OldSouthArabian::NumberFifty),
            _ => Err(()),
        }
    }
}

impl Into<u32> for OldSouthArabian {
    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 OldSouthArabian {
    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 OldSouthArabian {
    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 OldSouthArabian {
    /// The character with the lowest index in this unicode block
    pub fn new() -> Self {
        OldSouthArabian::LetterHe
    }

    /// The character's name, all lowercase and space-separated
    pub fn name(&self) -> &str {
        match self {
            OldSouthArabian::LetterHe => "old south arabian letter he",
            OldSouthArabian::LetterLamedh => "old south arabian letter lamedh",
            OldSouthArabian::LetterHeth => "old south arabian letter heth",
            OldSouthArabian::LetterMem => "old south arabian letter mem",
            OldSouthArabian::LetterQoph => "old south arabian letter qoph",
            OldSouthArabian::LetterWaw => "old south arabian letter waw",
            OldSouthArabian::LetterShin => "old south arabian letter shin",
            OldSouthArabian::LetterResh => "old south arabian letter resh",
            OldSouthArabian::LetterBeth => "old south arabian letter beth",
            OldSouthArabian::LetterTaw => "old south arabian letter taw",
            OldSouthArabian::LetterSat => "old south arabian letter sat",
            OldSouthArabian::LetterKaph => "old south arabian letter kaph",
            OldSouthArabian::LetterNun => "old south arabian letter nun",
            OldSouthArabian::LetterKheth => "old south arabian letter kheth",
            OldSouthArabian::LetterSadhe => "old south arabian letter sadhe",
            OldSouthArabian::LetterSamekh => "old south arabian letter samekh",
            OldSouthArabian::LetterFe => "old south arabian letter fe",
            OldSouthArabian::LetterAlef => "old south arabian letter alef",
            OldSouthArabian::LetterAyn => "old south arabian letter ayn",
            OldSouthArabian::LetterDhadhe => "old south arabian letter dhadhe",
            OldSouthArabian::LetterGimel => "old south arabian letter gimel",
            OldSouthArabian::LetterDaleth => "old south arabian letter daleth",
            OldSouthArabian::LetterGhayn => "old south arabian letter ghayn",
            OldSouthArabian::LetterTeth => "old south arabian letter teth",
            OldSouthArabian::LetterZayn => "old south arabian letter zayn",
            OldSouthArabian::LetterDhaleth => "old south arabian letter dhaleth",
            OldSouthArabian::LetterYodh => "old south arabian letter yodh",
            OldSouthArabian::LetterThaw => "old south arabian letter thaw",
            OldSouthArabian::LetterTheth => "old south arabian letter theth",
            OldSouthArabian::NumberOne => "old south arabian number one",
            OldSouthArabian::NumberFifty => "old south arabian number fifty",
        }
    }
}