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
/// A number of constants to give a name to all characters in this block.
mod constants {
    /// \u{fe20}: '︠'
    pub const COMBINING_LIGATURE_LEFT_HALF: char = '︠';
    /// \u{fe21}: '︡'
    pub const COMBINING_LIGATURE_RIGHT_HALF: char = '︡';
    /// \u{fe22}: '︢'
    pub const COMBINING_DOUBLE_TILDE_LEFT_HALF: char = '︢';
    /// \u{fe23}: '︣'
    pub const COMBINING_DOUBLE_TILDE_RIGHT_HALF: char = '︣';
    /// \u{fe24}: '︤'
    pub const COMBINING_MACRON_LEFT_HALF: char = '︤';
    /// \u{fe25}: '︥'
    pub const COMBINING_MACRON_RIGHT_HALF: char = '︥';
    /// \u{fe26}: '︦'
    pub const COMBINING_CONJOINING_MACRON: char = '︦';
    /// \u{fe27}: '︧'
    pub const COMBINING_LIGATURE_LEFT_HALF_BELOW: char = '︧';
    /// \u{fe28}: '︨'
    pub const COMBINING_LIGATURE_RIGHT_HALF_BELOW: char = '︨';
    /// \u{fe29}: '︩'
    pub const COMBINING_TILDE_LEFT_HALF_BELOW: char = '︩';
    /// \u{fe2a}: '︪'
    pub const COMBINING_TILDE_RIGHT_HALF_BELOW: char = '︪';
    /// \u{fe2b}: '︫'
    pub const COMBINING_MACRON_LEFT_HALF_BELOW: char = '︫';
    /// \u{fe2c}: '︬'
    pub const COMBINING_MACRON_RIGHT_HALF_BELOW: char = '︬';
    /// \u{fe2d}: '︭'
    pub const COMBINING_CONJOINING_MACRON_BELOW: char = '︭';
    /// \u{fe2e}: '︮'
    pub const COMBINING_CYRILLIC_TITLO_LEFT_HALF: char = '︮';
}

/// An enum to represent all characters in the CombiningHalfMarks block.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum CombiningHalfMarks {
    /// \u{fe20}: '︠'
    CombiningLigatureLeftHalf,
    /// \u{fe21}: '︡'
    CombiningLigatureRightHalf,
    /// \u{fe22}: '︢'
    CombiningDoubleTildeLeftHalf,
    /// \u{fe23}: '︣'
    CombiningDoubleTildeRightHalf,
    /// \u{fe24}: '︤'
    CombiningMacronLeftHalf,
    /// \u{fe25}: '︥'
    CombiningMacronRightHalf,
    /// \u{fe26}: '︦'
    CombiningConjoiningMacron,
    /// \u{fe27}: '︧'
    CombiningLigatureLeftHalfBelow,
    /// \u{fe28}: '︨'
    CombiningLigatureRightHalfBelow,
    /// \u{fe29}: '︩'
    CombiningTildeLeftHalfBelow,
    /// \u{fe2a}: '︪'
    CombiningTildeRightHalfBelow,
    /// \u{fe2b}: '︫'
    CombiningMacronLeftHalfBelow,
    /// \u{fe2c}: '︬'
    CombiningMacronRightHalfBelow,
    /// \u{fe2d}: '︭'
    CombiningConjoiningMacronBelow,
    /// \u{fe2e}: '︮'
    CombiningCyrillicTitloLeftHalf,
}

impl Into<char> for CombiningHalfMarks {
    fn into(self) -> char {
        use constants::*;
        match self {
            CombiningHalfMarks::CombiningLigatureLeftHalf => COMBINING_LIGATURE_LEFT_HALF,
            CombiningHalfMarks::CombiningLigatureRightHalf => COMBINING_LIGATURE_RIGHT_HALF,
            CombiningHalfMarks::CombiningDoubleTildeLeftHalf => COMBINING_DOUBLE_TILDE_LEFT_HALF,
            CombiningHalfMarks::CombiningDoubleTildeRightHalf => COMBINING_DOUBLE_TILDE_RIGHT_HALF,
            CombiningHalfMarks::CombiningMacronLeftHalf => COMBINING_MACRON_LEFT_HALF,
            CombiningHalfMarks::CombiningMacronRightHalf => COMBINING_MACRON_RIGHT_HALF,
            CombiningHalfMarks::CombiningConjoiningMacron => COMBINING_CONJOINING_MACRON,
            CombiningHalfMarks::CombiningLigatureLeftHalfBelow => COMBINING_LIGATURE_LEFT_HALF_BELOW,
            CombiningHalfMarks::CombiningLigatureRightHalfBelow => COMBINING_LIGATURE_RIGHT_HALF_BELOW,
            CombiningHalfMarks::CombiningTildeLeftHalfBelow => COMBINING_TILDE_LEFT_HALF_BELOW,
            CombiningHalfMarks::CombiningTildeRightHalfBelow => COMBINING_TILDE_RIGHT_HALF_BELOW,
            CombiningHalfMarks::CombiningMacronLeftHalfBelow => COMBINING_MACRON_LEFT_HALF_BELOW,
            CombiningHalfMarks::CombiningMacronRightHalfBelow => COMBINING_MACRON_RIGHT_HALF_BELOW,
            CombiningHalfMarks::CombiningConjoiningMacronBelow => COMBINING_CONJOINING_MACRON_BELOW,
            CombiningHalfMarks::CombiningCyrillicTitloLeftHalf => COMBINING_CYRILLIC_TITLO_LEFT_HALF,
        }
    }
}

