Refactorization: pass std::string directly to std::*fstream
This commit is contained in:
parent
d2146844dd
commit
b596b0d549
|
@ -52,7 +52,7 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
|
||||||
if (FileList == "-") { // read from stdin
|
if (FileList == "-") { // read from stdin
|
||||||
Files = &std::cin;
|
Files = &std::cin;
|
||||||
} else {
|
} else {
|
||||||
Infile.open(FileList.c_str());
|
Infile.open(FileList);
|
||||||
Files = &Infile;
|
Files = &Infile;
|
||||||
}
|
}
|
||||||
if (Files && *Files) {
|
if (Files && *Files) {
|
||||||
|
@ -68,7 +68,7 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
|
||||||
static void AddInclPathsToList(const std::string& FileList, std::list<std::string>* PathNames)
|
static void AddInclPathsToList(const std::string& FileList, std::list<std::string>* PathNames)
|
||||||
{
|
{
|
||||||
// To keep things initially simple, if the file can't be opened, just be silent and move on.
|
// To keep things initially simple, if the file can't be opened, just be silent and move on.
|
||||||
std::ifstream Files(FileList.c_str());
|
std::ifstream Files(FileList);
|
||||||
if (Files) {
|
if (Files) {
|
||||||
std::string PathName;
|
std::string PathName;
|
||||||
while (std::getline(Files, PathName)) { // next line
|
while (std::getline(Files, PathName)) { // next line
|
||||||
|
@ -189,7 +189,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
// exitcode-suppressions=filename.txt
|
// exitcode-suppressions=filename.txt
|
||||||
std::string filename = 24 + argv[i];
|
std::string filename = 24 + argv[i];
|
||||||
|
|
||||||
std::ifstream f(filename.c_str());
|
std::ifstream f(filename);
|
||||||
if (!f.is_open()) {
|
if (!f.is_open()) {
|
||||||
PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\".");
|
PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\".");
|
||||||
return false;
|
return false;
|
||||||
|
@ -204,7 +204,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
// Filter errors
|
// Filter errors
|
||||||
else if (std::strncmp(argv[i], "--suppressions-list=", 20) == 0) {
|
else if (std::strncmp(argv[i], "--suppressions-list=", 20) == 0) {
|
||||||
std::string filename = argv[i]+20;
|
std::string filename = argv[i]+20;
|
||||||
std::ifstream f(filename.c_str());
|
std::ifstream f(filename);
|
||||||
if (!f.is_open()) {
|
if (!f.is_open()) {
|
||||||
std::string message("cppcheck: Couldn't open the file: \"");
|
std::string message("cppcheck: Couldn't open the file: \"");
|
||||||
message += filename;
|
message += filename;
|
||||||
|
|
|
@ -48,7 +48,7 @@ void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::
|
||||||
std::map<std::string, unsigned int> fileCount;
|
std::map<std::string, unsigned int> fileCount;
|
||||||
|
|
||||||
const std::string filesTxt(buildDir + "/files.txt");
|
const std::string filesTxt(buildDir + "/files.txt");
|
||||||
std::ofstream fout(filesTxt.c_str());
|
std::ofstream fout(filesTxt);
|
||||||
for (std::list<std::string>::const_iterator f = sourcefiles.begin(); f != sourcefiles.end(); ++f) {
|
for (std::list<std::string>::const_iterator f = sourcefiles.begin(); f != sourcefiles.end(); ++f) {
|
||||||
const std::string afile = getFilename(*f);
|
const std::string afile = getFilename(*f);
|
||||||
if (fileCount.find(afile) == fileCount.end())
|
if (fileCount.find(afile) == fileCount.end())
|
||||||
|
@ -99,7 +99,7 @@ static bool skipAnalysis(const std::string &analyzerInfoFile, unsigned long long
|
||||||
std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg)
|
std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg)
|
||||||
{
|
{
|
||||||
const std::string files(buildDir + "/files.txt");
|
const std::string files(buildDir + "/files.txt");
|
||||||
std::ifstream fin(files.c_str());
|
std::ifstream fin(files);
|
||||||
if (fin.is_open()) {
|
if (fin.is_open()) {
|
||||||
std::string line;
|
std::string line;
|
||||||
const std::string endsWith(':' + cfg + ':' + sourcefile);
|
const std::string endsWith(':' + cfg + ':' + sourcefile);
|
||||||
|
|
|
@ -79,7 +79,7 @@ const char * CppCheck::extraVersion()
|
||||||
|
|
||||||
unsigned int CppCheck::check(const std::string &path)
|
unsigned int CppCheck::check(const std::string &path)
|
||||||
{
|
{
|
||||||
std::ifstream fin(path.c_str());
|
std::ifstream fin(path);
|
||||||
return processFile(Path::simplifyPath(path), emptyString, fin);
|
return processFile(Path::simplifyPath(path), emptyString, fin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ unsigned int CppCheck::check(const ImportProject::FileSettings &fs)
|
||||||
if (fs.platformType != Settings::Unspecified) {
|
if (fs.platformType != Settings::Unspecified) {
|
||||||
temp._settings.platform(fs.platformType);
|
temp._settings.platform(fs.platformType);
|
||||||
}
|
}
|
||||||
std::ifstream fin(fs.filename.c_str());
|
std::ifstream fin(fs.filename);
|
||||||
return temp.processFile(Path::simplifyPath(fs.filename), fs.cfg, fin);
|
return temp.processFile(Path::simplifyPath(fs.filename), fs.cfg, fin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
|
||||||
std::ofstream fdump;
|
std::ofstream fdump;
|
||||||
if (_settings.dump) {
|
if (_settings.dump) {
|
||||||
const std::string dumpfile(_settings.dumpFile.empty() ? (filename + ".dump") : _settings.dumpFile);
|
const std::string dumpfile(_settings.dumpFile.empty() ? (filename + ".dump") : _settings.dumpFile);
|
||||||
fdump.open(dumpfile.c_str());
|
fdump.open(dumpfile);
|
||||||
if (fdump.is_open()) {
|
if (fdump.is_open()) {
|
||||||
fdump << "<?xml version=\"1.0\"?>" << std::endl;
|
fdump << "<?xml version=\"1.0\"?>" << std::endl;
|
||||||
fdump << "<dumps>" << std::endl;
|
fdump << "<dumps>" << std::endl;
|
||||||
|
@ -806,7 +806,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map<s
|
||||||
|
|
||||||
// Load all analyzer info data..
|
// Load all analyzer info data..
|
||||||
const std::string filesTxt(buildDir + "/files.txt");
|
const std::string filesTxt(buildDir + "/files.txt");
|
||||||
std::ifstream fin(filesTxt.c_str());
|
std::ifstream fin(filesTxt);
|
||||||
std::string filesTxtLine;
|
std::string filesTxtLine;
|
||||||
while (std::getline(fin, filesTxtLine)) {
|
while (std::getline(fin, filesTxtLine)) {
|
||||||
const std::string::size_type firstColon = filesTxtLine.find(':');
|
const std::string::size_type firstColon = filesTxtLine.find(':');
|
||||||
|
|
|
@ -81,7 +81,7 @@ private:
|
||||||
CppCheckExecutor exec;
|
CppCheckExecutor exec;
|
||||||
exec.check(7, argv);
|
exec.check(7, argv);
|
||||||
std::string expected_filename = Path::getPathFromFilename(i->first) + "out.txt";
|
std::string expected_filename = Path::getPathFromFilename(i->first) + "out.txt";
|
||||||
std::ifstream ifs(expected_filename.c_str());
|
std::ifstream ifs(expected_filename);
|
||||||
std::string expected((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
std::string expected((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||||
std::string actual = GET_REDIRECT_ERROUT;
|
std::string actual = GET_REDIRECT_ERROUT;
|
||||||
// We need some uniformization to make this work on Unix and Windows
|
// We need some uniformization to make this work on Unix and Windows
|
||||||
|
|
Loading…
Reference in New Issue