Compare commits

..

No commits in common. "e4def7d21cbab0f05d303eaacda6b42741fe2183" and "a5856fb7fcdec44f53e2fd71d2f60f4f090734d3" have entirely different histories.

1 changed files with 7 additions and 33 deletions

View File

@ -4,22 +4,8 @@ use array_vec::ArrayStr;
use super::Buffer;
/// Holds computed constants for common escaping scheme identity checks.
pub struct CommonIdents<E: Escape>(PhantomData<E>);
pub(crate) struct CommonIdents<E: Escape>(PhantomData<E>);
/// Converts an array of ASCII bytes to an array of characters.
pub const fn ascii_chars<const N: usize>(s: &[u8; N]) -> [char; N] {
assert!(s.is_ascii());
let mut chars = ['\0'; N];
let mut i = 0;
while i < s.len() {
chars[i] = s[i] as char;
i += 1;
}
chars
}
/// Returns `true` if, for the given escaping scheme `E`, every character in `set` requires no escaping.
pub const fn are_all_chars_identity<E: Escape + ~const EscapeMeta>(set: &[char]) -> bool {
let mut i = 0;
while i < set.len() {
@ -31,31 +17,19 @@ 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");
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);
pub const BOOLS: bool =
are_all_chars_identity::<E>(&['t', 'r', 'u', 'e', 'f', 'a', 'l', 's']);
/// True if unsigned integers will never need escaping.
pub const UINTS: bool = Self::DIGITS;
pub const UINTS: bool =
are_all_chars_identity::<E>(&['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']);
/// True if signed integers will never need escaping.
pub const INTS: bool = Self::DIGITS && are_all_chars_identity::<E>(&['-']);
pub const INTS: bool = Self::UINTS && are_all_chars_identity::<E>(&['-']);
/// True if floats (using [`ryu`]'s formatting) will never need escaping.
pub const FLOATS: bool =
Self::DIGITS && are_all_chars_identity::<E>(&['-', '.', 'e']);
pub const FLOATS: bool = Self::INTS && are_all_chars_identity::<E>(&['.', 'e']);
}
/// Constant metadata about an impl of [`Escape`].
#[const_trait]
pub trait EscapeMeta {
/// Returns `true` if the escaping scheme will never map the given character, regardless of its