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)
This commit is contained in:
PKEuS 2012-07-24 12:21:05 -07:00
parent bb940e4722
commit f5e5d59562
4 changed files with 7 additions and 10 deletions

View File

@ -860,7 +860,6 @@ void Preprocessor::handleUndef(std::list<std::string> &configurations) const
{ {
if (_settings && !_settings->userUndefs.empty()) { if (_settings && !_settings->userUndefs.empty()) {
for (std::list<std::string>::iterator cfg = configurations.begin(); cfg != configurations.end();) { for (std::list<std::string>::iterator cfg = configurations.begin(); cfg != configurations.end();) {
const std::string strcfg(*cfg);
bool undef = false; bool undef = false;
for (std::set<std::string>::const_iterator it = _settings->userUndefs.begin(); it != _settings->userUndefs.end(); ++it) { for (std::set<std::string>::const_iterator it = _settings->userUndefs.begin(); it != _settings->userUndefs.end(); ++it) {
if (*it == *cfg) if (*it == *cfg)
@ -880,7 +879,7 @@ void Preprocessor::handleUndef(std::list<std::string> &configurations) const
if (undef) if (undef)
configurations.erase(cfg++); configurations.erase(cfg++);
else else
cfg++; ++cfg;
} }
} }
} }

View File

@ -20,6 +20,7 @@
#include "settings.h" #include "settings.h"
#include "path.h" #include "path.h"
#include <algorithm>
#include <sstream> #include <sstream>
#include <stack> #include <stack>
#include <cctype> // std::isdigit, std::isalnum, etc #include <cctype> // std::isdigit, std::isalnum, etc
@ -31,8 +32,7 @@ std::string Suppressions::parseFile(std::istream &istr)
std::string line; std::string line;
while (std::getline(istr, line)) while (std::getline(istr, line))
filedata += line + "\n"; filedata += line + "\n";
while (filedata.find("\r") != std::string::npos) std::replace(filedata.begin(), filedata.end(), '\r', '\n');
filedata[filedata.find("\r")] = '\n';
// Parse filedata.. // Parse filedata..
std::istringstream istr2(filedata); std::istringstream istr2(filedata);

View File

@ -22,6 +22,7 @@
#include "tokenlist.h" #include "tokenlist.h"
#include "errorlogger.h" #include "errorlogger.h"
#include "settings.h" #include "settings.h"
#include <algorithm>
#include <sstream> #include <sstream>
#include <list> #include <list>
#include <set> #include <set>
@ -353,8 +354,7 @@ std::set<std::string> TemplateSimplifier::simplifyTemplatesExpandSpecialized(Tok
const std::string pattern(s + " > ("); const std::string pattern(s + " > (");
// remove spaces to create new name // remove spaces to create new name
while (s.find(" ") != std::string::npos) s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
s.erase(s.find(" "), 1);
const std::string name(s + ">"); const std::string name(s + ">");
expandedtemplates.insert(name); expandedtemplates.insert(name);

View File

@ -140,8 +140,7 @@ private:
"\n" "\n"
"void Fred::f()\n" "void Fred::f()\n"
"{\n" "{\n"
"}\n" "}\n");
"\n");
ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str()); 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 // Don't warn about include files which implementation we don't see
@ -157,8 +156,7 @@ private:
"\n" "\n"
"int main()\n" "int main()\n"
"{\n" "{\n"
"}\n" "}\n");
"\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }