| 1 | //! Utilities for working with ASCII characters. |
| 2 | |
| 3 | /// Determine if a character is a valid ASCII character for float grammar. |
| 4 | #[inline(always)] |
| 5 | pub const fn is_valid_ascii(c: u8) -> bool { |
| 6 | // Below 0x20 is mostly control characters, with no representation. |
| 7 | // 0x7F is a control character, DEL, so don't include it. |
| 8 | // We also want the few visual characters below 0x20: |
| 9 | // 0x09 - Horizontal Tab |
| 10 | // 0x0A - Newline |
| 11 | // 0x0B - Vertical Tab (Deprecated) |
| 12 | // 0x0C - Form Feed (Deprecated) |
| 13 | // 0x0D - Carriage Return |
| 14 | (c >= 0x09 && c <= 0x0d) || (c >= 0x20 && c < 0x7F) |
| 15 | } |
| 16 | |
| 17 | /// Determine if a slice is all valid ASCII characters for float grammar. |
| 18 | #[inline(always)] |
| 19 | pub const fn is_valid_ascii_slice(slc: &[u8]) -> bool { |
| 20 | let mut index = 0; |
| 21 | while index < slc.len() { |
| 22 | if !is_valid_ascii(slc[index]) { |
| 23 | return false; |
| 24 | } |
| 25 | index += 1; |
| 26 | } |
| 27 | true |
| 28 | } |
| 29 | |
| 30 | /// Determine if a character is a valid ASCII letter. |
| 31 | #[inline(always)] |
| 32 | pub const fn is_valid_letter(c: u8) -> bool { |
| 33 | (c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) |
| 34 | } |
| 35 | |
| 36 | /// Determine if a slice is all valid ASCII letters. |
| 37 | #[inline(always)] |
| 38 | pub const fn is_valid_letter_slice(slc: &[u8]) -> bool { |
| 39 | let mut index = 0; |
| 40 | while index < slc.len() { |
| 41 | if !is_valid_letter(slc[index]) { |
| 42 | return false; |
| 43 | } |
| 44 | index += 1; |
| 45 | } |
| 46 | true |
| 47 | } |