Skip to content

Commit 4fa4404

Browse files
committed
support for comparing char8_t with sentinel
1 parent 1800359 commit 4fa4404

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

include/ctre/utf8.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ struct utf8_iterator {
3333
auto operator--(int) noexcept -> self_type;
3434
friend auto operator==(self_type, self_type) noexcept -> bool;
3535
auto operator*() noexcept -> reference;
36+
37+
friend constexpr auto operator==(self_type, const char8_t * ptr) noexcept {
38+
return *ptr == char8_t{0};
39+
}
3640
};
3741

3842
const char8_t * ptr{nullptr};

single-header/ctre-unicode.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,6 +3057,10 @@ struct utf8_iterator {
30573057
auto operator--(int) noexcept -> self_type;
30583058
friend auto operator==(self_type, self_type) noexcept -> bool;
30593059
auto operator*() noexcept -> reference;
3060+
3061+
friend constexpr auto operator==(self_type, const char8_t * ptr) noexcept {
3062+
return *ptr == char8_t{0};
3063+
}
30603064
};
30613065

30623066
const char8_t * ptr{nullptr};

single-header/ctre.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,6 +3054,10 @@ struct utf8_iterator {
30543054
auto operator--(int) noexcept -> self_type;
30553055
friend auto operator==(self_type, self_type) noexcept -> bool;
30563056
auto operator*() noexcept -> reference;
3057+
3058+
friend constexpr auto operator==(self_type, const char8_t * ptr) noexcept {
3059+
return *ptr == char8_t{0};
3060+
}
30573061
};
30583062

30593063
const char8_t * ptr{nullptr};

tests/mode.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ static_assert(CTRE_TEST("y(?i)"));
4141
static_assert(CTRE_TEST("y(?ic)"));
4242
static_assert(CTRE_TEST("y(?icsm)"));
4343

44+
static_assert(CTRE_TEST("(?i)Tom|Sawyer|Huckleberry|Finn"));
45+
4446

0 commit comments

Comments
 (0)