1#![no_std]
2pub mod ranges {
6
7 pub const fn ranges(r: Ranges) -> &'static [RangeInclusive<usize>] {
16 match r {
17 | Ranges::Printable => &PRINTABLE,
18 | Ranges::Control => &CONTROL,
19 | Ranges::Capital => &CAPITAL,
20 | Ranges::Small => &SMALL,
21 | Ranges::Letters => &LETTERS,
22 | Ranges::Digits => &DIGITS,
23 | Ranges::Symbols => &SYMBOLS,
24 | Ranges::Table => &TABLE,
25 }
26 }
27
28 #[derive(Clone, PartialEq, Debug)]
30 pub enum Ranges {
31 Printable,
33 Control,
35 Capital,
37 Small,
39 Letters,
41 Digits,
43 Symbols,
45 Table,
47 }
48
49 use core::ops::RangeInclusive;
50
51 pub static PRINTABLE: [RangeInclusive<usize>; 1] = [(32..=126)];
53 pub static CONTROL: [RangeInclusive<usize>; 2] = [(0..=31), (127..=127)];
55 pub static CAPITAL: [RangeInclusive<usize>; 1] = [(65..=90)];
57 pub static SMALL: [RangeInclusive<usize>; 1] = [(97..=122)];
59 pub static LETTERS: [RangeInclusive<usize>; 2] = [(65..=90), (97..=122)];
61 pub static DIGITS: [RangeInclusive<usize>; 1] = [(48..=57)];
63 pub static SYMBOLS: [RangeInclusive<usize>; 4] = [(32..=47), (58..=64), (91..=96), (123..=126)];
65 pub static TABLE: [RangeInclusive<usize>; 1] = [(0..=127)];
67
68 #[cfg(test)]
69 mod tests_of_units {
70
71 extern crate std;
72 use std::vec::Vec;
73 use super::{ranges as ranges_fn, *};
74 use huski_auxies::{ccr1, ccr2, len};
75
76 #[test]
77 fn ranges() {
78 assert_eq!(&PRINTABLE, ranges_fn(Ranges::Printable));
79 assert_eq!(&CONTROL, ranges_fn(Ranges::Control));
80 assert_eq!(&CAPITAL, ranges_fn(Ranges::Capital));
81 assert_eq!(&SMALL, ranges_fn(Ranges::Small));
82 assert_eq!(&LETTERS, ranges_fn(Ranges::Letters));
83 assert_eq!(&DIGITS, ranges_fn(Ranges::Digits));
84 assert_eq!(&SYMBOLS, ranges_fn(Ranges::Symbols));
85 assert_eq!(&TABLE, ranges_fn(Ranges::Table));
86 }
87
88 #[test]
89 fn printable() {
90 let start = 0x20; let end = 0x7e; assert_eq!(1, PRINTABLE.len());
94
95 let printable = ccr2!(&PRINTABLE);
96 let proof = ccr1!(start..=end);
97
98 assert_eq!(proof, printable);
99 }
100
101 #[test]
102 fn control() {
103 let start = 0x0; let end = 0x1f; let extra = 0x7f; assert_eq!(2, CONTROL.len());
108
109 let control = ccr2!(&CONTROL);
110 let proof = ccr1!(start..=end, extra..=extra);
111
112 assert_eq!(proof, control);
113 }
114
115 #[test]
116 fn capital() {
117 let start = 'A' as usize; let end = 'Z' as usize; assert_eq!(1, CAPITAL.len());
121
122 let capital = ccr2!(&CAPITAL);
123 let proof = ccr1!(start..=end);
124
125 assert_eq!(proof, capital);
126 }
127
128 #[test]
129 fn small() {
130 let start = 'a' as usize; let end = 'z' as usize; assert_eq!(1, SMALL.len());
134
135 let small = ccr2!(&SMALL);
136 let proof = ccr1!(start..=end);
137
138 assert_eq!(proof, small);
139 }
140
141 #[test]
142 fn letters() {
143 let start_c = 'A' as usize;
144 let end_c = 'Z' as usize;
145
146 let start_s = 'a' as usize;
147 let end_s = 'z' as usize;
148
149 assert_eq!(2, LETTERS.len());
150
151 let letters = ccr2!(&LETTERS);
152 let proof = ccr1!(start_c..=end_c, start_s..=end_s);
153
154 assert_eq!(proof, letters);
155 }
156
157 #[test]
158 fn digits() {
159 let start = '0' as usize; let end = '9' as usize; assert_eq!(1, DIGITS.len());
163 let digits = ccr2!(&DIGITS);
164 let proof = ccr1!(start..=end);
165
166 assert_eq!(proof, digits);
167 }
168
169 #[test]
170 fn symbols() {
171 let start_1 = ' ' as usize; let end_1 = '/' as usize; let start_2 = ':' as usize; let end_2 = '@' as usize; let start_3 = '[' as usize; let end_3 = '`' as usize; let start_4 = '{' as usize; let end_4 = '~' as usize; assert_eq!(4, SYMBOLS.len());
184 let symbols = ccr2!(&SYMBOLS);
185 let proof = ccr1!(
186 start_1..=end_1,
187 start_2..=end_2,
188 start_3..=end_3,
189 start_4..=end_4
190 );
191
192 assert_eq!(proof, symbols);
193 }
194 }
195}
196
197pub mod table {
199
200 pub static TABLE: [(&str, &str); 128] = [
202 ("NUL", "Null"),
203 ("SOH", "Start of heading"),
204 ("STX", "Start of text"),
205 ("ETX", "End of text"),
206 ("EOT", "End of transmission"),
207 ("ENQ", "Enquiry"),
208 ("ACK", "Acknowledgement"),
209 ("BEL", "Bell"),
210 ("BS", "Backspace"),
211 ("HT", "Horizontal tab"),
212 ("LF", "Line feed"),
213 ("VT", "Vertical tab"),
214 ("FF", "Form feed"),
215 ("CR", "Carriage return"),
216 ("SO", "Shift out"),
217 ("SI", "Shift in"),
218 ("DLE", "Data link escape"),
219 ("DC1", "Device control 1"),
220 ("DC2", "Device control 2"),
221 ("DC3", "Device control 3"),
222 ("DC4", "Device control 4"),
223 ("NAK", "Negative acknowlegment"),
224 ("SYN", "Synchronous idle"),
225 ("ETB", "End of transmission block"),
226 ("CAN", "Cancel"),
227 ("EM", "End of medium"),
228 ("SUB", "Substitude"),
229 ("ESC", "Escape"),
230 ("FS", "File separator"),
231 ("GS", "Group separator"),
232 ("RS", "Record separator"),
233 ("US", "Unit separator"),
234 (" ", "Space"),
235 ("!", "Exlamation mark"),
236 ("\"", "Double quotation mark"),
237 ("#", "Number sign"),
238 ("$", "Dollar sign"),
239 ("%", "Percent sign"),
240 ("&", "Ampersand"),
241 ("'", "Apostrophe"),
242 ("(", "Left parenthesis"),
243 (")", "Right parenthesis"),
244 ("*", "Asterisk"),
245 ("+", "Plus sign"),
246 (",", "Comma"),
247 ("-", "Hyphen/Minus sign"),
248 (".", "Period"),
249 ("/", "Solidus"),
250 ("0", ""),
251 ("1", ""),
252 ("2", ""),
253 ("3", ""),
254 ("4", ""),
255 ("5", ""),
256 ("6", ""),
257 ("7", ""),
258 ("8", ""),
259 ("9", ""),
260 (":", "Colon"),
261 (";", "Semicolon"),
262 ("<", "Less-than sign"),
263 ("=", "Equals sign"),
264 (">", "Greater-than sign"),
265 ("?", "Question mark"),
266 ("@", "At sign"),
267 ("A", ""),
268 ("B", ""),
269 ("C", ""),
270 ("D", ""),
271 ("E", ""),
272 ("F", ""),
273 ("G", ""),
274 ("H", ""),
275 ("I", ""),
276 ("J", ""),
277 ("K", ""),
278 ("L", ""),
279 ("M", ""),
280 ("N", ""),
281 ("O", ""),
282 ("P", ""),
283 ("Q", ""),
284 ("R", ""),
285 ("S", ""),
286 ("T", ""),
287 ("U", ""),
288 ("V", ""),
289 ("W", ""),
290 ("X", ""),
291 ("Y", ""),
292 ("Z", ""),
293 ("[", "Left bracket"),
294 ("\\", "Reverse solidus"),
295 ("]", "Right bracket"),
296 ("^", "Circumflex accent"),
297 ("_", "Underscore"),
298 ("`", "Grave accent"),
299 ("a", ""),
300 ("b", ""),
301 ("c", ""),
302 ("d", ""),
303 ("e", ""),
304 ("f", ""),
305 ("g", ""),
306 ("h", ""),
307 ("i", ""),
308 ("j", ""),
309 ("k", ""),
310 ("l", ""),
311 ("m", ""),
312 ("n", ""),
313 ("o", ""),
314 ("p", ""),
315 ("q", ""),
316 ("r", ""),
317 ("s", ""),
318 ("t", ""),
319 ("u", ""),
320 ("v", ""),
321 ("w", ""),
322 ("x", ""),
323 ("y", ""),
324 ("z", ""),
325 ("{", "Left brace"),
326 ("|", "Verical line"),
327 ("}", "Right brace"),
328 ("~", "Tilde"),
329 ("DEL", "Delete"),
330 ];
331}