@@ -15,6 +15,12 @@ constexpr inline auto match_re(const Iterator begin, const EndIterator end, Patt
15
15
return evaluate (begin, begin, end, return_type{}, ctll::list<start_mark, Pattern, assert_end, end_mark, accept>());
16
16
}
17
17
18
+ template <typename Iterator, typename EndIterator, typename Pattern>
19
+ constexpr inline auto ordered_match_re (const Iterator begin, const EndIterator end, Pattern pattern) noexcept {
20
+ using return_type = decltype (regex_results (std::declval<Iterator>(), find_captures (pattern)));
21
+ return ordered_evaluate (begin, begin, end, return_type{}, ctll::list<start_mark, Pattern, assert_end, end_mark, accept>());
22
+ }
23
+
18
24
template <typename Iterator, typename EndIterator, typename Pattern>
19
25
constexpr inline auto search_re (const Iterator begin, const EndIterator end, Pattern pattern) noexcept {
20
26
using return_type = decltype (regex_results (std::declval<Iterator>(), find_captures (pattern)));
@@ -39,18 +45,33 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator, Iterator, const EndIterat
39
45
return captures.matched ();
40
46
}
41
47
48
+ template <typename R, typename Iterator, typename EndIterator>
49
+ constexpr CTRE_FORCE_INLINE R ordered_evaluate (const Iterator, Iterator, const EndIterator, R captures, ctll::list<accept>) noexcept {
50
+ return captures.matched ();
51
+ }
52
+
42
53
// mark start of outer capture
43
54
template <typename R, typename Iterator, typename EndIterator, typename ... Tail>
44
55
constexpr CTRE_FORCE_INLINE R evaluate (const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<start_mark, Tail...>) noexcept {
45
56
return evaluate (begin, current, end, captures.set_start_mark (current), ctll::list<Tail...>());
46
57
}
47
58
59
+ template <typename R, typename Iterator, typename EndIterator, typename ... Tail>
60
+ constexpr CTRE_FORCE_INLINE R ordered_evaluate (const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<start_mark, Tail...>) noexcept {
61
+ return ordered_evaluate (begin, current, end, captures.set_start_mark (current), ctll::list<Tail...>());
62
+ }
63
+
48
64
// mark end of outer capture
49
65
template <typename R, typename Iterator, typename EndIterator, typename ... Tail>
50
66
constexpr CTRE_FORCE_INLINE R evaluate (const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<end_mark, Tail...>) noexcept {
51
67
return evaluate (begin, current, end, captures.set_end_mark (current), ctll::list<Tail...>());
52
68
}
53
69
70
+ template <typename R, typename Iterator, typename EndIterator, typename ... Tail>
71
+ constexpr CTRE_FORCE_INLINE R ordered_evaluate (const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<end_mark, Tail...>) noexcept {
72
+ return ordered_evaluate (begin, current, end, captures.set_end_mark (current), ctll::list<Tail...>());
73
+ }
74
+
54
75
// mark end of cycle
55
76
template <typename R, typename Iterator, typename EndIterator, typename ... Tail>
56
77
constexpr CTRE_FORCE_INLINE R evaluate (const Iterator, Iterator current, const EndIterator, R captures, ctll::list<end_cycle_mark>) noexcept {
@@ -67,13 +88,33 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
67
88
return evaluate (begin, current+1 , end, captures, ctll::list<Tail...>());
68
89
}
69
90
91
+ template <typename R, typename Iterator, typename EndIterator, typename CharacterLike, typename ... Tail, typename = std::enable_if_t <(MatchesCharacter<CharacterLike>::template value<decltype(*std::declval<Iterator>())>)>>
92
+ constexpr CTRE_FORCE_INLINE R ordered_evaluate (const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<CharacterLike, Tail...>) noexcept {
93
+ if (end == current) { // target is shorter than pattern
94
+ captures.mask_elg ({0 ,1 ,0 });
95
+ return captures;
96
+ }
97
+ captures.mask_elg (CharacterLike::compare_char (*current));
98
+ if (captures) {
99
+ if (!captures.is_less () && !captures.is_greater ())
100
+ return evaluate (begin, current+1 , end, captures.unmatch (), ctll::list<Tail...>());
101
+ return ordered_evaluate (begin, current+1 , end, captures, ctll::list<Tail...>());
102
+ }
103
+ return captures;
104
+ }
105
+
70
106
// matching strings in patterns
71
107
72
108
template <typename Iterator> struct string_match_result {
73
109
Iterator current;
74
110
bool match;
75
111
};
76
112
113
+ template <typename Iterator> struct string_compare_result {
114
+ Iterator current;
115
+ equal_less_greater elg;
116
+ };
117
+
77
118
template <auto Head, auto ... String, typename Iterator, typename EndIterator> constexpr CTRE_FORCE_INLINE string_match_result<Iterator> evaluate_match_string (Iterator current, const EndIterator end) noexcept {
78
119
if ((end != current) && (Head == *current)) {
79
120
if constexpr (sizeof ...(String) > 0 ) {
@@ -145,6 +186,15 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
145
186
} else {
146
187
return evaluate (begin, current, end, captures, ctll::list<HeadContent, Tail...>());
147
188
}
189
+ }
190
+
191
+ template <typename R, typename Iterator, typename EndIterator, typename HeadContent, typename ... TailContent, typename ... Tail>
192
+ constexpr CTRE_FORCE_INLINE R ordered_evaluate (const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<sequence<HeadContent, TailContent...>, Tail...>) noexcept {
193
+ if constexpr (sizeof ...(TailContent) > 0 ) {
194
+ return ordered_evaluate (begin, current, end, captures, ctll::list<HeadContent, sequence<TailContent...>, Tail...>());
195
+ } else {
196
+ return ordered_evaluate (begin, current, end, captures, ctll::list<HeadContent, Tail...>());
197
+ }
148
198
149
199
}
150
200
@@ -171,6 +221,15 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
171
221
return evaluate (begin, current, end, captures, ctll::list<Tail...>());
172
222
}
173
223
224
+ template <typename R, typename Iterator, typename EndIterator, typename ... Tail>
225
+ constexpr CTRE_FORCE_INLINE R ordered_evaluate (const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<assert_end, Tail...>) noexcept {
226
+ if (end != current) { // target is longer than pattern
227
+ captures.mask_elg ({0 ,0 ,1 });
228
+ return captures;
229
+ }
230
+ return ordered_evaluate (begin, current, end, captures, ctll::list<Tail...>());
231
+ }
232
+
174
233
// lazy repeat
175
234
template <typename R, typename Iterator, typename EndIterator, size_t A, size_t B, typename ... Content, typename ... Tail>
176
235
constexpr CTRE_FORCE_INLINE R evaluate (const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<lazy_repeat<A,B,Content...>, Tail...>) noexcept {
0 commit comments