huski_lib_core/
lib.rs

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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#![no_std]
//! American Standard Code for Information Interchange table aide no-std library core.

/// Module contains ASCII code ranges information.
pub mod ranges {

    /// Provides `&[RangeInclusive<usize>]` for demand of `r`.
    /// ```
    /// use huski_lib_core::ranges::{ranges, Ranges};    
    ///
    /// let rs = ranges(Ranges::Capital);
    /// assert_eq!('A', rs[0].clone().min().unwrap() as u8 as char);
    /// assert_eq!('Z', rs[0].clone().max().unwrap() as u8 as char);
    /// ```
    pub fn ranges(r: Ranges) -> &'static [RangeInclusive<usize>] {
        match r {
            | Ranges::Printable => &PRINTABLE,
            | Ranges::Control => &CONTROL,
            | Ranges::Capital => &CAPITAL,
            | Ranges::Small => &SMALL,
            | Ranges::Letters => &LETTERS,
            | Ranges::Digits => &DIGITS,
            | Ranges::Symbols => &SYMBOLS,
            | Ranges::Table => &TABLE,
        }
    }

    /// Code ranges
    #[derive(Clone, PartialEq)]
    pub enum Ranges {
        /// Printable codes
        Printable,
        /// Control codes
        Control,
        /// Capital letter codes
        Capital,
        /// Small letter codes
        Small,
        /// All letter codes
        Letters,
        /// Digit codes
        Digits,
        /// Symbols codes
        Symbols,
        /// Whole table codes
        Table,
    }

    use core::ops::RangeInclusive;

    /// Printable codes
    pub static PRINTABLE: [RangeInclusive<usize>; 1] = [(32..=126)];
    /// Control codes
    pub static CONTROL: [RangeInclusive<usize>; 2] = [(0..=31), (127..=127)];
    /// Capital letter codes
    pub static CAPITAL: [RangeInclusive<usize>; 1] = [(65..=90)];
    /// Small letter codes
    pub static SMALL: [RangeInclusive<usize>; 1] = [(97..=122)];
    /// All letter codes
    pub static LETTERS: [RangeInclusive<usize>; 2] = [(65..=90), (97..=122)];
    /// Digit codes
    pub static DIGITS: [RangeInclusive<usize>; 1] = [(48..=57)];
    /// Symbols codes
    pub static SYMBOLS: [RangeInclusive<usize>; 4] = [(32..=47), (58..=64), (91..=96), (123..=126)];
    /// Whole table codes
    pub static TABLE: [RangeInclusive<usize>; 1] = [(0..=127)];

    #[cfg(test)]
    mod tests_of_units {

        extern crate std;
        use std::vec::Vec;
        use super::{ranges as ranges_fn, *};
        use huski_auxies::{ccr1, ccr2, len};

        #[test]
        fn ranges() {
            assert_eq!(&PRINTABLE, ranges_fn(Ranges::Printable));
            assert_eq!(&CONTROL, ranges_fn(Ranges::Control));
            assert_eq!(&CAPITAL, ranges_fn(Ranges::Capital));
            assert_eq!(&SMALL, ranges_fn(Ranges::Small));
            assert_eq!(&LETTERS, ranges_fn(Ranges::Letters));
            assert_eq!(&DIGITS, ranges_fn(Ranges::Digits));
            assert_eq!(&SYMBOLS, ranges_fn(Ranges::Symbols));
            assert_eq!(&TABLE, ranges_fn(Ranges::Table));
        }

        #[test]
        fn printable() {
            let start = 0x20; // 32
            let end = 0x7e; // 126

            assert_eq!(1, PRINTABLE.len());

            let printable = ccr2!(&PRINTABLE);
            let proof = ccr1!(start..=end);

            assert_eq!(proof, printable);
        }

        #[test]
        fn control() {
            let start = 0x0; // 0
            let end = 0x1f; // 31
            let extra = 0x7f; // 127

            assert_eq!(2, CONTROL.len());

            let control = ccr2!(&CONTROL);
            let proof = ccr1!(start..=end, extra..=extra);

            assert_eq!(proof, control);
        }

        #[test]
        fn capital() {
            let start = 'A' as usize; // 65
            let end = 'Z' as usize; // 90

            assert_eq!(1, CAPITAL.len());

            let capital = ccr2!(&CAPITAL);
            let proof = ccr1!(start..=end);

            assert_eq!(proof, capital);
        }

        #[test]
        fn small() {
            let start = 'a' as usize; // 97
            let end = 'z' as usize; // 122

            assert_eq!(1, SMALL.len());

            let small = ccr2!(&SMALL);
            let proof = ccr1!(start..=end);

            assert_eq!(proof, small);
        }

        #[test]
        fn letters() {
            let start_c = 'A' as usize;
            let end_c = 'Z' as usize;

            let start_s = 'a' as usize;
            let end_s = 'z' as usize;

            assert_eq!(2, LETTERS.len());

            let letters = ccr2!(&LETTERS);
            let proof = ccr1!(start_c..=end_c, start_s..=end_s);

            assert_eq!(proof, letters);
        }

        #[test]
        fn digits() {
            let start = '0' as usize; // 48
            let end = '9' as usize; // 57

            assert_eq!(1, DIGITS.len());
            let digits = ccr2!(&DIGITS);
            let proof = ccr1!(start..=end);

            assert_eq!(proof, digits);
        }

        #[test]
        fn symbols() {
            let start_1 = ' ' as usize; // 32
            let end_1 = '/' as usize; // 47

            let start_2 = ':' as usize; // 58
            let end_2 = '@' as usize; // 64

            let start_3 = '[' as usize; // 91
            let end_3 = '`' as usize; // 96

            let start_4 = '{' as usize; // 123
            let end_4 = '~' as usize; // 126

            assert_eq!(4, SYMBOLS.len());
            let symbols = ccr2!(&SYMBOLS);
            let proof = ccr1!(
                start_1..=end_1,
                start_2..=end_2,
                start_3..=end_3,
                start_4..=end_4
            );

            assert_eq!(proof, symbols);
        }
    }
}

