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:
parent
f0a6b9376b
commit
28149b16f3
3 changed files with 28 additions and 23 deletions
|
@ -277,6 +277,10 @@ namespace utf8
|
||||||
throw std::logic_error("Comparing utf-8 iterators defined with different ranges");
|
throw std::logic_error("Comparing utf-8 iterators defined with different ranges");
|
||||||
return (it == rhs.it);
|
return (it == rhs.it);
|
||||||
}
|
}
|
||||||
|
bool operator != (const iterator& rhs) const
|
||||||
|
{
|
||||||
|
return !(operator == (rhs));
|
||||||
|
}
|
||||||
iterator& operator ++ ()
|
iterator& operator ++ ()
|
||||||
{
|
{
|
||||||
next(it, range_end);
|
next(it, range_end);
|
||||||
|
|
|
@ -123,7 +123,7 @@ namespace internal
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we have enough memory?
|
// Do we have enough memory?
|
||||||
if (end - it < length)
|
if (std::distance(it, end) < length)
|
||||||
return NOT_ENOUGH_ROOM;
|
return NOT_ENOUGH_ROOM;
|
||||||
|
|
||||||
// Check trail octets and calculate the code point
|
// Check trail octets and calculate the code point
|
||||||
|
@ -147,7 +147,7 @@ namespace internal
|
||||||
cp += (*it) & 0x3f;
|
cp += (*it) & 0x3f;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
--it; --it;
|
std::advance(it, -2);
|
||||||
return INCOMPLETE_SEQUENCE;
|
return INCOMPLETE_SEQUENCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,12 +165,12 @@ namespace internal
|
||||||
cp += (*it) & 0x3f;
|
cp += (*it) & 0x3f;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
--it; --it; --it;
|
std::advance(it, -3);
|
||||||
return INCOMPLETE_SEQUENCE;
|
return INCOMPLETE_SEQUENCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
--it; --it;
|
std::advance(it, -2);
|
||||||
return INCOMPLETE_SEQUENCE;
|
return INCOMPLETE_SEQUENCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,22 +192,19 @@ namespace internal
|
||||||
|
|
||||||
if (cp < 0x80) {
|
if (cp < 0x80) {
|
||||||
if (length != 1) {
|
if (length != 1) {
|
||||||
for (octet_difference_type i = 0; i < length - 1; ++i)
|
std::advance(it, -(length-1));
|
||||||
--it;
|
|
||||||
return OVERLONG_SEQUENCE;
|
return OVERLONG_SEQUENCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (cp < 0x800) {
|
else if (cp < 0x800) {
|
||||||
if (length != 2) {
|
if (length != 2) {
|
||||||
for (octet_difference_type i = 0; i < length - 1; ++i)
|
std::advance(it, -(length-1));
|
||||||
--it;
|
|
||||||
return OVERLONG_SEQUENCE;
|
return OVERLONG_SEQUENCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (cp < 0x10000) {
|
else if (cp < 0x10000) {
|
||||||
if (length != 3) {
|
if (length != 3) {
|
||||||
for (octet_difference_type i = 0; i < length - 1; ++i)
|
std::advance(it, -(length-1));
|
||||||
--it;
|
|
||||||
return OVERLONG_SEQUENCE;
|
return OVERLONG_SEQUENCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,34 +178,38 @@ namespace utf8
|
||||||
octet_iterator base () const { return it; }
|
octet_iterator base () const { return it; }
|
||||||
uint32_t operator * () const
|
uint32_t operator * () const
|
||||||
{
|
{
|
||||||
octet_iterator temp = it;
|
octet_iterator temp = it;
|
||||||
return next(temp);
|
return next(temp);
|
||||||
}
|
}
|
||||||
bool operator == (const iterator& rhs) const
|
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 ++ ()
|
iterator& operator ++ ()
|
||||||
{
|
{
|
||||||
next(it);
|
std::advance(it, internal::sequence_length(it));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
iterator operator ++ (int)
|
iterator operator ++ (int)
|
||||||
{
|
{
|
||||||
iterator temp = *this;
|
iterator temp = *this;
|
||||||
next(it);
|
std::advance(it, internal::sequence_length(it));
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
iterator& operator -- ()
|
iterator& operator -- ()
|
||||||
{
|
{
|
||||||
prior(it);
|
prior(it);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
iterator operator -- (int)
|
iterator operator -- (int)
|
||||||
{
|
{
|
||||||
iterator temp = *this;
|
iterator temp = *this;
|
||||||
prior(it);
|
prior(it);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
}; // class iterator
|
}; // class iterator
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue