CheckAlpha: Expanded checking to include 'isupper' and 'islower'

This commit is contained in:
Daniel Marjamäki 2008-11-06 00:04:52 +00:00
parent f8a60ae5c2
commit 6a3d957366
1 changed files with 28 additions and 2 deletions

View File

@ -91,11 +91,37 @@ void WarningIsAlpha()
{ {
for (const TOKEN *tok = tokens; tok; tok = tok->next) for (const TOKEN *tok = tokens; tok; tok = tok->next)
{ {
bool err = false;
if ( tok->str[0] != '(' ) if ( tok->str[0] != '(' )
continue; continue;
bool err = false;
err |= Match(tok, "( %var% >= 'A' && %var% <= 'Z' )");
err |= Match(tok, "( * %var% >= 'A' && * %var% <= 'Z' )");
err |= Match(tok, "( ( %var% >= 'A' ) && ( %var% <= 'Z' ) )");
err |= Match(tok, "( ( * %var% >= 'A' ) && ( * %var% <= 'Z' ) )");
if (err)
{
std::ostringstream ostr;
ostr << FileLine(tok) << ": The condition can be simplified; use 'isupper'";
ReportErr(ostr.str());
continue;
}
err = false;
err |= Match(tok, "( %var% >= 'a' && %var% <= 'z' )");
err |= Match(tok, "( * %var% >= 'a' && * %var% <= 'z' )");
err |= Match(tok, "( ( %var% >= 'a' ) && ( %var% <= 'z' ) )");
err |= Match(tok, "( ( * %var% >= 'a' ) && ( * %var% <= 'z' ) )");
if (err)
{
std::ostringstream ostr;
ostr << FileLine(tok) << ": The condition can be simplified; use 'islower'";
ReportErr(ostr.str());
continue;
}
err = false;
err |= Match(tok, "( %var% >= 'A' && %var% <= 'Z' ) || ( %var% >= 'a' && %var% <= 'z' )"); err |= Match(tok, "( %var% >= 'A' && %var% <= 'Z' ) || ( %var% >= 'a' && %var% <= 'z' )");
err |= Match(tok, "( %var% >= 'a' && %var% <= 'z' ) || ( %var% >= 'A' && %var% <= 'Z' )"); err |= Match(tok, "( %var% >= 'a' && %var% <= 'z' ) || ( %var% >= 'A' && %var% <= 'Z' )");
err |= Match(tok, "( * %var% >= 'A' && * %var% <= 'Z' ) || ( * %var% >= 'a' && * %var% <= 'z' )"); err |= Match(tok, "( * %var% >= 'A' && * %var% <= 'Z' ) || ( * %var% >= 'a' && * %var% <= 'z' )");