Reduce raw string pointers usage.

* Change some functions to take `std::string` instead of
  `const char*` in the following classes: `cmMakeFile`, `cmake`,
  `cmCoreTryCompile`, `cmSystemTools`,  `cmState`, `cmLocalGenerator`
  and a few others.
* Greatly reduce using of `const char*` overloads for
  `cmSystemTools::MakeDirectory` and `cmSystemTools::RelativePath`.
* Remove many redundant `c_str()` conversions throughout the code.
This commit is contained in:
Pavel Solodovnikov
2018-01-31 18:20:02 +03:00
parent 4499cc8bb6
commit 653b894683
120 changed files with 471 additions and 507 deletions

View File

@@ -173,7 +173,7 @@ protected:
std::string line;
while (cmSystemTools::GetLineFromStream(fin, line)) {
if (cmHasLiteralPrefix(line.c_str(), "#include")) {
if (cmHasLiteralPrefix(line, "#include")) {
// if it is an include line then create a string class
size_t qstart = line.find('\"', 8);
size_t qend;
@@ -213,51 +213,51 @@ protected:
cxxFile = root + ".cxx";
bool found = false;
// try jumping to .cxx .cpp and .c in order
if (cmSystemTools::FileExists(cxxFile.c_str())) {
if (cmSystemTools::FileExists(cxxFile)) {
found = true;
}
for (std::string path : this->IncludeDirectories) {
path = path + "/";
path = path + cxxFile;
if (cmSystemTools::FileExists(path.c_str())) {
if (cmSystemTools::FileExists(path)) {
found = true;
}
}
if (!found) {
cxxFile = root + ".cpp";
if (cmSystemTools::FileExists(cxxFile.c_str())) {
if (cmSystemTools::FileExists(cxxFile)) {
found = true;
}
for (std::string path : this->IncludeDirectories) {
path = path + "/";
path = path + cxxFile;
if (cmSystemTools::FileExists(path.c_str())) {
if (cmSystemTools::FileExists(path)) {
found = true;
}
}
}
if (!found) {
cxxFile = root + ".c";
if (cmSystemTools::FileExists(cxxFile.c_str())) {
if (cmSystemTools::FileExists(cxxFile)) {
found = true;
}
for (std::string path : this->IncludeDirectories) {
path = path + "/";
path = path + cxxFile;
if (cmSystemTools::FileExists(path.c_str())) {
if (cmSystemTools::FileExists(path)) {
found = true;
}
}
}
if (!found) {
cxxFile = root + ".txx";
if (cmSystemTools::FileExists(cxxFile.c_str())) {
if (cmSystemTools::FileExists(cxxFile)) {
found = true;
}
for (std::string path : this->IncludeDirectories) {
path = path + "/";
path = path + cxxFile;
if (cmSystemTools::FileExists(path.c_str())) {
if (cmSystemTools::FileExists(path)) {
found = true;
}
}
@@ -426,7 +426,7 @@ protected:
path = path + "/";
}
path = path + fname;
if (cmSystemTools::FileExists(path.c_str(), true) &&
if (cmSystemTools::FileExists(path, true) &&
!cmSystemTools::FileIsDirectory(path)) {
std::string fp = cmSystemTools::CollapseFullPath(path);
this->DirectoryToFileToPathMap[extraPath ? extraPath : ""][fname] = fp;
@@ -440,7 +440,7 @@ protected:
path = path + "/";
}
path = path + fname;
if (cmSystemTools::FileExists(path.c_str(), true) &&
if (cmSystemTools::FileExists(path, true) &&
!cmSystemTools::FileIsDirectory(path)) {
std::string fp = cmSystemTools::CollapseFullPath(path);
this->DirectoryToFileToPathMap[extraPath][fname] = fp;