From e4def7d21cbab0f05d303eaacda6b42741fe2183 Mon Sep 17 00:00:00 2001 From: Michael Pfaff Date: Fri, 15 Mar 2024 19:50:13 -0400 Subject: [PATCH] Add some more common escaping scheme identity checks --- sailfish/src/escape.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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`].