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
/// A number of constants to give a name to all characters in this block.
mod constants {
    /// \u{10190}: '𐆐'
    pub const ROMAN_SEXTANS_SIGN: char = '𐆐';
    /// \u{10191}: '𐆑'
    pub const ROMAN_UNCIA_SIGN: char = '𐆑';
    /// \u{10192}: '𐆒'
    pub const ROMAN_SEMUNCIA_SIGN: char = '𐆒';
    /// \u{10193}: '𐆓'
    pub const ROMAN_SEXTULA_SIGN: char = '𐆓';
    /// \u{10194}: '𐆔'
    pub const ROMAN_DIMIDIA_SEXTULA_SIGN: char = '𐆔';
    /// \u{10195}: '𐆕'
    pub const ROMAN_SILIQUA_SIGN: char = '𐆕';
    /// \u{10196}: '𐆖'
    pub const ROMAN_DENARIUS_SIGN: char = '𐆖';
    /// \u{10197}: '𐆗'
    pub const ROMAN_QUINARIUS_SIGN: char = '𐆗';
    /// \u{10198}: '𐆘'
    pub const ROMAN_SESTERTIUS_SIGN: char = '𐆘';
    /// \u{10199}: '𐆙'
    pub const ROMAN_DUPONDIUS_SIGN: char = '𐆙';
    /// \u{1019a}: '𐆚'
    pub const ROMAN_AS_SIGN: char = '𐆚';
    /// \u{1019b}: '𐆛'
    pub const ROMAN_CENTURIAL_SIGN: char = '𐆛';
    /// \u{101a0}: '𐆠'
    pub const GREEK_SYMBOL_TAU_RHO: char = '𐆠';
}

/// An enum to represent all characters in the AncientSymbols block.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum AncientSymbols {
    /// \u{10190}: '𐆐'
    RomanSextansSign,
    /// \u{10191}: '𐆑'
    RomanUnciaSign,
    /// \u{10192}: '𐆒'
    RomanSemunciaSign,
    /// \u{10193}: '𐆓'
    RomanSextulaSign,
    /// \u{10194}: '𐆔'
    RomanDimidiaSextulaSign,
    /// \u{10195}: '𐆕'
    RomanSiliquaSign,
    /// \u{10196}: '𐆖'
    RomanDenariusSign,
    /// \u{10197}: '𐆗'
    RomanQuinariusSign,
    /// \u{10198}: '𐆘'
    RomanSestertiusSign,
    /// \u{10199}: '𐆙'
    RomanDupondiusSign,
    /// \u{1019a}: '𐆚'
    RomanAsSign,
    /// \u{1019b}: '𐆛'
    RomanCenturialSign,
    /// \u{101a0}: '𐆠'
    GreekSymbolTauRho,
}

impl Into<char> for AncientSymbols {
    fn into(self) -> char {
        use constants::*;
        match self {
            AncientSymbols::RomanSextansSign => ROMAN_SEXTANS_SIGN,
            AncientSymbols::RomanUnciaSign => ROMAN_UNCIA_SIGN,
            AncientSymbols::RomanSemunciaSign => ROMAN_SEMUNCIA_SIGN,
            AncientSymbols::RomanSextulaSign => ROMAN_SEXTULA_SIGN,
            AncientSymbols::RomanDimidiaSextulaSign => ROMAN_DIMIDIA_SEXTULA_SIGN,
            AncientSymbols::RomanSiliquaSign => ROMAN_SILIQUA_SIGN,
            AncientSymbols::RomanDenariusSign => ROMAN_DENARIUS_SIGN,
            AncientSymbols::RomanQuinariusSign => ROMAN_QUINARIUS_SIGN,
            AncientSymbols::RomanSestertiusSign => ROMAN_SESTERTIUS_SIGN,
            AncientSymbols::RomanDupondiusSign => ROMAN_DUPONDIUS_SIGN,
            AncientSymbols::RomanAsSign => ROMAN_AS_SIGN,
            AncientSymbols::RomanCenturialSign => ROMAN_CENTURIAL_SIGN,
            AncientSymbols::GreekSymbolTauRho => GREEK_SYMBOL_TAU_RHO,
        }
    }
}

impl std::convert::TryFrom<char> for AncientSymbols {
    type Error = ();
    fn try_from(c: char) -> Result<Self, Self::Error> {
        use constants::*;
        match c {
            ROMAN_SEXTANS_SIGN => Ok(AncientSymbols::RomanSextansSign),
            ROMAN_UNCIA_SIGN => Ok(AncientSymbols::RomanUnciaSign),
            ROMAN_SEMUNCIA_SIGN => Ok(AncientSymbols::RomanSemunciaSign),
            ROMAN_SEXTULA_SIGN => Ok(AncientSymbols::RomanSextulaSign),
            ROMAN_DIMIDIA_SEXTULA_SIGN => Ok(AncientSymbols::RomanDimidiaSextulaSign),
            ROMAN_SILIQUA_SIGN => Ok(AncientSymbols::RomanSiliquaSign),
            ROMAN_DENARIUS_SIGN => Ok(AncientSymbols::RomanDenariusSign),
            ROMAN_QUINARIUS_SIGN => Ok(AncientSymbols::RomanQuinariusSign),
            ROMAN_SESTERTIUS_SIGN => Ok(AncientSymbols::RomanSestertiusSign),
            ROMAN_DUPONDIUS_SIGN => Ok(AncientSymbols::RomanDupondiusSign),
            ROMAN_AS_SIGN => Ok(AncientSymbols::RomanAsSign),
            ROMAN_CENTURIAL_SIGN => Ok(AncientSymbols::RomanCenturialSign),
            GREEK_SYMBOL_TAU_RHO => Ok(AncientSymbols::GreekSymbolTauRho),
            _ => Err(()),
        }
    }
}

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

    /// The character's name, all lowercase and space-separated
    pub fn name(&self) -> &str {
        match self {
            AncientSymbols::RomanSextansSign => "roman sextans sign",
            AncientSymbols::RomanUnciaSign => "roman uncia sign",
            AncientSymbols::RomanSemunciaSign => "roman semuncia sign",
            AncientSymbols::RomanSextulaSign => "roman sextula sign",
            AncientSymbols::RomanDimidiaSextulaSign => "roman dimidia sextula sign",
            AncientSymbols::RomanSiliquaSign => "roman siliqua sign",
            AncientSymbols::RomanDenariusSign => "roman denarius sign",
            AncientSymbols::RomanQuinariusSign => "roman quinarius sign",
            AncientSymbols::RomanSestertiusSign => "roman sestertius sign",
            AncientSymbols::RomanDupondiusSign => "roman dupondius sign",
            AncientSymbols::RomanAsSign => "roman as sign",
            AncientSymbols::RomanCenturialSign => "roman centurial sign",
            AncientSymbols::GreekSymbolTauRho => "greek symbol tau rho",
        }
    }
}