impl std::convert::TryFrom<char> for CombiningHalfMarks {
    type Error = ();
    fn try_from(c: char) -> Result<Self, Self::Error> {
        use constants::*;
        match c {
            COMBINING_LIGATURE_LEFT_HALF => Ok(CombiningHalfMarks::CombiningLigatureLeftHalf),
            COMBINING_LIGATURE_RIGHT_HALF => Ok(CombiningHalfMarks::CombiningLigatureRightHalf),
            COMBINING_DOUBLE_TILDE_LEFT_HALF => Ok(CombiningHalfMarks::CombiningDoubleTildeLeftHalf),
            COMBINING_DOUBLE_TILDE_RIGHT_HALF => Ok(CombiningHalfMarks::CombiningDoubleTildeRightHalf),
            COMBINING_MACRON_LEFT_HALF => Ok(CombiningHalfMarks::CombiningMacronLeftHalf),
            COMBINING_MACRON_RIGHT_HALF => Ok(CombiningHalfMarks::CombiningMacronRightHalf),
            COMBINING_CONJOINING_MACRON => Ok(CombiningHalfMarks::CombiningConjoiningMacron),
            COMBINING_LIGATURE_LEFT_HALF_BELOW => Ok(CombiningHalfMarks::CombiningLigatureLeftHalfBelow),
            COMBINING_LIGATURE_RIGHT_HALF_BELOW => Ok(CombiningHalfMarks::CombiningLigatureRightHalfBelow),
            COMBINING_TILDE_LEFT_HALF_BELOW => Ok(CombiningHalfMarks::CombiningTildeLeftHalfBelow),
            COMBINING_TILDE_RIGHT_HALF_BELOW => Ok(CombiningHalfMarks::CombiningTildeRightHalfBelow),
            COMBINING_MACRON_LEFT_HALF_BELOW => Ok(CombiningHalfMarks::CombiningMacronLeftHalfBelow),
            COMBINING_MACRON_RIGHT_HALF_BELOW => Ok(CombiningHalfMarks::CombiningMacronRightHalfBelow),
            COMBINING_CONJOINING_MACRON_BELOW => Ok(CombiningHalfMarks::CombiningConjoiningMacronBelow),
            COMBINING_CYRILLIC_TITLO_LEFT_HALF => Ok(CombiningHalfMarks::CombiningCyrillicTitloLeftHalf),
            _ => Err(()),
        }
    }
}

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

    /// The character's name, all lowercase and space-separated
    pub fn name(&self) -> &str {
        match self {
            CombiningHalfMarks::CombiningLigatureLeftHalf => "combining ligature left half",
            CombiningHalfMarks::CombiningLigatureRightHalf => "combining ligature right half",
            CombiningHalfMarks::CombiningDoubleTildeLeftHalf => "combining double tilde left half",
            CombiningHalfMarks::CombiningDoubleTildeRightHalf => "combining double tilde right half",
            CombiningHalfMarks::CombiningMacronLeftHalf => "combining macron left half",
            CombiningHalfMarks::CombiningMacronRightHalf => "combining macron right half",
            CombiningHalfMarks::CombiningConjoiningMacron => "combining conjoining macron",
            CombiningHalfMarks::CombiningLigatureLeftHalfBelow => "combining ligature left half below",
            CombiningHalfMarks::CombiningLigatureRightHalfBelow => "combining ligature right half below",
            CombiningHalfMarks::CombiningTildeLeftHalfBelow => "combining tilde left half below",
            CombiningHalfMarks::CombiningTildeRightHalfBelow => "combining tilde right half below",
            CombiningHalfMarks::CombiningMacronLeftHalfBelow => "combining macron left half below",
            CombiningHalfMarks::CombiningMacronRightHalfBelow => "combining macron right half below",
            CombiningHalfMarks::CombiningConjoiningMacronBelow => "combining conjoining macron below",
            CombiningHalfMarks::CombiningCyrillicTitloLeftHalf => "combining cyrillic titlo left half",
        }
    }
}