From f65848a59046bfa364dfefe16bed69682ae80e22 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 4 Mar 2022 00:03:18 -0800 Subject: [PATCH] simplify ReplaceStringInPlace slightly Signed-off-by: Rosen Penev --- src/basicio.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basicio.cpp b/src/basicio.cpp index 2465d1c7..7532af85 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -55,10 +55,10 @@ namespace { /// @brief replace each substring of the subject that matches the given search string with the given replacement. void ReplaceStringInPlace(std::string& subject, const std::string& search, const std::string& replace) { - size_t pos = 0; - while ((pos = subject.find(search, pos)) != std::string::npos) { + auto pos = subject.find(search); + while (pos != std::string::npos) { subject.replace(pos, search.length(), replace); - pos += replace.length(); + pos += subject.find(search, pos + replace.length()); } } }