rusmpp_extra/encoding/gsm7bit/alphabet/
default.rs1use super::Encoded;
2
3#[non_exhaustive]
4#[derive(Debug)]
5pub struct Gsm7BitDefaultAlphabet;
7
8impl Default for Gsm7BitDefaultAlphabet {
9 fn default() -> Self {
10 Self::new()
11 }
12}
13
14impl Gsm7BitDefaultAlphabet {
15 pub const fn new() -> Self {
17 Self
18 }
19}
20
21impl Gsm7BitDefaultAlphabet {
22 pub(super) const fn encode(&self, ch: char) -> Option<Encoded> {
27 if let Some(byte) = Standard::encode(ch) {
28 Some(Encoded::Standard(byte))
29 } else if let Some(byte) = Extended::encode(ch) {
30 Some(Encoded::Extended(byte))
31 } else {
32 None
33 }
34 }
35}
36
37struct Standard;
38
39struct Extended;
40
41impl Standard {
42 const fn encode(ch: char) -> Option<u8> {
43 let byte = match ch {
44 '@' => 0x00,
45 '£' => 0x01,
46 '$' => 0x02,
47 '¥' => 0x03,
48 'è' => 0x04,
49 'é' => 0x05,
50 'ù' => 0x06,
51 'ì' => 0x07,
52 'ò' => 0x08,
53 'Ç' => 0x09,
54 '\n' => 0x0a,
55 'Ø' => 0x0b,
56 'ø' => 0x0c,
57 '\r' => 0x0d,
58 'Å' => 0x0e,
59 'å' => 0x0f,
60
61 'Δ' => 0x10,
62 '_' => 0x11,
63 'Φ' => 0x12,
64 'Γ' => 0x13,
65 'Λ' => 0x14,
66 'Ω' => 0x15,
67 'Π' => 0x16,
68 'Ψ' => 0x17,
69 'Σ' => 0x18,
70 'Θ' => 0x19,
71 'Ξ' => 0x1A,
72 'Æ' => 0x1C,
73 'æ' => 0x1D,
74 'ß' => 0x1E,
75 'É' => 0x1F,
76
77 ' ' => 0x20,
78 '!' => 0x21,
79 '"' => 0x22,
80 '#' => 0x23,
81 '¤' => 0x24,
82 '%' => 0x25,
83 '&' => 0x26,
84 '\'' => 0x27,
85 '(' => 0x28,
86 ')' => 0x29,
87 '*' => 0x2A,
88 '+' => 0x2B,
89 ',' => 0x2C,
90 '-' => 0x2D,
91 '.' => 0x2E,
92 '/' => 0x2F,
93
94 '0' => 0x30,
95 '1' => 0x31,
96 '2' => 0x32,
97 '3' => 0x33,
98 '4' => 0x34,
99 '5' => 0x35,
100 '6' => 0x36,
101 '7' => 0x37,
102 '8' => 0x38,
103 '9' => 0x39,
104 ':' => 0x3A,
105 ';' => 0x3B,
106 '<' => 0x3C,
107 '=' => 0x3D,
108 '>' => 0x3E,
109 '?' => 0x3F,
110
111 '¡' => 0x40,
112 'A' => 0x41,
113 'B' => 0x42,
114 'C' => 0x43,
115 'D' => 0x44,
116 'E' => 0x45,
117 'F' => 0x46,
118 'G' => 0x47,
119 'H' => 0x48,
120 'I' => 0x49,
121 'J' => 0x4A,
122 'K' => 0x4B,
123 'L' => 0x4C,
124 'M' => 0x4D,
125 'N' => 0x4E,
126 'O' => 0x4F,
127
128 'P' => 0x50,
129 'Q' => 0x51,
130 'R' => 0x52,
131 'S' => 0x53,
132 'T' => 0x54,
133 'U' => 0x55,
134 'V' => 0x56,
135 'W' => 0x57,
136 'X' => 0x58,
137 'Y' => 0x59,
138 'Z' => 0x5A,
139 'Ä' => 0x5B,
140 'Ö' => 0x5C,
141 'Ñ' => 0x5D,
142 'Ü' => 0x5E,
143 '§' => 0x5F,
144
145 '¿' => 0x60,
146 'a' => 0x61,
147 'b' => 0x62,
148 'c' => 0x63,
149 'd' => 0x64,
150 'e' => 0x65,
151 'f' => 0x66,
152 'g' => 0x67,
153 'h' => 0x68,
154 'i' => 0x69,
155 'j' => 0x6A,
156 'k' => 0x6B,
157 'l' => 0x6C,
158 'm' => 0x6D,
159 'n' => 0x6E,
160 'o' => 0x6F,
161
162 'p' => 0x70,
163 'q' => 0x71,
164 'r' => 0x72,
165 's' => 0x73,
166 't' => 0x74,
167 'u' => 0x75,
168 'v' => 0x76,
169 'w' => 0x77,
170 'x' => 0x78,
171 'y' => 0x79,
172 'z' => 0x7A,
173 'ä' => 0x7B,
174 'ö' => 0x7C,
175 'ñ' => 0x7D,
176 'ü' => 0x7E,
177 'à' => 0x7F,
178 _ => return None,
179 };
180
181 Some(byte)
182 }
183}
184
185impl Extended {
186 const fn encode(ch: char) -> Option<u8> {
187 let byte = match ch {
188 '^' => 0x14,
189 '{' => 0x28,
190 '}' => 0x29,
191 '\\' => 0x2F,
192 '[' => 0x3C,
193 '~' => 0x3D,
194 ']' => 0x3E,
195 '|' => 0x40,
196 '€' => 0x65,
197 _ => return None,
198 };
199
200 Some(byte)
201 }
202}