summaryrefslogtreecommitdiff
path: root/src/utf8.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-07-27 21:36:32 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-07-27 21:36:32 +0100
commit14f59d415d2e77d70e9282ec100029b87cbb1799 (patch)
tree94c584dad65fbe412769ea3b53591b838f15321c /src/utf8.hh
parentdf0773feeb59391c998f30c658b80997790f30fd (diff)
Avoid underlying iterator copies in utf8_iterator
Diffstat (limited to 'src/utf8.hh')
-rw-r--r--src/utf8.hh19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/utf8.hh b/src/utf8.hh
index 8e7d209a..62d9dcbd 100644
--- a/src/utf8.hh
+++ b/src/utf8.hh
@@ -25,13 +25,19 @@ inline bool is_character_start(char c)
return (c & 0xC0) != 0x80;
}
-// returns an iterator to next character first byte
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)
while (it != end and (*(it) & 0xC0) == 0x80)
++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;
}
@@ -45,12 +51,17 @@ Iterator finish(Iterator it, const Iterator& end)
return it;
}
-// returns an iterator to the previous character first byte
template<typename Iterator>
-Iterator previous(Iterator it, const Iterator& begin)
+void to_previous(Iterator& it, const Iterator& begin)
{
while (it != begin and (*(--it) & 0xC0) == 0x80)
;
+}
+// returns an iterator to the previous character first byte
+template<typename Iterator>
+Iterator previous(Iterator it, const Iterator& begin)
+{
+ to_previous(it, begin);
return it;
}