utf8: use CharCount instead of size_t
This commit is contained in:
parent
61c8ef6ce4
commit
ee882d9d02
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include "unicode.hh"
|
#include "unicode.hh"
|
||||||
|
#include "units.hh"
|
||||||
#include "assert.hh"
|
#include "assert.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
|
@ -43,8 +44,8 @@ Iterator previous(Iterator it)
|
||||||
// returns an iterator pointing to the first byte of the
|
// returns an iterator pointing to the first byte of the
|
||||||
// dth character after (or before if d < 0) the character
|
// dth character after (or before if d < 0) the character
|
||||||
// pointed by it
|
// pointed by it
|
||||||
template<typename Iterator, typename Distance>
|
template<typename Iterator>
|
||||||
Iterator advance(Iterator it, Iterator end, Distance d)
|
Iterator advance(Iterator it, Iterator end, CharCount d)
|
||||||
{
|
{
|
||||||
if (d < 0)
|
if (d < 0)
|
||||||
{
|
{
|
||||||
|
@ -61,9 +62,9 @@ Iterator advance(Iterator it, Iterator end, Distance d)
|
||||||
|
|
||||||
// returns the character count between begin and end
|
// returns the character count between begin and end
|
||||||
template<typename Iterator>
|
template<typename Iterator>
|
||||||
size_t distance(Iterator begin, Iterator end)
|
CharCount distance(Iterator begin, Iterator end)
|
||||||
{
|
{
|
||||||
size_t dist = 0;
|
CharCount dist = 0;
|
||||||
while (begin != end)
|
while (begin != end)
|
||||||
{
|
{
|
||||||
if ((*begin++ & 0xC0) != 0x80)
|
if ((*begin++ & 0xC0) != 0x80)
|
||||||
|
|
|
@ -47,7 +47,7 @@ public:
|
||||||
return save;
|
return save;
|
||||||
}
|
}
|
||||||
|
|
||||||
utf8_iterator operator+(int count) const
|
utf8_iterator operator+(CharCount count) const
|
||||||
{
|
{
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
return operator-(-count);
|
return operator-(-count);
|
||||||
|
@ -58,7 +58,7 @@ public:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
utf8_iterator operator-(int count) const
|
utf8_iterator operator-(CharCount count) const
|
||||||
{
|
{
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
return operator+(-count);
|
return operator+(-count);
|
||||||
|
@ -92,12 +92,12 @@ public:
|
||||||
return m_it >= other.m_it;
|
return m_it >= other.m_it;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t operator-(utf8_iterator other) const
|
CharCount operator-(utf8_iterator other) const
|
||||||
{
|
{
|
||||||
//assert(other < *this);
|
//assert(other < *this);
|
||||||
check_invariant();
|
check_invariant();
|
||||||
other.check_invariant();
|
other.check_invariant();
|
||||||
size_t dist = 0;
|
CharCount dist = 0;
|
||||||
while (other.m_it != m_it)
|
while (other.m_it != m_it)
|
||||||
{
|
{
|
||||||
++dist;
|
++dist;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user