Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ static bool isCPPCastKeyword(const Token* tok)
{
if (!tok)
return false;
return endsWith(tok->str(), "_cast", 5);
return endsWith(tok->str(), "_cast");
}

static bool isTrivialConstructor(const Token* tok)
Expand Down
2 changes: 1 addition & 1 deletion lib/checkstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void CheckString::checkIncorrectStringCompare()
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
// skip "assert(str && ..)" and "assert(.. && str)"
if ((endsWith(tok->str(), "assert", 6) || endsWith(tok->str(), "ASSERT", 6)) &&
if ((endsWith(tok->str(), "assert") || endsWith(tok->str(), "ASSERT")) &&
Token::Match(tok, "%name% (") &&
(Token::Match(tok->tokAt(2), "%str% &&") || Token::Match(tok->next()->link()->tokAt(-2), "&& %str% )")))
tok = tok->next()->link();
Expand Down
2 changes: 1 addition & 1 deletion lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ void clangimport::parseClangAstDump(Tokenizer *tokenizer, std::istream &f)
const std::string nodeType = line.substr(pos1+1, pos2 - pos1 - 1);
const std::string ext = line.substr(pos2);

if (pos1 == 1 && endsWith(nodeType, "Decl", 4)) {
if (pos1 == 1 && endsWith(nodeType, "Decl")) {
if (!tree.empty())
tree[0]->createTokens1(tokenList);
tree.clear();
Expand Down
8 changes: 4 additions & 4 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace {
if (fileName.find(".") == std::string::npos)
return getAddonInfo(fileName + ".py", exename);

if (endsWith(fileName, ".py", 3)) {
if (endsWith(fileName, ".py")) {
scriptFile = getFullPath(fileName, exename);
if (scriptFile.empty())
return "Did not find addon " + fileName;
Expand All @@ -160,7 +160,7 @@ namespace {
return "";
}

if (!endsWith(fileName, ".json", 5))
if (!endsWith(fileName, ".json"))
return "Failed to open addon " + fileName;

std::ifstream fin(fileName);
Expand Down Expand Up @@ -1312,7 +1312,7 @@ void CppCheck::executeAddons(const std::vector<std::string>& files)

std::string fileList;

if (files.size() >= 2 || endsWith(files[0], ".ctu-info", 9)) {
if (files.size() >= 2 || endsWith(files[0], ".ctu-info")) {
fileList = Path::getPathFromFilename(files[0]) + FILELIST;
std::ofstream fout(fileList);
for (const std::string& f: files)
Expand All @@ -1327,7 +1327,7 @@ void CppCheck::executeAddons(const std::vector<std::string>& files)
mExitCode = 1;
continue;
}
if (addon != "misra" && !addonInfo.ctu && endsWith(files.back(), ".ctu-info", 9))
if (addon != "misra" && !addonInfo.ctu && endsWith(files.back(), ".ctu-info"))
continue;

const std::string results =
Expand Down
12 changes: 6 additions & 6 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,24 @@ ImportProject::Type ImportProject::import(const std::string &filename, Settings

const std::string fileFilter = settings ? settings->fileFilter : std::string();

if (endsWith(filename, ".json", 5)) {
if (endsWith(filename, ".json")) {
importCompileCommands(fin);
setRelativePaths(filename);
return ImportProject::Type::COMPILE_DB;
} else if (endsWith(filename, ".sln", 4)) {
} else if (endsWith(filename, ".sln")) {
importSln(fin, mPath, fileFilter);
setRelativePaths(filename);
return ImportProject::Type::VS_SLN;
} else if (endsWith(filename, ".vcxproj", 8)) {
} else if (endsWith(filename, ".vcxproj")) {
std::map<std::string, std::string, cppcheck::stricmp> variables;
importVcxproj(filename, variables, emptyString, fileFilter);
setRelativePaths(filename);
return ImportProject::Type::VS_VCXPROJ;
} else if (endsWith(filename, ".bpr", 4)) {
} else if (endsWith(filename, ".bpr")) {
importBcb6Prj(filename);
setRelativePaths(filename);
return ImportProject::Type::BORLAND;
} else if (settings && endsWith(filename, ".cppcheck", 9)) {
} else if (settings && endsWith(filename, ".cppcheck")) {
const bool success = importCppcheckGuiProject(fin, settings);
setRelativePaths(filename);
return success ? ImportProject::Type::CPPCHECK_GUI : ImportProject::Type::MISSING;
Expand Down Expand Up @@ -294,7 +294,7 @@ void ImportProject::FileSettings::parseCommand(std::string command)
defs += fval;
if (defval.size() >= 3 && defval.compare(0,2,"=\"")==0 && defval.back()=='\"')
defval = "=" + unescape(defval.substr(2, defval.size() - 3));
else if (defval.size() >= 5 && defval.compare(0,3,"=\\\"")==0 && endsWith(defval,"\\\"",2))
else if (defval.size() >= 5 && defval.compare(0, 3, "=\\\"") == 0 && endsWith(defval, "\\\""))
defval = "=\"" + unescape(defval.substr(3, defval.size() - 5)) + "\"";
if (!defval.empty())
defs += defval;
Expand Down
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ Function::Function(const Token *tokenDef, const std::string &clangType)

setFlags(tokenDef, tokenDef->scope());

if (endsWith(clangType, " const", 6))
if (endsWith(clangType, " const"))
isConst(true);
}

Expand Down
8 changes: 7 additions & 1 deletion lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ struct EnumClassHash {

inline bool endsWith(const std::string &str, char c)
{
return str[str.size()-1U] == c;
return !str.empty() && str.back() == c;
}

inline bool endsWith(const std::string &str, const char end[], std::size_t endlen)
{
return (str.size() >= endlen) && (str.compare(str.size()-endlen, endlen, end)==0);
}

template<std::size_t N>
bool endsWith(const std::string& str, const char (&end)[N])
{
return endsWith(str, end, N - 1);
}

inline static bool isPrefixStringCharLiteral(const std::string &str, char q, const std::string& p)
{
if (!endsWith(str, q))
Expand Down