summaryrefslogtreecommitdiff
path: root/src/utf8_iterator.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-05-09 21:56:08 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-05-09 21:56:08 +0100
commitbff9d45bdb01922264e01da2582173fea700523a (patch)
tree2ad5ec5caadaaf818198b5230d10e636c811ba5a /src/utf8_iterator.hh
parente3cddf37832691a0b9179cf91a0ea15b97ad3712 (diff)
Make utf8_iterator codepoint type and difference type configurable
Diffstat (limited to 'src/utf8_iterator.hh')
-rw-r--r--src/utf8_iterator.hh20
1 files changed, 11 insertions, 9 deletions
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<typename Iterator,
+ typename CodepointType = Codepoint,
+ typename DifferenceType = CharCount,
typename InvalidPolicy = utf8::InvalidPolicy::Pass>
class iterator : public std::iterator<std::bidirectional_iterator_tag,
- Codepoint, CharCount>
+ 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<InvalidPolicy>(m_it, m_end);
+ m_value = (CodepointType)utf8::codepoint<InvalidPolicy>(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;
};
}