Merge topic 'string-improve'

0ee984defa CTest: Use std::string arguments

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !8046
diff --git a/Source/CTest/cmCTestGenericHandler.cxx b/Source/CTest/cmCTestGenericHandler.cxx
index 1c292c7..728e88e 100644
--- a/Source/CTest/cmCTestGenericHandler.cxx
+++ b/Source/CTest/cmCTestGenericHandler.cxx
@@ -26,13 +26,8 @@
  * is non-null, otherwise removing key `op` (if it exists).
  */
 void SetMapValue(cmCTestGenericHandler::t_StringToString& map,
-                 const std::string& op, const char* value)
+                 const std::string& op, const std::string& value)
 {
-  if (!value) {
-    map.erase(op);
-    return;
-  }
-
   map[op] = value;
 }
 void SetMapValue(cmCTestGenericHandler::t_StringToString& map,
@@ -47,7 +42,8 @@
 }
 }
 
-void cmCTestGenericHandler::SetOption(const std::string& op, const char* value)
+void cmCTestGenericHandler::SetOption(const std::string& op,
+                                      const std::string& value)
 {
   SetMapValue(this->Options, op, value);
 }
@@ -57,7 +53,7 @@
 }
 
 void cmCTestGenericHandler::SetPersistentOption(const std::string& op,
-                                                const char* value)
+                                                const std::string& value)
 {
   this->SetOption(op, value);
   SetMapValue(this->PersistentOptions, op, value);
diff --git a/Source/CTest/cmCTestGenericHandler.h b/Source/CTest/cmCTestGenericHandler.h
index 4bdb9c2..a0197d6 100644
--- a/Source/CTest/cmCTestGenericHandler.h
+++ b/Source/CTest/cmCTestGenericHandler.h
@@ -85,17 +85,9 @@
    * so calling a single-getter for a key that has only been set
    * as a multi-value will return nullptr.
    */
-  void SetPersistentOption(const std::string& op, const char* value);
-  void SetPersistentOption(const std::string& op, const std::string& value)
-  {
-    this->SetPersistentOption(op, cmValue(value));
-  }
+  void SetPersistentOption(const std::string& op, const std::string& value);
   void SetPersistentOption(const std::string& op, cmValue value);
-  void SetOption(const std::string& op, const char* value);
-  void SetOption(const std::string& op, const std::string& value)
-  {
-    this->SetOption(op, cmValue(value));
-  }
+  void SetOption(const std::string& op, const std::string& value);
   void SetOption(const std::string& op, cmValue value);
   cmValue GetOption(const std::string& op);
 
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index f60a1e9..2938294 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -410,7 +410,8 @@
   return PartCount;
 }
 
