Add some more common escaping scheme identity checks

This commit is contained in:
Michael Pfaff 2024-03-15 19:50:13 -04:00
parent 28a1e3a3f0
commit e4def7d21c
1 changed files with 14 additions and 4 deletions

View File

@ -31,18 +31,28 @@ pub const fn are_all_chars_identity<E: Escape + ~const EscapeMeta>(set: &[char])
true
}
const ALPHA_LOWERCASE_CHARS: &[char] = &ascii_chars(b"abcdefghijklmnopqrstuvwxyz");
const ALPHA_UPPERCASE_CHARS: &[char] = &ascii_chars(b"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
const DIGIT_CHARS: &[char] = &ascii_chars(b"0123456789");
const BOOL_CHARS: &[char] = &ascii_chars(b"truefals");
const UINT_CHARS: &[char] = &ascii_chars(b"0123456789");
impl<E: Escape> CommonIdents<E> {
/// True if lowercase ASCII alphabetic characters will never need escaping.
pub const ALPHA_LOWERCASE: bool = are_all_chars_identity::<E>(ALPHA_LOWERCASE_CHARS);
/// True if uppercase ASCII alphabetic characters will never need escaping.
pub const ALPHA_UPPERCASE: bool = are_all_chars_identity::<E>(ALPHA_UPPERCASE_CHARS);
/// True if base10 digit characters will never need escaping.
pub const DIGITS: bool = are_all_chars_identity::<E>(DIGIT_CHARS);
/// True if `true` and `false` will never need escaping.
pub const BOOLS: bool = are_all_chars_identity::<E>(BOOL_CHARS);
/// True if unsigned integers will never need escaping.
pub const UINTS: bool = are_all_chars_identity::<E>(UINT_CHARS);
pub const UINTS: bool = Self::DIGITS;
/// True if signed integers will never need escaping.
pub const INTS: bool = Self::UINTS && are_all_chars_identity::<E>(&['-']);
pub const INTS: bool = Self::DIGITS && are_all_chars_identity::<E>(&['-']);
/// True if floats (using [`ryu`]'s formatting) will never need escaping.
pub const FLOATS: bool = Self::INTS && are_all_chars_identity::<E>(&['.', 'e']);
pub const FLOATS: bool =
Self::DIGITS && are_all_chars_identity::<E>(&['-', '.', 'e']);
}
/// Constant metadata about an impl of [`Escape`].