From d23fd26ce0fb5e25cc1f1c13c7c87cf92511f564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 30 Aug 2020 18:15:48 +0200 Subject: [PATCH] Cppcheck: Try to fix addon problems when paths have spaces --- lib/cppcheck.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index f948e8b78..c0fec7e2f 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -168,21 +168,22 @@ static std::vector split(const std::string &str, const std::string { std::vector ret; for (std::string::size_type startPos = 0U; startPos < str.size();) { - std::string::size_type endPos; - if (str[startPos] == '\"') { - endPos = str.find("\"", startPos + 1); - if (endPos < str.size()) - endPos++; - } else { - endPos = str.find(sep, startPos + 1); - } - if (endPos == std::string::npos) { - ret.push_back(str.substr(startPos)); + startPos = str.find_first_not_of(sep, startPos); + if (startPos == std::string::npos) break; + + if (str[startPos] == '\"') { + const std::string::size_type endPos = str.find("\"", startPos + 1); + ret.push_back(str.substr(startPos + 1, endPos - startPos - 1)); + startPos = (endPos < str.size()) ? (endPos + 1) : endPos; + continue; } + + const std::string::size_type endPos = str.find(sep, startPos + 1); ret.push_back(str.substr(startPos, endPos - startPos)); - startPos = str.find_first_not_of(sep, endPos); + startPos = endPos; } + return ret; }