Refactorization: pass std::string directly to std::*fstream

This commit is contained in:
PKEuS 2018-04-11 09:50:42 +02:00
parent d2146844dd
commit b596b0d549
4 changed files with 11 additions and 11 deletions

View File

@ -52,7 +52,7 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
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<std::string>
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.
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;

View File

@ -48,7 +48,7 @@ void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::
std::map<std::string, unsigned int> fileCount;
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) {
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);

View File

@ -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 << "<?xml version=\"1.0\"?>" << 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..
const std::string filesTxt(buildDir + "/files.txt");
std::ifstream fin(filesTxt.c_str());
std::ifstream fin(filesTxt);
std::string filesTxtLine;
while (std::getline(fin, filesTxtLine)) {
const std::string::size_type firstColon = filesTxtLine.find(':');

View File

@ -81,7 +81,7 @@ private:
CppCheckExecutor exec;
exec.check(7, argv);
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 actual = GET_REDIRECT_ERROUT;
// We need some uniformization to make this work on Unix and Windows