summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2019-08-16 18:49:13 +0000
committerKitware Robot <kwrobot@kitware.com>2019-08-16 14:49:28 -0400
commitdcf2beb7dec757b7e28eba43fb7f2d5498bded39 (patch)
treeb4dcb409eea4f99a58f02711edba5452c8613cfc /Source
parent6f1781c63ad58c3c84987dce7eee36668ed2ba57 (diff)
parent935fbe0b0454163678bc4ef19e1bee95a7a31b4d (diff)
downloadcmake-dcf2beb7dec757b7e28eba43fb7f2d5498bded39.tar.gz
Merge topic 'cmStringAlgorithms_ulong'
935fbe0b04 cmStringAlgorithms: Add cmStrToLong and cmStrToULong Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3681
Diffstat (limited to 'Source')
-rw-r--r--Source/CTest/cmCTestMultiProcessHandler.cxx4
-rw-r--r--Source/CTest/cmCTestSubmitHandler.cxx5
-rw-r--r--Source/CTest/cmCTestTestCommand.cxx7
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx3
-rw-r--r--Source/cmCTest.cxx10
-rw-r--r--Source/cmFileCommand.cxx3
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx2
-rw-r--r--Source/cmParseArgumentsCommand.cxx4
-rw-r--r--Source/cmPolicies.cxx2
-rw-r--r--Source/cmQtAutoGenInitializer.cxx4
-rw-r--r--Source/cmQtAutoGenerator.cxx4
-rw-r--r--Source/cmQtAutoMocUic.cxx5
-rw-r--r--Source/cmStringAlgorithms.cxx34
-rw-r--r--Source/cmStringAlgorithms.h9
-rw-r--r--Source/cmStringCommand.cxx2
-rw-r--r--Source/cmSystemTools.cxx22
-rw-r--r--Source/cmSystemTools.h4
-rw-r--r--Source/cmakemain.cxx4
18 files changed, 70 insertions, 58 deletions
diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx
index 42534f7010..ae965eaa85 100644
--- a/Source/CTest/cmCTestMultiProcessHandler.cxx
+++ b/Source/CTest/cmCTestMultiProcessHandler.cxx
@@ -10,6 +10,7 @@
#include "cmDuration.h"
#include "cmListFileCache.h"
#include "cmRange.h"
+#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmWorkingDirectory.h"
@@ -110,8 +111,7 @@ void cmCTestMultiProcessHandler::SetTestLoad(unsigned long load)
std::string fake_load_value;
if (cmSystemTools::GetEnv("__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING",
fake_load_value)) {
- if (!cmSystemTools::StringToULong(fake_load_value.c_str(),
- &this->FakeLoadForTesting)) {
+ if (!cmStrToULong(fake_load_value, &this->FakeLoadForTesting)) {
cmSystemTools::Error("Failed to parse fake load value: " +
fake_load_value);
}
diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx
index 17ef350d68..f97d7ebae7 100644
--- a/Source/CTest/cmCTestSubmitHandler.cxx
+++ b/Source/CTest/cmCTestSubmitHandler.cxx
@@ -529,8 +529,7 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
auto retryDelay = std::chrono::seconds(0);
if (!retryDelayString.empty()) {
unsigned long retryDelayValue = 0;
- if (!cmSystemTools::StringToULong(retryDelayString.c_str(),
- &retryDelayValue)) {
+ if (!cmStrToULong(retryDelayString, &retryDelayValue)) {
cmCTestLog(this->CTest, WARNING,
"Invalid value for 'RETRY_DELAY' : " << retryDelayString
<< std::endl);
@@ -540,7 +539,7 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
}
unsigned long retryCount = 0;
if (!retryCountString.empty()) {
- if (!cmSystemTools::StringToULong(retryCountString.c_str(), &retryCount)) {
+ if (!cmStrToULong(retryCountString, &retryCount)) {
cmCTestLog(this->CTest, WARNING,
"Invalid value for 'RETRY_DELAY' : " << retryCountString
<< std::endl);
diff --git a/Source/CTest/cmCTestTestCommand.cxx b/Source/CTest/cmCTestTestCommand.cxx
index cfd5e3dd23..24de5b4034 100644
--- a/Source/CTest/cmCTestTestCommand.cxx
+++ b/Source/CTest/cmCTestTestCommand.cxx
@@ -7,7 +7,7 @@
#include "cmCTestTestHandler.h"
#include "cmDuration.h"
#include "cmMakefile.h"
-#include "cmSystemTools.h"
+#include "cmStringAlgorithms.h"
#include <chrono>
#include <sstream>
@@ -110,15 +110,14 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
unsigned long testLoad;
const char* ctestTestLoad = this->Makefile->GetDefinition("CTEST_TEST_LOAD");
if (this->Values[ctt_TEST_LOAD] && *this->Values[ctt_TEST_LOAD]) {
- if (!cmSystemTools::StringToULong(this->Values[ctt_TEST_LOAD],
- &testLoad)) {
+ if (!cmStrToULong(this->Values[ctt_TEST_LOAD], &testLoad)) {
testLoad = 0;
cmCTestLog(this->CTest, WARNING,
"Invalid value for 'TEST_LOAD' : "
<< this->Values[ctt_TEST_LOAD] << std::endl);
}
} else if (ctestTestLoad && *ctestTestLoad) {
- if (!cmSystemTools::StringToULong(ctestTestLoad, &testLoad)) {
+ if (!cmStrToULong(ctestTestLoad, &testLoad)) {
testLoad = 0;
cmCTestLog(this->CTest, WARNING,
"Invalid value for 'CTEST_TEST_LOAD' : " << ctestTestLoad
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 67c24ca046..17e7822c31 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -2193,8 +2193,7 @@ bool cmCTestTestHandler::SetTestsProperties(
cmListFileContext fc;
fc.FilePath = triples[i - 3];
long line = 0;
- if (!cmSystemTools::StringToLong(triples[i - 2].c_str(),
- &line)) {
+ if (!cmStrToLong(triples[i - 2], &line)) {
line = 0;
}
fc.Line = line;
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index c0ca73bb32..92ed839687 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -754,7 +754,7 @@ bool cmCTest::UpdateCTestConfiguration()
std::string const& testLoad = this->GetCTestConfiguration("TestLoad");
if (!testLoad.empty()) {
unsigned long load;
- if (cmSystemTools::StringToULong(testLoad.c_str(), &load)) {
+ if (cmStrToULong(testLoad, &load)) {
this->SetTestLoad(load);
} else {
cmCTestLog(this, WARNING,
@@ -1854,7 +1854,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
i++;
long repeat = 1;
- if (!cmSystemTools::StringToLong(args[i].c_str(), &repeat)) {
+ if (!cmStrToLong(args[i], &repeat)) {
errormsg =
"'--repeat-until-fail' given non-integer value '" + args[i] + "'";
return false;
@@ -1868,7 +1868,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
if (this->CheckArgument(arg, "--test-load") && i < args.size() - 1) {
i++;
unsigned long load;
- if (cmSystemTools::StringToULong(args[i].c_str(), &load)) {
+ if (cmStrToULong(args[i], &load)) {
this->SetTestLoad(load);
} else {
cmCTestLog(this, WARNING,
@@ -1942,7 +1942,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
i < args.size() - 1) {
i++;
long outputSize;
- if (cmSystemTools::StringToLong(args[i].c_str(), &outputSize)) {
+ if (cmStrToLong(args[i], &outputSize)) {
this->Impl->TestHandler.SetTestOutputSizePassed(int(outputSize));
} else {
cmCTestLog(this, WARNING,
@@ -1954,7 +1954,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
i < args.size() - 1) {
i++;
long outputSize;
- if (cmSystemTools::StringToLong(args[i].c_str(), &outputSize)) {
+ if (cmStrToLong(args[i], &outputSize)) {
this->Impl->TestHandler.SetTestOutputSizeFailed(int(outputSize));
} else {
cmCTestLog(this, WARNING,
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index d76692ce05..87e97dd448 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -2357,8 +2357,7 @@ bool HandleLockCommand(std::vector<std::string> const& args,
return false;
}
long scanned;
- if (!cmSystemTools::StringToLong(args[i].c_str(), &scanned) ||
- scanned < 0) {
+ if (!cmStrToLong(args[i], &scanned) || scanned < 0) {
std::ostringstream e;
e << "TIMEOUT value \"" << args[i] << "\" is not an unsigned integer.";
status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, e.str());
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index addb0c7bb7..29caa1624b 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -560,7 +560,7 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures()
if (pos != std::string::npos) {
const char* fv = &this->NinjaVersion[pos + k_DYNDEP_.size()];
unsigned long dyndep = 0;
- cmSystemTools::StringToULong(fv, &dyndep);
+ cmStrToULong(fv, &dyndep);
if (dyndep == 1) {
this->NinjaSupportsDyndeps = true;
}
diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx
index 04fa0fb5a6..df9407d5de 100644
--- a/Source/cmParseArgumentsCommand.cxx
+++ b/Source/cmParseArgumentsCommand.cxx
@@ -131,7 +131,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
}
parseFromArgV = true;
argIter++; // move past PARSE_ARGV
- if (!cmSystemTools::StringToULong(argIter->c_str(), &argvStart)) {
+ if (!cmStrToULong(*argIter, &argvStart)) {
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"PARSE_ARGV index '" + *argIter +
"' is not an unsigned integer");
@@ -185,7 +185,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
// in the PARSE_ARGV move read the arguments from ARGC and ARGV#
std::string argc = this->Makefile->GetSafeDefinition("ARGC");
unsigned long count;
- if (!cmSystemTools::StringToULong(argc.c_str(), &count)) {
+ if (!cmStrToULong(argc, &count)) {
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"PARSE_ARGV called with ARGC='" + argc +
"' that is not an unsigned integer");
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index 51a61dce7d..d33cd32804 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -34,7 +34,7 @@ static bool stringToId(const char* input, cmPolicies::PolicyID& pid)
}
}
long id;
- if (!cmSystemTools::StringToLong(input + 3, &id)) {
+ if (!cmStrToLong(input + 3, &id)) {
return false;
}
if (id >= cmPolicies::CMPCOUNT) {
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index 360df253cb..d6bef6b2fb 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -243,7 +243,7 @@ bool cmQtAutoGenInitializer::InitCustomTargets()
this->Verbosity = makefile->GetSafeDefinition("CMAKE_AUTOGEN_VERBOSE");
if (!this->Verbosity.empty()) {
unsigned long iVerb = 0;
- if (!cmSystemTools::StringToULong(this->Verbosity.c_str(), &iVerb)) {
+ if (!cmStrToULong(this->Verbosity, &iVerb)) {
// Non numeric verbosity
this->Verbosity = cmSystemTools::IsOn(this->Verbosity) ? "1" : "0";
}
@@ -1523,7 +1523,7 @@ void cmQtAutoGenInitializer::AddCleanFile(std::string const& fileName)
static unsigned int CharPtrToUInt(const char* const input)
{
unsigned long tmp = 0;
- if (input != nullptr && cmSystemTools::StringToULong(input, &tmp)) {
+ if (input != nullptr && cmStrToULong(input, &tmp)) {
return static_cast<unsigned int>(tmp);
}
return 0;
diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx
index 0ad87b192a..996b2bc1ae 100644
--- a/Source/cmQtAutoGenerator.cxx
+++ b/Source/cmQtAutoGenerator.cxx
@@ -22,7 +22,7 @@ cmQtAutoGenerator::Logger::Logger()
std::string verbose;
if (cmSystemTools::GetEnv("VERBOSE", verbose) && !verbose.empty()) {
unsigned long iVerbose = 0;
- if (cmSystemTools::StringToULong(verbose.c_str(), &iVerbose)) {
+ if (cmStrToULong(verbose, &iVerbose)) {
SetVerbosity(static_cast<unsigned int>(iVerbose));
} else {
// Non numeric verbosity
@@ -46,7 +46,7 @@ cmQtAutoGenerator::Logger::~Logger() = default;
void cmQtAutoGenerator::Logger::RaiseVerbosity(std::string const& value)
{
unsigned long verbosity = 0;
- if (cmSystemTools::StringToULong(value.c_str(), &verbosity)) {
+ if (cmStrToULong(value, &verbosity)) {
if (this->Verbosity_ < verbosity) {
this->Verbosity_ = static_cast<unsigned int>(verbosity);
}
diff --git a/Source/cmQtAutoMocUic.cxx b/Source/cmQtAutoMocUic.cxx
index e693816ba5..6f3b2c6cc7 100644
--- a/Source/cmQtAutoMocUic.cxx
+++ b/Source/cmQtAutoMocUic.cxx
@@ -1582,7 +1582,7 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
BaseConst_.MultiConfig = InfoGetBool("AM_MULTI_CONFIG");
{
unsigned long num = 1;
- if (cmSystemTools::StringToULong(InfoGet("AM_PARALLEL").c_str(), &num)) {
+ if (cmStrToULong(InfoGet("AM_PARALLEL"), &num)) {
num = std::max<unsigned long>(num, 1);
num = std::min<unsigned long>(num, ParallelMax);
}
@@ -1630,8 +1630,7 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
// - Qt environment
{
unsigned long qtv = BaseConst_.QtVersionMajor;
- if (cmSystemTools::StringToULong(InfoGet("AM_QT_VERSION_MAJOR").c_str(),
- &qtv)) {
+ if (cmStrToULong(InfoGet("AM_QT_VERSION_MAJOR"), &qtv)) {
BaseConst_.QtVersionMajor = static_cast<unsigned int>(qtv);
}
}
diff --git a/Source/cmStringAlgorithms.cxx b/Source/cmStringAlgorithms.cxx
index eca761b147..fa47d77606 100644
--- a/Source/cmStringAlgorithms.cxx
+++ b/Source/cmStringAlgorithms.cxx
@@ -4,6 +4,8 @@
#include <algorithm>
#include <cstdio>
+#include <errno.h>
+#include <stdlib.h>
std::string cmTrimWhitespace(cm::string_view str)
{
@@ -138,3 +140,35 @@ std::string cmCatViews(std::initializer_list<cm::string_view> views)
}
return result;
}
+
+bool cmStrToLong(const char* str, long* value)
+{
+ errno = 0;
+ char* endp;
+ *value = strtol(str, &endp, 10);
+ return (*endp == '\0') && (endp != str) && (errno == 0);
+}
+
+bool cmStrToLong(std::string const& str, long* value)
+{
+ return cmStrToLong(str.c_str(), value);
+}
+
+bool cmStrToULong(const char* str, unsigned long* value)
+{
+ errno = 0;
+ char* endp;
+ while (cmIsSpace(*str)) {
+ ++str;
+ }
+ if (*str == '-') {
+ return false;
+ }
+ *value = strtoul(str, &endp, 10);
+ return (*endp == '\0') && (endp != str) && (errno == 0);
+}
+
+bool cmStrToULong(std::string const& str, unsigned long* value)
+{
+ return cmStrToULong(str.c_str(), value);
+}
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h
index 44b01b8012..968cc14369 100644
--- a/Source/cmStringAlgorithms.h
+++ b/Source/cmStringAlgorithms.h
@@ -193,4 +193,13 @@ inline void cmStripSuffixIfExists(std::string& str, cm::string_view suffix)
}
}
+/** Converts a string to long. Expects that the whole string is an integer. */
+bool cmStrToLong(const char* str, long* value);
+bool cmStrToLong(std::string const& str, long* value);
+
+/** Converts a string to unsigned long. Expects that the whole string is an
+ * integer */
+bool cmStrToULong(const char* str, unsigned long* value);
+bool cmStrToULong(std::string const& str, unsigned long* value);
+
#endif
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 46d94591aa..41d48ed3bd 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -736,7 +736,7 @@ bool cmStringCommand::HandleRepeatCommand(std::vector<std::string> const& args)
}
unsigned long times;
- if (!cmSystemTools::StringToULong(args[ArgPos::TIMES].c_str(), &times)) {
+ if (!cmStrToULong(args[ArgPos::TIMES], &times)) {
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"repeat count is not a positive number.");
return true;
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index ee60f163a0..9341f8362a 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -2854,28 +2854,6 @@ bool cmSystemTools::RepeatedRemoveDirectory(const std::string& dir)
#endif
}
-bool cmSystemTools::StringToLong(const char* str, long* value)
-{
- errno = 0;
- char* endp;
- *value = strtol(str, &endp, 10);
- return (*endp == '\0') && (endp != str) && (errno == 0);
-}
-
-bool cmSystemTools::StringToULong(const char* str, unsigned long* value)
-{
- errno = 0;
- char* endp;
- while (isspace(*str)) {
- ++str;
- }
- if (*str == '-') {
- return false;
- }
- *value = strtoul(str, &endp, 10);
- return (*endp == '\0') && (endp != str) && (errno == 0);
-}
-
std::string cmSystemTools::EncodeURL(std::string const& in, bool escapeSlashes)
{
std::string out;
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 4f76b00489..4bb6730fc6 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -500,10 +500,6 @@ public:
/** Remove a directory; repeat a few times in case of locked files. */
static bool RepeatedRemoveDirectory(const std::string& dir);
- /** Convert string to long. Expected that the whole string is an integer */
- static bool StringToLong(const char* str, long* value);
- static bool StringToULong(const char* str, unsigned long* value);
-
/** Encode a string as a URL. */
static std::string EncodeURL(std::string const& in,
bool escapeSlashes = true);
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 522f9a4b5b..74c0d0fec5 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -321,7 +321,7 @@ int extract_job_number(int& index, char const* current, char const* next,
unsigned long numJobs = 0;
if (jobString.empty()) {
jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
- } else if (cmSystemTools::StringToULong(jobString.c_str(), &numJobs)) {
+ } else if (cmStrToULong(jobString, &numJobs)) {
if (numJobs == 0) {
std::cerr
<< "The <jobs> value requires a positive integer argument.\n\n";
@@ -439,7 +439,7 @@ int do_build(int ac, char const* const* av)
jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
} else {
unsigned long numJobs = 0;
- if (cmSystemTools::StringToULong(parallel.c_str(), &numJobs)) {
+ if (cmStrToULong(parallel, &numJobs)) {
if (numJobs == 0) {
std::cerr << "The CMAKE_BUILD_PARALLEL_LEVEL environment variable "
"requires a positive integer argument.\n\n";