Skip to content

Commit

Permalink
fix issue #329: lookbehind rotating inner regex in select<...>
Browse files Browse the repository at this point in the history
  • Loading branch information
hanickadot committed Feb 25, 2025
1 parent a9418a5 commit dadd207
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion include/ctre/rotate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ static auto rotate(end_lookbehind_mark) -> end_lookbehind_mark;
template <size_t Id> static auto rotate(numeric_mark<Id>) -> numeric_mark<Id>;
static auto rotate(any) -> any;

template <typename... Content> static auto rotate(select<Content...>) -> select<Content...>;
static auto rotate(empty) -> empty;


Expand Down Expand Up @@ -92,6 +91,10 @@ static auto rotate(assert_subject_end_line) -> assert_subject_end_line;
static auto rotate(assert_line_begin) -> assert_line_begin;
static auto rotate(assert_line_end) -> assert_line_end;

// select rotates only insides of selection, not select itself
template <typename... Content> static auto rotate(select<Content...>) -> select<decltype(rotate(Content{}))...>;


};

}
Expand Down
4 changes: 3 additions & 1 deletion single-header/ctre-unicode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,6 @@ static auto rotate(end_lookbehind_mark) -> end_lookbehind_mark;
template <size_t Id> static auto rotate(numeric_mark<Id>) -> numeric_mark<Id>;
static auto rotate(any) -> any;

template <typename... Content> static auto rotate(select<Content...>) -> select<Content...>;
static auto rotate(empty) -> empty;

template <size_t a, size_t b, typename... Content> static auto rotate(repeat<a,b,Content...>) -> decltype(ctre::convert_to_repeat<repeat, a, b>(ctll::rotate(ctll::list<decltype(rotate(Content{}))...>{})));
Expand Down Expand Up @@ -2112,6 +2111,9 @@ static auto rotate(assert_subject_end_line) -> assert_subject_end_line;
static auto rotate(assert_line_begin) -> assert_line_begin;
static auto rotate(assert_line_end) -> assert_line_end;

// select rotates only insides of selection, not select itself
template <typename... Content> static auto rotate(select<Content...>) -> select<decltype(rotate(Content{}))...>;

};

}
Expand Down
4 changes: 3 additions & 1 deletion single-header/ctre.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,6 @@ static auto rotate(end_lookbehind_mark) -> end_lookbehind_mark;
template <size_t Id> static auto rotate(numeric_mark<Id>) -> numeric_mark<Id>;
static auto rotate(any) -> any;

template <typename... Content> static auto rotate(select<Content...>) -> select<Content...>;
static auto rotate(empty) -> empty;

template <size_t a, size_t b, typename... Content> static auto rotate(repeat<a,b,Content...>) -> decltype(ctre::convert_to_repeat<repeat, a, b>(ctll::rotate(ctll::list<decltype(rotate(Content{}))...>{})));
Expand Down Expand Up @@ -2109,6 +2108,9 @@ static auto rotate(assert_subject_end_line) -> assert_subject_end_line;
static auto rotate(assert_line_begin) -> assert_line_begin;
static auto rotate(assert_line_end) -> assert_line_end;

// select rotates only insides of selection, not select itself
template <typename... Content> static auto rotate(select<Content...>) -> select<decltype(rotate(Content{}))...>;

};

}
Expand Down
3 changes: 3 additions & 0 deletions tests/generating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,8 @@ static_assert(same_f(CTRE_GEN("(?<!a)"), ctre::lookbehind_negative<ctre::charact
static_assert(same_f(CTRE_GEN("(?<=ab)"), ctre::lookbehind_positive<ctre::string<'b','a'>>()));
static_assert(same_f(CTRE_GEN("(?<!ab)"), ctre::lookbehind_negative<ctre::string<'b','a'>>()));

static_assert(same_f(CTRE_GEN("(?<=ab|cd)"), ctre::lookbehind_positive<ctre::select<ctre::string<'b','a'>, ctre::string<'d','c'>>>()));
static_assert(same_f(CTRE_GEN("(?<!ab|cd)"), ctre::lookbehind_negative<ctre::select<ctre::string<'b','a'>, ctre::string<'d','c'>>>()));

static_assert(same_f(CTRE_GEN("(?<=(ab))"), ctre::lookbehind_positive<ctre::capture<1, ctre::string<'b','a'>>>()));
static_assert(same_f(CTRE_GEN("(?<!(ab))"), ctre::lookbehind_negative<ctre::capture<1, ctre::string<'b','a'>>>()));
5 changes: 5 additions & 0 deletions tests/matching3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,8 @@ TEST_MATCH(225, R"( ?[\p{N}])", " 1");
TEST_MATCH(226, R"( ?\p{N})", " 1");
TEST_MATCH(227, R"( ?\p{N}+)", " 1234");

// issue #339 (rotate didn't rotate inside of selection)
TEST_SEARCH(228, "(?<=ba|cd)s", "bas");
TEST_NOT_SEARCH(229, "(?<!ba|cd)s", "bas"); // negative means both "ba|cd most not be there"
TEST_SEARCH(230, "(?<=ba|cd)s", "cds");
TEST_NOT_SEARCH(231, "(?<!ba|cd)s", "cds"); // negative means both "ba|cd most not be there"

0 comments on commit dadd207

Please sign in to comment.