/// Module contains ASCII code table information.
pub mod table {

    /// ASCII table information
    pub static TABLE: [(&str, &str); 128] = [
        ("NUL", "Null"),
        ("SOH", "Start of heading"),
        ("STX", "Start of text"),
        ("ETX", "End of text"),
        ("EOT", "End of transmission"),
        ("ENQ", "Enquiry"),
        ("ACK", "Acknowledgement"),
        ("BEL", "Bell"),
        ("BS", "Backspace"),
        ("HT", "Horizontal tab"),
        ("LF", "Line feed"),
        ("VT", "Vertical tab"),
        ("FF", "Form feed"),
        ("CR", "Carriage return"),
        ("SO", "Shift out"),
        ("SI", "Shift in"),
        ("DLE", "Data link escape"),
        ("DC1", "Device control 1"),
        ("DC2", "Device control 2"),
        ("DC3", "Device control 3"),
        ("DC4", "Device control 4"),
        ("NAK", "Negative acknowlegment"),
        ("SYN", "Synchronous idle"),
        ("ETB", "End of transmission block"),
        ("CAN", "Cancel"),
        ("EM", "End of medium"),
        ("SUB", "Substitude"),
        ("ESC", "Escape"),
        ("FS", "File separator"),
        ("GS", "Group separator"),
        ("RS", "Record separator"),
        ("US", "Unit separator"),
        (" ", "Space"),
        ("!", "Exlamation mark"),
        ("\"", "Double quotation mark"),
        ("#", "Number sign"),
        ("$", "Dollar sign"),
        ("%", "Percent sign"),
        ("&", "Ampersand"),
        ("'", "Apostrophe"),
        ("(", "Left parenthesis"),
        (")", "Right parenthesis"),
        ("*", "Asterisk"),
        ("+", "Plus sign"),
        (",", "Comma"),
        ("-", "Hyphen/Minus sign"),
        (".", "Period"),
        ("/", "Solidus"),
        ("0", ""),
        ("1", ""),
        ("2", ""),
        ("3", ""),
        ("4", ""),
        ("5", ""),
        ("6", ""),
        ("7", ""),
        ("8", ""),
        ("9", ""),
        (":", "Colon"),
        (";", "Semicolon"),
        ("<", "Less-than sign"),
        ("=", "Equals sign"),
        (">", "Greater-than sign"),
        ("?", "Question mark"),
        ("@", "At sign"),
        ("A", ""),
        ("B", ""),
        ("C", ""),
        ("D", ""),
        ("E", ""),
        ("F", ""),
        ("G", ""),
        ("H", ""),
        ("I", ""),
        ("J", ""),
        ("K", ""),
        ("L", ""),
        ("M", ""),
        ("N", ""),
        ("O", ""),
        ("P", ""),
        ("Q", ""),
        ("R", ""),
        ("S", ""),
        ("T", ""),
        ("U", ""),
        ("V", ""),
        ("W", ""),
        ("X", ""),
        ("Y", ""),
        ("Z", ""),
        ("[", "Left bracket"),
        ("\\", "Reverse solidus"),
        ("]", "Right bracket"),
        ("^", "Circumflex accent"),
        ("_", "Underscore"),
        ("`", "Grave accent"),
        ("a", ""),
        ("b", ""),
        ("c", ""),
        ("d", ""),
        ("e", ""),
        ("f", ""),
        ("g", ""),
        ("h", ""),
        ("i", ""),
        ("j", ""),
        ("k", ""),
        ("l", ""),
        ("m", ""),
        ("n", ""),
        ("o", ""),
        ("p", ""),
        ("q", ""),
        ("r", ""),
        ("s", ""),
        ("t", ""),
        ("u", ""),
        ("v", ""),
        ("w", ""),
        ("x", ""),
        ("y", ""),
        ("z", ""),
        ("{", "Left brace"),
        ("|", "Verical line"),
        ("}", "Right brace"),
        ("~", "Tilde"),
        ("DEL", "Delete"),
    ];
}