Support operator--() for util::utf8_iterator
This commit is contained in:
parent
9f0f07885d
commit
6cf5eb008b
2 changed files with 20 additions and 1 deletions
|
|
@ -17,12 +17,16 @@ namespace psemek::util
|
||||||
using pointer = void;
|
using pointer = void;
|
||||||
using reference = void;
|
using reference = void;
|
||||||
using difference_type = std::ptrdiff_t;
|
using difference_type = std::ptrdiff_t;
|
||||||
using iterator_category = std::input_iterator_tag;
|
using iterator_category = std::bidirectional_iterator_tag;
|
||||||
|
|
||||||
char const * ptr;
|
char const * ptr;
|
||||||
|
|
||||||
utf8_iterator & operator ++();
|
utf8_iterator & operator ++();
|
||||||
utf8_iterator operator ++(int);
|
utf8_iterator operator ++(int);
|
||||||
|
|
||||||
|
utf8_iterator & operator --();
|
||||||
|
utf8_iterator operator --(int);
|
||||||
|
|
||||||
char32_t operator *() const;
|
char32_t operator *() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,21 @@ namespace psemek::util
|
||||||
return copy;
|
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
|
char32_t utf8_iterator::operator *() const
|
||||||
{
|
{
|
||||||
if (is_1_byte(ptr[0]))
|
if (is_1_byte(ptr[0]))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue