Commit bdfb466c authored by Marco Bubke's avatar Marco Bubke

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's avatarTim Jenssen <>
parent 63e7e83e
......@@ -473,6 +473,17 @@ public:
replaceLargerSized(fromText, toText);
void replace(char fromCharacter, char toCharacter)
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();
......@@ -747,6 +747,15 @@ TEST(SmallString, Clear)
TEST(SmallString, ReplaceWithCharacter)
SmallString text("here is some text, here is some text, here is some text");
text.replace('s', 'x');
ASSERT_THAT(text, SmallString("here ix xome text, here ix xome text, here ix xome text"));
TEST(SmallString, ReplaceWithEqualSizedText)
SmallString text("here is some text");
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment