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{fe30}: '︰'
    pub const PRESENTATION_FORM_FOR_VERTICAL_TWO_DOT_LEADER: char = '︰';
    /// \u{fe31}: '︱'
    pub const PRESENTATION_FORM_FOR_VERTICAL_EM_DASH: char = '︱';
    /// \u{fe32}: '︲'
    pub const PRESENTATION_FORM_FOR_VERTICAL_EN_DASH: char = '︲';
    /// \u{fe33}: '︳'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LOW_LINE: char = '︳';
    /// \u{fe34}: '︴'
    pub const PRESENTATION_FORM_FOR_VERTICAL_WAVY_LOW_LINE: char = '︴';
    /// \u{fe35}: '︵'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LEFT_PARENTHESIS: char = '︵';
    /// \u{fe36}: '︶'
    pub const PRESENTATION_FORM_FOR_VERTICAL_RIGHT_PARENTHESIS: char = '︶';
    /// \u{fe37}: '︷'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LEFT_CURLY_BRACKET: char = '︷';
    /// \u{fe38}: '︸'
    pub const PRESENTATION_FORM_FOR_VERTICAL_RIGHT_CURLY_BRACKET: char = '︸';
    /// \u{fe39}: '︹'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LEFT_TORTOISE_SHELL_BRACKET: char = '︹';
    /// \u{fe3a}: '︺'
    pub const PRESENTATION_FORM_FOR_VERTICAL_RIGHT_TORTOISE_SHELL_BRACKET: char = '︺';
    /// \u{fe3b}: '︻'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LEFT_BLACK_LENTICULAR_BRACKET: char = '︻';
    /// \u{fe3c}: '︼'
    pub const PRESENTATION_FORM_FOR_VERTICAL_RIGHT_BLACK_LENTICULAR_BRACKET: char = '︼';
    /// \u{fe3d}: '︽'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LEFT_DOUBLE_ANGLE_BRACKET: char = '︽';
    /// \u{fe3e}: '︾'
    pub const PRESENTATION_FORM_FOR_VERTICAL_RIGHT_DOUBLE_ANGLE_BRACKET: char = '︾';
    /// \u{fe3f}: '︿'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LEFT_ANGLE_BRACKET: char = '︿';
    /// \u{fe40}: '﹀'
    pub const PRESENTATION_FORM_FOR_VERTICAL_RIGHT_ANGLE_BRACKET: char = '﹀';
    /// \u{fe41}: '﹁'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LEFT_CORNER_BRACKET: char = '﹁';
    /// \u{fe42}: '﹂'
    pub const PRESENTATION_FORM_FOR_VERTICAL_RIGHT_CORNER_BRACKET: char = '﹂';
    /// \u{fe43}: '﹃'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LEFT_WHITE_CORNER_BRACKET: char = '﹃';
    /// \u{fe44}: '﹄'
    pub const PRESENTATION_FORM_FOR_VERTICAL_RIGHT_WHITE_CORNER_BRACKET: char = '﹄';
    /// \u{fe45}: '﹅'
    pub const SESAME_DOT: char = '﹅';
    /// \u{fe46}: '﹆'
    pub const WHITE_SESAME_DOT: char = '﹆';
    /// \u{fe47}: '﹇'
    pub const PRESENTATION_FORM_FOR_VERTICAL_LEFT_SQUARE_BRACKET: char = '﹇';
    /// \u{fe48}: '﹈'
    pub const PRESENTATION_FORM_FOR_VERTICAL_RIGHT_SQUARE_BRACKET: char = '﹈';
    /// \u{fe49}: '﹉'
    pub const DASHED_OVERLINE: char = '﹉';
    /// \u{fe4a}: '﹊'
    pub const CENTRELINE_OVERLINE: char = '﹊';
    /// \u{fe4b}: '﹋'
    pub const WAVY_OVERLINE: char = '﹋';
    /// \u{fe4c}: '﹌'
    pub const DOUBLE_WAVY_OVERLINE: char = '﹌';
    /// \u{fe4d}: '﹍'
    pub const DASHED_LOW_LINE: char = '﹍';
    /// \u{fe4e}: '﹎'
    pub const CENTRELINE_LOW_LINE: char = '﹎';
}

