diff --git a/include/ctre/atoms_characters.hpp b/include/ctre/atoms_characters.hpp index dbbee4cb..6a3b6451 100644 --- a/include/ctre/atoms_characters.hpp +++ b/include/ctre/atoms_characters.hpp @@ -39,75 +39,38 @@ template struct set { } }; +template struct enumeration : set...> { }; + template struct negate { template inline static constexpr bool match_char(CharT value) noexcept { return !(Content::match_char(value) || ... || false); } }; -struct word_chars { +template struct char_range { template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { - return (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z') || (value >= '0' && value <= '9') || (value == '_'); + return (value >= A) && (value <= B); } }; -struct space_chars { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { - return value == ' ' || value == '\t' || value == '\n' || value == '\v' || value == '\f' || value == '\r'; - } -}; +using word_chars = set, char_range<'a','z'>, char_range<'0','9'>, character<'_'>>; -struct alphanum_chars { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { - return (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z') || (value >= '0' && value <= '9'); - } -}; +using space_chars = enumeration<' ', '\t', '\n', '\v', '\f', '\r'>; -struct alpha_chars { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { - return (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z'); - } -}; +using alphanum_chars = set, char_range<'a','z'>, char_range<'0','9'> >; -struct xdigit_chars { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { - return (value >= 'A' && value <= 'F') || (value >= 'a' && value <= 'f') || (value >= '0' && value <= '9'); - } -}; +using alpha_chars = set, char_range<'a','z'> >; -struct punct_chars { - template inline static constexpr bool match_char(CharT value) noexcept { - return value == '!' || value == '"' || value == '#' || value == '$' || value == '%' - || value == '&' || value == '\''|| value == '(' || value == ')' || value == '*' || value == ',' - || value == '-' || value == '.' || value == '/' || value == ':' || value == ';' - || value == '<' || value == '=' || value == '>' || value == '?' || value == '@' || value == '[' - || value == '\\'|| value == ']' || value == '^' || value == '_' || value == '`' - || value == '{' || value == '|' || value == '}' || value == '~'; - } -}; +using xdigit_chars = set, char_range<'a','f'>, char_range<'0','9'> >; -struct digit_chars { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { - return (value >= '0' && value <= '9'); - } -}; +using punct_chars = + enumeration<'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', ',', '-', + '.', '/', '=', ';', '<', '=', '>', '?', '@', '[', '\\', ']', + '^', '_', '`', '{', '|', '}', '~'>; -struct ascii_chars { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { - return (value >= '\x00' && value <= '\x7F'); - } -}; +using digit_chars = char_range<'0','9'>; -template struct char_range { - template CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept { - return (value >= A) && (value <= B); - } -}; -template struct enumeration { - template inline static constexpr bool match_char(CharT value) noexcept { - return ((value == Cs) || ... || false); - } -}; +using ascii_chars = char_range<'\x00','\x7F'>; }