Skip to content

Commit a947f4f

Browse files
author
Hana Dusíková
committed
added post increment operator to utf8 iterator
1 parent 84b7897 commit a947f4f

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

include/ctre/utf8.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ struct utf8_iterator {
6565
return *this;
6666
}
6767

68+
constexpr utf8_iterator operator++(int) noexcept {
69+
auto previous = *this;
70+
this->operator++();
71+
return previous;
72+
}
73+
6874
constexpr utf8_iterator operator+(unsigned step) const noexcept {
6975
utf8_iterator result = *this;
7076
while (step > 0) {

single-header/ctre-unicode.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,6 +2684,12 @@ struct utf8_iterator {
26842684
return *this;
26852685
}
26862686

2687+
constexpr utf8_iterator operator++(int) noexcept {
2688+
auto previous = *this;
2689+
this->operator++();
2690+
return previous;
2691+
}
2692+
26872693
constexpr utf8_iterator operator+(unsigned step) const noexcept {
26882694
utf8_iterator result = *this;
26892695
while (step > 0) {
@@ -3868,9 +3874,10 @@ template <typename Iterator> struct string_match_result {
38683874
};
38693875

38703876
template <typename CharT, typename Iterator, typename EndIterator> constexpr CTRE_FORCE_INLINE bool compare_character(CharT c, Iterator & it, const EndIterator & end) {
3871-
bool same = ((it != end) && (*it == c));
3872-
++it;
3873-
return same;
3877+
if (it != end) {
3878+
return *it++ == c;
3879+
}
3880+
return false;
38743881
}
38753882

38763883
template <auto... String, size_t... Idx, typename Iterator, typename EndIterator> constexpr CTRE_FORCE_INLINE string_match_result<Iterator> evaluate_match_string(Iterator current, [[maybe_unused]] const EndIterator end, std::index_sequence<Idx...>) noexcept {

single-header/ctre.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,6 +2681,12 @@ struct utf8_iterator {
26812681
return *this;
26822682
}
26832683

2684+
constexpr utf8_iterator operator++(int) noexcept {
2685+
auto previous = *this;
2686+
this->operator++();
2687+
return previous;
2688+
}
2689+
26842690
constexpr utf8_iterator operator+(unsigned step) const noexcept {
26852691
utf8_iterator result = *this;
26862692
while (step > 0) {
@@ -3865,9 +3871,10 @@ template <typename Iterator> struct string_match_result {
38653871
};
38663872

38673873
template <typename CharT, typename Iterator, typename EndIterator> constexpr CTRE_FORCE_INLINE bool compare_character(CharT c, Iterator & it, const EndIterator & end) {
3868-
bool same = ((it != end) && (*it == c));
3869-
++it;
3870-
return same;
3874+
if (it != end) {
3875+
return *it++ == c;
3876+
}
3877+
return false;
38713878
}
38723879

38733880
template <auto... String, size_t... Idx, typename Iterator, typename EndIterator> constexpr CTRE_FORCE_INLINE string_match_result<Iterator> evaluate_match_string(Iterator current, [[maybe_unused]] const EndIterator end, std::index_sequence<Idx...>) noexcept {

0 commit comments

Comments
 (0)