Support operator--() for util::utf8_iterator

This commit is contained in:
Nikita Lisitsa 2025-04-13 12:42:51 +03:00
parent 9f0f07885d
commit 6cf5eb008b
2 changed files with 20 additions and 1 deletions

View file

@ -17,12 +17,16 @@ namespace psemek::util
using pointer = void;
using reference = void;
using difference_type = std::ptrdiff_t;
using iterator_category = std::input_iterator_tag;
using iterator_category = std::bidirectional_iterator_tag;
char const * ptr;
utf8_iterator & operator ++();
utf8_iterator operator ++(int);
utf8_iterator & operator --();
utf8_iterator operator --(int);
char32_t operator *() const;
};

View file

@ -82,6 +82,21 @@ namespace psemek::util
return copy;
}
utf8_iterator & utf8_iterator::operator --()
{
--ptr;
while (is_middle_byte(*ptr))
--ptr;
return *this;
}
utf8_iterator utf8_iterator::operator --(int)
{
utf8_iterator copy(*this);
--(*this);
return copy;
}
char32_t utf8_iterator::operator *() const
{
if (is_1_byte(ptr[0]))