Skip to content

Commit b45902e

Browse files
author
Hana Dusíková
committed
removing structured bindings and remove implicit std::basic_string_view operator template argument
1 parent 8baea47 commit b45902e

File tree

3 files changed

+200
-12
lines changed

3 files changed

+200
-12
lines changed

include/ctre/evaluation.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ template <typename R, typename Iterator, typename EndIterator, auto... String, t
9090
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<string<String...>, Tail...>) noexcept {
9191
if constexpr (sizeof...(String) == 0) {
9292
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
93-
} else if (auto [it, ok] = evaluate_match_string<String...>(current, end); ok) {
94-
return evaluate(begin, it, end, captures, ctll::list<Tail...>());
93+
} else if (auto tmp = evaluate_match_string<String...>(current, end); tmp.match) {
94+
return evaluate(begin, tmp.current, end, captures, ctll::list<Tail...>());
9595
} else {
9696
return not_matched;
9797
}
@@ -338,8 +338,8 @@ template <typename R, typename Id, typename Iterator, typename EndIterator, type
338338
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<back_reference_with_name<Id>, Tail...>) noexcept {
339339

340340
if (const auto ref = captures.template get<Id>()) {
341-
if (auto [it, matches] = match_against_range(current, end, ref.begin(), ref.end()); matches) {
342-
return evaluate(begin, it, end, captures, ctll::list<Tail...>());
341+
if (auto tmp = match_against_range(current, end, ref.begin(), ref.end()); tmp.match) {
342+
return evaluate(begin, tmp.current, end, captures, ctll::list<Tail...>());
343343
}
344344
}
345345
return not_matched;
@@ -350,8 +350,8 @@ template <typename R, size_t Id, typename Iterator, typename EndIterator, typena
350350
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<back_reference<Id>, Tail...>) noexcept {
351351

352352
if (const auto ref = captures.template get<Id>()) {
353-
if (auto [it, matches] = match_against_range(current, end, ref.begin(), ref.end()); matches) {
354-
return evaluate(begin, it, end, captures, ctll::list<Tail...>());
353+
if (auto tmp = match_against_range(current, end, ref.begin(), ref.end()); tmp.match) {
354+
return evaluate(begin, tmp.current, end, captures, ctll::list<Tail...>());
355355
}
356356
}
357357
return not_matched;

include/ctre/return_type.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ template <size_t Id, typename Name = void> struct captured_content {
5858
return std::basic_string_view<char_type>(&*_begin, static_cast<size_t>(std::distance(_begin, _end)));
5959
}
6060

61-
template <typename U = char_type>
62-
constexpr operator std::basic_string_view<U>() const noexcept {
61+
constexpr operator std::basic_string_view<char_type>() const noexcept {
6362
return to_view();
6463
}
6564

@@ -76,7 +75,7 @@ static constexpr inline auto capture_not_exists = capture_not_exists_tag{};
7675
template <typename... Captures> struct captures;
7776

7877
template <typename Head, typename... Tail> struct captures<Head, Tail...>: captures<Tail...> {
79-
Head head;
78+
Head head{};
8079
constexpr CTRE_FORCE_INLINE captures() noexcept { }
8180
template <size_t id> CTRE_FORCE_INLINE static constexpr bool exists() noexcept {
8281
if constexpr (id == Head::get_id()) {
@@ -141,7 +140,7 @@ template <> struct captures<> {
141140
template <typename Iterator, typename... Captures> struct regex_results {
142141
using char_type = typename std::iterator_traits<Iterator>::value_type;
143142

144-
captures<captured_content<0>::template storage<Iterator>, typename Captures::template storage<Iterator>...> _captures;
143+
captures<captured_content<0>::template storage<Iterator>, typename Captures::template storage<Iterator>...> _captures{};
145144

146145
constexpr CTRE_FORCE_INLINE regex_results() noexcept { }
147146
constexpr CTRE_FORCE_INLINE regex_results(not_matched_tag_t) noexcept { }
@@ -170,8 +169,7 @@ template <typename Iterator, typename... Captures> struct regex_results {
170169
return bool(_captures.template select<0>());
171170
}
172171

173-
template <typename U = char_type>
174-
constexpr operator std::basic_string_view<U>() const noexcept {
172+
constexpr operator std::basic_string_view<char_type>() const noexcept {
175173
return to_view();
176174
}
177175

tests/matching3.cpp

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
#include <ctre.hpp>
2+
#include <string_view>
3+
4+
using namespace ctre::literals;
5+
using namespace ctre::test_literals;
6+
using namespace std::string_view_literals;
7+
8+
#define TEST_MATCH(id, pattern, subject) static constexpr inline auto _ptn ## id = ctll::basic_fixed_string(pattern); static_assert(ctre::re<_ptn ## id>().match(subject));
9+
10+
#define TEST_SEARCH(id, pattern, subject) static constexpr inline auto _ptn ## id = ctll::basic_fixed_string(pattern); static_assert(ctre::re<_ptn ## id>().search(subject));
11+
12+
#define TEST_NOT_MATCH(id, pattern, subject) static constexpr inline auto _ptn ## id = ctll::basic_fixed_string(pattern); static_assert(!ctre::re<_ptn ## id>().match(subject));
13+
14+
#define TEST_NOT_SEARCH(id, pattern, subject) static constexpr inline auto _ptn ## id = ctll::basic_fixed_string(pattern); static_assert(!ctre::re<_ptn ## id>().search(subject));
15+
16+
17+
TEST_MATCH(1, "blabla","blabla");
18+
TEST_NOT_MATCH(2,"blabla","blabla2");
19+
20+
TEST_SEARCH(3, "", "abc");
21+
TEST_MATCH(4, "abc", "abc");
22+
23+
TEST_MATCH(5, "a", "a");
24+
TEST_SEARCH(6, "a", "abc");
25+
TEST_SEARCH(7, "b", "abc");
26+
TEST_NOT_MATCH(8, "^b", "abc");
27+
TEST_NOT_MATCH(9, "b", "a");
28+
TEST_MATCH(10, ".", "a");
29+
TEST_SEARCH(11, ".", "abc");
30+
TEST_MATCH(12, "[\\-]", "-");
31+
TEST_MATCH(13, "[\\\\]", "\\");
32+
TEST_MATCH(14, "[a-z]", "a");
33+
TEST_MATCH(15, "[a-z]", "f");
34+
TEST_MATCH(16, "[a-z]", "z");
35+
TEST_NOT_MATCH(17, "[a-z]", "Z");
36+
TEST_MATCH(18, "^[\\x30-\\x39]+?$", "123456789");
37+
TEST_MATCH(19, "[a-z0-9]", "0");
38+
TEST_NOT_MATCH(20, "[a-z0-9]", "A");
39+
TEST_MATCH(21, "[[:xdigit:]]", "0");
40+
TEST_MATCH(22, "[[:xdigit:]]", "9");
41+
TEST_MATCH(22b, "[[:xdigit:]]", "a");
42+
TEST_MATCH(23, "[[:xdigit:]]", "A");
43+
TEST_MATCH(24, "[[:xdigit:]]", "f");
44+
TEST_NOT_MATCH(25, "[[:xdigit:]]", "g");
45+
TEST_MATCH(26, "abcdef", "abcdef");
46+
TEST_NOT_MATCH(27, "abcdef", "abcGef");
47+
TEST_MATCH(28, "", "");
48+
TEST_MATCH(29, "(?:a|b|c)", "a");
49+
TEST_MATCH(30, "(?:a|b|c)", "b");
50+
TEST_MATCH(31, "(?:a|b|c)", "c");
51+
TEST_NOT_MATCH(32, "(?:a|b|c)", "d");
52+
TEST_MATCH(33, "(?:xy)?", "xy");
53+
TEST_MATCH(34, "(?:xy)?", "");
54+
TEST_SEARCH(35, "(?:xy)?", "zxy");
55+
TEST_SEARCH(36, "(?:xy)?$", "zxy");
56+
TEST_NOT_MATCH(37, "~(?:xy)?$", "zxy");
57+
58+
TEST_MATCH(38, "^abc", "abc");
59+
TEST_MATCH(39, "^def$", "def");
60+
TEST_NOT_MATCH(40, "a^", "a");
61+
TEST_NOT_MATCH(41, "$a", "a");
62+
63+
TEST_SEARCH(42, "a+?", "aaax");
64+
TEST_SEARCH(43, "a+?", "ax");
65+
TEST_NOT_MATCH(44, "a+?", "x");
66+
67+
TEST_SEARCH(45, "a++", "aaax");
68+
TEST_SEARCH(46, "a++", "ax");
69+
TEST_NOT_MATCH(47, "a++", "x");
70+
71+
TEST_MATCH(48, "a*?x", "aaax");
72+
TEST_MATCH(49, "a*?x", "ax");
73+
TEST_MATCH(50, "a*?x", "x");
74+
TEST_NOT_MATCH(51, "a*?x", "y");
75+
76+
TEST_MATCH(52, "a*+x", "aaax");
77+
TEST_MATCH(53, "a*+x", "ax");
78+
TEST_MATCH(54, "a*+x", "x");
79+
TEST_NOT_MATCH(55, "a*+x", "y");
80+
81+
TEST_NOT_MATCH(56, "a*+ab", "aaab");
82+
TEST_NOT_MATCH(57, "a++ab", "aaab");
83+
TEST_NOT_MATCH(58, "a*+ab", "ab");
84+
TEST_NOT_MATCH(59, "a++ab", "aab");
85+
86+
TEST_MATCH(60, "a*+ba", "aaba");
87+
TEST_MATCH(61, "a++ba", "aaba");
88+
TEST_MATCH(62, "a*+ba", "ba");
89+
TEST_MATCH(63, "a++ba", "aba");
90+
91+
TEST_MATCH(64, "a{3,}x", "aaax");
92+
TEST_MATCH(65, "a{3,}x", "aaaax");
93+
94+
TEST_MATCH(66, "^a{5}", "aaaaa");
95+
TEST_SEARCH(67, "^a{5}", "aaaaaa");
96+
TEST_NOT_MATCH(68, "^a{5}$", "aaaaaa");
97+
98+
TEST_MATCH(69, "a*", "aaa");
99+
TEST_MATCH(70, "a+", "aaa");
100+
TEST_MATCH(71, "a*", "");
101+
TEST_MATCH(72, "a+", "a");
102+
103+
TEST_MATCH(73, "a*$", "aaa");
104+
TEST_MATCH(74, "a+$", "aaa");
105+
TEST_MATCH(75, "a*$", "");
106+
TEST_MATCH(76, "a+$", "a");
107+
108+
TEST_MATCH(77, "a*xb", "aaxb");
109+
TEST_MATCH(78, "a+xb", "aaxb");
110+
TEST_MATCH(79, "a*xb", "xb");
111+
TEST_MATCH(80, "a+xb", "axb");
112+
113+
TEST_MATCH(81, "a*ab", "aaab");
114+
TEST_MATCH(82, "a+ab", "aaab");
115+
TEST_MATCH(83, "a*ab", "ab");
116+
TEST_MATCH(84, "a+ab", "aab");
117+
118+
TEST_NOT_MATCH(85, "^a{2,5}ab", "aab");
119+
TEST_MATCH(86, "^a{2,5}ab", "aaab");
120+
TEST_MATCH(87, "^a{2,5}ab", "aaaab");
121+
TEST_MATCH(88, "^a{2,5}ab", "aaaaab");
122+
TEST_MATCH(89, "^a{2,5}ab", "aaaaaab");
123+
TEST_NOT_MATCH(90, "^a{2,5}ab", "aaaaaaab");
124+
125+
TEST_MATCH(91, "(abc)", "abc");
126+
TEST_MATCH(92, "(abc)+", "abc");
127+
TEST_MATCH(93, "(abc)+", "abcabc");
128+
TEST_MATCH(94, "(abc)+", "abcabcabc");
129+
130+
TEST_MATCH(95, "(?<name>abc)", "abc");
131+
TEST_MATCH(96, "(?<name>abc)+", "abc");
132+
TEST_MATCH(97, "(?<name>abc)+", "abcabc");
133+
TEST_MATCH(98, "(?<name>abc)+", "abcabcabc");
134+
TEST_NOT_MATCH(99, "(?<name>abc)+", "name");
135+
136+
137+
138+
139+
140+
TEST_MATCH(101, "^([0-9]+[a-z]+)+", "123abc456def");
141+
142+
143+
144+
TEST_MATCH(102, "^([0-9]++[a-z]++)+", "123abc456def");
145+
146+
147+
148+
TEST_SEARCH(103, "^([0-9]+?[a-z]+?)+", "123abc456def");
149+
150+
151+
152+
TEST_MATCH(104, "^([0-9]+?[a-z]++)+", "123abc456def");
153+
154+
155+
156+
157+
158+
159+
TEST_MATCH(105, "^([a-z]+):\\g{1}$", "abc:abc"sv);
160+
161+
TEST_NOT_MATCH(106, "^([a-z]+):\\g{1}$", "abc:abce"sv);
162+
TEST_MATCH(107, "^([a-z]+)\\g{1}$", "abcabc"sv);
163+
TEST_NOT_MATCH(108, "^([a-z]+)\\g{1}$", "abcabcd"sv);
164+
165+
TEST_MATCH(109, "^([a-z]+)\\g{-1}$", "abcabc"sv);
166+
167+
168+
TEST_MATCH(110, "^(?<text>[a-z]+):\\g{text}$", "abc:abc"sv);
169+
170+
TEST_MATCH(111, "^abc$", "abc");
171+
172+
173+
174+
175+
176+
177+
TEST_MATCH(112, "\\[\\]", "[]");
178+
179+
180+
181+
182+
183+
184+
185+
186+
187+
188+
189+
190+

0 commit comments

Comments
 (0)