From 4b52df675a5270f58d3bbdc1cf3e78571a7ef76b Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 18 Feb 2012 14:44:04 +0100 Subject: [PATCH] Some refactorizations --- cli/pathmatch.cpp | 2 +- cli/pathmatch.h | 4 ++-- lib/cppcheck.cpp | 2 +- lib/cppcheck.h | 2 +- lib/errorlogger.cpp | 10 ++++------ lib/settings.h | 9 +++------ lib/suppressions.cpp | 14 ++++++++------ lib/suppressions.h | 2 +- test/redirect.h | 2 +- 9 files changed, 22 insertions(+), 25 deletions(-) diff --git a/cli/pathmatch.cpp b/cli/pathmatch.cpp index fc212892a..96879695c 100644 --- a/cli/pathmatch.cpp +++ b/cli/pathmatch.cpp @@ -25,7 +25,7 @@ PathMatch::PathMatch(const std::vector &masks) { } -bool PathMatch::Match(const std::string &path, bool caseSensitive) +bool PathMatch::Match(const std::string &path, bool caseSensitive) const { if (path.empty()) return false; diff --git a/cli/pathmatch.h b/cli/pathmatch.h index 257cbede7..cb96ae839 100644 --- a/cli/pathmatch.h +++ b/cli/pathmatch.h @@ -44,7 +44,7 @@ public: * matching paths? * @return true if any of the masks match the path, false otherwise. */ - bool Match(const std::string &path, bool caseSensitive = true); + bool Match(const std::string &path, bool caseSensitive = true) const; protected: @@ -53,7 +53,7 @@ protected: * @param path Path to edit. * @return path without filename part. */ - std::string RemoveFilename(const std::string &path); + static std::string RemoveFilename(const std::string &path); private: std::vector _masks; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 7780dcf5f..90fb6c2cd 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -80,7 +80,7 @@ unsigned int CppCheck::check(const std::string &path, const std::string &content return retval; } -std::string CppCheck::replaceAll(std::string code, const std::string &from, const std::string &to) +std::string CppCheck::replaceAll(std::string code, const std::string &from, const std::string &to) const { size_t pos = 0; while ((pos = code.find(from, pos)) != std::string::npos) { diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 3b20665bd..821dbc937 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -173,7 +173,7 @@ private: * @brief Replace "from" strings with "to" strings in "code" * and return it. */ - std::string replaceAll(std::string code, const std::string &from, const std::string &to); + std::string replaceAll(std::string code, const std::string &from, const std::string &to) const; unsigned int exitcode; std::list _errorList; diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 858ac5e55..697600d60 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -30,9 +30,8 @@ InternalError::InternalError(const Token *tok, const std::string &errorMsg) : } ErrorLogger::ErrorMessage::ErrorMessage() - :_severity(Severity::none) + : _severity(Severity::none), _inconclusive(false) { - _inconclusive = false; } ErrorLogger::ErrorMessage::ErrorMessage(const std::list &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive) @@ -327,15 +326,14 @@ std::string ErrorLogger::callStackToString(const std::list >::iterator g = _globs.begin(); g != _globs.end(); ++g) { if (match(g->first, file)) { - if (g->second.find(0U) != g->second.end()) { - g->second[0U] = true; + std::map::iterator l = g->second.find(0U); + if (l != g->second.end()) { + l->second = true; return true; } - std::map::iterator l = g->second.find(line); + l = g->second.find(line); if (l != g->second.end()) { l->second = true; return true; @@ -200,11 +201,12 @@ bool Suppressions::FileMatcher::isSuppressedLocal(const std::string &file, unsig { std::map >::iterator f = _files.find(file); if (f != _files.end()) { - if (f->second.find(0U) != f->second.end()) { - f->second[0U] = true; + std::map::iterator l = f->second.find(0U); + if (l != f->second.end()) { + l->second = true; return true; } - std::map::iterator l = f->second.find(line); + l = f->second.find(line); if (l != f->second.end()) { l->second = true; return true; diff --git a/lib/suppressions.h b/lib/suppressions.h index 5f786fe72..3abdc37d1 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -118,7 +118,7 @@ public: bool isSuppressedLocal(const std::string &errorId, const std::string &file, unsigned int line); struct SuppressionEntry { - SuppressionEntry(const std::string &aid, const std::string &afile, const unsigned int &aline) + SuppressionEntry(const std::string &aid, const std::string &afile, unsigned int aline) : id(aid), file(afile), line(aline) { } diff --git a/test/redirect.h b/test/redirect.h index 81b101efa..cdcb8b07d 100644 --- a/test/redirect.h +++ b/test/redirect.h @@ -51,7 +51,7 @@ public: } /** Return what would be printed to cout. See also clearOutput() */ - std::string getOutput() { + std::string getOutput() const { return _out.str(); }