return containsAt(pattern, size() - pattern.size());
}
+ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &with)
+{
+ if(pattern.size() == 0 || pattern.size() > size())
+ return *this;
+
+ const int patternSize = pattern.size();
+ const int withSize = with.size();
+
+ int offset = find(pattern);
+
+ while(offset >= 0)
+ {
+ const int originalSize = size();
+
+ if(withSize > patternSize)
+ resize(originalSize + withSize - patternSize);
+
+ if(patternSize != withSize)
+ ::memcpy(data() + offset + withSize, mid(offset + patternSize).data(), originalSize - offset - patternSize);
+
+ if(withSize < patternSize)
+ resize(originalSize + withSize - patternSize);
+
+ ::memcpy(data() + offset, with.data(), withSize);
+
+ offset = find(pattern, offset + withSize);
+ }
+
+ return *this;
+}
+
int ByteVector::endsWithPartialMatch(const ByteVector &pattern) const
{
if(pattern.size() > size())
*/
bool endsWith(const ByteVector &pattern) const;
+ /*!
+ * Replaces \a pattern with \a with and returns a reference to the ByteVector
+ * after the operation. This \e does modify the vector.
+ */
+ ByteVector &replace(const ByteVector &pattern, const ByteVector &with);
+
/*!
* Checks for a partial match of \a pattern at the end of the vector. It
* returns the offset of the partial match within the vector, or -1 if the