diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 20b39179e8e..05f1bd71d86 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -949,7 +949,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a // --library else if (std::strncmp(argv[i], "--library=", 10) == 0) { - std::list libs = splitString(argv[i] + 10, ','); + std::vector libs = splitString(argv[i] + 10, ','); for (auto& l : libs) { if (l.empty()) { mLogger.printError("empty library specified."); diff --git a/lib/utils.cpp b/lib/utils.cpp index 0288dffe25a..8d5c7509c56 100644 --- a/lib/utils.cpp +++ b/lib/utils.cpp @@ -186,20 +186,18 @@ std::string replaceEscapeSequences(const std::string &source) { } -std::list splitString(const std::string& str, char sep) +std::vector splitString(const std::string& str, char sep) { - if (std::strchr(str.c_str(), sep) == nullptr) - return {str}; - - std::list l; - std::string p(str); - for (;;) { - const std::string::size_type pos = p.find(sep); - if (pos == std::string::npos) + std::vector l; + + std::string::size_type pos1 = 0; + std::string::size_type pos2; + while (true) { + pos2 = str.find(sep, pos1); + l.push_back(str.substr(pos1, pos2 - pos1)); + if (pos2 == std::string::npos) break; - l.push_back(p.substr(0,pos)); - p = p.substr(pos+1); + pos1 = pos2 + 1; } - l.push_back(std::move(p)); return l; } diff --git a/lib/utils.h b/lib/utils.h index 563f8fd57b0..0c50b534090 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -403,7 +402,7 @@ static inline T* empty_if_null(T* p) * @param sep The seperator * @return The list of seperate strings (including empty ones). The whole input string if no seperator found. */ -CPPCHECKLIB std::list splitString(const std::string& str, char sep); +CPPCHECKLIB std::vector splitString(const std::string& str, char sep); namespace utils { template