token: when Token::Match reached the end of input, it returned true if the next pattern was !!. It now returns true only if all remaining patterns are !!.
This commit is contained in:
parent
9e5973fa16
commit
febdc3fe6e
|
@ -173,15 +173,6 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
|
||||||
while (*p == ' ')
|
while (*p == ' ')
|
||||||
++p;
|
++p;
|
||||||
|
|
||||||
if (!tok)
|
|
||||||
{
|
|
||||||
// If we have no tokens, pattern "!!else" should return true
|
|
||||||
if (p[1] == '!' && p[0] == '!' && strlen(p) > 2)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract token from pattern..
|
// Extract token from pattern..
|
||||||
// TODO: Refactor this so there can't be buffer overflows
|
// TODO: Refactor this so there can't be buffer overflows
|
||||||
char str[500];
|
char str[500];
|
||||||
|
@ -198,6 +189,15 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
|
||||||
if (str[0] == 0)
|
if (str[0] == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (!tok)
|
||||||
|
{
|
||||||
|
// If we have no tokens, pattern "!!else" should return true
|
||||||
|
if (str[1] == '!' && str[0] == '!' && strlen(str) > 2)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Compare the first character of the string for optimization reasons
|
// Compare the first character of the string for optimization reasons
|
||||||
// before doing more detailed checks.
|
// before doing more detailed checks.
|
||||||
bool patternIdentified = false;
|
bool patternIdentified = false;
|
||||||
|
|
|
@ -492,6 +492,18 @@ private:
|
||||||
ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "!!else"));
|
ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "!!else"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const std::string code("");
|
||||||
|
|
||||||
|
// tokenize..
|
||||||
|
Tokenizer tokenizer;
|
||||||
|
std::istringstream istr(code);
|
||||||
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
|
||||||
|
// Match..
|
||||||
|
ASSERT_EQUALS(false, Token::Match(tokenizer.tokens(), "!!else something"));
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const std::string code("if ;");
|
const std::string code("if ;");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue