MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / ParseNaturalNumber

Function ParseNaturalNumber

rtpose_wrapper/src/gtest/gtest-all.cpp:1368–1406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1366// it here.
1367template <typename Integer>
1368bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
1369 // Fail fast if the given string does not begin with a digit;
1370 // this bypasses strtoXXX's "optional leading whitespace and plus
1371 // or minus sign" semantics, which are undesirable here.
1372 if (str.empty() || !IsDigit(str[0])) {
1373 return false;
1374 }
1375 errno = 0;
1376
1377 char* end;
1378 // BiggestConvertible is the largest integer type that system-provided
1379 // string-to-number conversion routines can return.
1380
1381# if GTEST_OS_WINDOWS && !defined(__GNUC__)
1382
1383 // MSVC and C++ Builder define __int64 instead of the standard long long.
1384 typedef unsigned __int64 BiggestConvertible;
1385 const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
1386
1387# else
1388
1389 typedef unsigned long long BiggestConvertible; // NOLINT
1390 const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
1391
1392# endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
1393
1394 const bool parse_success = *end == '\0' && errno == 0;
1395
1396 // TODO(vladl@google.com): Convert this to compile time assertion when it is
1397 // available.
1398 GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
1399
1400 const Integer result = static_cast<Integer>(parsed);
1401 if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
1402 *number = result;
1403 return true;
1404 }
1405 return false;
1406}
1407#endif // GTEST_HAS_DEATH_TEST
1408
1409// TestResult contains some private methods that should be hidden from

Callers 1

Calls 1

IsDigitFunction · 0.85

Tested by

no test coverage detected