1
2#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
4pub enum Ugaritic {
5 LetterAlpa,
7 LetterBeta,
9 LetterGamla,
11 LetterKha,
13 LetterDelta,
15 LetterHo,
17 LetterWo,
19 LetterZeta,
21 LetterHota,
23 LetterTet,
25 LetterYod,
27 LetterKaf,
29 LetterShin,
31 LetterLamda,
33 LetterMem,
35 LetterDhal,
37 LetterNun,
39 LetterZu,
41 LetterSamka,
43 LetterAin,
45 LetterPu,
47 LetterSade,
49 LetterQopa,
51 LetterRasha,
53 LetterThanna,
55 LetterGhain,
57 LetterTo,
59 LetterI,
61 LetterU,
63 LetterSsu,
65}
66
67impl Into<char> for Ugaritic {
68 fn into(self) -> char {
69 match self {
70 Ugaritic::LetterAlpa => '𐎀',
71 Ugaritic::LetterBeta => '𐎁',
72 Ugaritic::LetterGamla => '𐎂',
73 Ugaritic::LetterKha => '𐎃',
74 Ugaritic::LetterDelta => '𐎄',
75 Ugaritic::LetterHo => '𐎅',
76 Ugaritic::LetterWo => '𐎆',
77 Ugaritic::LetterZeta => '𐎇',
78 Ugaritic::LetterHota => '𐎈',
79 Ugaritic::LetterTet => '𐎉',
80 Ugaritic::LetterYod => '𐎊',
81 Ugaritic::LetterKaf => '𐎋',
82 Ugaritic::LetterShin => '𐎌',
83 Ugaritic::LetterLamda => '𐎍',
84 Ugaritic::LetterMem => '𐎎',
85 Ugaritic::LetterDhal => '𐎏',
86 Ugaritic::LetterNun => '𐎐',
87 Ugaritic::LetterZu => '𐎑',
88 Ugaritic::LetterSamka => '𐎒',
89 Ugaritic::LetterAin => '𐎓',
90 Ugaritic::LetterPu => '𐎔',
91 Ugaritic::LetterSade => '𐎕',
92 Ugaritic::LetterQopa => '𐎖',
93 Ugaritic::LetterRasha => '𐎗',
94 Ugaritic::LetterThanna => '𐎘',
95 Ugaritic::LetterGhain => '𐎙',
96 Ugaritic::LetterTo => '𐎚',
97 Ugaritic::LetterI => '𐎛',
98 Ugaritic::LetterU => '𐎜',
99 Ugaritic::LetterSsu => '𐎝',
100 }
101 }
102}
103
104impl std::convert::TryFrom<char> for Ugaritic {
105 type Error = ();
106 fn try_from(c: char) -> Result<Self, Self::Error> {
107 match c {
108 '𐎀' => Ok(Ugaritic::LetterAlpa),
109 '𐎁' => Ok(Ugaritic::LetterBeta),
110 '𐎂' => Ok(Ugaritic::LetterGamla),
111 '𐎃' => Ok(Ugaritic::LetterKha),
112 '𐎄' => Ok(Ugaritic::LetterDelta),
113 '𐎅' => Ok(Ugaritic::LetterHo),
114 '𐎆' => Ok(Ugaritic::LetterWo),
115 '𐎇' => Ok(Ugaritic::LetterZeta),
116 '𐎈' => Ok(Ugaritic::LetterHota),
117 '𐎉' => Ok(Ugaritic::LetterTet),
118 '𐎊' => Ok(Ugaritic::LetterYod),
119 '𐎋' => Ok(Ugaritic::LetterKaf),
120 '𐎌' => Ok(Ugaritic::LetterShin),
121 '𐎍' => Ok(Ugaritic::LetterLamda),
122 '𐎎' => Ok(Ugaritic::LetterMem),
123 '𐎏' => Ok(Ugaritic::LetterDhal),
124 '𐎐' => Ok(Ugaritic::LetterNun),
125 '𐎑' => Ok(Ugaritic::LetterZu),
126 '𐎒' => Ok(Ugaritic::LetterSamka),
127 '𐎓' => Ok(Ugaritic::LetterAin),
128 '𐎔' => Ok(Ugaritic::LetterPu),
129 '𐎕' => Ok(Ugaritic::LetterSade),
130 '𐎖' => Ok(Ugaritic::LetterQopa),
131 '𐎗' => Ok(Ugaritic::LetterRasha),
132 '𐎘' => Ok(Ugaritic::LetterThanna),
133 '𐎙' => Ok(Ugaritic::LetterGhain),
134 '𐎚' => Ok(Ugaritic::LetterTo),
135 '𐎛' => Ok(Ugaritic::LetterI),
136 '𐎜' => Ok(Ugaritic::LetterU),
137 '𐎝' => Ok(Ugaritic::LetterSsu),
138 _ => Err(()),
139 }
140 }
141}
142
143impl Into<u32> for Ugaritic {
144 fn into(self) -> u32 {
145 let c: char = self.into();
146 let hex = c
147 .escape_unicode()
148 .to_string()
149 .replace("\\u{", "")
150 .replace("}", "");
151 u32::from_str_radix(&hex, 16).unwrap()
152 }
153}
154
155impl std::convert::TryFrom<u32> for Ugaritic {
156 type Error = ();
157 fn try_from(u: u32) -> Result<Self, Self::Error> {
158 if let Ok(c) = char::try_from(u) {
159 Self::try_from(c)
160 } else {
161 Err(())
162 }
163 }
164}
165
166impl Iterator for Ugaritic {
167 type Item = Self;
168 fn next(&mut self) -> Option<Self> {
169 let index: u32 = (*self).into();
170 use std::convert::TryFrom;
171 Self::try_from(index + 1).ok()
172 }
173}
174
175impl Ugaritic {
176 pub fn new() -> Self {
178 Ugaritic::LetterAlpa
179 }
180
181 pub fn name(&self) -> String {
183 let s = std::format!("Ugaritic{:#?}", self);
184 string_morph::to_sentence_case(&s)
185 }
186}