@@ -39,77 +39,38 @@ template <typename... Content> struct set {
3939 }
4040};
4141
42+ template <auto ... Cs> struct enumeration : set<character<Cs>...> { };
43+
4244template <typename ... Content> struct negate {
4345 template <typename CharT> inline static constexpr bool match_char (CharT value) noexcept {
4446 return !(Content::match_char (value) || ... || false );
4547 }
4648};
4749
48- // I know word_chars and others can be expressed with set<> and range<>, but this makes the regex bad readable when debugging, please keep this in mind when touching this code in future :)
49-
50- struct word_chars {
50+ template <auto A, auto B> struct char_range {
5151 template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char (CharT value) noexcept {
52- return (value >= ' A ' && value <= ' Z ' ) || (value >= ' a ' && value <= ' z ' ) || (value >= ' 0 ' && value <= ' 9 ' ) || (value == ' _ ' );
52+ return (value >= A) && (value <= B );
5353 }
5454};
5555
56- struct space_chars {
57- template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char (CharT value) noexcept {
58- return value == ' ' || value == ' \t ' || value == ' \n ' || value == ' \v ' || value == ' \f ' || value == ' \r ' ;
59- }
60- };
56+ struct word_chars : set<char_range<' A' ,' Z' >, char_range<' a' ,' z' >, char_range<' 0' ,' 9' >, character<' _' > > { };
6157
62- struct alphanum_chars {
63- template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char (CharT value) noexcept {
64- return (value >= ' A' && value <= ' Z' ) || (value >= ' a' && value <= ' z' ) || (value >= ' 0' && value <= ' 9' );
65- }
66- };
58+ struct space_chars : enumeration<' ' , ' \t ' , ' \n ' , ' \v ' , ' \f ' , ' \r ' > {};
6759
68- struct alpha_chars {
69- template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char (CharT value) noexcept {
70- return (value >= ' A' && value <= ' Z' ) || (value >= ' a' && value <= ' z' );
71- }
72- };
60+ struct alphanum_chars : set<char_range<' A' ,' Z' >, char_range<' a' ,' z' >, char_range<' 0' ,' 9' > > { };
7361
74- struct xdigit_chars {
75- template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char (CharT value) noexcept {
76- return (value >= ' A' && value <= ' F' ) || (value >= ' a' && value <= ' f' ) || (value >= ' 0' && value <= ' 9' );
77- }
78- };
62+ struct alpha_chars : set<char_range<' A' ,' Z' >, char_range<' a' ,' z' > > { };
7963
80- struct punct_chars {
81- template <typename CharT> inline static constexpr bool match_char (CharT value) noexcept {
82- return value == ' !' || value == ' "' || value == ' #' || value == ' $' || value == ' %'
83- || value == ' &' || value == ' \' ' || value == ' (' || value == ' )' || value == ' *' || value == ' ,'
84- || value == ' -' || value == ' .' || value == ' /' || value == ' :' || value == ' ;'
85- || value == ' <' || value == ' =' || value == ' >' || value == ' ?' || value == ' @' || value == ' ['
86- || value == ' \\ ' || value == ' ]' || value == ' ^' || value == ' _' || value == ' `'
87- || value == ' {' || value == ' |' || value == ' }' || value == ' ~' ;
88- }
89- };
64+ struct xdigit_chars : set<char_range<' A' ,' F' >, char_range<' a' ,' f' >, char_range<' 0' ,' 9' > > { };
9065
91- struct digit_chars {
92- template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char (CharT value) noexcept {
93- return (value >= ' 0' && value <= ' 9' );
94- }
95- };
66+ struct punct_chars
67+ : enumeration<' !' , ' "' , ' #' , ' $' , ' %' , ' &' , ' \' ' , ' (' , ' )' , ' *' , ' ,' , ' -' ,
68+ ' .' , ' /' , ' :' , ' ;' , ' <' , ' =' , ' >' , ' ?' , ' @' , ' [' , ' \\ ' , ' ]' ,
69+ ' ^' , ' _' , ' `' , ' {' , ' |' , ' }' , ' ~' > {};
9670
97- struct ascii_chars {
98- template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char (CharT value) noexcept {
99- return (value >= ' \x00 ' && value <= ' \x7F ' );
100- }
101- };
71+ struct digit_chars : char_range<' 0' ,' 9' > { };
10272
103- template <auto A, auto B> struct char_range {
104- template <typename CharT> CTRE_FORCE_INLINE static constexpr bool match_char (CharT value) noexcept {
105- return (value >= A) && (value <= B);
106- }
107- };
108- template <auto ... Cs> struct enumeration {
109- template <typename CharT> inline static constexpr bool match_char (CharT value) noexcept {
110- return ((value == Cs) || ... || false );
111- }
112- };
73+ struct ascii_chars : char_range<' \x00 ' ,' \x7F ' > { };
11374
11475}
11576
0 commit comments