Skip to content

Commit

Permalink
fixes #305: binary_property and property wasn't handler in first-foll…
Browse files Browse the repository at this point in the history
…ow checker
  • Loading branch information
hanickadot committed Apr 25, 2024
1 parent 9725886 commit 713005f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
15 changes: 12 additions & 3 deletions include/ctre/first.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ template <auto A, typename CB> constexpr int64_t negative_helper(ctre::character
} else {
return A;
}
}
}

template <auto A, auto B, typename CB> constexpr int64_t negative_helper(ctre::char_range<A,B>, CB & cb, int64_t start) {
if (A != (std::numeric_limits<int64_t>::min)()) {
Expand All @@ -345,7 +345,7 @@ template <auto A, auto B, typename CB> constexpr int64_t negative_helper(ctre::c
} else {
return B;
}
}
}

template <auto Head, auto... Tail, typename CB> constexpr int64_t negative_helper(ctre::enumeration<Head, Tail...>, CB & cb, int64_t start) {
int64_t nstart = negative_helper(ctre::character<Head>{}, cb, start);
Expand Down Expand Up @@ -417,7 +417,7 @@ template <size_t Capacity> class point_set {
auto last = end();
auto it = first;
auto count = std::distance(first, last);
while (count != 0) {
while (count != 0) {
it = first;
auto step = count / 2;
std::advance(it, step);
Expand Down Expand Up @@ -487,6 +487,15 @@ template <size_t Capacity> class point_set {
constexpr bool check(can_be_anything) {
return used > 0;
}
template <typename PropertyType, PropertyType Property>
constexpr bool check(ctre::binary_property<PropertyType, Property>) {
return check(can_be_anything{});
}

template <typename PropertyType, PropertyType Property, auto Value>
constexpr bool check(ctre::property<PropertyType, Property, Value>) {
return check(can_be_anything{});
}
template <typename... Content> constexpr bool check(ctre::negative_set<Content...> nset) {
bool collision = false;
negative_helper(nset, [&](int64_t low, int64_t high){
Expand Down
15 changes: 12 additions & 3 deletions single-header/ctre-unicode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4282,7 +4282,7 @@ template <auto A, typename CB> constexpr int64_t negative_helper(ctre::character
} else {
return A;
}
}
}

template <auto A, auto B, typename CB> constexpr int64_t negative_helper(ctre::char_range<A,B>, CB & cb, int64_t start) {
if (A != (std::numeric_limits<int64_t>::min)()) {
Expand All @@ -4295,7 +4295,7 @@ template <auto A, auto B, typename CB> constexpr int64_t negative_helper(ctre::c
} else {
return B;
}
}
}

template <auto Head, auto... Tail, typename CB> constexpr int64_t negative_helper(ctre::enumeration<Head, Tail...>, CB & cb, int64_t start) {
int64_t nstart = negative_helper(ctre::character<Head>{}, cb, start);
Expand Down Expand Up @@ -4367,7 +4367,7 @@ template <size_t Capacity> class point_set {
auto last = end();
auto it = first;
auto count = std::distance(first, last);
while (count != 0) {
while (count != 0) {
it = first;
auto step = count / 2;
std::advance(it, step);
Expand Down Expand Up @@ -4437,6 +4437,15 @@ template <size_t Capacity> class point_set {
constexpr bool check(can_be_anything) {
return used > 0;
}
template <typename PropertyType, PropertyType Property>
constexpr bool check(ctre::binary_property<PropertyType, Property>) {
return check(can_be_anything{});
}

template <typename PropertyType, PropertyType Property, auto Value>
constexpr bool check(ctre::property<PropertyType, Property, Value>) {
return check(can_be_anything{});
}
template <typename... Content> constexpr bool check(ctre::negative_set<Content...> nset) {
bool collision = false;
negative_helper(nset, [&](int64_t low, int64_t high){
Expand Down
15 changes: 12 additions & 3 deletions single-header/ctre.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4279,7 +4279,7 @@ template <auto A, typename CB> constexpr int64_t negative_helper(ctre::character
} else {
return A;
}
}
}

template <auto A, auto B, typename CB> constexpr int64_t negative_helper(ctre::char_range<A,B>, CB & cb, int64_t start) {
if (A != (std::numeric_limits<int64_t>::min)()) {
Expand All @@ -4292,7 +4292,7 @@ template <auto A, auto B, typename CB> constexpr int64_t negative_helper(ctre::c
} else {
return B;
}
}
}

template <auto Head, auto... Tail, typename CB> constexpr int64_t negative_helper(ctre::enumeration<Head, Tail...>, CB & cb, int64_t start) {
int64_t nstart = negative_helper(ctre::character<Head>{}, cb, start);
Expand Down Expand Up @@ -4364,7 +4364,7 @@ template <size_t Capacity> class point_set {
auto last = end();
auto it = first;
auto count = std::distance(first, last);
while (count != 0) {
while (count != 0) {
it = first;
auto step = count / 2;
std::advance(it, step);
Expand Down Expand Up @@ -4434,6 +4434,15 @@ template <size_t Capacity> class point_set {
constexpr bool check(can_be_anything) {
return used > 0;
}
template <typename PropertyType, PropertyType Property>
constexpr bool check(ctre::binary_property<PropertyType, Property>) {
return check(can_be_anything{});
}

template <typename PropertyType, PropertyType Property, auto Value>
constexpr bool check(ctre::property<PropertyType, Property, Value>) {
return check(can_be_anything{});
}
template <typename... Content> constexpr bool check(ctre::negative_set<Content...> nset) {
bool collision = false;
negative_helper(nset, [&](int64_t low, int64_t high){
Expand Down
1 change: 1 addition & 0 deletions tests/_bad_cycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ using namespace std::string_view_literals;
static_assert(match("ab"sv, ctre::plus<ctre::select<ctre::string<'a','b'>, ctre::character<'a'>>>()), "(ab|a)+");
// this will need fix in different branch as this is a long standing problem
//static_assert(match("ab"sv, ctre::plus<ctre::select<ctre::character<'a'>, ctre::string<'a','b'>>>()), "(a|ab)+");

6 changes: 4 additions & 2 deletions tests/matching3.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <ctre.hpp>
#include <ctre-unicode.hpp>
#include <string_view>

void empty_symbol() { }
Expand Down Expand Up @@ -230,5 +230,7 @@ TEST_NOT_SEARCH(222, u8"(?<=ě)b", u8"čb");
TEST_MATCH(223, "(?>abc)?", "abc");
TEST_MATCH(224, "(?>abc)?", "");


TEST_MATCH(225, R"( ?[\p{N}])", " 1");
TEST_MATCH(226, R"( ?\p{N})", " 1");
TEST_MATCH(227, R"( ?\p{N}+)", " 1234");

0 comments on commit 713005f

Please sign in to comment.