From bff9d45bdb01922264e01da2582173fea700523a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 9 May 2016 21:56:08 +0100 Subject: [PATCH] Make utf8_iterator codepoint type and difference type configurable --- src/normal.cc | 2 +- src/selectors.hh | 2 +- src/utf8_iterator.hh | 20 +++++++++++--------- src/word_db.cc | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 89ac2a9c..ed0f3e02 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -311,7 +311,7 @@ Codepoint swap_case(Codepoint cp) template void for_each_codepoint(Context& context, NormalParams) { - using Utf8It = utf8::iterator; + using Utf8It = utf8::iterator; ScopedEdition edition(context); Buffer& buffer = context.buffer(); diff --git a/src/selectors.hh b/src/selectors.hh index fd896068..67c231d4 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -24,7 +24,7 @@ inline Selection target_eol(Selection sel) return sel; } -using Utf8Iterator = utf8::iterator; +using Utf8Iterator = utf8::iterator; inline Selection utf8_range(const BufferIterator& first, const BufferIterator& last) { diff --git a/src/utf8_iterator.hh b/src/utf8_iterator.hh index eed250e9..46e277ed 100644 --- a/src/utf8_iterator.hh +++ b/src/utf8_iterator.hh @@ -14,9 +14,11 @@ namespace utf8 // adapter for an iterator on bytes which permits to iterate // on unicode codepoints instead. template class iterator : public std::iterator + CodepointType, DifferenceType> { public: iterator() = default; @@ -58,7 +60,7 @@ public: return save; } - iterator operator+(CharCount count) const + iterator operator+(DifferenceType count) const { if (count < 0) return operator-(-count); @@ -69,7 +71,7 @@ public: return res; } - iterator operator-(CharCount count) const + iterator operator-(DifferenceType count) const { if (count < 0) return operator+(-count); @@ -98,12 +100,12 @@ public: bool operator> (const Iterator& other) const { return m_it > other; } bool operator>= (const Iterator& other) const { return m_it >= other; } - CharCount operator-(const iterator& other) const + DifferenceType operator-(const iterator& other) const { - return utf8::distance(other.m_it, m_it); + return (DifferenceType)utf8::distance(other.m_it, m_it); } - Codepoint operator*() const + CodepointType operator*() const { return get_value(); } @@ -113,17 +115,17 @@ public: private: void invalidate_value() { m_value = -1; } - Codepoint get_value() const + CodepointType get_value() const { if (m_value == -1) - m_value = utf8::codepoint(m_it, m_end); + m_value = (CodepointType)utf8::codepoint(m_it, m_end); return m_value; } Iterator m_it; Iterator m_begin; Iterator m_end; - mutable Codepoint m_value = -1; + mutable CodepointType m_value = -1; }; } diff --git a/src/word_db.cc b/src/word_db.cc index 412b5249..2e9581cb 100644 --- a/src/word_db.cc +++ b/src/word_db.cc @@ -13,7 +13,7 @@ using WordList = Vector; static WordList get_words(StringView content) { WordList res; - using Utf8It = utf8::iterator; + using Utf8It = utf8::iterator; const char* word_start = content.begin(); bool in_word = false; for (Utf8It it{word_start, content}, end{content.end(), content}; it != end; ++it)