/// An enum to represent all characters in the CJKCompatibilityForms block.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum CJKCompatibilityForms {
    /// \u{fe30}: '︰'
    PresentationFormForVerticalTwoDotLeader,
    /// \u{fe31}: '︱'
    PresentationFormForVerticalEmDash,
    /// \u{fe32}: '︲'
    PresentationFormForVerticalEnDash,
    /// \u{fe33}: '︳'
    PresentationFormForVerticalLowLine,
    /// \u{fe34}: '︴'
    PresentationFormForVerticalWavyLowLine,
    /// \u{fe35}: '︵'
    PresentationFormForVerticalLeftParenthesis,
    /// \u{fe36}: '︶'
    PresentationFormForVerticalRightParenthesis,
    /// \u{fe37}: '︷'
    PresentationFormForVerticalLeftCurlyBracket,
    /// \u{fe38}: '︸'
    PresentationFormForVerticalRightCurlyBracket,
    /// \u{fe39}: '︹'
    PresentationFormForVerticalLeftTortoiseShellBracket,
    /// \u{fe3a}: '︺'
    PresentationFormForVerticalRightTortoiseShellBracket,
    /// \u{fe3b}: '︻'
    PresentationFormForVerticalLeftBlackLenticularBracket,
    /// \u{fe3c}: '︼'
    PresentationFormForVerticalRightBlackLenticularBracket,
    /// \u{fe3d}: '︽'
    PresentationFormForVerticalLeftDoubleAngleBracket,
    /// \u{fe3e}: '︾'
    PresentationFormForVerticalRightDoubleAngleBracket,
    /// \u{fe3f}: '︿'
    PresentationFormForVerticalLeftAngleBracket,
    /// \u{fe40}: '﹀'
    PresentationFormForVerticalRightAngleBracket,
    /// \u{fe41}: '﹁'
    PresentationFormForVerticalLeftCornerBracket,
    /// \u{fe42}: '﹂'
    PresentationFormForVerticalRightCornerBracket,
    /// \u{fe43}: '﹃'
    PresentationFormForVerticalLeftWhiteCornerBracket,
    /// \u{fe44}: '﹄'
    PresentationFormForVerticalRightWhiteCornerBracket,
    /// \u{fe45}: '﹅'
    SesameDot,
    /// \u{fe46}: '﹆'
    WhiteSesameDot,
    /// \u{fe47}: '﹇'
    PresentationFormForVerticalLeftSquareBracket,
    /// \u{fe48}: '﹈'
    PresentationFormForVerticalRightSquareBracket,
    /// \u{fe49}: '﹉'
    DashedOverline,
    /// \u{fe4a}: '﹊'
    CentrelineOverline,
    /// \u{fe4b}: '﹋'
    WavyOverline,
    /// \u{fe4c}: '﹌'
    DoubleWavyOverline,
    /// \u{fe4d}: '﹍'
    DashedLowLine,
    /// \u{fe4e}: '﹎'
    CentrelineLowLine,
}

