From b596b0d54974b9cd02743b7170e5607d0c40bea3 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 11 Apr 2018 09:50:42 +0200 Subject: [PATCH] Refactorization: pass std::string directly to std::*fstream --- cli/cmdlineparser.cpp | 8 ++++---- lib/analyzerinfo.cpp | 4 ++-- lib/cppcheck.cpp | 8 ++++---- test/testsamples.cpp | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 194f6ff9e..1171528af 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -52,7 +52,7 @@ static void AddFilesToList(const std::string& FileList, std::vector if (FileList == "-") { // read from stdin Files = &std::cin; } else { - Infile.open(FileList.c_str()); + Infile.open(FileList); Files = &Infile; } if (Files && *Files) { @@ -68,7 +68,7 @@ static void AddFilesToList(const std::string& FileList, std::vector static void AddInclPathsToList(const std::string& FileList, std::list* PathNames) { // 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) { std::string PathName; while (std::getline(Files, PathName)) { // next line @@ -189,7 +189,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) // exitcode-suppressions=filename.txt std::string filename = 24 + argv[i]; - std::ifstream f(filename.c_str()); + std::ifstream f(filename); if (!f.is_open()) { PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\"."); return false; @@ -204,7 +204,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) // Filter errors else if (std::strncmp(argv[i], "--suppressions-list=", 20) == 0) { std::string filename = argv[i]+20; - std::ifstream f(filename.c_str()); + std::ifstream f(filename); if (!f.is_open()) { std::string message("cppcheck: Couldn't open the file: \""); message += filename; diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index 81cd343bc..692dbe614 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -48,7 +48,7 @@ void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std:: std::map fileCount; const std::string filesTxt(buildDir + "/files.txt"); - std::ofstream fout(filesTxt.c_str()); + std::ofstream fout(filesTxt); for (std::list::const_iterator f = sourcefiles.begin(); f != sourcefiles.end(); ++f) { const std::string afile = getFilename(*f); 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) { const std::string files(buildDir + "/files.txt"); - std::ifstream fin(files.c_str()); + std::ifstream fin(files); if (fin.is_open()) { std::string line; const std::string endsWith(':' + cfg + ':' + sourcefile); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 612b353f3..225bc8854 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -79,7 +79,7 @@ const char * CppCheck::extraVersion() 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); } @@ -101,7 +101,7 @@ unsigned int CppCheck::check(const ImportProject::FileSettings &fs) if (fs.platformType != Settings::Unspecified) { 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); } @@ -196,7 +196,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin std::ofstream fdump; if (_settings.dump) { const std::string dumpfile(_settings.dumpFile.empty() ? (filename + ".dump") : _settings.dumpFile); - fdump.open(dumpfile.c_str()); + fdump.open(dumpfile); if (fdump.is_open()) { fdump << "" << std::endl; fdump << "" << std::endl; @@ -806,7 +806,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::mapfirst) + "out.txt"; - std::ifstream ifs(expected_filename.c_str()); + std::ifstream ifs(expected_filename); std::string expected((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); std::string actual = GET_REDIRECT_ERROUT; // We need some uniformization to make this work on Unix and Windows