Skip to content

Commit f92ef7d

Browse files
committed
Refactoring. Use 'endsWith()'
1 parent 101dc28 commit f92ef7d

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkstring.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//---------------------------------------------------------------------------
2121
#include "checkstring.h"
2222
#include "symboldatabase.h"
23+
#include "utils.h"
2324

2425
//---------------------------------------------------------------------------
2526

@@ -270,7 +271,7 @@ void CheckString::checkIncorrectStringCompare()
270271
const Scope * scope = symbolDatabase->functionScopes[i];
271272
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
272273
// skip "assert(str && ..)" and "assert(.. && str)"
273-
if (tok->str().size() >= 6U && (tok->str().find("assert") == tok->str().size() - 6U || tok->str().find("ASSERT") == tok->str().size() - 6U) &&
274+
if ((endsWith(tok->str(), "assert", 6) || endsWith(tok->str(), "ASSERT", 6)) &&
274275
Token::Match(tok, "%name% (") &&
275276
(Token::Match(tok->tokAt(2), "%str% &&") || Token::Match(tok->next()->link()->tokAt(-2), "&& %str% )")))
276277
tok = tok->next()->link();

lib/utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@ inline bool endsWith(const std::string &str, char c)
6060
return str.back() == c;
6161
}
6262

63+
inline bool endsWith(const std::string &str, const char end[], std::size_t endlen)
64+
{
65+
return (str.size() >= endlen) && (str.compare(str.size()-endlen, endlen, end)==0);
66+
}
67+
6368
#endif

0 commit comments

Comments
 (0)