-int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
+int cmCTest::Initialize(const std::string& binary_dir,
+                        cmCTestStartCommand* command)
 {
   bool quiet = false;
   if (command && command->ShouldBeQuiet()) {
@@ -683,7 +684,7 @@
   this->SetCTestConfigurationFromCMakeVariable(
     mf, "BuildName", "CTEST_BUILD_NAME", command->ShouldBeQuiet());
 
-  if (!this->Initialize(bld_dir.c_str(), command)) {
+  if (!this->Initialize(bld_dir, command)) {
     return false;
   }
   cmCTestOptionalLog(this, OUTPUT,
@@ -943,8 +944,7 @@
       (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
     cmCTestUpdateHandler* uphandler = this->GetUpdateHandler();
     uphandler->SetPersistentOption(
-      "SourceDirectory",
-      this->GetCTestConfiguration("SourceDirectory").c_str());
+      "SourceDirectory", this->GetCTestConfiguration("SourceDirectory"));
     update_count = uphandler->ProcessHandler();
     if (update_count < 0) {
       res |= cmCTest::UPDATE_ERRORS;
@@ -2139,9 +2139,9 @@
            i < args.size() - 1) {
     i++;
     this->GetTestHandler()->SetPersistentOption("TestsToRunInformation",
-                                                args[i].c_str());
+                                                args[i]);
     this->GetMemCheckHandler()->SetPersistentOption("TestsToRunInformation",
-                                                    args[i].c_str());
+                                                    args[i]);
   } else if (this->CheckArgument(arg, "-U"_s, "--union")) {
     this->GetTestHandler()->SetPersistentOption("UseUnion", "true");
     this->GetMemCheckHandler()->SetPersistentOption("UseUnion", "true");
@@ -2149,9 +2149,9 @@
              i < args.size() - 1) {
     i++;
     this->GetTestHandler()->SetPersistentOption("IncludeRegularExpression",
-                                                args[i].c_str());
+                                                args[i]);
     this->GetMemCheckHandler()->SetPersistentOption("IncludeRegularExpression",
-                                                    args[i].c_str());
+                                                    args[i]);
   } else if (this->CheckArgument(arg, "-L"_s, "--label-regex") &&
              i < args.size() - 1) {
     i++;
@@ -2172,41 +2172,40 @@
            i < args.size() - 1) {
     i++;
     this->GetTestHandler()->SetPersistentOption("ExcludeRegularExpression",
-                                                args[i].c_str());
+                                                args[i]);
     this->GetMemCheckHandler()->SetPersistentOption("ExcludeRegularExpression",
-                                                    args[i].c_str());
+                                                    args[i]);
   }
 
   else if (this->CheckArgument(arg, "-FA"_s, "--fixture-exclude-any") &&
            i < args.size() - 1) {
     i++;
     this->GetTestHandler()->SetPersistentOption(
-      "ExcludeFixtureRegularExpression", args[i].c_str());
+      "ExcludeFixtureRegularExpression", args[i]);
     this->GetMemCheckHandler()->SetPersistentOption(
-      "ExcludeFixtureRegularExpression", args[i].c_str());
+      "ExcludeFixtureRegularExpression", args[i]);
   } else if (this->CheckArgument(arg, "-FS"_s, "--fixture-exclude-setup") &&
              i < args.size() - 1) {
     i++;
     this->GetTestHandler()->SetPersistentOption(
-      "ExcludeFixtureSetupRegularExpression", args[i].c_str());
+      "ExcludeFixtureSetupRegularExpression", args[i]);
     this->GetMemCheckHandler()->SetPersistentOption(
-      "ExcludeFixtureSetupRegularExpression", args[i].c_str());
+      "ExcludeFixtureSetupRegularExpression", args[i]);
   } else if (this->CheckArgument(arg, "-FC"_s, "--fixture-exclude-cleanup") &&
              i < args.size() - 1) {
     i++;
     this->GetTestHandler()->SetPersistentOption(
-      "ExcludeFixtureCleanupRegularExpression", args[i].c_str());
+      "ExcludeFixtureCleanupRegularExpression", args[i]);
     this->GetMemCheckHandler()->SetPersistentOption(
-      "ExcludeFixtureCleanupRegularExpression", args[i].c_str());
+      "ExcludeFixtureCleanupRegularExpression", args[i]);
   }
 
   else if (this->CheckArgument(arg, "--resource-spec-file"_s) &&
            i < args.size() - 1) {
     i++;
-    this->GetTestHandler()->SetPersistentOption("ResourceSpecFile",
-                                                args[i].c_str());
+    this->GetTestHandler()->SetPersistentOption("ResourceSpecFile", args[i]);
     this->GetMemCheckHandler()->SetPersistentOption("ResourceSpecFile",
-                                                    args[i].c_str());
+                                                    args[i]);
   }
 
   else if (this->CheckArgument(arg, "--rerun-failed"_s)) {
@@ -2314,8 +2313,8 @@
                                             const std::string& optionName)
 {
   if (!value.empty()) {
-    this->GetTestHandler()->SetPersistentOption(optionName, value.c_str());
-    this->GetMemCheckHandler()->SetPersistentOption(optionName, value.c_str());
+    this->GetTestHandler()->SetPersistentOption(optionName, value);
+    this->GetMemCheckHandler()->SetPersistentOption(optionName, value);
   }
 }
 
@@ -2903,7 +2902,7 @@
       }
     }
 
-    if (!this->Initialize(workDir.c_str(), nullptr)) {
+    if (!this->Initialize(workDir, nullptr)) {
       res = 12;
       cmCTestLog(this, ERROR_MESSAGE,
                  "Problem initializing the dashboard." << std::endl);
diff --git a/Source/cmCTest.h b/Source/cmCTest.h
index 0017b3e..9a8d5a6 100644
--- a/Source/cmCTest.h
+++ b/Source/cmCTest.h
@@ -481,7 +481,7 @@
    * call this method because it sets CTEST_COMMAND to drive a build
    * through the ctest command line.
    */
-  int Initialize(const char* binary_dir, cmCTestStartCommand* command);
+  int Initialize(const std::string& binary_dir, cmCTestStartCommand* command);
 
   /** parse the option after -D and convert it into the appropriate steps */
   bool AddTestsForDashboardType(std::string& targ);