From f5e5d59562dd4c84519d107a03b3f80c617e6399 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 24 Jul 2012 12:21:05 -0700 Subject: [PATCH] Refactorizations: - Removed redundant newlines at the end of test cases - Make use of STL algorithms instead of own implementations of std::replace and std::remove+string::erase - Removed unused variable (found by cppcheck) - Prefer postfix increment (found by cppcheck) --- lib/preprocessor.cpp | 3 +-- lib/suppressions.cpp | 4 ++-- lib/templatesimplifier.cpp | 4 ++-- test/testunusedprivfunc.cpp | 6 ++---- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index b422d05a8..cb0f73483 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -860,7 +860,6 @@ void Preprocessor::handleUndef(std::list &configurations) const { if (_settings && !_settings->userUndefs.empty()) { for (std::list::iterator cfg = configurations.begin(); cfg != configurations.end();) { - const std::string strcfg(*cfg); bool undef = false; for (std::set::const_iterator it = _settings->userUndefs.begin(); it != _settings->userUndefs.end(); ++it) { if (*it == *cfg) @@ -880,7 +879,7 @@ void Preprocessor::handleUndef(std::list &configurations) const if (undef) configurations.erase(cfg++); else - cfg++; + ++cfg; } } } diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 899455bd7..ebce78bbe 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -20,6 +20,7 @@ #include "settings.h" #include "path.h" +#include #include #include #include // std::isdigit, std::isalnum, etc @@ -31,8 +32,7 @@ std::string Suppressions::parseFile(std::istream &istr) std::string line; while (std::getline(istr, line)) filedata += line + "\n"; - while (filedata.find("\r") != std::string::npos) - filedata[filedata.find("\r")] = '\n'; + std::replace(filedata.begin(), filedata.end(), '\r', '\n'); // Parse filedata.. std::istringstream istr2(filedata); diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 6fb36e93f..540ea7a41 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -22,6 +22,7 @@ #include "tokenlist.h" #include "errorlogger.h" #include "settings.h" +#include #include #include #include @@ -353,8 +354,7 @@ std::set TemplateSimplifier::simplifyTemplatesExpandSpecialized(Tok const std::string pattern(s + " > ("); // remove spaces to create new name - while (s.find(" ") != std::string::npos) - s.erase(s.find(" "), 1); + s.erase(std::remove(s.begin(), s.end(), ' '), s.end()); const std::string name(s + ">"); expandedtemplates.insert(name); diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 39719bd3a..9b05e9cb7 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -140,8 +140,7 @@ private: "\n" "void Fred::f()\n" "{\n" - "}\n" - "\n"); + "}\n"); ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str()); // Don't warn about include files which implementation we don't see @@ -157,8 +156,7 @@ private: "\n" "int main()\n" "{\n" - "}\n" - "\n"); + "}\n"); ASSERT_EQUALS("", errout.str()); }