The requirement for octet_iterator is bidirectional rather than random access now. Other minor changes

git-svn-id: http://svn.code.sf.net/p/utfcpp/code@72 a809a056-fc17-0410-9590-b4f493f8b08e
This commit is contained in:
ntrifunovic 2006-12-18 01:49:58 +00:00
parent 77c267b49e
commit e022e54c64
3 changed files with 28 additions and 23 deletions

View file

@ -277,6 +277,10 @@ namespace utf8
throw std::logic_error("Comparing utf-8 iterators defined with different ranges");
return (it == rhs.it);
}
bool operator != (const iterator& rhs) const
{
return !(operator == (rhs));
}
iterator& operator ++ ()
{
next(it, range_end);

View file

@ -123,7 +123,7 @@ namespace internal
}
// Do we have enough memory?
if (end - it < length)
if (std::distance(it, end) < length)
return NOT_ENOUGH_ROOM;
// Check trail octets and calculate the code point
@ -147,7 +147,7 @@ namespace internal
cp += (*it) & 0x3f;
}
else {
--it; --it;
std::advance(it, -2);
return INCOMPLETE_SEQUENCE;
}
}
@ -165,12 +165,12 @@ namespace internal
cp += (*it) & 0x3f;
}
else {
--it; --it; --it;
std::advance(it, -3);
return INCOMPLETE_SEQUENCE;
}
}
else {
--it; --it;
std::advance(it, -2);
return INCOMPLETE_SEQUENCE;
}
}
@ -192,22 +192,19 @@ namespace internal
if (cp < 0x80) {
if (length != 1) {
for (octet_difference_type i = 0; i < length - 1; ++i)
--it;
std::advance(it, -(length-1));
return OVERLONG_SEQUENCE;
}
}
else if (cp < 0x800) {
if (length != 2) {
for (octet_difference_type i = 0; i < length - 1; ++i)
--it;
std::advance(it, -(length-1));
return OVERLONG_SEQUENCE;
}
}
else if (cp < 0x10000) {
if (length != 3) {
for (octet_difference_type i = 0; i < length - 1; ++i)
--it;
std::advance(it, -(length-1));
return OVERLONG_SEQUENCE;
}
}

View file

@ -178,34 +178,38 @@ namespace utf8
octet_iterator base () const { return it; }
uint32_t operator * () const
{
octet_iterator temp = it;
return next(temp);
octet_iterator temp = it;
return next(temp);
}
bool operator == (const iterator& rhs) const
{
return (it == rhs.it);
return (it == rhs.it);
}
bool operator != (const iterator& rhs) const
{
return !(operator == (rhs));
}
iterator& operator ++ ()
{
next(it);
return *this;
std::advance(it, internal::sequence_length(it));
return *this;
}
iterator operator ++ (int)
{
iterator temp = *this;
next(it);
return temp;
iterator temp = *this;
std::advance(it, internal::sequence_length(it));
return temp;
}
iterator& operator -- ()
{
prior(it);
return *this;
prior(it);
return *this;
}
iterator operator -- (int)
{
iterator temp = *this;
prior(it);
return temp;
iterator temp = *this;
prior(it);
return temp;
}
}; // class iterator