Skip to content

Commit b596b0d

Browse files
committed
Refactorization: pass std::string directly to std::*fstream
1 parent d214684 commit b596b0d

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
5252
if (FileList == "-") { // read from stdin
5353
Files = &std::cin;
5454
} else {
55-
Infile.open(FileList.c_str());
55+
Infile.open(FileList);
5656
Files = &Infile;
5757
}
5858
if (Files && *Files) {
@@ -68,7 +68,7 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
6868
static void AddInclPathsToList(const std::string& FileList, std::list<std::string>* PathNames)
6969
{
7070
// To keep things initially simple, if the file can't be opened, just be silent and move on.
71-
std::ifstream Files(FileList.c_str());
71+
std::ifstream Files(FileList);
7272
if (Files) {
7373
std::string PathName;
7474
while (std::getline(Files, PathName)) { // next line
@@ -189,7 +189,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
189189
// exitcode-suppressions=filename.txt
190190
std::string filename = 24 + argv[i];
191191

192-
std::ifstream f(filename.c_str());
192+
std::ifstream f(filename);
193193
if (!f.is_open()) {
194194
PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\".");
195195
return false;
@@ -204,7 +204,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
204204
// Filter errors
205205
else if (std::strncmp(argv[i], "--suppressions-list=", 20) == 0) {
206206
std::string filename = argv[i]+20;
207-
std::ifstream f(filename.c_str());
207+
std::ifstream f(filename);
208208
if (!f.is_open()) {
209209
std::string message("cppcheck: Couldn't open the file: \"");
210210
message += filename;

lib/analyzerinfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::
4848
std::map<std::string, unsigned int> fileCount;
4949

5050
const std::string filesTxt(buildDir + "/files.txt");
51-
std::ofstream fout(filesTxt.c_str());
51+
std::ofstream fout(filesTxt);
5252
for (std::list<std::string>::const_iterator f = sourcefiles.begin(); f != sourcefiles.end(); ++f) {
5353
const std::string afile = getFilename(*f);
5454
if (fileCount.find(afile) == fileCount.end())
@@ -99,7 +99,7 @@ static bool skipAnalysis(const std::string &analyzerInfoFile, unsigned long long
9999
std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg)
100100
{
101101
const std::string files(buildDir + "/files.txt");
102-
std::ifstream fin(files.c_str());
102+
std::ifstream fin(files);
103103
if (fin.is_open()) {
104104
std::string line;
105105
const std::string endsWith(':' + cfg + ':' + sourcefile);

lib/cppcheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const char * CppCheck::extraVersion()
7979

8080
unsigned int CppCheck::check(const std::string &path)
8181
{
82-
std::ifstream fin(path.c_str());
82+
std::ifstream fin(path);
8383
return processFile(Path::simplifyPath(path), emptyString, fin);
8484
}
8585

@@ -101,7 +101,7 @@ unsigned int CppCheck::check(const ImportProject::FileSettings &fs)
101101
if (fs.platformType != Settings::Unspecified) {
102102
temp._settings.platform(fs.platformType);
103103
}
104-
std::ifstream fin(fs.filename.c_str());
104+
std::ifstream fin(fs.filename);
105105
return temp.processFile(Path::simplifyPath(fs.filename), fs.cfg, fin);
106106
}
107107

@@ -196,7 +196,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
196196
std::ofstream fdump;
197197
if (_settings.dump) {
198198
const std::string dumpfile(_settings.dumpFile.empty() ? (filename + ".dump") : _settings.dumpFile);
199-
fdump.open(dumpfile.c_str());
199+
fdump.open(dumpfile);
200200
if (fdump.is_open()) {
201201
fdump << "<?xml version=\"1.0\"?>" << std::endl;
202202
fdump << "<dumps>" << std::endl;
@@ -806,7 +806,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map<s
806806

807807
// Load all analyzer info data..
808808
const std::string filesTxt(buildDir + "/files.txt");
809-
std::ifstream fin(filesTxt.c_str());
809+
std::ifstream fin(filesTxt);
810810
std::string filesTxtLine;
811811
while (std::getline(fin, filesTxtLine)) {
812812
const std::string::size_type firstColon = filesTxtLine.find(':');

test/testsamples.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class TestSamples : public TestFixture {
8181
CppCheckExecutor exec;
8282
exec.check(7, argv);
8383
std::string expected_filename = Path::getPathFromFilename(i->first) + "out.txt";
84-
std::ifstream ifs(expected_filename.c_str());
84+
std::ifstream ifs(expected_filename);
8585
std::string expected((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
8686
std::string actual = GET_REDIRECT_ERROUT;
8787
// We need some uniformization to make this work on Unix and Windows

0 commit comments

Comments
 (0)