diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 189d0f1c7..d62b76ab0 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -63,12 +63,14 @@ const char * CppCheck::extraVersion() unsigned int CppCheck::check(const std::string &path) { - return processFile(path, ""); + std::ifstream fin(path.c_str()); + return processFile(path, fin); } unsigned int CppCheck::check(const std::string &path, const std::string &content) { - return processFile(path, content); + std::istringstream iss(content); + return processFile(path, iss); } void CppCheck::replaceAll(std::string& code, const std::string &from, const std::string &to) @@ -129,7 +131,7 @@ bool CppCheck::findError(std::string code, const char FileName[]) return true; } -unsigned int CppCheck::processFile(const std::string& filename, const std::string& fileContent) +unsigned int CppCheck::processFile(const std::string& filename, std::istream& fileStream) { exitcode = 0; @@ -151,15 +153,9 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin std::list configurations; std::string filedata = ""; - 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 - std::ifstream fin(filename.c_str()); + { Timer t("Preprocessor::preprocess", _settings._showtime, &S_timerResults); - preprocessor.preprocess(fin, filedata, configurations, filename, _settings._includePaths); + preprocessor.preprocess(fileStream, filedata, configurations, filename, _settings._includePaths); } if (_settings.checkConfiguration) { diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 43ea22722..7ab93b626 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -142,10 +142,10 @@ private: /** * @brief Process one file. * @param filename file name - * @param fileContent If this is non-empty then the file will not be loaded + * @param fileStream stream the file content can be read from * @return amount of errors found */ - unsigned int processFile(const std::string& filename, const std::string& fileContent); + unsigned int processFile(const std::string& filename, std::istream& fileStream); /** @brief Check file */ bool checkFile(const std::string &code, const char FileName[], std::set& checksums);