Fixit: it was missing the piece after the last found occurence

This commit is contained in:
Iwan Kawrakow 2023-08-27 16:43:50 +03:00
parent 5021d7bc3f
commit 86e3511500

View file

@ -117,7 +117,10 @@ void replace_all(std::string & s, const std::string & search, const std::string
std::string result; std::string result;
for (size_t pos = 0; ; pos += search.length()) { for (size_t pos = 0; ; pos += search.length()) {
auto new_pos = s.find(search, pos); auto new_pos = s.find(search, pos);
if (new_pos == std::string::npos) break; if (new_pos == std::string::npos) {
result += s.substr(pos, s.size() - pos);
break;
}
result += s.substr(pos, new_pos - pos) + replace; result += s.substr(pos, new_pos - pos) + replace;
pos = new_pos; pos = new_pos;
} }