Fixit: it was missing the piece after the last found occurence
This commit is contained in:
parent
5021d7bc3f
commit
86e3511500
1 changed files with 4 additions and 1 deletions
|
@ -117,7 +117,10 @@ void replace_all(std::string & s, const std::string & search, const std::string
|
|||
std::string result;
|
||||
for (size_t pos = 0; ; pos += search.length()) {
|
||||
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;
|
||||
pos = new_pos;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue