huski_lib_core/
lib.rs

1#![no_std]
2//! American Standard Code for Information Interchange table aide no-std library core.
3
4/// Module contains ASCII code ranges information.
5pub mod ranges {
6
7    /// Provides `&[RangeInclusive<usize>]` for demand of `r`.
8    /// ```
9    /// use huski_lib_core::ranges::{ranges, Ranges};    
10    ///
11    /// let rs = ranges(Ranges::Capital);
12    /// assert_eq!('A', rs[0].clone().min().unwrap() as u8 as char);
13    /// assert_eq!('Z', rs[0].clone().max().unwrap() as u8 as char);
14    /// ```
15    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    /// Code ranges
29    #[derive(Clone, PartialEq, Debug)]
30    pub enum Ranges {
31        /// Printable codes
32        Printable,
33        /// Control codes
34        Control,
35        /// Capital letter codes
36        Capital,
37        /// Small letter codes
38        Small,
39        /// All letter codes
40        Letters,
41        /// Digit codes
42        Digits,
43        /// Symbols codes
44        Symbols,
45        /// Whole table codes
46        Table,
47    }
48
49    use core::ops::RangeInclusive;
50
51    /// Printable codes
52    pub static PRINTABLE: [RangeInclusive<usize>; 1] = [(32..=126)];
53    /// Control codes
54    pub static CONTROL: [RangeInclusive<usize>; 2] = [(0..=31), (127..=127)];
55    /// Capital letter codes
56    pub static CAPITAL: [RangeInclusive<usize>; 1] = [(65..=90)];
57    /// Small letter codes
58    pub static SMALL: [RangeInclusive<usize>; 1] = [(97..=122)];
59    /// All letter codes
60    pub static LETTERS: [RangeInclusive<usize>; 2] = [(65..=90), (97..=122)];
61    /// Digit codes
62    pub static DIGITS: [RangeInclusive<usize>; 1] = [(48..=57)];
63    /// Symbols codes
64    pub static SYMBOLS: [RangeInclusive<usize>; 4] = [(32..=47), (58..=64), (91..=96), (123..=126)];
65    /// Whole table codes
66    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; // 32
91            let end = 0x7e; // 126
92
93            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; // 0
104            let end = 0x1f; // 31
105            let extra = 0x7f; // 127
106
107            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; // 65
118            let end = 'Z' as usize; // 90
119
120            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; // 97
131            let end = 'z' as usize; // 122
132
133            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; // 48
160            let end = '9' as usize; // 57
161
162            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; // 32
172            let end_1 = '/' as usize; // 47
173
174            let start_2 = ':' as usize; // 58
175            let end_2 = '@' as usize; // 64
176
177            let start_3 = '[' as usize; // 91
178            let end_3 = '`' as usize; // 96
179
180            let start_4 = '{' as usize; // 123
181            let end_4 = '~' as usize; // 126
182
183            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
197/// Module contains ASCII code table information.
198pub mod table {
199
200    /// ASCII table information
201    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}