less copies and allocations in replaceInPlace

This commit is contained in:
Martin Jeřábek
2024-02-25 18:01:28 +01:00
committed by Martin Hořeňovský
parent cde3509664
commit 4d8affc989
15 changed files with 318 additions and 102 deletions

View File

@@ -57,6 +57,17 @@ TEST_CASE("replaceInPlace", "[string-manip]") {
CHECK_FALSE(Catch::replaceInPlace(letters, "x", "z"));
CHECK(letters == letters);
}
SECTION("no replace in already-replaced string") {
SECTION("lengthening") {
CHECK(Catch::replaceInPlace(letters, "c", "cc"));
CHECK(letters == "abccdefccg");
}
SECTION("shortening") {
std::string s = "----";
CHECK(Catch::replaceInPlace(s, "--", "-"));
CHECK(s == "--");
}
}
SECTION("escape '") {
std::string s = "didn't";
CHECK(Catch::replaceInPlace(s, "'", "|'"));