Browse Source

Replace empty-string comparisons with checking against `empty()`.

Pavel Solodovnikov 8 years ago
parent
commit
37d9387be3

+ 1 - 1
Source/CPack/IFW/cmCPackIFWRepository.cxx

@@ -162,7 +162,7 @@ protected:
   void CharacterDataHandler(const char* data, int length) override
   void CharacterDataHandler(const char* data, int length) override
   {
   {
     std::string content(data, data + length);
     std::string content(data, data + length);
-    if (content == "" || content == " " || content == "  " ||
+    if (content.empty() || content == " " || content == "  " ||
         content == "\n") {
         content == "\n") {
       return;
       return;
     }
     }

+ 2 - 2
Source/CTest/cmCTestBuildHandler.cxx

@@ -260,11 +260,11 @@ std::string cmCTestBuildHandler::GetMakeCommand()
                      "MakeCommand:" << makeCommand << "\n", this->Quiet);
                      "MakeCommand:" << makeCommand << "\n", this->Quiet);
 
 
   std::string configType = this->CTest->GetConfigType();
   std::string configType = this->CTest->GetConfigType();
-  if (configType == "") {
+  if (configType.empty()) {
     configType =
     configType =
       this->CTest->GetCTestConfiguration("DefaultCTestConfigurationType");
       this->CTest->GetCTestConfiguration("DefaultCTestConfigurationType");
   }
   }
-  if (configType == "") {
+  if (configType.empty()) {
     configType = "Release";
     configType = "Release";
   }
   }
 
 

+ 1 - 1
Source/CTest/cmCTestMultiProcessHandler.cxx

@@ -491,7 +491,7 @@ void cmCTestMultiProcessHandler::ReadCostData()
     }
     }
     // Next part of the file is the failed tests
     // Next part of the file is the failed tests
     while (std::getline(fin, line)) {
     while (std::getline(fin, line)) {
-      if (line != "") {
+      if (!line.empty()) {
         this->LastTestsFailed.push_back(line);
         this->LastTestsFailed.push_back(line);
       }
       }
     }
     }

+ 2 - 2
Source/CTest/cmCTestRunTest.cxx

@@ -494,7 +494,7 @@ bool cmCTestRunTest::StartTest(size_t total)
     }
     }
   }
   }
   // log and return if we did not find the executable
   // log and return if we did not find the executable
-  if (this->ActualCommand == "") {
+  if (this->ActualCommand.empty()) {
     // if the command was not found create a TestResult object
     // if the command was not found create a TestResult object
     // that has that information
     // that has that information
     this->TestProcess = new cmProcess;
     this->TestProcess = new cmProcess;
@@ -595,7 +595,7 @@ double cmCTestRunTest::ResolveTimeout()
 {
 {
   double timeout = this->TestProperties->Timeout;
   double timeout = this->TestProperties->Timeout;
 
 
-  if (this->CTest->GetStopTime() == "") {
+  if (this->CTest->GetStopTime().empty()) {
     return timeout;
     return timeout;
   }
   }
   struct tm* lctime;
   struct tm* lctime;

+ 1 - 1
Source/CTest/cmCTestSVN.cxx

@@ -410,7 +410,7 @@ void cmCTestSVN::DoRevisionSVN(Revision const& revision,
 
 
   // Ignore changes in the old revision for external repositories
   // Ignore changes in the old revision for external repositories
   if (revision.Rev == revision.SVNInfo->OldRevision &&
   if (revision.Rev == revision.SVNInfo->OldRevision &&
-      revision.SVNInfo->LocalPath != "") {
+      !revision.SVNInfo->LocalPath.empty()) {
     return;
     return;
   }
   }
 
 

+ 5 - 5
Source/CTest/cmCTestSubmitHandler.cxx

@@ -496,11 +496,11 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
           ? ""
           ? ""
           : this->GetOption("RetryCount");
           : this->GetOption("RetryCount");
 
 
-        int delay = retryDelay == ""
+        int delay = retryDelay.empty()
           ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
           ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
                    .c_str())
                    .c_str())
           : atoi(retryDelay.c_str());
           : atoi(retryDelay.c_str());
-        int count = retryCount == ""
+        int count = retryCount.empty()
           ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount")
           ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount")
                    .c_str())
                    .c_str())
           : atoi(retryCount.c_str());
           : atoi(retryCount.c_str());
@@ -1032,14 +1032,14 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
     ? ""
     ? ""
     : this->GetOption("RetryCount");
     : this->GetOption("RetryCount");
   unsigned long retryDelay = 0;
   unsigned long retryDelay = 0;
-  if (retryDelayString != "") {
+  if (!retryDelayString.empty()) {
     if (!cmSystemTools::StringToULong(retryDelayString.c_str(), &retryDelay)) {
     if (!cmSystemTools::StringToULong(retryDelayString.c_str(), &retryDelay)) {
       cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
       cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
                    << retryDelayString << std::endl);
                    << retryDelayString << std::endl);
     }
     }
   }
   }
   unsigned long retryCount = 0;
   unsigned long retryCount = 0;
