@@ -37,34 +37,32 @@ template <size_t Limit> constexpr CTRE_FORCE_INLINE bool less_than(size_t i) {
37
37
}
38
38
}
39
39
40
+ template <typename ResultIterator, typename Pattern> using return_type = decltype (regex_results(std::declval<ResultIterator>(), find_captures(Pattern{})));
41
+
40
42
// calling with pattern prepare stack and triplet of iterators
41
- template <typename Iterator, typename EndIterator, typename Pattern>
42
- constexpr inline auto match_re (const Iterator begin, const EndIterator end, Pattern pattern) noexcept {
43
- using return_type = decltype (regex_results (std::declval<Iterator>(), find_captures (pattern)));
44
- return evaluate (begin, begin, end, return_type{}, ctll::list<start_mark, Pattern, assert_end, end_mark, accept>());
43
+ template <typename Iterator, typename EndIterator, typename Pattern, typename ResultIterator = Iterator>
44
+ constexpr inline auto match_re (const Iterator begin, const EndIterator end, Pattern) noexcept {
45
+ return evaluate (begin, begin, end, return_type<ResultIterator, Pattern>{}, ctll::list<start_mark, Pattern, assert_end, end_mark, accept>());
45
46
}
46
47
47
- template <typename Iterator, typename EndIterator, typename Pattern>
48
- constexpr inline auto starts_with_re (const Iterator begin, const EndIterator end, Pattern pattern) noexcept {
49
- using return_type = decltype (regex_results (std::declval<Iterator>(), find_captures (pattern)));
50
- return evaluate (begin, begin, end, return_type{}, ctll::list<start_mark, Pattern, end_mark, accept>());
48
+ template <typename Iterator, typename EndIterator, typename Pattern, typename ResultIterator = Iterator>
49
+ constexpr inline auto starts_with_re (const Iterator begin, const EndIterator end, Pattern) noexcept {
50
+ return evaluate (begin, begin, end, return_type<ResultIterator, Pattern>{}, ctll::list<start_mark, Pattern, end_mark, accept>());
51
51
}
52
52
53
- template <typename Iterator, typename EndIterator, typename Pattern>
54
- constexpr inline auto search_re (const Iterator begin, const EndIterator end, Pattern pattern) noexcept {
55
- using return_type = decltype (regex_results (std::declval<Iterator>(), find_captures (pattern)));
56
-
53
+ template <typename Iterator, typename EndIterator, typename Pattern, typename ResultIterator = Iterator>
54
+ constexpr inline auto search_re (const Iterator begin, const EndIterator end, Pattern) noexcept {
57
55
constexpr bool fixed = starts_with_anchor (ctll::list<Pattern>{});
58
56
59
57
auto it = begin;
60
58
for (; end != it && !fixed; ++it) {
61
- if (auto out = evaluate (begin, it, end, return_type{}, ctll::list<start_mark, Pattern, end_mark, accept>())) {
59
+ if (auto out = evaluate (begin, it, end, return_type<ResultIterator, Pattern> {}, ctll::list<start_mark, Pattern, end_mark, accept>())) {
62
60
return out;
63
61
}
64
62
}
65
63
66
64
// in case the RE is empty or fixed
67
- return evaluate (begin, it, end, return_type{}, ctll::list<start_mark, Pattern, end_mark, accept>());
65
+ return evaluate (begin, it, end, return_type<ResultIterator, Pattern> {}, ctll::list<start_mark, Pattern, end_mark, accept>());
68
66
}
69
67
70
68
@@ -109,7 +107,7 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator, Iterator current, const E
109
107
110
108
template <typename R, typename Iterator, typename EndIterator, typename CharacterLike, typename ... Tail, typename = std::enable_if_t <(MatchesCharacter<CharacterLike>::template value<decltype (*std::declval<Iterator>())>)>>
111
109
constexpr CTRE_FORCE_INLINE R evaluate (const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<CharacterLike, Tail...>) noexcept {
112
- if (end == current ) return not_matched;
110
+ if (current == end ) return not_matched;
113
111
if (!CharacterLike::match_char (*current)) return not_matched;
114
112
return evaluate (begin, current+1 , end, captures, ctll::list<Tail...>());
115
113
}
0 commit comments