impl Into<char> for CJKCompatibilityForms {
    fn into(self) -> char {
        use constants::*;
        match self {
            CJKCompatibilityForms::PresentationFormForVerticalTwoDotLeader => PRESENTATION_FORM_FOR_VERTICAL_TWO_DOT_LEADER,
            CJKCompatibilityForms::PresentationFormForVerticalEmDash => PRESENTATION_FORM_FOR_VERTICAL_EM_DASH,
            CJKCompatibilityForms::PresentationFormForVerticalEnDash => PRESENTATION_FORM_FOR_VERTICAL_EN_DASH,
            CJKCompatibilityForms::PresentationFormForVerticalLowLine => PRESENTATION_FORM_FOR_VERTICAL_LOW_LINE,
            CJKCompatibilityForms::PresentationFormForVerticalWavyLowLine => PRESENTATION_FORM_FOR_VERTICAL_WAVY_LOW_LINE,
            CJKCompatibilityForms::PresentationFormForVerticalLeftParenthesis => PRESENTATION_FORM_FOR_VERTICAL_LEFT_PARENTHESIS,
            CJKCompatibilityForms::PresentationFormForVerticalRightParenthesis => PRESENTATION_FORM_FOR_VERTICAL_RIGHT_PARENTHESIS,
            CJKCompatibilityForms::PresentationFormForVerticalLeftCurlyBracket => PRESENTATION_FORM_FOR_VERTICAL_LEFT_CURLY_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalRightCurlyBracket => PRESENTATION_FORM_FOR_VERTICAL_RIGHT_CURLY_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalLeftTortoiseShellBracket => PRESENTATION_FORM_FOR_VERTICAL_LEFT_TORTOISE_SHELL_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalRightTortoiseShellBracket => PRESENTATION_FORM_FOR_VERTICAL_RIGHT_TORTOISE_SHELL_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalLeftBlackLenticularBracket => PRESENTATION_FORM_FOR_VERTICAL_LEFT_BLACK_LENTICULAR_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalRightBlackLenticularBracket => PRESENTATION_FORM_FOR_VERTICAL_RIGHT_BLACK_LENTICULAR_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalLeftDoubleAngleBracket => PRESENTATION_FORM_FOR_VERTICAL_LEFT_DOUBLE_ANGLE_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalRightDoubleAngleBracket => PRESENTATION_FORM_FOR_VERTICAL_RIGHT_DOUBLE_ANGLE_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalLeftAngleBracket => PRESENTATION_FORM_FOR_VERTICAL_LEFT_ANGLE_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalRightAngleBracket => PRESENTATION_FORM_FOR_VERTICAL_RIGHT_ANGLE_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalLeftCornerBracket => PRESENTATION_FORM_FOR_VERTICAL_LEFT_CORNER_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalRightCornerBracket => PRESENTATION_FORM_FOR_VERTICAL_RIGHT_CORNER_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalLeftWhiteCornerBracket => PRESENTATION_FORM_FOR_VERTICAL_LEFT_WHITE_CORNER_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalRightWhiteCornerBracket => PRESENTATION_FORM_FOR_VERTICAL_RIGHT_WHITE_CORNER_BRACKET,
            CJKCompatibilityForms::SesameDot => SESAME_DOT,
            CJKCompatibilityForms::WhiteSesameDot => WHITE_SESAME_DOT,
            CJKCompatibilityForms::PresentationFormForVerticalLeftSquareBracket => PRESENTATION_FORM_FOR_VERTICAL_LEFT_SQUARE_BRACKET,
            CJKCompatibilityForms::PresentationFormForVerticalRightSquareBracket => PRESENTATION_FORM_FOR_VERTICAL_RIGHT_SQUARE_BRACKET,
            CJKCompatibilityForms::DashedOverline => DASHED_OVERLINE,
            CJKCompatibilityForms::CentrelineOverline => CENTRELINE_OVERLINE,
            CJKCompatibilityForms::WavyOverline => WAVY_OVERLINE,
            CJKCompatibilityForms::DoubleWavyOverline => DOUBLE_WAVY_OVERLINE,
            CJKCompatibilityForms::DashedLowLine => DASHED_LOW_LINE,
            CJKCompatibilityForms::CentrelineLowLine => CENTRELINE_LOW_LINE,
        }
    }
}

