use std::ops::Range;
#[derive(Debug, Clone)]
pub enum CharType<'a> {
Any,
DecDigit, Digit(u32), Numeric, AlphaNum,
Upper,
Lower,
Alpha,
Spaces,
Punctuation,
Char(char),
Chars(&'a [char]),
Range(Range<char>),
Between(char, char),
}
impl<'a> CharType<'a> {
pub fn is_in_range(&self, c_ref: &char) -> bool {
let c = c_ref.to_owned();
match self {
Self::Any => true,
Self::DecDigit => c.is_ascii_digit(),
Self::Digit(radix) => c.is_digit(*radix),
Self::Numeric => c.is_numeric(),
Self::AlphaNum => c.is_alphanumeric(),
Self::Lower => c.is_lowercase(),
Self::Upper => c.is_uppercase(),
Self::Alpha => c.is_alphabetic(),
Self::Spaces => c.is_whitespace(),
Self::Punctuation => c.is_ascii_punctuation(),
Self::Char(ch) => c == *ch,
Self::Chars(chars) => chars.contains(&c),
Self::Range(cr) => cr.contains(&c),
Self::Between(c1, c2) => c >= *c1 && c <= *c2,
}
}
}