Skip to content

Commit 47c440b

Browse files
committed
Added handling of \G.
1 parent 44a7255 commit 47c440b

File tree

5 files changed

+357
-296
lines changed

5 files changed

+357
-296
lines changed

include/cpp2regex.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ template<typename CharT, int min_count, int max_count, int kind> class range_tok
7070
#line 673 "cpp2regex.h2"
7171
template<typename CharT, typename matcher_wrapper> class regular_expression;
7272

73-
#line 756 "cpp2regex.h2"
73+
#line 760 "cpp2regex.h2"
7474
}
7575
}
7676

@@ -149,7 +149,7 @@ template<typename CharT, typename Iter, int max_groups> class match_context
149149

150150
private: std::array<match_group<Iter>,max_groups> groups {};
151151

152-
public: match_context(Iter const& begin_, Iter const& end_);
152+
public: explicit match_context(Iter const& begin_, Iter const& end_);
153153

154154
#line 68 "cpp2regex.h2"
155155
public: match_context(match_context const& that);
@@ -212,7 +212,7 @@ template<typename Func> class on_return
212212
{
213213
private: Func func;
214214

215-
public: on_return(Func const& f);
215+
public: explicit on_return(Func const& f);
216216
#line 136 "cpp2regex.h2"
217217
public: auto operator=(Func const& f) -> on_return& ;
218218

@@ -577,7 +577,7 @@ template<typename CharT, typename matcher_wrapper> class regular_expression
577577
public: context<Iter> ctx;
578578
public: int pos;
579579

580-
public: search_return(cpp2::impl::in<bool> matched_, context<Iter> const& ctx_, Iter const& pos_);
580+
public: explicit search_return(cpp2::impl::in<bool> matched_, context<Iter> const& ctx_, Iter const& pos_);
581581

582582
#line 690 "cpp2regex.h2"
583583
public: [[nodiscard]] auto group_number() const& -> decltype(auto);
@@ -608,7 +608,7 @@ template<typename CharT, typename matcher_wrapper> class regular_expression
608608
public: [[nodiscard]] auto search(cpp2::impl::in<bview<CharT>> str, auto const& start, auto const& length) const& -> decltype(auto);
609609
public: template<typename Iter> [[nodiscard]] auto search(Iter const& start, Iter const& end) const& -> search_return<Iter>;
610610

611-
#line 742 "cpp2regex.h2"
611+
#line 746 "cpp2regex.h2"
612612
public: [[nodiscard]] auto to_string() const& -> decltype(auto);
613613

614614
// Helper functions
@@ -619,7 +619,7 @@ template<typename CharT, typename matcher_wrapper> class regular_expression
619619
public: auto operator=(regular_expression const&) -> void = delete;
620620

621621

622-
#line 754 "cpp2regex.h2"
622+
#line 758 "cpp2regex.h2"
623623
};
624624

625625
}
@@ -1171,15 +1171,19 @@ template<typename CharT, bool negate> [[nodiscard]] auto word_boundary_token_mat
11711171
if (cur == ctx.end) {
11721172
break;
11731173
}
1174+
1175+
if (matcher<Iter>::is_start_match()) {
1176+
break; // Always break with \G option.
1177+
}
11741178
}
11751179

11761180
return search_return<Iter>(r.matched, cpp2::move(ctx), cpp2::move(r).pos);
11771181
}
11781182

1179-
#line 742 "cpp2regex.h2"
1183+
#line 746 "cpp2regex.h2"
11801184
template <typename CharT, typename matcher_wrapper> [[nodiscard]] auto regular_expression<CharT,matcher_wrapper>::to_string() const& -> decltype(auto) { return matcher_wrapper::to_string(); }
11811185

1182-
#line 746 "cpp2regex.h2"
1186+
#line 750 "cpp2regex.h2"
11831187
template <typename CharT, typename matcher_wrapper> [[nodiscard]] auto regular_expression<CharT,matcher_wrapper>::get_iter(cpp2::impl::in<bview<CharT>> str, auto const& pos) -> auto{
11841188
if (cpp2::impl::cmp_less(pos,str.size())) {
11851189
return str.begin() + pos;
@@ -1189,7 +1193,7 @@ template<typename CharT, bool negate> [[nodiscard]] auto word_boundary_token_mat
11891193
}
11901194
}
11911195

1192-
#line 756 "cpp2regex.h2"
1196+
#line 760 "cpp2regex.h2"
11931197
}
11941198
}
11951199

include/cpp2regex.h2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,10 @@ regular_expression: <CharT, matcher_wrapper> type =
734734
if cur == ctx.end {
735735
break;
736736
}
737+
738+
if matcher<Iter>::is_start_match() {
739+
break; // Always break with \G option.
740+
}
737741
}
738742

739743
return search_return<Iter>(r.matched, ctx, r.pos);

regression-tests/pure2-regex_04_start_end.cpp2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ test_tests_04_start_end: @regex type = {
172172
regex_07 := R"(^)";
173173
regex_08 := R"($)";
174174
regex_09 := R"($b)";
175+
regex_10 := R"(\GX.*X)";
175176
run: (this) = {
176177
std::cout << "Running tests_04_start_end:"<< std::endl;
177178
test(regex_01, "01", R"(^abc$)", "abc", "y", R"($&)", "abc");
@@ -183,6 +184,7 @@ test_tests_04_start_end: @regex type = {
183184
test(regex_07, "07", R"(^)", "abc", "y", R"($&)", "");
184185
test(regex_08, "08", R"($)", "abc", "y", R"($&)", "");
185186
test(regex_09, "09", R"($b)", "b", "n", R"(-)", "-");
187+
test(regex_10, "10", R"(\GX.*X)", "aaaXbX", "n", R"(-)", "-");
186188
std::cout << std::endl;
187189
}
188190
}

0 commit comments

Comments
 (0)