Skip to content

Commit

Permalink
Merge pull request #25 from leni536/refactor_atom_characters2
Browse files Browse the repository at this point in the history
Refactor atoms_characters.hpp
  • Loading branch information
hanickadot authored Oct 30, 2018
2 parents 715364e + 6e7922c commit 7de344d
Showing 1 changed file with 15 additions and 52 deletions.
67 changes: 15 additions & 52 deletions include/ctre/atoms_characters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,75 +39,38 @@ template <typename... Content> struct set {
}
};

template <auto... Cs> struct enumeration : set<character<Cs>...> { };

template <typename... Content> struct negate {
template <typename CharT> inline static constexpr bool match_char(CharT value) noexcept {
return !(Content::match_char(value) || ... || false);
}
};

struct word_chars {
template <auto A, auto B> struct char_range {
template <typename CharT> 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 <typename CharT> 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<'a','z'>, char_range<'0','9'>, character<'_'>>;

struct alphanum_chars {
template <typename CharT> 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 <typename CharT> 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<'a','z'>, char_range<'0','9'> >;

struct xdigit_chars {
template <typename CharT> 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'>, char_range<'a','z'> >;

struct punct_chars {
template <typename CharT> 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<'a','f'>, char_range<'0','9'> >;

struct digit_chars {
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept {
return (value >= '0' && value <= '9');
}
};
using punct_chars =
enumeration<'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', ',', '-',
'.', '/', '=', ';', '<', '=', '>', '?', '@', '[', '\\', ']',
'^', '_', '`', '{', '|', '}', '~'>;

struct ascii_chars {
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept {
return (value >= '\x00' && value <= '\x7F');
}
};
using digit_chars = char_range<'0','9'>;

template <auto A, auto B> struct char_range {
template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char(CharT value) noexcept {
return (value >= A) && (value <= B);
}
};
template <auto... Cs> struct enumeration {
template <typename CharT> inline static constexpr bool match_char(CharT value) noexcept {
return ((value == Cs) || ... || false);
}
};
using ascii_chars = char_range<'\x00','\x7F'>;

}

Expand Down

0 comments on commit 7de344d

Please sign in to comment.