impl std::convert::TryFrom<char> for CJKCompatibilityForms {
    type Error = ();
    fn try_from(c: char) -> Result<Self, Self::Error> {
        use constants::*;
        match c {
            PRESENTATION_FORM_FOR_VERTICAL_TWO_DOT_LEADER => Ok(CJKCompatibilityForms::PresentationFormForVerticalTwoDotLeader),
            PRESENTATION_FORM_FOR_VERTICAL_EM_DASH => Ok(CJKCompatibilityForms::PresentationFormForVerticalEmDash),
            PRESENTATION_FORM_FOR_VERTICAL_EN_DASH => Ok(CJKCompatibilityForms::PresentationFormForVerticalEnDash),
            PRESENTATION_FORM_FOR_VERTICAL_LOW_LINE => Ok(CJKCompatibilityForms::PresentationFormForVerticalLowLine),
            PRESENTATION_FORM_FOR_VERTICAL_WAVY_LOW_LINE => Ok(CJKCompatibilityForms::PresentationFormForVerticalWavyLowLine),
            PRESENTATION_FORM_FOR_VERTICAL_LEFT_PARENTHESIS => Ok(CJKCompatibilityForms::PresentationFormForVerticalLeftParenthesis),
            PRESENTATION_FORM_FOR_VERTICAL_RIGHT_PARENTHESIS => Ok(CJKCompatibilityForms::PresentationFormForVerticalRightParenthesis),
            PRESENTATION_FORM_FOR_VERTICAL_LEFT_CURLY_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalLeftCurlyBracket),
            PRESENTATION_FORM_FOR_VERTICAL_RIGHT_CURLY_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalRightCurlyBracket),
            PRESENTATION_FORM_FOR_VERTICAL_LEFT_TORTOISE_SHELL_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalLeftTortoiseShellBracket),
            PRESENTATION_FORM_FOR_VERTICAL_RIGHT_TORTOISE_SHELL_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalRightTortoiseShellBracket),
            PRESENTATION_FORM_FOR_VERTICAL_LEFT_BLACK_LENTICULAR_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalLeftBlackLenticularBracket),
            PRESENTATION_FORM_FOR_VERTICAL_RIGHT_BLACK_LENTICULAR_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalRightBlackLenticularBracket),
            PRESENTATION_FORM_FOR_VERTICAL_LEFT_DOUBLE_ANGLE_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalLeftDoubleAngleBracket),
            PRESENTATION_FORM_FOR_VERTICAL_RIGHT_DOUBLE_ANGLE_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalRightDoubleAngleBracket),
            PRESENTATION_FORM_FOR_VERTICAL_LEFT_ANGLE_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalLeftAngleBracket),
            PRESENTATION_FORM_FOR_VERTICAL_RIGHT_ANGLE_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalRightAngleBracket),
            PRESENTATION_FORM_FOR_VERTICAL_LEFT_CORNER_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalLeftCornerBracket),
            PRESENTATION_FORM_FOR_VERTICAL_RIGHT_CORNER_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalRightCornerBracket),
            PRESENTATION_FORM_FOR_VERTICAL_LEFT_WHITE_CORNER_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalLeftWhiteCornerBracket),
            PRESENTATION_FORM_FOR_VERTICAL_RIGHT_WHITE_CORNER_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalRightWhiteCornerBracket),
            SESAME_DOT => Ok(CJKCompatibilityForms::SesameDot),
            WHITE_SESAME_DOT => Ok(CJKCompatibilityForms::WhiteSesameDot),
            PRESENTATION_FORM_FOR_VERTICAL_LEFT_SQUARE_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalLeftSquareBracket),
            PRESENTATION_FORM_FOR_VERTICAL_RIGHT_SQUARE_BRACKET => Ok(CJKCompatibilityForms::PresentationFormForVerticalRightSquareBracket),
            DASHED_OVERLINE => Ok(CJKCompatibilityForms::DashedOverline),
            CENTRELINE_OVERLINE => Ok(CJKCompatibilityForms::CentrelineOverline),
            WAVY_OVERLINE => Ok(CJKCompatibilityForms::WavyOverline),
            DOUBLE_WAVY_OVERLINE => Ok(CJKCompatibilityForms::DoubleWavyOverline),
            DASHED_LOW_LINE => Ok(CJKCompatibilityForms::DashedLowLine),
            CENTRELINE_LOW_LINE => Ok(CJKCompatibilityForms::CentrelineLowLine),
            _ => Err(()),
        }
    }
}

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

    /// The character's name, all lowercase and space-separated
    pub fn name(&self) -> &str {
        match self {
            CJKCompatibilityForms::PresentationFormForVerticalTwoDotLeader => "presentation form for vertical two dot leader",
            CJKCompatibilityForms::PresentationFormForVerticalEmDash => "presentation form for vertical em dash",
            CJKCompatibilityForms::PresentationFormForVerticalEnDash => "presentation form for vertical en dash",
            CJKCompatibilityForms::PresentationFormForVerticalLowLine => "presentation form for vertical low line",
            CJKCompatibilityForms::PresentationFormForVerticalWavyLowLine => "presentation form for vertical wavy low line",
            CJKCompatibilityForms::PresentationFormForVerticalLeftParenthesis => "presentation form for vertical left parenthesis",
            CJKCompatibilityForms::PresentationFormForVerticalRightParenthesis => "presentation form for vertical right parenthesis",
            CJKCompatibilityForms::PresentationFormForVerticalLeftCurlyBracket => "presentation form for vertical left curly bracket",
            CJKCompatibilityForms::PresentationFormForVerticalRightCurlyBracket => "presentation form for vertical right curly bracket",
            CJKCompatibilityForms::PresentationFormForVerticalLeftTortoiseShellBracket => "presentation form for vertical left tortoise shell bracket",
            CJKCompatibilityForms::PresentationFormForVerticalRightTortoiseShellBracket => "presentation form for vertical right tortoise shell bracket",
            CJKCompatibilityForms::PresentationFormForVerticalLeftBlackLenticularBracket => "presentation form for vertical left black lenticular bracket",
            CJKCompatibilityForms::PresentationFormForVerticalRightBlackLenticularBracket => "presentation form for vertical right black lenticular bracket",
            CJKCompatibilityForms::PresentationFormForVerticalLeftDoubleAngleBracket => "presentation form for vertical left double angle bracket",
            CJKCompatibilityForms::PresentationFormForVerticalRightDoubleAngleBracket => "presentation form for vertical right double angle bracket",
            CJKCompatibilityForms::PresentationFormForVerticalLeftAngleBracket => "presentation form for vertical left angle bracket",
            CJKCompatibilityForms::PresentationFormForVerticalRightAngleBracket => "presentation form for vertical right angle bracket",
            CJKCompatibilityForms::PresentationFormForVerticalLeftCornerBracket => "presentation form for vertical left corner bracket",
            CJKCompatibilityForms::PresentationFormForVerticalRightCornerBracket => "presentation form for vertical right corner bracket",
            CJKCompatibilityForms::PresentationFormForVerticalLeftWhiteCornerBracket => "presentation form for vertical left white corner bracket",
            CJKCompatibilityForms::PresentationFormForVerticalRightWhiteCornerBracket => "presentation form for vertical right white corner bracket",
            CJKCompatibilityForms::SesameDot => "sesame dot",
            CJKCompatibilityForms::WhiteSesameDot => "white sesame dot",
            CJKCompatibilityForms::PresentationFormForVerticalLeftSquareBracket => "presentation form for vertical left square bracket",
            CJKCompatibilityForms::PresentationFormForVerticalRightSquareBracket => "presentation form for vertical right square bracket",
            CJKCompatibilityForms::DashedOverline => "dashed overline",
            CJKCompatibilityForms::CentrelineOverline => "centreline overline",
            CJKCompatibilityForms::WavyOverline => "wavy overline",
            CJKCompatibilityForms::DoubleWavyOverline => "double wavy overline",
            CJKCompatibilityForms::DashedLowLine => "dashed low line",
            CJKCompatibilityForms::CentrelineLowLine => "centreline low line",
        }
    }
}