match: skip initial !! patterns if on first token.
This commit is contained in:
parent
12a7d1df4b
commit
764e44790f
|
@ -167,6 +167,7 @@ bool Token::simpleMatch(const Token *tok, const char pattern[])
|
|||
bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
|
||||
{
|
||||
const char *p = pattern;
|
||||
bool firstpattern = true;
|
||||
while (*p)
|
||||
{
|
||||
// Skip spaces in pattern..
|
||||
|
@ -198,6 +199,12 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
|
|||
return false;
|
||||
}
|
||||
|
||||
// If we are in the first token, we skip all initial !! patterns
|
||||
if (firstpattern && !tok->previous() && tok->next() && str[1] == '!' && str[0] == '!' && str[2] != '\0')
|
||||
continue;
|
||||
|
||||
firstpattern = false;
|
||||
|
||||
// Compare the first character of the string for optimization reasons
|
||||
// before doing more detailed checks.
|
||||
bool patternIdentified = false;
|
||||
|
|
|
@ -504,6 +504,18 @@ private:
|
|||
ASSERT_EQUALS(false, Token::Match(tokenizer.tokens(), "!!else something"));
|
||||
}
|
||||
|
||||
{
|
||||
const std::string code("if ;");
|
||||
|
||||
// tokenize..
|
||||
Tokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
// Match..
|
||||
ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "!!return if"));
|
||||
}
|
||||
|
||||
{
|
||||
const std::string code("if ;");
|
||||
|
||||
|
|
Loading…
Reference in New Issue