Utils: Add replace for characters

It is much more performant to have a overload of char instead of providing
a string all the time.

Change-Id: I1a4ed82bf056f6af0c1f91c236b3fc30afa7f5d8
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2017-02-02 11:56:24 +01:00
parent 63e7e83e22
commit bdfb466cd2
2 changed files with 20 additions and 0 deletions

View File

@@ -473,6 +473,17 @@ public:
replaceLargerSized(fromText, toText);
}
void replace(char fromCharacter, char toCharacter)
{
reserve(size());
auto operation = [=] (char currentCharacter) {
return currentCharacter == fromCharacter ? toCharacter : currentCharacter;
};
std::transform(begin(), end(), begin(), operation);
}
void replace(size_type position, size_type length, SmallStringView replacementText)
{
size_type newSize = size() - length + replacementText.size();