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
0 commit comments