Refactoring. Use 'endsWith()'

This commit is contained in:
Daniel Marjamäki 2017-04-23 10:17:35 +02:00
parent 101dc28afa
commit f92ef7d8e2
2 changed files with 7 additions and 1 deletions

View File

@ -20,6 +20,7 @@
//---------------------------------------------------------------------------
#include "checkstring.h"
#include "symboldatabase.h"
#include "utils.h"
//---------------------------------------------------------------------------
@ -270,7 +271,7 @@ void CheckString::checkIncorrectStringCompare()
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
// skip "assert(str && ..)" and "assert(.. && str)"
if (tok->str().size() >= 6U && (tok->str().find("assert") == tok->str().size() - 6U || tok->str().find("ASSERT") == tok->str().size() - 6U) &&
if ((endsWith(tok->str(), "assert", 6) || endsWith(tok->str(), "ASSERT", 6)) &&
Token::Match(tok, "%name% (") &&
(Token::Match(tok->tokAt(2), "%str% &&") || Token::Match(tok->next()->link()->tokAt(-2), "&& %str% )")))
tok = tok->next()->link();

View File

@ -60,4 +60,9 @@ inline bool endsWith(const std::string &str, char c)
return 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);
}
#endif