Skip to content

Commit 997c9ce

Browse files
committed
Refactor CppCheck::_fileContents to a function parameter
1 parent e6686df commit 997c9ce

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

lib/cppcheck.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,12 @@ const char * CppCheck::extraVersion()
6262

6363
unsigned int CppCheck::check(const std::string &path)
6464
{
65-
return processFile(path);
65+
return processFile(path, "");
6666
}
6767

6868
unsigned int CppCheck::check(const std::string &path, const std::string &content)
6969
{
70-
_fileContent = content;
71-
const unsigned int retval = processFile(path);
72-
_fileContent.clear();
73-
return retval;
70+
return processFile(path, content);
7471
}
7572

7673
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[])
129126
return true;
130127
}
131128

132-
unsigned int CppCheck::processFile(const std::string& filename)
129+
unsigned int CppCheck::processFile(const std::string& filename, const std::string& fileContent)
133130
{
134131
exitcode = 0;
135132

@@ -151,9 +148,9 @@ unsigned int CppCheck::processFile(const std::string& filename)
151148
std::list<std::string> configurations;
152149
std::string filedata = "";
153150

154-
if (!_fileContent.empty()) {
155-
// File content was given as a string
156-
std::istringstream iss(_fileContent);
151+
if (!fileContent.empty()) {
152+
// File content was given as a string (democlient)
153+
std::istringstream iss(fileContent);
157154
preprocessor.preprocess(iss, filedata, configurations, filename, _settings._includePaths);
158155
} else {
159156
// Only file name was given, read the content from file

lib/cppcheck.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,13 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
135135
/** @brief There has been a internal error => Report information message */
136136
void internalError(const std::string &filename, const std::string &msg);
137137

138-
/** @brief Process one file. */
139-
unsigned int processFile(const std::string& filename);
138+
/**
139+
* @brief Process one file.
140+
* @param filename file name
141+
* @param fileContent If this is non-empty then the file will not be loaded
142+
* @return amount of errors found
143+
*/
144+
unsigned int processFile(const std::string& filename, const std::string& fileContent);
140145

141146
/** @brief Check file */
142147
void checkFile(const std::string &code, const char FileName[]);
@@ -179,7 +184,6 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
179184

180185
std::list<std::string> _errorList;
181186
Settings _settings;
182-
std::string _fileContent;
183187

184188
void reportProgress(const std::string &filename, const char stage[], const std::size_t value);
185189

0 commit comments

Comments
 (0)