Kelson has submitted this change and it was merged.

Change subject: Better replaceStringInPlaceOnce.
......................................................................


Better replaceStringInPlaceOnce.

If we do only one replace, we do not need a while and a update of pos.
(Thank to cppcheck)

Change-Id: I5c825590c3a5ed7e01020b415b5ea695baa070a0
---
M zimwriterfs/tools.cpp
1 file changed, 2 insertions(+), 4 deletions(-)

Approvals:
  Kelson: Verified; Looks good to me, approved



diff --git a/zimwriterfs/tools.cpp b/zimwriterfs/tools.cpp
index cc6091d..b73b5ca 100644
--- a/zimwriterfs/tools.cpp
+++ b/zimwriterfs/tools.cpp
@@ -423,11 +423,9 @@
 void replaceStringInPlaceOnce(std::string& subject,
                               const std::string& search,
                               const std::string& replace) {
-  size_t pos = 0;
-  while ((pos = subject.find(search, pos)) != std::string::npos) {
+  size_t pos = subject.find(search, 0);
+  if (pos != std::string::npos) {
     subject.replace(pos, search.length(), replace);
-    pos += replace.length();
-    return; /* Do it once */
   }
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/303778
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5c825590c3a5ed7e01020b415b5ea695baa070a0
Gerrit-PatchSet: 1
Gerrit-Project: openzim
Gerrit-Branch: master
Gerrit-Owner: Mgautierfr <mgaut...@kymeria.fr>
Gerrit-Reviewer: Kelson <kel...@kiwix.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to