From 997c9ce1004d67ddb0ad0cc3b79448cee3944703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 31 Aug 2013 10:28:21 +0200 Subject: [PATCH] Refactor CppCheck::_fileContents to a function parameter --- lib/cppcheck.cpp | 15 ++++++--------- lib/cppcheck.h | 10 +++++++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index d528a3f56..798873e57 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -62,15 +62,12 @@ const char * CppCheck::extraVersion() unsigned int CppCheck::check(const std::string &path) { - return processFile(path); + return processFile(path, ""); } unsigned int CppCheck::check(const std::string &path, const std::string &content) { - _fileContent = content; - const unsigned int retval = processFile(path); - _fileContent.clear(); - return retval; + return processFile(path, content); } void CppCheck::replaceAll(std::string& code, const std::string &from, const std::string &to) @@ -129,7 +126,7 @@ bool CppCheck::findError(std::string code, const char FileName[]) return true; } -unsigned int CppCheck::processFile(const std::string& filename) +unsigned int CppCheck::processFile(const std::string& filename, const std::string& fileContent) { exitcode = 0; @@ -151,9 +148,9 @@ unsigned int CppCheck::processFile(const std::string& filename) std::list configurations; std::string filedata = ""; - if (!_fileContent.empty()) { - // File content was given as a string - std::istringstream iss(_fileContent); + if (!fileContent.empty()) { + // File content was given as a string (democlient) + std::istringstream iss(fileContent); preprocessor.preprocess(iss, filedata, configurations, filename, _settings._includePaths); } else { // Only file name was given, read the content from file diff --git a/lib/cppcheck.h b/lib/cppcheck.h index ad5ccc624..acbd7f0e7 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -135,8 +135,13 @@ private: /** @brief There has been a internal error => Report information message */ void internalError(const std::string &filename, const std::string &msg); - /** @brief Process one file. */ - unsigned int processFile(const std::string& filename); + /** + * @brief Process one file. + * @param filename file name + * @param fileContent If this is non-empty then the file will not be loaded + * @return amount of errors found + */ + unsigned int processFile(const std::string& filename, const std::string& fileContent); /** @brief Check file */ void checkFile(const std::string &code, const char FileName[]); @@ -179,7 +184,6 @@ private: std::list _errorList; Settings _settings; - std::string _fileContent; void reportProgress(const std::string &filename, const char stage[], const std::size_t value);