| 1413 | // it here. |
| 1414 | template <typename Integer> |
| 1415 | bool ParseNaturalNumber(const ::std::string& str, Integer* number) { |
| 1416 | // Fail fast if the given string does not begin with a digit; |
| 1417 | // this bypasses strtoXXX's "optional leading whitespace and plus |
| 1418 | // or minus sign" semantics, which are undesirable here. |
| 1419 | if (str.empty() || !IsDigit(str[0])) { |
| 1420 | return false; |
| 1421 | } |
| 1422 | errno = 0; |
| 1423 | |
| 1424 | char* end; |
| 1425 | // BiggestConvertible is the largest integer type that system-provided |
| 1426 | // string-to-number conversion routines can return. |
| 1427 | |
| 1428 | # if GTEST_OS_WINDOWS && !defined(__GNUC__) |
| 1429 | |
| 1430 | // MSVC and C++ Builder define __int64 instead of the standard long long. |
| 1431 | typedef unsigned __int64 BiggestConvertible; |
| 1432 | const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10); |
| 1433 | |
| 1434 | # else |
| 1435 | |
| 1436 | typedef unsigned long long BiggestConvertible; // NOLINT |
| 1437 | const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10); |
| 1438 | |
| 1439 | # endif // GTEST_OS_WINDOWS && !defined(__GNUC__) |
| 1440 | |
| 1441 | const bool parse_success = *end == '\0' && errno == 0; |
| 1442 | |
| 1443 | // TODO(vladl@google.com): Convert this to compile time assertion when it is |
| 1444 | // available. |
| 1445 | GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed)); |
| 1446 | |
| 1447 | const Integer result = static_cast<Integer>(parsed); |
| 1448 | if (parse_success && static_cast<BiggestConvertible>(result) == parsed) { |
| 1449 | *number = result; |
| 1450 | return true; |
| 1451 | } |
| 1452 | return false; |
| 1453 | } |
| 1454 | #endif // GTEST_HAS_DEATH_TEST |
| 1455 | |
| 1456 | // TestResult contains some private methods that should be hidden from |
no test coverage detected