| 1379 | // it here. |
| 1380 | template <typename Integer> |
| 1381 | bool ParseNaturalNumber(const ::std::string& str, Integer* number) { |
| 1382 | // Fail fast if the given string does not begin with a digit; |
| 1383 | // this bypasses strtoXXX's "optional leading whitespace and plus |
| 1384 | // or minus sign" semantics, which are undesirable here. |
| 1385 | if (str.empty() || !IsDigit(str[0])) { |
| 1386 | return false; |
| 1387 | } |
| 1388 | errno = 0; |
| 1389 | |
| 1390 | char* end; |
| 1391 | // BiggestConvertible is the largest integer type that system-provided |
| 1392 | // string-to-number conversion routines can return. |
| 1393 | |
| 1394 | # if GTEST_OS_WINDOWS && !defined(__GNUC__) |
| 1395 | |
| 1396 | // MSVC and C++ Builder define __int64 instead of the standard long long. |
| 1397 | typedef unsigned __int64 BiggestConvertible; |
| 1398 | const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10); |
| 1399 | |
| 1400 | # else |
| 1401 | |
| 1402 | typedef unsigned long long BiggestConvertible; // NOLINT |
| 1403 | const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10); |
| 1404 | |
| 1405 | # endif // GTEST_OS_WINDOWS && !defined(__GNUC__) |
| 1406 | |
| 1407 | const bool parse_success = *end == '\0' && errno == 0; |
| 1408 | |
| 1409 | GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed)); |
| 1410 | |
| 1411 | const Integer result = static_cast<Integer>(parsed); |
| 1412 | if (parse_success && static_cast<BiggestConvertible>(result) == parsed) { |
| 1413 | *number = result; |
| 1414 | return true; |
| 1415 | } |
| 1416 | return false; |
| 1417 | } |
| 1418 | #endif // GTEST_HAS_DEATH_TEST |
| 1419 | |
| 1420 | // TestResult contains some private methods that should be hidden from |
no test coverage detected