mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Add an overload of ByteVector::replace() which takes chars.
Currently, this is only way of using ByteVector::replace().
This commit is contained in:
parent
a9acca5d81
commit
07d95e0dc0
@ -54,7 +54,7 @@ bool Mod::FileBase::readString(String &s, unsigned long size)
|
||||
{
|
||||
data.resize(index);
|
||||
}
|
||||
data.replace((char) 0xff, ' ');
|
||||
data.replace('\xff', ' ');
|
||||
|
||||
s = data;
|
||||
return true;
|
||||
|
@ -475,18 +475,32 @@ bool ByteVector::endsWith(const ByteVector &pattern) const
|
||||
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;
|
||||
|
@ -179,6 +179,12 @@ namespace TagLib {
|
||||
*/
|
||||
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.
|
||||
|
@ -134,7 +134,7 @@ public:
|
||||
if(index > -1) {
|
||||
data.resize(index);
|
||||
}
|
||||
data.replace((char) 0xff, ' ');
|
||||
data.replace('\xff', ' ');
|
||||
value = data;
|
||||
return count;
|
||||
}
|
||||
|
@ -266,6 +266,11 @@ public:
|
||||
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"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user