Fix ByteVector to return correct iterators after detached.

This commit is contained in:
Tsuda Kageyu 2015-04-29 10:28:08 +09:00
parent 5bad35c4cb
commit ab047f6054
2 changed files with 10 additions and 8 deletions

View File

@ -712,7 +712,7 @@ ByteVector &ByteVector::resize(uint size, char padding)
ByteVector::Iterator ByteVector::begin()
{
detach();
return d->data->data.begin();
return d->data->data.begin() + d->offset;
}
ByteVector::ConstIterator ByteVector::begin() const
@ -723,7 +723,7 @@ ByteVector::ConstIterator ByteVector::begin() const
ByteVector::Iterator ByteVector::end()
{
detach();
return d->data->data.end();
return d->data->data.begin() + d->offset + d->length;
}
ByteVector::ConstIterator ByteVector::end() const
@ -734,25 +734,23 @@ ByteVector::ConstIterator ByteVector::end() const
ByteVector::ReverseIterator ByteVector::rbegin()
{
detach();
return d->data->data.rbegin();
return d->data->data.rbegin() + (d->data->data.size() - (d->offset + d->length));
}
ByteVector::ConstReverseIterator ByteVector::rbegin() const
{
std::vector<char> &v = d->data->data;
return v.rbegin() + (v.size() - (d->offset + d->length));
return d->data->data.rbegin() + (d->data->data.size() - (d->offset + d->length));
}
ByteVector::ReverseIterator ByteVector::rend()
{
detach();
return d->data->data.rend();
return d->data->data.rbegin() + (d->data->data.size() - d->offset);
}
ByteVector::ConstReverseIterator ByteVector::rend() const
{
std::vector<char> &v = d->data->data;
return v.rbegin() + (v.size() - d->offset);
return d->data->data.rbegin() + (d->data->data.size() - d->offset);
}
bool ByteVector::isNull() const

View File

@ -319,6 +319,10 @@ public:
*it4 = 'A';
CPPUNIT_ASSERT_EQUAL('a', *it3);
CPPUNIT_ASSERT_EQUAL('A', *it4);
ByteVector v3;
v3 = ByteVector("taglib").mid(3);
CPPUNIT_ASSERT_EQUAL('l', *v3.begin());
}
};