Added check: 'IsAlpha'
This commit is contained in:
parent
7b07271134
commit
cf7485ce0c
|
@ -59,6 +59,39 @@ void WarningIsDigit()
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
// Use standard function "isalpha" instead
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void WarningIsAlpha()
|
||||||
|
{
|
||||||
|
for (TOKEN *tok = tokens; tok; tok = tok->next)
|
||||||
|
{
|
||||||
|
bool err = false;
|
||||||
|
|
||||||
|
if ( tok->str[0] != '(' )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
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' ) )");
|
||||||
|
err |= match(tok, "( ( * var >= 'A' ) && ( * var <= 'Z' ) ) || ( ( * var >= 'a' ) && ( * var <= 'z' ) )");
|
||||||
|
err |= match(tok, "( ( * var >= 'a' ) && ( * var <= 'z' ) ) || ( ( * var >= 'A' ) && ( * var <= 'Z' ) )");
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
std::ostringstream ostr;
|
||||||
|
ostr << FileLine(tok) << ": The condition can be simplified; use 'isalpha'";
|
||||||
|
ReportErr(ostr.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// Redundant code..
|
// Redundant code..
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -10,6 +10,9 @@ void WarningOldStylePointerCast();
|
||||||
// Use standard functions instead
|
// Use standard functions instead
|
||||||
void WarningIsDigit();
|
void WarningIsDigit();
|
||||||
|
|
||||||
|
// Use standard functions instead
|
||||||
|
void WarningIsAlpha();
|
||||||
|
|
||||||
// Redundant code
|
// Redundant code
|
||||||
void WarningRedundantCode();
|
void WarningRedundantCode();
|
||||||
|
|
||||||
|
|
2
main.cpp
2
main.cpp
|
@ -74,6 +74,7 @@ static void CppCheck(const char FileName[])
|
||||||
if ( ShowWarnings )
|
if ( ShowWarnings )
|
||||||
{
|
{
|
||||||
// Including header which is not needed
|
// Including header which is not needed
|
||||||
|
// Todo: This is really slow!
|
||||||
WarningIncludeHeader();
|
WarningIncludeHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +111,7 @@ static void CppCheck(const char FileName[])
|
||||||
|
|
||||||
// Use standard functions instead
|
// Use standard functions instead
|
||||||
WarningIsDigit();
|
WarningIsDigit();
|
||||||
|
WarningIsAlpha();
|
||||||
|
|
||||||
CheckOperatorEq1();
|
CheckOperatorEq1();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue