diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 479ae4fad01f..f7d20d132e66 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -436,9 +436,9 @@ bool ImportProject::importSln(std::istream &istr, const std::string &path, const return false; } - if (line.find("Microsoft Visual Studio Solution File") != 0) { + if (!startsWith(line, "Microsoft Visual Studio Solution File")) { // Skip BOM - if (!std::getline(istr, line) || line.find("Microsoft Visual Studio Solution File") != 0) { + if (!std::getline(istr, line) || !startsWith(line, "Microsoft Visual Studio Solution File")) { printError("Visual Studio solution file header not found"); return false; } diff --git a/lib/library.cpp b/lib/library.cpp index 2874d553fa19..4c886f699240 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1174,7 +1174,7 @@ const Library::Container* Library::detectContainerInternal(const Token* const ty if (container.startPattern.empty()) continue; - const int offset = (withoutStd && container.startPattern2.find("std :: ") == 0) ? 7 : 0; + const int offset = (withoutStd && startsWith(container.startPattern2, "std :: ")) ? 7 : 0; // If endPattern is undefined, it will always match, but itEndPattern has to be defined. if (detect != IteratorOnly && container.endPattern.empty()) { diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 1eede5650e70..d1f41d4554a8 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -28,6 +28,7 @@ #include "suppressions.h" #include "fixture.h" #include "timer.h" +#include "utils.h" #include #include @@ -272,7 +273,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck"}; ASSERT(parser->parseFromArgs(1, argv)); ASSERT_EQUALS(true, parser->getShowHelp()); - ASSERT(GET_REDIRECT_OUTPUT.find("Cppcheck - A tool for static C/C++ code analysis") == 0); + ASSERT(startsWith(GET_REDIRECT_OUTPUT, "Cppcheck - A tool for static C/C++ code analysis")); } void helpshort() { @@ -280,7 +281,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "-h"}; ASSERT(parser->parseFromArgs(2, argv)); ASSERT_EQUALS(true, parser->getShowHelp()); - ASSERT(GET_REDIRECT_OUTPUT.find("Cppcheck - A tool for static C/C++ code analysis") == 0); + ASSERT(startsWith(GET_REDIRECT_OUTPUT, "Cppcheck - A tool for static C/C++ code analysis")); } void helplong() { @@ -288,7 +289,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--help"}; ASSERT(parser->parseFromArgs(2, argv)); ASSERT_EQUALS(true, parser->getShowHelp()); - ASSERT(GET_REDIRECT_OUTPUT.find("Cppcheck - A tool for static C/C++ code analysis") == 0); + ASSERT(startsWith(GET_REDIRECT_OUTPUT, "Cppcheck - A tool for static C/C++ code analysis")); } void showversion() { @@ -1594,7 +1595,7 @@ class TestCmdlineParser : public TestFixture { const char * const argv[] = {"cppcheck", "--doc"}; ASSERT(parser->parseFromArgs(2, argv)); ASSERT(parser->exitAfterPrinting()); - ASSERT(GET_REDIRECT_OUTPUT.find("## ") == 0); + ASSERT(startsWith(GET_REDIRECT_OUTPUT, "## ")); } void showtime() {