Skip to content

Commit 2b41178

Browse files
committed
check for implicit anchor
1 parent 0e646f3 commit 2b41178

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

include/ctre/evaluation.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "atoms.hpp"
66
#include "atoms_unicode.hpp"
77
#include "starts_with_anchor.hpp"
8+
#include "has_implicit_anchor.hpp"
89
#include "utility.hpp"
910
#include "return_type.hpp"
1011
#include "find_captures.hpp"

include/ctre/has_implicit_anchor.hpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifndef CTRE__HAS_IMPLICIT_ANCHOR__HPP
2+
#define CTRE__HAS_IMPLICIT_ANCHOR__HPP
3+
4+
#include "atoms.hpp"
5+
#include "atoms_unicode.hpp"
6+
7+
namespace ctre {
8+
9+
template<typename... Content>
10+
constexpr bool has_implicit_anchor(ctll::list<repeat<0, 0, any>, Content...>) noexcept {
11+
return true;
12+
}
13+
template<typename... Content>
14+
constexpr bool has_implicit_anchor(ctll::list<repeat<1, 0, any>, Content...>) noexcept {
15+
return true;
16+
}
17+
18+
template<typename... Content>
19+
constexpr bool has_implicit_anchor(ctll::list<possessive_repeat<0, 0, any>, Content...>) noexcept {
20+
return true;
21+
}
22+
23+
template<typename... Content>
24+
constexpr bool has_implicit_anchor(ctll::list<possessive_repeat<1, 0, any>, Content...>) noexcept {
25+
return true;
26+
}
27+
28+
template<typename... Content>
29+
constexpr bool has_implicit_anchor(ctll::list<lazy_repeat<0, 0, any>, Content...>) noexcept {
30+
return true;
31+
}
32+
33+
template<typename... Content>
34+
constexpr bool has_implicit_anchor(ctll::list<lazy_repeat<1, 0, any>, Content...>) noexcept {
35+
return true;
36+
}
37+
38+
template<typename... Content, typename... Tail>
39+
constexpr bool has_implicit_anchor(ctll::list<sequence<Content...>, Tail...>) noexcept {
40+
return has_implicit_anchor(ctll::list<Content..., Tail...>{});
41+
}
42+
43+
//TODO: we may check captures as implicit anchors*, but they must not be backreferenced because for example "(.+)X\1" will not work properly with "1234X2345"
44+
/*
45+
template<size_t Id, typename... Content, typename... Tail>
46+
constexpr bool has_implicit_anchor(ctll::list<capture<Id, Content...>, Tail...>) noexcept {
47+
//Id must not be backreferenced
48+
return !id_backreference(Id) && has_implicit_anchor(ctll::list<Content..., Tail...>{});
49+
}
50+
51+
template<size_t Id, typename Name, typename... Content, typename... Tail>
52+
constexpr bool has_implicit_anchor(ctll::list<capture_with_name<Id, Name, Content...>, Tail...>) noexcept {
53+
//Id must not be backreferenced
54+
return !id_backreference(Id) && has_implicit_anchor(ctll::list<Content..., Tail...>{});
55+
}
56+
*/
57+
58+
template<typename... Opts, typename... Tail>
59+
constexpr bool has_implicit_anchor(ctll::list<select<Opts...>, Tail...>) noexcept {
60+
return (has_implicit_anchor(ctll::list<Opts, Tail...>{}) && ...);
61+
}
62+
63+
constexpr bool has_implicit_anchor(...) noexcept {
64+
return false;
65+
}
66+
}
67+
68+
#endif

include/ctre/wrapper.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct search_method {
6363
template <typename Modifier = singleline, typename ResultIterator = void, typename RE, typename IteratorBegin, typename IteratorEnd> constexpr CTRE_FORCE_INLINE static auto exec(IteratorBegin orig_begin, IteratorBegin begin, IteratorEnd end, RE) noexcept {
6464
using result_iterator = std::conditional_t<std::is_same_v<ResultIterator, void>, IteratorBegin, ResultIterator>;
6565

66-
constexpr bool fixed = starts_with_anchor(Modifier{}, ctll::list<RE>{});
66+
constexpr bool fixed = starts_with_anchor(Modifier{}, ctll::list<RE>{}) || has_implicit_anchor(ctll::list<RE>{});
6767

6868
auto it = begin;
6969

0 commit comments

Comments
 (0)