summaryrefslogtreecommitdiffstats
path: root/Source/cmStringAlgorithms.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2019-08-16 18:49:13 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-08-16 18:49:28 (GMT)
commitdcf2beb7dec757b7e28eba43fb7f2d5498bded39 (patch)
treeb4dcb409eea4f99a58f02711edba5452c8613cfc /Source/cmStringAlgorithms.cxx
parent6f1781c63ad58c3c84987dce7eee36668ed2ba57 (diff)
parent935fbe0b0454163678bc4ef19e1bee95a7a31b4d (diff)
downloadCMake-dcf2beb7dec757b7e28eba43fb7f2d5498bded39.zip
CMake-dcf2beb7dec757b7e28eba43fb7f2d5498bded39.tar.gz
CMake-dcf2beb7dec757b7e28eba43fb7f2d5498bded39.tar.bz2
Merge topic 'cmStringAlgorithms_ulong'
935fbe0b04 cmStringAlgorithms: Add cmStrToLong and cmStrToULong Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3681
Diffstat (limited to 'Source/cmStringAlgorithms.cxx')
-rw-r--r--Source/cmStringAlgorithms.cxx34
1 files changed, 34 insertions, 0 deletions
diff --git a/Source/cmStringAlgorithms.cxx b/Source/cmStringAlgorithms.cxx
index eca761b..fa47d77 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);
+}