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:
Leandro Penz 2009-01-10 00:33:48 +00:00
parent 9e5973fa16
commit febdc3fe6e
2 changed files with 21 additions and 9 deletions

View File

@ -173,15 +173,6 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
while (*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..
// TODO: Refactor this so there can't be buffer overflows
char str[500];
@ -198,6 +189,15 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
if (str[0] == 0)
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
// before doing more detailed checks.
bool patternIdentified = false;

View File

@ -492,6 +492,18 @@ private:
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 ;");