Refactor CppCheck::_fileContents to a function parameter

This commit is contained in:
Daniel Marjamäki 2013-08-31 10:28:21 +02:00
parent e6686dfb5b
commit 997c9ce100
2 changed files with 13 additions and 12 deletions

View File

@ -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<std::string> 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

View File

@ -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<std::string> _errorList;
Settings _settings;
std::string _fileContent;
void reportProgress(const std::string &filename, const char stage[], const std::size_t value);