Currently, this is only way of using ByteVector::replace().
{
data.resize(index);
}
- data.replace((char) 0xff, ' ');
+ data.replace('\xff', ' ');
s = data;
return true;
return containsAt(pattern, size() - pattern.size());
}
+ByteVector &ByteVector::replace(char oldByte, char newByte)
+{
+ detach();
+
+ for(ByteVector::Iterator it = begin(); it != end(); ++it) {
+ if(*it == oldByte)
+ *it = newByte;
+ }
+
+ return *this;
+}
+
ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &with)
{
if(pattern.size() == 0 || pattern.size() > size())
return *this;
+ if(pattern.size() == 1 && with.size() == 1)
+ return replace(pattern[0], with[0]);
+
const size_t withSize = with.size();
const size_t patternSize = pattern.size();
const ptrdiff_t diff = withSize - patternSize;
size_t offset = 0;
- while (true)
- {
+ while (true) {
offset = find(pattern, offset);
if(offset == static_cast<size_t>(-1)) // Use npos in taglib2.
break;
*/
bool endsWith(const ByteVector &pattern) const;
+ /*!
+ * Replaces \a oldByte with \a newByte and returns a reference to the
+ * ByteVector after the operation. This \e does modify the vector.
+ */
+ ByteVector &replace(char oldByte, char newByte);
+
/*!
* Replaces \a pattern with \a with and returns a reference to the ByteVector
* after the operation. This \e does modify the vector.
if(index > -1) {
data.resize(index);
}
- data.replace((char) 0xff, ' ');
+ data.replace('\xff', ' ');
value = data;
return count;
}
a.replace(ByteVector("a"), ByteVector("x"));
CPPUNIT_ASSERT_EQUAL(ByteVector("xbcdxbf"), a);
}
+ {
+ ByteVector a("abcdabf");
+ a.replace('a', 'x');
+ CPPUNIT_ASSERT_EQUAL(ByteVector("xbcdxbf"), a);
+ }
{
ByteVector a("abcdabf");
a.replace(ByteVector("ab"), ByteVector("xy"));