diff options
| author | Brad King <brad.king@kitware.com> | 2022-09-21 14:12:02 (GMT) |
|---|---|---|
| committer | Kitware Robot <kwrobot@kitware.com> | 2022-09-21 14:12:10 (GMT) |
| commit | 3e20442246dac1bef1111a80e70ed0d59b55a4a4 (patch) | |
| tree | bbe4dc0820abb3e4163aecb97fc1d39536cd0096 /Source/cmStringAlgorithms.cxx | |
| parent | 27a05e84e2c6f5de56b0b4015b8ed6bc89ce9132 (diff) | |
| parent | 8fc822e13a8bf8695e475655f647d5d69f99c414 (diff) | |
| download | CMake-3e20442246dac1bef1111a80e70ed0d59b55a4a4.zip CMake-3e20442246dac1bef1111a80e70ed0d59b55a4a4.tar.gz CMake-3e20442246dac1bef1111a80e70ed0d59b55a4a4.tar.bz2 | |
Merge topic 'parse-large-int' into release-3.24
8fc822e13a file: Avoid strange istringstream crash in cmake.org binaries on Alpine Linux
31f158e4c8 cmStringAlgorithms: Add functions to parse strings to long long integers
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7698
Diffstat (limited to 'Source/cmStringAlgorithms.cxx')
| -rw-r--r-- | Source/cmStringAlgorithms.cxx | 32 |
1 files changed, 32 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) { |
