diff --git a/sailfish/src/escape.rs b/sailfish/src/escape.rs index 8bed03d..39a2ac4 100644 --- a/sailfish/src/escape.rs +++ b/sailfish/src/escape.rs @@ -31,18 +31,28 @@ pub const fn are_all_chars_identity(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 CommonIdents { + /// True if lowercase ASCII alphabetic characters will never need escaping. + pub const ALPHA_LOWERCASE: bool = are_all_chars_identity::(ALPHA_LOWERCASE_CHARS); + /// True if uppercase ASCII alphabetic characters will never need escaping. + pub const ALPHA_UPPERCASE: bool = are_all_chars_identity::(ALPHA_UPPERCASE_CHARS); + /// True if base10 digit characters will never need escaping. + pub const DIGITS: bool = are_all_chars_identity::(DIGIT_CHARS); + /// True if `true` and `false` will never need escaping. pub const BOOLS: bool = are_all_chars_identity::(BOOL_CHARS); /// True if unsigned integers will never need escaping. - pub const UINTS: bool = are_all_chars_identity::(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::(&['-']); + pub const INTS: bool = Self::DIGITS && are_all_chars_identity::(&['-']); /// True if floats (using [`ryu`]'s formatting) will never need escaping. - pub const FLOATS: bool = Self::INTS && are_all_chars_identity::(&['.', 'e']); + pub const FLOATS: bool = + Self::DIGITS && are_all_chars_identity::(&['-', '.', 'e']); } /// Constant metadata about an impl of [`Escape`].