From eb06a6f00b83755ed47bf6c03cedb588e47fed68 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 20 Dec 2015 11:13:32 -1000 Subject: [PATCH] Add handy UTF8Iterator class to utf8proc header --- include/utf8proc.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/utf8proc.h b/include/utf8proc.h index 8f11806..0dfe537 100644 --- a/include/utf8proc.h +++ b/include/utf8proc.h @@ -222,5 +222,41 @@ static inline utf8proc_ssize_t utf8proc_encode_char(utf8proc_int32_t uc, utf8pro } else return 0; } +#ifdef __cplusplus +#include + +class UTF8Iterator : public std::iterator +{ + std::string::const_iterator m_it; +public: + UTF8Iterator(const std::string::const_iterator& it) : m_it(it) {} + UTF8Iterator& operator+=(size_t v) + { + for (size_t i=0 ; i(m_it.base()), -1, &dummy); + if (sz > 0) + m_it += sz; + } + return *this; + } + UTF8Iterator operator+(size_t v) const + { + UTF8Iterator ret(m_it); + ret += v; + return ret; + } + uint32_t operator*() const + { + utf8proc_int32_t ret; + utf8proc_iterate(reinterpret_cast(m_it.base()), -1, &ret); + return ret; + } + std::string::const_iterator iter() const {return m_it;} +}; + +#endif + #endif