cmStringAlgorithms: Add cmStrToLong and cmStrToULong

This adds the following functions to cmStringAlgorithms:
- `cmStrToLong`: moved from `cmSystemTools::StringToLong`
- `cmStrToULong`: moved from `cmSystemTools::StringToULong`

Overloads of the given functions for `std::string` are added as well.
This commit is contained in:
Sebastian Holtermann
2019-08-10 13:37:34 +02:00
parent 32a7605e69
commit 935fbe0b04
20 changed files with 105 additions and 74 deletions

View File

@@ -167,5 +167,40 @@ int testStringAlgorithms(int /*unused*/, char* /*unused*/ [])
assert_ok(!cmHasLiteralSuffix(str, "ab"), "cmHasLiteralPrefix string not");
}
// ----------------------------------------------------------------------
// Test cmStrToLong
{
long value;
assert_ok(cmStrToLong("1", &value) && value == 1,
"cmStrToLong parses a positive decimal integer.");
assert_ok(cmStrToLong(" 1", &value) && value == 1,
"cmStrToLong parses a decimal integer after whitespace.");
assert_ok(cmStrToLong("-1", &value) && value == -1,
"cmStrToLong parses a negative decimal integer.");
assert_ok(
cmStrToLong(" -1", &value) && value == -1,
"cmStrToLong parses a negative decimal integer after whitespace.");
assert_ok(!cmStrToLong("1x", &value),
"cmStrToLong rejects trailing content.");
}
// ----------------------------------------------------------------------
// Test cmStrToULong
{
unsigned long value;
assert_ok(cmStrToULong("1", &value) && value == 1,
"cmStrToULong parses a decimal integer.");
assert_ok(cmStrToULong(" 1", &value) && value == 1,
"cmStrToULong parses a decimal integer after whitespace.");
assert_ok(!cmStrToULong("-1", &value),
"cmStrToULong rejects a negative number.");
assert_ok(!cmStrToULong(" -1", &value),
"cmStrToULong rejects a negative number after whitespace.");
assert_ok(!cmStrToULong("1x", &value),
"cmStrToULong rejects trailing content.");
}
return failed;
}