Merge pull request #231 from TsudaKageyu/containsat

Fixed behavior change of ByteVector::containsAt()
This commit is contained in:
Tsuda Kageyu 2013-06-01 12:03:34 -07:00
commit c4c5b06643
2 changed files with 10 additions and 5 deletions

View File

@ -601,11 +601,11 @@ bool ByteVector::containsAt(const ByteVector &pattern, uint offset, uint pattern
patternLength = pattern.size();
// do some sanity checking -- all of these things are needed for the search to be valid
if(offset + patternLength > size() || patternOffset >= pattern.size() || patternLength == 0)
const uint compareLength = patternLength - patternOffset;
if(offset + compareLength > size() || patternOffset >= pattern.size() || patternLength == 0)
return false;
return (::memcmp(data() + offset, pattern.data() + patternOffset, patternLength - patternOffset) == 0);
return (::memcmp(data() + offset, pattern.data() + patternOffset, compareLength) == 0);
}
bool ByteVector::startsWith(const ByteVector &pattern) const

View File

@ -112,12 +112,17 @@ public:
ByteVector s2("f");
CPPUNIT_ASSERT(ByteVectorList::split(s2, " ").size() == 1);
CPPUNIT_ASSERT(ByteVector().size() == 0);
CPPUNIT_ASSERT(ByteVector("asdf").clear().size() == 0);
CPPUNIT_ASSERT(ByteVector("asdf").clear() == ByteVector());
}
ByteVector i("blah blah");
ByteVector j("blah");
CPPUNIT_ASSERT(i.containsAt(j, 5, 0));
CPPUNIT_ASSERT(i.containsAt(j, 6, 1));
CPPUNIT_ASSERT(i.containsAt(j, 6, 1, 3));
}
void testFind1()
{
CPPUNIT_ASSERT_EQUAL(4, ByteVector("....SggO."). find("SggO"));