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
/// A number of constants to give a name to all characters in this block.
mod constants {
    /// \u{a830}: '꠰'
    pub const NORTH_INDIC_FRACTION_ONE_QUARTER: char = '꠰';
    /// \u{a831}: '꠱'
    pub const NORTH_INDIC_FRACTION_ONE_HALF: char = '꠱';
    /// \u{a832}: '꠲'
    pub const NORTH_INDIC_FRACTION_THREE_QUARTERS: char = '꠲';
    /// \u{a833}: '꠳'
    pub const NORTH_INDIC_FRACTION_ONE_SIXTEENTH: char = '꠳';
    /// \u{a834}: '꠴'
    pub const NORTH_INDIC_FRACTION_ONE_EIGHTH: char = '꠴';
    /// \u{a835}: '꠵'
    pub const NORTH_INDIC_FRACTION_THREE_SIXTEENTHS: char = '꠵';
    /// \u{a836}: '꠶'
    pub const NORTH_INDIC_QUARTER_MARK: char = '꠶';
    /// \u{a837}: '꠷'
    pub const NORTH_INDIC_PLACEHOLDER_MARK: char = '꠷';
    /// \u{a838}: '꠸'
    pub const NORTH_INDIC_RUPEE_MARK: char = '꠸';
    /// \u{a839}: '꠹'
    pub const NORTH_INDIC_QUANTITY_MARK: char = '꠹';
}

/// An enum to represent all characters in the CommonIndicNumberForms block.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum CommonIndicNumberForms {
    /// \u{a830}: '꠰'
    NorthIndicFractionOneQuarter,
    /// \u{a831}: '꠱'
    NorthIndicFractionOneHalf,
    /// \u{a832}: '꠲'
    NorthIndicFractionThreeQuarters,
    /// \u{a833}: '꠳'
    NorthIndicFractionOneSixteenth,
    /// \u{a834}: '꠴'
    NorthIndicFractionOneEighth,
    /// \u{a835}: '꠵'
    NorthIndicFractionThreeSixteenths,
    /// \u{a836}: '꠶'
    NorthIndicQuarterMark,
    /// \u{a837}: '꠷'
    NorthIndicPlaceholderMark,
    /// \u{a838}: '꠸'
    NorthIndicRupeeMark,
    /// \u{a839}: '꠹'
    NorthIndicQuantityMark,
}

impl Into<char> for CommonIndicNumberForms {
    fn into(self) -> char {
        use constants::*;
        match self {
            CommonIndicNumberForms::NorthIndicFractionOneQuarter => NORTH_INDIC_FRACTION_ONE_QUARTER,
            CommonIndicNumberForms::NorthIndicFractionOneHalf => NORTH_INDIC_FRACTION_ONE_HALF,
            CommonIndicNumberForms::NorthIndicFractionThreeQuarters => NORTH_INDIC_FRACTION_THREE_QUARTERS,
            CommonIndicNumberForms::NorthIndicFractionOneSixteenth => NORTH_INDIC_FRACTION_ONE_SIXTEENTH,
            CommonIndicNumberForms::NorthIndicFractionOneEighth => NORTH_INDIC_FRACTION_ONE_EIGHTH,
            CommonIndicNumberForms::NorthIndicFractionThreeSixteenths => NORTH_INDIC_FRACTION_THREE_SIXTEENTHS,
            CommonIndicNumberForms::NorthIndicQuarterMark => NORTH_INDIC_QUARTER_MARK,
            CommonIndicNumberForms::NorthIndicPlaceholderMark => NORTH_INDIC_PLACEHOLDER_MARK,
            CommonIndicNumberForms::NorthIndicRupeeMark => NORTH_INDIC_RUPEE_MARK,
            CommonIndicNumberForms::NorthIndicQuantityMark => NORTH_INDIC_QUANTITY_MARK,
        }
    }
}

impl std::convert::TryFrom<char> for CommonIndicNumberForms {
    type Error = ();
    fn try_from(c: char) -> Result<Self, Self::Error> {
        use constants::*;
        match c {
            NORTH_INDIC_FRACTION_ONE_QUARTER => Ok(CommonIndicNumberForms::NorthIndicFractionOneQuarter),
            NORTH_INDIC_FRACTION_ONE_HALF => Ok(CommonIndicNumberForms::NorthIndicFractionOneHalf),
            NORTH_INDIC_FRACTION_THREE_QUARTERS => Ok(CommonIndicNumberForms::NorthIndicFractionThreeQuarters),
            NORTH_INDIC_FRACTION_ONE_SIXTEENTH => Ok(CommonIndicNumberForms::NorthIndicFractionOneSixteenth),
            NORTH_INDIC_FRACTION_ONE_EIGHTH => Ok(CommonIndicNumberForms::NorthIndicFractionOneEighth),
            NORTH_INDIC_FRACTION_THREE_SIXTEENTHS => Ok(CommonIndicNumberForms::NorthIndicFractionThreeSixteenths),
            NORTH_INDIC_QUARTER_MARK => Ok(CommonIndicNumberForms::NorthIndicQuarterMark),
            NORTH_INDIC_PLACEHOLDER_MARK => Ok(CommonIndicNumberForms::NorthIndicPlaceholderMark),
            NORTH_INDIC_RUPEE_MARK => Ok(CommonIndicNumberForms::NorthIndicRupeeMark),
            NORTH_INDIC_QUANTITY_MARK => Ok(CommonIndicNumberForms::NorthIndicQuantityMark),
            _ => Err(()),
        }
    }
}

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

    /// The character's name, all lowercase and space-separated
    pub fn name(&self) -> &str {
        match self {
            CommonIndicNumberForms::NorthIndicFractionOneQuarter => "north indic fraction one quarter",
            CommonIndicNumberForms::NorthIndicFractionOneHalf => "north indic fraction one half",
            CommonIndicNumberForms::NorthIndicFractionThreeQuarters => "north indic fraction three quarters",
            CommonIndicNumberForms::NorthIndicFractionOneSixteenth => "north indic fraction one sixteenth",
            CommonIndicNumberForms::NorthIndicFractionOneEighth => "north indic fraction one eighth",
            CommonIndicNumberForms::NorthIndicFractionThreeSixteenths => "north indic fraction three sixteenths",
            CommonIndicNumberForms::NorthIndicQuarterMark => "north indic quarter mark",
            CommonIndicNumberForms::NorthIndicPlaceholderMark => "north indic placeholder mark",
            CommonIndicNumberForms::NorthIndicRupeeMark => "north indic rupee mark",
            CommonIndicNumberForms::NorthIndicQuantityMark => "north indic quantity mark",
        }
    }
}