Minor additional cleanup in utf8.hh

This commit is contained in:
Maxime Coste 2015-09-23 22:09:37 +01:00
parent ceafa5459a
commit e601bd5fe8

View File

@ -61,19 +61,6 @@ Iterator advance(Iterator it, const Iterator& end, CharCount d)
return it; return it;
} }
// returns the character count between begin and end
template<typename Iterator>
CharCount distance(Iterator begin, const Iterator& end)
{
CharCount dist = 0;
while (begin != end)
{
if ((*begin++ & 0xC0) != 0x80)
++dist;
}
return dist;
}
// return true if it points to the first byte of a (either single or // return true if it points to the first byte of a (either single or
// multibyte) character // multibyte) character
inline bool is_character_start(char c) inline bool is_character_start(char c)
@ -81,6 +68,20 @@ inline bool is_character_start(char c)
return (c & 0xC0) != 0x80; return (c & 0xC0) != 0x80;
} }
// returns the character count between begin and end
template<typename Iterator>
CharCount distance(Iterator begin, const Iterator& end)
{
CharCount dist = 0;
while (begin != end)
{
if (is_character_start(*begin++))
++dist;
}
return dist;
}
// returns an iterator to the first byte of the character it is into // returns an iterator to the first byte of the character it is into
template<typename Iterator> template<typename Iterator>
Iterator character_start(Iterator it, const Iterator& begin) Iterator character_start(Iterator it, const Iterator& begin)