From 26f017e9c685ff022ad7527b775194de3d1c37be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 5 Feb 2011 12:53:28 +0100 Subject: [PATCH] scripts: added tabs.pl - in my opinion it is bad to use tabs inside string constants. spaces or \t should be used instead. --- scripts/tabs.pl | 35 +++++++++++++++++++++++++++++++++++ test/testclass.cpp | 12 ++++++------ test/testmathlib.cpp | 20 ++++++++++---------- test/testnullpointer.cpp | 2 +- test/testuninitvar.cpp | 6 +++--- 5 files changed, 55 insertions(+), 20 deletions(-) create mode 100755 scripts/tabs.pl diff --git a/scripts/tabs.pl b/scripts/tabs.pl new file mode 100755 index 000000000..bf58359ae --- /dev/null +++ b/scripts/tabs.pl @@ -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 = ; + 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) +} + + diff --git a/test/testclass.cpp b/test/testclass.cpp index a8cb213e1..fd284f8fb 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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 class E,class D> class C : E\n" "{\n" "public:\n" - " int f();\n" + " int f();\n" "};\n" "class E : C\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()); diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index f05a029bc..cd3637da3 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -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")); } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 0c9e09a1f..35b239974 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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" diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 9c24fe6a5..3dc598f83 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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());