Skip to content

Commit b838127

Browse files
committed
Fix: Misplaced UTF-8 skip in StringZilla
1 parent 6f045aa commit b838127

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

include/stringzilla/stringzilla.hpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -607,33 +607,6 @@ class range_matches {
607607
return temp;
608608
}
609609

610-
/**
611-
* @brief Advance the iterator by @p n UTF-8 codepoints, decoding new batches as needed.
612-
* @note This is forward-only; negative offsets are unsupported. Uses the fast C API to skip bytes.
613-
*/
614-
iterator &operator+=(size_type n) noexcept {
615-
if (n == 0 || octets_offset_ >= octets_length_) return *this;
616-
617-
sz_cptr_t ptr = sz_utf8_find_nth(octets_start_ + octets_offset_, octets_length_ - octets_offset_, n);
618-
if (!ptr) {
619-
// Past the end.
620-
octets_offset_ = octets_length_;
621-
runes_count_ = 0;
622-
runes_offset_ = 0;
623-
return *this;
624-
}
625-
626-
octets_offset_ = static_cast<size_type>(ptr - octets_start_);
627-
decode_batch_();
628-
return *this;
629-
}
630-
631-
iterator operator+(size_type n) const noexcept {
632-
iterator tmp = *this;
633-
tmp += n;
634-
return tmp;
635-
}
636-
637610
// Assumes both iterators point to the same underlying string.
638611
bool operator!=(iterator const &other) const noexcept { return remaining_.data() != other.remaining_.data(); }
639612
bool operator==(iterator const &other) const noexcept { return remaining_.data() == other.remaining_.data(); }
@@ -1073,6 +1046,33 @@ class range_utf8_chars {
10731046
return temp;
10741047
}
10751048

1049+
/**
1050+
* @brief Advance the iterator by @p n UTF-8 codepoints, decoding new batches as needed.
1051+
* @note This is forward-only; negative offsets are unsupported. Uses the fast C API to skip bytes.
1052+
*/
1053+
iterator &operator+=(size_type n) noexcept {
1054+
if (n == 0 || octets_offset_ >= octets_length_) return *this;
1055+
1056+
sz_cptr_t ptr = sz_utf8_find_nth(octets_start_ + octets_offset_, octets_length_ - octets_offset_, n);
1057+
if (!ptr) {
1058+
// Past the end.
1059+
octets_offset_ = octets_length_;
1060+
runes_count_ = 0;
1061+
runes_offset_ = 0;
1062+
return *this;
1063+
}
1064+
1065+
octets_offset_ = static_cast<size_type>(ptr - octets_start_);
1066+
decode_batch_();
1067+
return *this;
1068+
}
1069+
1070+
iterator operator+(size_type n) const noexcept {
1071+
iterator tmp = *this;
1072+
tmp += n;
1073+
return tmp;
1074+
}
1075+
10761076
bool operator==(iterator const &other) const noexcept {
10771077
// Check if both iterators have exhausted their data
10781078
bool this_at_end = (runes_count_ == 0 && octets_offset_ >= octets_length_);

0 commit comments

Comments
 (0)