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:
parent
95e917b27f
commit
26f017e9c6
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
@ -488,11 +488,11 @@ private:
|
|||
" UString& operator=( const UString& s );\n"
|
||||
"};\n"
|
||||
"UString& UString::assign( const char* c_str ) {\n"
|
||||
" std::string tmp( c_str );\n"
|
||||
" return assign( tmp );\n"
|
||||
" std::string tmp( c_str );\n"
|
||||
" return assign( tmp );\n"
|
||||
"}\n"
|
||||
"UString& UString::operator=( const UString& s ) {\n"
|
||||
" return assign( s );\n"
|
||||
" return assign( s );\n"
|
||||
"}\n");
|
||||
}
|
||||
|
||||
|
@ -2723,7 +2723,7 @@ private:
|
|||
" A()\n"
|
||||
" {\n"
|
||||
" init();\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" void init() { init(0); }\n"
|
||||
"\n"
|
||||
|
@ -5452,12 +5452,12 @@ private:
|
|||
checkConst("template<template<class> class E,class D> class C : E<D>\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" int f();\n"
|
||||
" int f();\n"
|
||||
"};\n"
|
||||
"class E : C<D,int>\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" int f() { return C< ::D,int>::f(); }\n"
|
||||
" int f() { return C< ::D,int>::f(); }\n"
|
||||
"};\n");
|
||||
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
|
|
@ -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.0E+3", "3"));
|
||||
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("536870912" , MathLib::multiply("512","1048576"));
|
||||
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("536870912" , MathLib::multiply("512","1048576"));
|
||||
|
||||
// divide
|
||||
ASSERT_EQUALS("1" , MathLib::divide("1", "1"));
|
||||
ASSERT_EQUALS("0" , MathLib::divide("0", "1"));
|
||||
ASSERT_EQUALS("5" , MathLib::divide("-10", "-2"));
|
||||
ASSERT_EQUALS("1" , MathLib::divide("1", "1"));
|
||||
ASSERT_EQUALS("0" , MathLib::divide("0", "1"));
|
||||
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("5" , MathLib::divide("25.5", "5.1"));
|
||||
ASSERT_EQUALS("7" , MathLib::divide("21.", "3"));
|
||||
ASSERT_EQUALS("1" , MathLib::divide("3", "2"));
|
||||
ASSERT_EQUALS("5" , MathLib::divide("25.5", "5.1"));
|
||||
ASSERT_EQUALS("7" , MathLib::divide("21.", "3"));
|
||||
ASSERT_EQUALS("1" , MathLib::divide("3", "2"));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -668,7 +668,7 @@ private:
|
|||
check("void f(int a) {\n"
|
||||
" const char *p = 0;\n"
|
||||
" if (a) {\n"
|
||||
" p = \"abcd\";\n"
|
||||
" p = \"abcd\";\n"
|
||||
" }\n"
|
||||
" for (int i = 0; i < 3; i++) {\n"
|
||||
" if (a && (p[i] == '1'));\n"
|
||||
|
|
|
@ -736,9 +736,9 @@ private:
|
|||
checkUninitVar("enum ABCD { A, B, C, D };\n"
|
||||
"\n"
|
||||
"static void f(char *str ) {\n"
|
||||
" enum ABCD i;\n"
|
||||
" for (i = 0; i < D; i++) {\n"
|
||||
" str[i] = 0;\n"
|
||||
" enum ABCD i;\n"
|
||||
" for (i = 0; i < D; i++) {\n"
|
||||
" str[i] = 0;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
|
Loading…
Reference in New Issue