mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-01 03:29:18 -05:00
Merge topic 'cmStringAlgorithms_ulong'
935fbe0b04 cmStringAlgorithms: Add cmStrToLong and cmStrToULong
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3681
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user