-  if (retryCountString != "") {
+  if (!retryCountString.empty()) {
     if (!cmSystemTools::StringToULong(retryCountString.c_str(), &retryCount)) {
     if (!cmSystemTools::StringToULong(retryCountString.c_str(), &retryCount)) {
       cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
       cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
                    << retryCountString << std::endl);
                    << retryCountString << std::endl);
@@ -1361,7 +1361,7 @@ int cmCTestSubmitHandler::ProcessHandler()
 
 
   std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
   std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
 
 
-  if (dropMethod == "" || dropMethod == "ftp") {
+  if (dropMethod.empty() || dropMethod == "ftp") {
     ofs << "Using drop method: FTP" << std::endl;
     ofs << "Using drop method: FTP" << std::endl;
     cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
     cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
                        "   Using FTP submit method" << std::endl
                        "   Using FTP submit method" << std::endl

+ 2 - 2
Source/CTest/cmCTestTestHandler.cxx

@@ -1596,7 +1596,7 @@ std::string cmCTestTestHandler::FindExecutable(
   // wasn't specified
   // wasn't specified
   if (fullPath.empty() && filepath.empty()) {
   if (fullPath.empty() && filepath.empty()) {
     std::string const path = cmSystemTools::FindProgram(filename.c_str());
     std::string const path = cmSystemTools::FindProgram(filename.c_str());
-    if (path != "") {
+    if (!path.empty()) {
       resultingConfig.clear();
       resultingConfig.clear();
       return path;
       return path;
     }
     }
@@ -1802,7 +1802,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
     if (fileNameSubstring != pattern) {
     if (fileNameSubstring != pattern) {
       continue;
       continue;
     }
     }
-    if (logName == "") {
+    if (logName.empty()) {
       logName = fileName;
       logName = fileName;
     } else {
     } else {
       // if multiple matching logs were found we use the most recently
       // if multiple matching logs were found we use the most recently

+ 2 - 2
Source/CTest/cmParseCoberturaCoverage.cxx

@@ -78,7 +78,7 @@ protected:
             }
             }
           }
           }
 
 
-          if (this->CurFileName == "") {
+          if (this->CurFileName.empty()) {
             // Check if this is a path that is relative to our source or
             // Check if this is a path that is relative to our source or
             // binary directories.
             // binary directories.
             for (std::string const& filePath : FilePaths) {
             for (std::string const& filePath : FilePaths) {
@@ -91,7 +91,7 @@ protected:
           }
           }
 
 
           cmsys::ifstream fin(this->CurFileName.c_str());
           cmsys::ifstream fin(this->CurFileName.c_str());
-          if (this->CurFileName == "" || !fin) {
+          if (this->CurFileName.empty() || !fin) {
             this->CurFileName =
             this->CurFileName =
               this->Coverage.BinaryDir + "/" + atts[tagCount + 1];
               this->Coverage.BinaryDir + "/" + atts[tagCount + 1];
             fin.open(this->CurFileName.c_str());
             fin.open(this->CurFileName.c_str());

+ 2 - 1
Source/CTest/cmParseDelphiCoverage.cxx

@@ -71,7 +71,8 @@ public:
         }
         }
       }
       }
       // Based up what was found, add a line to the coverageVector
       // Based up what was found, add a line to the coverageVector
-      if (!beginSet.empty() && line != "" && !blockComFlag && !lineComFlag) {
+      if (!beginSet.empty() && !line.empty() && !blockComFlag &&
+          !lineComFlag) {
         coverageVector.push_back(0);
         coverageVector.push_back(0);
       } else {
       } else {
         coverageVector.push_back(-1);
         coverageVector.push_back(-1);

+ 1 - 1
Source/CTest/cmParseJacocoCoverage.cxx

@@ -36,7 +36,7 @@ protected:
     } else if (name == "sourcefile") {
     } else if (name == "sourcefile") {
       std::string fileName = atts[1];
       std::string fileName = atts[1];
 
 
-      if (this->PackagePath == "") {
+      if (this->PackagePath.empty()) {
         if (!this->FindPackagePath(fileName)) {
         if (!this->FindPackagePath(fileName)) {
           cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find file: "
           cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find file: "
                        << this->PackageName << "/" << fileName << std::endl);
                        << this->PackageName << "/" << fileName << std::endl);

+ 3 - 3
Source/cmCTest.cxx

@@ -147,7 +147,7 @@ std::string cmCTest::CurrentTime()
 std::string cmCTest::GetCostDataFile()
 std::string cmCTest::GetCostDataFile()
 {
 {
   std::string fname = this->GetCTestConfiguration("CostDataFile");
   std::string fname = this->GetCTestConfiguration("CostDataFile");
-  if (fname == "") {
+  if (fname.empty()) {
     fname = this->GetBinaryDir() + "/Testing/Temporary/CTestCostData.txt";
     fname = this->GetBinaryDir() + "/Testing/Temporary/CTestCostData.txt";
   }
   }
   return fname;
   return fname;
@@ -1235,7 +1235,7 @@ std::string cmCTest::SafeBuildIdField(const std::string& value)
 {
 {
   std::string safevalue(value);
   std::string safevalue(value);
 
 
-  if (safevalue != "") {
+  if (!safevalue.empty()) {
     // Disallow non-filename and non-space whitespace characters.
     // Disallow non-filename and non-space whitespace characters.
     // If they occur, replace them with ""
     // If they occur, replace them with ""
     //
     //
@@ -1254,7 +1254,7 @@ std::string cmCTest::SafeBuildIdField(const std::string& value)
     }
     }
   }
   }
 
 
-  if (safevalue == "") {
+  if (safevalue.empty()) {
     safevalue = "(empty)";
     safevalue = "(empty)";
   }
   }
 
 

+ 1 - 1
Source/cmDependsJavaParserHelper.cxx

@@ -310,7 +310,7 @@ void cmDependsJavaParserHelper::Error(const char* str)
 void cmDependsJavaParserHelper::UpdateCombine(const char* str1,
 void cmDependsJavaParserHelper::UpdateCombine(const char* str1,
                                               const char* str2)
                                               const char* str2)
 {
 {
-  if (this->CurrentCombine == "" && str1 != nullptr) {
+  if (this->CurrentCombine.empty() && str1 != nullptr) {
     this->CurrentCombine = str1;
     this->CurrentCombine = str1;
   }
   }
   this->CurrentCombine += ".";
   this->CurrentCombine += ".";

+ 2 - 2
Source/cmFindLibraryCommand.cxx

@@ -68,8 +68,8 @@ bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn,
     this->AddArchitecturePaths("x32");
     this->AddArchitecturePaths("x32");
   }
   }
 
 
-  std::string library = this->FindLibrary();
-  if (library != "") {
+  std::string const library = this->FindLibrary();
+  if (!library.empty()) {
     // Save the value in the cache
     // Save the value in the cache
     this->Makefile->AddCacheDefinition(this->VariableName, library.c_str(),
     this->Makefile->AddCacheDefinition(this->VariableName, library.c_str(),
                                        this->VariableDocumentation.c_str(),
                                        this->VariableDocumentation.c_str(),

+ 2 - 2
Source/cmFindProgramCommand.cxx

@@ -97,8 +97,8 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn,
     return true;
     return true;
   }
   }
 
 
-  std::string result = FindProgram();
-  if (result != "") {
+  std::string const result = FindProgram();
+  if (!result.empty()) {
     // Save the value in the cache
     // Save the value in the cache
     this->Makefile->AddCacheDefinition(this->VariableName, result.c_str(),
     this->Makefile->AddCacheDefinition(this->VariableName, result.c_str(),
                                        this->VariableDocumentation.c_str(),
                                        this->VariableDocumentation.c_str(),

+ 2 - 2
Source/cmGlobalUnixMakefileGenerator3.cxx

@@ -230,7 +230,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
 
 
   // The all and preinstall rules might never have any dependencies
   // The all and preinstall rules might never have any dependencies
   // added to them.
   // added to them.
-  if (this->EmptyRuleHackDepends != "") {
+  if (!this->EmptyRuleHackDepends.empty()) {
     depends.push_back(this->EmptyRuleHackDepends);
     depends.push_back(this->EmptyRuleHackDepends);
   }
   }
 
 
@@ -438,7 +438,7 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2(
 
 
   // Work-around for makes that drop rules that have no dependencies
   // Work-around for makes that drop rules that have no dependencies
   // or commands.
   // or commands.
-  if (depends.empty() && this->EmptyRuleHackDepends != "") {
+  if (depends.empty() && !this->EmptyRuleHackDepends.empty()) {
     depends.push_back(this->EmptyRuleHackDepends);
     depends.push_back(this->EmptyRuleHackDepends);
   }
   }
 
 

+ 2 - 2
Source/cmGlobalVisualStudioGenerator.cxx

@@ -150,7 +150,7 @@ void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
 {
 {
   std::string dir = this->GetUserMacrosDirectory();
   std::string dir = this->GetUserMacrosDirectory();
 
 
-  if (dir != "") {
+  if (!dir.empty()) {
     std::string src = cmSystemTools::GetCMakeRoot();
     std::string src = cmSystemTools::GetCMakeRoot();
     src += "/Templates/" CMAKE_VSMACROS_FILENAME;
     src += "/Templates/" CMAKE_VSMACROS_FILENAME;
 
 
@@ -190,7 +190,7 @@ void cmGlobalVisualStudioGenerator::CallVisualStudioMacro(
   //  - the CMake vsmacros file is registered
   //  - the CMake vsmacros file is registered
   //  - there were .sln/.vcproj files changed during generation
   //  - there were .sln/.vcproj files changed during generation
   //
   //
-  if (dir != "") {
+  if (!dir.empty()) {
     std::string macrosFile = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
     std::string macrosFile = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
     std::string nextSubkeyName;
     std::string nextSubkeyName;
     if (cmSystemTools::FileExists(macrosFile.c_str()) &&
     if (cmSystemTools::FileExists(macrosFile.c_str()) &&

+ 1 - 1
Source/cmLoadCommandCommand.cxx

@@ -197,7 +197,7 @@ bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& args,
 
 
   // Try to find the program.
   // Try to find the program.
   std::string fullPath = cmSystemTools::FindFile(moduleName, path);
   std::string fullPath = cmSystemTools::FindFile(moduleName, path);
-  if (fullPath == "") {
+  if (fullPath.empty()) {
     std::ostringstream e;
     std::ostringstream e;
     e << "Attempt to load command failed from file \"" << moduleName << "\"";
     e << "Attempt to load command failed from file \"" << moduleName << "\"";
     this->SetError(e.str());
     this->SetError(e.str());

+ 2 - 2
Source/cmLocalGenerator.cxx

@@ -1410,7 +1410,7 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName,
 
 
   // If the input name is the empty string, there is no real
   // If the input name is the empty string, there is no real
   // dependency. Short-circuit the other checks:
   // dependency. Short-circuit the other checks:
-  if (name == "") {
+  if (name.empty()) {
     return false;
     return false;
   }
   }
 
 
@@ -2096,7 +2096,7 @@ void cmLocalGenerator::GenerateTargetInstallRules(
     }
     }
 
 
     // Install this target if a destination is given.
     // Install this target if a destination is given.
-    if (l->Target->GetInstallPath() != "") {
+    if (!l->Target->GetInstallPath().empty()) {
       // Compute the full install destination.  Note that converting
       // Compute the full install destination.  Note that converting
       // to unix slashes also removes any trailing slash.
       // to unix slashes also removes any trailing slash.
       // We also skip over the leading slash given by the user.
       // We also skip over the leading slash given by the user.

+ 3 - 3
Source/cmLocalVisualStudio7Generator.cxx

@@ -1591,7 +1591,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
 
 
   // If the group has a name, write the header.
   // If the group has a name, write the header.
   std::string name = sg->GetName();
   std::string name = sg->GetName();
-  if (name != "") {
+  if (!name.empty()) {
     this->WriteVCProjBeginGroup(fout, name.c_str(), "");
     this->WriteVCProjBeginGroup(fout, name.c_str(), "");
   }
   }
 
 
@@ -1709,7 +1709,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
   }
   }
 
 
   // If the group has a name, write the footer.
   // If the group has a name, write the footer.
-  if (name != "") {
+  if (!name.empty()) {
     this->WriteVCProjEndGroup(fout);
     this->WriteVCProjEndGroup(fout);
   }
   }
 
 
@@ -2006,7 +2006,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFooter(
        i != props.end(); ++i) {
        i != props.end(); ++i) {
     if (i->find("VS_GLOBAL_") == 0) {
     if (i->find("VS_GLOBAL_") == 0) {
       std::string name = i->substr(10);
       std::string name = i->substr(10);
-      if (name != "") {
+      if (!name.empty()) {
         /* clang-format off */
         /* clang-format off */
         fout << "\t\t<Global\n"
         fout << "\t\t<Global\n"
              << "\t\t\tName=\"" << name << "\"\n"
              << "\t\t\tName=\"" << name << "\"\n"

+ 1 - 1
Source/cmOutputRequiredFilesCommand.cxx

@@ -510,7 +510,7 @@ void cmOutputRequiredFilesCommand::ListDependencies(
   // now recurse with info's dependencies
   // now recurse with info's dependencies
   for (cmDependInformation* d : info->DependencySet) {
   for (cmDependInformation* d : info->DependencySet) {
     if (visited->find(d) == visited->end()) {
     if (visited->find(d) == visited->end()) {
-      if (info->FullPath != "") {
+      if (!info->FullPath.empty()) {
         std::string tmp = d->FullPath;
         std::string tmp = d->FullPath;
         std::string::size_type pos = tmp.rfind('.');
         std::string::size_type pos = tmp.rfind('.');
         if (pos != std::string::npos && (tmp.substr(pos) != ".h")) {
         if (pos != std::string::npos && (tmp.substr(pos) != ".h")) {

+ 1 - 1
Source/cmPolicies.cxx

@@ -140,7 +140,7 @@ static bool GetPolicyDefault(cmMakefile* mf, std::string const& policy,
     *defaultSetting = cmPolicies::NEW;
     *defaultSetting = cmPolicies::NEW;
   } else if (defaultValue == "OLD") {
   } else if (defaultValue == "OLD") {
     *defaultSetting = cmPolicies::OLD;
     *defaultSetting = cmPolicies::OLD;
-  } else if (defaultValue == "") {
+  } else if (defaultValue.empty()) {
     *defaultSetting = cmPolicies::WARN;
     *defaultSetting = cmPolicies::WARN;
   } else {
   } else {
     std::ostringstream e;
     std::ostringstream e;

+ 1 - 1
Source/cmServer.cxx

@@ -84,7 +84,7 @@ void cmServer::ProcessRequest(cmConnection* connection,
   const cmServerRequest request(this, connection, value[kTYPE_KEY].asString(),
   const cmServerRequest request(this, connection, value[kTYPE_KEY].asString(),
                                 value[kCOOKIE_KEY].asString(), value);
                                 value[kCOOKIE_KEY].asString(), value);
 
 
-  if (request.Type == "") {
+  if (request.Type.empty()) {
     cmServerResponse response(request);
     cmServerResponse response(request);
     response.SetError("No type given in request.");
     response.SetError("No type given in request.");
     this->WriteResponse(connection, response, nullptr);
     this->WriteResponse(connection, response, nullptr);

+ 1 - 1
Source/cmSystemTools.cxx

@@ -1375,7 +1375,7 @@ std::string cmSystemTools::CollapseCombinedPath(std::string const& dir,
   if (fileComponents.empty()) {
   if (fileComponents.empty()) {
     return dir;
     return dir;
   }
   }
-  if (fileComponents[0] != "") {
+  if (!fileComponents[0].empty()) {
     // File is not a relative path.
     // File is not a relative path.
     return file;
     return file;
   }
   }

+ 2 - 2
Source/cmVisualStudio10TargetGenerator.cxx

@@ -407,7 +407,7 @@ void cmVisualStudio10TargetGenerator::Generate()
       continue;
       continue;
     std::string globalKey = keyIt->substr(strlen(prefix));
     std::string globalKey = keyIt->substr(strlen(prefix));
     // Skip invalid or separately-handled properties.
     // Skip invalid or separately-handled properties.
-    if (globalKey == "" || globalKey == "PROJECT_TYPES" ||
+    if (globalKey.empty() || globalKey == "PROJECT_TYPES" ||
         globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") {
         globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") {
       continue;
       continue;
     }
     }
@@ -614,7 +614,7 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
        ++i) {
        ++i) {
     if (i->first.find("VS_DOTNET_REFERENCE_") == 0) {
     if (i->first.find("VS_DOTNET_REFERENCE_") == 0) {
       std::string name = i->first.substr(20);
       std::string name = i->first.substr(20);
-      if (name != "") {
+      if (!name.empty()) {
         std::string path = i->second.GetValue();
         std::string path = i->second.GetValue();
         if (!cmsys::SystemTools::FileIsFullPath(path)) {
         if (!cmsys::SystemTools::FileIsFullPath(path)) {
           path = std::string(this->GeneratorTarget->Target->GetMakefile()
           path = std::string(this->GeneratorTarget->Target->GetMakefile()