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
mod constants {
pub const NORTH_INDIC_FRACTION_ONE_QUARTER: char = '꠰';
pub const NORTH_INDIC_FRACTION_ONE_HALF: char = '꠱';
pub const NORTH_INDIC_FRACTION_THREE_QUARTERS: char = '꠲';
pub const NORTH_INDIC_FRACTION_ONE_SIXTEENTH: char = '꠳';
pub const NORTH_INDIC_FRACTION_ONE_EIGHTH: char = '꠴';
pub const NORTH_INDIC_FRACTION_THREE_SIXTEENTHS: char = '꠵';
pub const NORTH_INDIC_QUARTER_MARK: char = '꠶';
pub const NORTH_INDIC_PLACEHOLDER_MARK: char = '꠷';
pub const NORTH_INDIC_RUPEE_MARK: char = '꠸';
pub const NORTH_INDIC_QUANTITY_MARK: char = '꠹';
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum CommonIndicNumberForms {
NorthIndicFractionOneQuarter,
NorthIndicFractionOneHalf,
NorthIndicFractionThreeQuarters,
NorthIndicFractionOneSixteenth,
NorthIndicFractionOneEighth,
NorthIndicFractionThreeSixteenths,
NorthIndicQuarterMark,
NorthIndicPlaceholderMark,
NorthIndicRupeeMark,
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 {
pub fn new() -> Self {
CommonIndicNumberForms::NorthIndicFractionOneQuarter
}
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",
}
}
}