From e601bd5fe8cc6525b45cd243462cd093281843d7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 23 Sep 2015 22:09:37 +0100 Subject: [PATCH] Minor additional cleanup in utf8.hh --- src/utf8.hh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/utf8.hh b/src/utf8.hh index dd7974e7..545255fd 100644 --- a/src/utf8.hh +++ b/src/utf8.hh @@ -61,19 +61,6 @@ Iterator advance(Iterator it, const Iterator& end, CharCount d) return it; } -// returns the character count between begin and end -template -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 // multibyte) character inline bool is_character_start(char c) @@ -81,6 +68,20 @@ inline bool is_character_start(char c) return (c & 0xC0) != 0x80; } +// returns the character count between begin and end +template +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 template Iterator character_start(Iterator it, const Iterator& begin)