scripts: added tabs.pl - in my opinion it is bad to use tabs inside string constants. spaces or \t should be used instead.

This commit is contained in:
Daniel Marjamäki 2011-02-05 12:53:28 +01:00
parent 95e917b27f
commit 26f017e9c6
5 changed files with 55 additions and 20 deletions

35
scripts/tabs.pl Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/perl
# warn if there are tabs in string constants, it can have surprising effects.
# example usage:
# scripts/tabs.pl lib/checkstl.cpp
sub checkfile
{
my $filename = $_[0];
# parse file
open(FILE, $filename);
my @lines = <FILE>;
close(FILE);
# check comments..
my $linenr = 0;
foreach $line (@lines)
{
$linenr = $linenr + 1;
# is there a tab in a string
if ($line =~ /".*\t.*"/)
{
print "[$filename:$linenr] tab inside string constant\n";
}
}
}
foreach $filename (@ARGV)
{
checkfile($filename)
}

View File

@ -488,11 +488,11 @@ private:
" UString& operator=( const UString& s );\n" " UString& operator=( const UString& s );\n"
"};\n" "};\n"
"UString& UString::assign( const char* c_str ) {\n" "UString& UString::assign( const char* c_str ) {\n"
" std::string tmp( c_str );\n" " std::string tmp( c_str );\n"
" return assign( tmp );\n" " return assign( tmp );\n"
"}\n" "}\n"
"UString& UString::operator=( const UString& s ) {\n" "UString& UString::operator=( const UString& s ) {\n"
" return assign( s );\n" " return assign( s );\n"
"}\n"); "}\n");
} }
@ -2723,7 +2723,7 @@ private:
" A()\n" " A()\n"
" {\n" " {\n"
" init();\n" " init();\n"
" }\n" " }\n"
"\n" "\n"
" void init() { init(0); }\n" " void init() { init(0); }\n"
"\n" "\n"
@ -5452,12 +5452,12 @@ private:
checkConst("template<template<class> class E,class D> class C : E<D>\n" checkConst("template<template<class> class E,class D> class C : E<D>\n"
"{\n" "{\n"
"public:\n" "public:\n"
" int f();\n" " int f();\n"
"};\n" "};\n"
"class E : C<D,int>\n" "class E : C<D,int>\n"
"{\n" "{\n"
"public:\n" "public:\n"
" int f() { return C< ::D,int>::f(); }\n" " int f() { return C< ::D,int>::f(); }\n"
"};\n"); "};\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());

View File

@ -66,20 +66,20 @@ private:
ASSERT_EQUALS("3000" , MathLib::multiply("1.0E3", "3")); ASSERT_EQUALS("3000" , MathLib::multiply("1.0E3", "3"));
ASSERT_EQUALS("-3000" , MathLib::multiply("-1.0E3", "3")); ASSERT_EQUALS("-3000" , MathLib::multiply("-1.0E3", "3"));
ASSERT_EQUALS("-3000" , MathLib::multiply("-1.0E+3", "3")); ASSERT_EQUALS("-3000" , MathLib::multiply("-1.0E+3", "3"));
ASSERT_EQUALS("0" , MathLib::multiply("-1.0E+3", "0")); ASSERT_EQUALS("0" , MathLib::multiply("-1.0E+3", "0"));
ASSERT_EQUALS("0" , MathLib::multiply("+1.0E+3", "0")); ASSERT_EQUALS("0" , MathLib::multiply("+1.0E+3", "0"));
ASSERT_EQUALS("2147483648" , MathLib::multiply("2","1073741824")); ASSERT_EQUALS("2147483648" , MathLib::multiply("2","1073741824"));
ASSERT_EQUALS("536870912" , MathLib::multiply("512","1048576")); ASSERT_EQUALS("536870912" , MathLib::multiply("512","1048576"));
// divide // divide
ASSERT_EQUALS("1" , MathLib::divide("1", "1")); ASSERT_EQUALS("1" , MathLib::divide("1", "1"));
ASSERT_EQUALS("0" , MathLib::divide("0", "1")); ASSERT_EQUALS("0" , MathLib::divide("0", "1"));
ASSERT_EQUALS("5" , MathLib::divide("-10", "-2")); ASSERT_EQUALS("5" , MathLib::divide("-10", "-2"));
ASSERT_EQUALS("-2.5", MathLib::divide("-10.", "4")); ASSERT_EQUALS("-2.5", MathLib::divide("-10.", "4"));
ASSERT_EQUALS("2.5" , MathLib::divide("-10.", "-4")); ASSERT_EQUALS("2.5" , MathLib::divide("-10.", "-4"));
ASSERT_EQUALS("5" , MathLib::divide("25.5", "5.1")); ASSERT_EQUALS("5" , MathLib::divide("25.5", "5.1"));
ASSERT_EQUALS("7" , MathLib::divide("21.", "3")); ASSERT_EQUALS("7" , MathLib::divide("21.", "3"));
ASSERT_EQUALS("1" , MathLib::divide("3", "2")); ASSERT_EQUALS("1" , MathLib::divide("3", "2"));
} }

View File

@ -668,7 +668,7 @@ private:
check("void f(int a) {\n" check("void f(int a) {\n"
" const char *p = 0;\n" " const char *p = 0;\n"
" if (a) {\n" " if (a) {\n"
" p = \"abcd\";\n" " p = \"abcd\";\n"
" }\n" " }\n"
" for (int i = 0; i < 3; i++) {\n" " for (int i = 0; i < 3; i++) {\n"
" if (a && (p[i] == '1'));\n" " if (a && (p[i] == '1'));\n"

View File

@ -736,9 +736,9 @@ private:
checkUninitVar("enum ABCD { A, B, C, D };\n" checkUninitVar("enum ABCD { A, B, C, D };\n"
"\n" "\n"
"static void f(char *str ) {\n" "static void f(char *str ) {\n"
" enum ABCD i;\n" " enum ABCD i;\n"
" for (i = 0; i < D; i++) {\n" " for (i = 0; i < D; i++) {\n"
" str[i] = 0;\n" " str[i] = 0;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());