Add '%char%' as pattern to match in Token::Match.
All and only those single characters enclosed in "'" are accepted.
This commit is contained in:
parent
7c370ec873
commit
87c931b74b
|
@ -621,6 +621,15 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
|
||||||
patternUnderstood = true;
|
patternUnderstood = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
// Character (%char%)
|
||||||
|
{
|
||||||
|
if (tok->_type != eChar)
|
||||||
|
return false;
|
||||||
|
p += 6;
|
||||||
|
patternUnderstood = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
// String (%str%)
|
// String (%str%)
|
||||||
{
|
{
|
||||||
|
|
|
@ -123,6 +123,7 @@ public:
|
||||||
* - "%type%" Anything that can be a variable type, e.g. "int", but not "delete".
|
* - "%type%" Anything that can be a variable type, e.g. "int", but not "delete".
|
||||||
* - "%num%" Any numeric token, e.g. "23"
|
* - "%num%" Any numeric token, e.g. "23"
|
||||||
* - "%bool%" true or false
|
* - "%bool%" true or false
|
||||||
|
* - "%char%" Any token enclosed in '-character.
|
||||||
* - "%str%" Any token starting with "-character (C-string).
|
* - "%str%" Any token starting with "-character (C-string).
|
||||||
* - "%varid%" Match with parameter varid
|
* - "%varid%" Match with parameter varid
|
||||||
* - "%or%" A bitwise-or operator '|'
|
* - "%or%" A bitwise-or operator '|'
|
||||||
|
|
|
@ -56,6 +56,7 @@ private:
|
||||||
TEST_CASE(matchSingleChar);
|
TEST_CASE(matchSingleChar);
|
||||||
TEST_CASE(matchNothingOrAnyNotElse);
|
TEST_CASE(matchNothingOrAnyNotElse);
|
||||||
TEST_CASE(matchType);
|
TEST_CASE(matchType);
|
||||||
|
TEST_CASE(matchChar);
|
||||||
TEST_CASE(matchStr);
|
TEST_CASE(matchStr);
|
||||||
TEST_CASE(matchVarid);
|
TEST_CASE(matchVarid);
|
||||||
TEST_CASE(matchNumeric);
|
TEST_CASE(matchNumeric);
|
||||||
|
@ -276,6 +277,17 @@ private:
|
||||||
ASSERT_EQUALS(false, Token::Match(noType.tokens(), "%type%"));
|
ASSERT_EQUALS(false, Token::Match(noType.tokens(), "%type%"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void matchChar() {
|
||||||
|
givenACodeSampleToTokenize chr1("'a'", true);
|
||||||
|
ASSERT_EQUALS(true, Token::Match(chr1.tokens(), "%char%"));
|
||||||
|
|
||||||
|
givenACodeSampleToTokenize chr2("'1'", true);
|
||||||
|
ASSERT_EQUALS(true, Token::Match(chr2.tokens(), "%char%"));
|
||||||
|
|
||||||
|
givenACodeSampleToTokenize noChr("\"10\"", true);
|
||||||
|
ASSERT_EQUALS(false, Token::Match(noChr.tokens(), "%char%"));
|
||||||
|
}
|
||||||
|
|
||||||
void matchStr() {
|
void matchStr() {
|
||||||
givenACodeSampleToTokenize noStr1("abc", true);
|
givenACodeSampleToTokenize noStr1("abc", true);
|
||||||
ASSERT_EQUALS(false, Token::Match(noStr1.tokens(), "%str%"));
|
ASSERT_EQUALS(false, Token::Match(noStr1.tokens(), "%str%"));
|
||||||
|
|
Loading…
Reference in New Issue