From b2cd0aabf59cef83c0f5ac5a9b8cc724fd153e69 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Wed, 9 Sep 2015 18:43:32 +0300 Subject: [PATCH] Simplify overengineered search-replace code --- lib/tokenize.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d3f9a06a7..d4deedeb2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6245,9 +6245,11 @@ bool Tokenizer::simplifyKnownVariables() const Token * const valueToken = tok2->tokAt(4); std::string value(valueToken->str()); if (tok2->str() == "sprintf") { - std::string::difference_type n = -1; - while (static_cast(n = value.find("%%",n+1)) != std::string::npos) { - value.replace(n,2,"%"); + std::string::size_type n = 0; + while ((n = value.find("%%", n)) != std::string::npos) { + // Replace "%%" with "%" - erase the first '%' and continue past the second '%' + value.erase(n, 1); + ++n; } } const unsigned int valueVarId(0);