ByteVector::append() can't take the vector itself.

This commit is contained in:
Tsuda Kageyu 2016-02-20 19:42:46 +09:00
parent 98a57744c3
commit 7d8aa7b8bd
2 changed files with 20 additions and 8 deletions

View File

@ -554,12 +554,16 @@ int ByteVector::endsWithPartialMatch(const ByteVector &pattern) const
ByteVector &ByteVector::append(const ByteVector &v)
{
if(v.d->length != 0) {
detach();
unsigned int originalSize = size();
resize(originalSize + v.size());
::memcpy(data() + originalSize, v.data(), v.size());
}
if(v.isEmpty())
return *this;
detach();
const unsigned int originalSize = size();
const unsigned int appendSize = v.size();
resize(originalSize + v.size());
::memcpy(data() + originalSize, v.data(), appendSize);
return *this;
}

View File

@ -48,7 +48,8 @@ class TestByteVector : public CppUnit::TestFixture
CPPUNIT_TEST(testReplace);
CPPUNIT_TEST(testIterator);
CPPUNIT_TEST(testResize);
CPPUNIT_TEST(testAppend);
CPPUNIT_TEST(testAppend1);
CPPUNIT_TEST(testAppend2);
CPPUNIT_TEST(testBase64);
CPPUNIT_TEST_SUITE_END();
@ -403,7 +404,7 @@ public:
CPPUNIT_ASSERT_EQUAL(-1, c.find('C'));
}
void testAppend()
void testAppend1()
{
ByteVector v1("foo");
v1.append("bar");
@ -441,6 +442,13 @@ public:
CPPUNIT_ASSERT_EQUAL(ByteVector("taglib"), v8);
}
void testAppend2()
{
ByteVector a("1234");
a.append(a);
CPPUNIT_ASSERT_EQUAL(ByteVector("12341234"), a);
}
void testBase64()
{
ByteVector sempty;