summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-09-20 15:12:23 (GMT)
committerBrad King <brad.king@kitware.com>2022-09-20 16:00:08 (GMT)
commit31f158e4c881bea2b526102b2024b0fb34ade42d (patch)
tree5013888d1c3c2dd765c641946e82fc8468c6485c /Source
parent5d80d7cb6a76e92ac5b0fa5352cdda64415124b7 (diff)
downloadCMake-31f158e4c881bea2b526102b2024b0fb34ade42d.zip
CMake-31f158e4c881bea2b526102b2024b0fb34ade42d.tar.gz
CMake-31f158e4c881bea2b526102b2024b0fb34ade42d.tar.bz2
cmStringAlgorithms: Add functions to parse strings to long long integers
Diffstat (limited to 'Source')
-rw-r--r--Source/cmStringAlgorithms.cxx32
-rw-r--r--Source/cmStringAlgorithms.h10
2 files changed, 42 insertions, 0 deletions
diff --git a/Source/cmStringAlgorithms.cxx b/Source/cmStringAlgorithms.cxx
index 1bb6808..f73c854 100644
--- a/Source/cmStringAlgorithms.cxx
+++ b/Source/cmStringAlgorithms.cxx
@@ -250,6 +250,38 @@ bool cmStrToULong(std::string const& str, unsigned long* value)
return cmStrToULong(str.c_str(), value);
}
+bool cmStrToLongLong(const char* str, long long* value)
+{
+ errno = 0;
+ char* endp;
+ *value = strtoll(str, &endp, 10);
+ return (*endp == '\0') && (endp != str) && (errno == 0);
+}
+
+bool cmStrToLongLong(std::string const& str, long long* value)
+{
+ return cmStrToLongLong(str.c_str(), value);
+}
+
+bool cmStrToULongLong(const char* str, unsigned long long* value)
+{
+ errno = 0;
+ char* endp;
+ while (cmIsSpace(*str)) {
+ ++str;
+ }
+ if (*str == '-') {
+ return false;
+ }
+ *value = strtoull(str, &endp, 10);
+ return (*endp == '\0') && (endp != str) && (errno == 0);
+}
+
+bool cmStrToULongLong(std::string const& str, unsigned long long* value)
+{
+ return cmStrToULongLong(str.c_str(), value);
+}
+
template <typename Range>
std::size_t getJoinedLength(Range const& rng, cm::string_view separator)
{
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h
index 492e588..83938bc 100644
--- a/Source/cmStringAlgorithms.h
+++ b/Source/cmStringAlgorithms.h
@@ -303,3 +303,13 @@ bool cmStrToLong(std::string const& str, long* value);
* integer */
bool cmStrToULong(const char* str, unsigned long* value);
bool cmStrToULong(std::string const& str, unsigned long* value);
+
+/** Converts a string to long long. Expects that the whole string
+ * is an integer */
+bool cmStrToLongLong(const char* str, long long* value);
+bool cmStrToLongLong(std::string const& str, long long* value);
+
+/** Converts a string to unsigned long long. Expects that the whole string
+ * is an integer */
+bool cmStrToULongLong(const char* str, unsigned long long* value);
+bool cmStrToULongLong(std::string const& str, unsigned long long* value);