Avoid underlying iterator copies in utf8_iterator
This commit is contained in:
parent
df0773feeb
commit
14f59d415d
19
src/utf8.hh
19
src/utf8.hh
|
@ -25,13 +25,19 @@ inline bool is_character_start(char c)
|
||||||
return (c & 0xC0) != 0x80;
|
return (c & 0xC0) != 0x80;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns an iterator to next character first byte
|
|
||||||
template<typename Iterator>
|
template<typename Iterator>
|
||||||
Iterator next(Iterator it, const Iterator& end)
|
void to_next(Iterator& it, const Iterator& end)
|
||||||
{
|
{
|
||||||
if (it != end and read(it) & 0x80)
|
if (it != end and read(it) & 0x80)
|
||||||
while (it != end and (*(it) & 0xC0) == 0x80)
|
while (it != end and (*(it) & 0xC0) == 0x80)
|
||||||
++it;
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns an iterator to next character first byte
|
||||||
|
template<typename Iterator>
|
||||||
|
Iterator next(Iterator it, const Iterator& end)
|
||||||
|
{
|
||||||
|
to_next(it, end);
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,12 +51,17 @@ Iterator finish(Iterator it, const Iterator& end)
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Iterator>
|
||||||
|
void to_previous(Iterator& it, const Iterator& begin)
|
||||||
|
{
|
||||||
|
while (it != begin and (*(--it) & 0xC0) == 0x80)
|
||||||
|
;
|
||||||
|
}
|
||||||
// returns an iterator to the previous character first byte
|
// returns an iterator to the previous character first byte
|
||||||
template<typename Iterator>
|
template<typename Iterator>
|
||||||
Iterator previous(Iterator it, const Iterator& begin)
|
Iterator previous(Iterator it, const Iterator& begin)
|
||||||
{
|
{
|
||||||
while (it != begin and (*(--it) & 0xC0) == 0x80)
|
to_previous(it, begin);
|
||||||
;
|
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
|
|
||||||
iterator& operator++()
|
iterator& operator++()
|
||||||
{
|
{
|
||||||
m_it = utf8::next(m_it, m_end);
|
utf8::to_next(m_it, m_end);
|
||||||
invalidate_value();
|
invalidate_value();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public:
|
||||||
|
|
||||||
iterator& operator--()
|
iterator& operator--()
|
||||||
{
|
{
|
||||||
m_it = utf8::previous(m_it, m_begin);
|
utf8::to_previous(m_it, m_begin);
|
||||||
invalidate_value();
|
invalidate_value();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user