cmSystemTools: Add StringToInt helper

Convert a string to a signed integer and reject any extra input.

Co-Author: Rolf Eike Beer <eike@sf-mail.de>
This commit is contained in:
Ruslan Baratov 2014-11-26 01:45:26 +03:00 committed by Brad King
parent 3350e4d209
commit 05d6531c7a
2 changed files with 11 additions and 0 deletions

View File

@ -2923,3 +2923,11 @@ std::vector<std::string> cmSystemTools::tokenize(const std::string& str,
}
return tokens;
}
//----------------------------------------------------------------------------
bool cmSystemTools::StringToInt(const char* str, int* value)
{
char *endp;
*value = static_cast<int>(strtol(str, &endp, 10));
return (*endp == '\0') && (endp != str);
}

View File

@ -458,6 +458,9 @@ public:
static std::vector<std::string> tokenize(const std::string& str,
const std::string& sep);
/** Convert string to int. Expected that the whole string is an integer */
static bool StringToInt(const char* str, int* value);
#ifdef _WIN32
struct WindowsFileRetry
{