| 322 | } |
| 323 | |
| 324 | bool ParseUInt64(const std::string& str, uint64_t *out) |
| 325 | { |
| 326 | if (!ParsePrechecks(str)) |
| 327 | return false; |
| 328 | if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoull accepts these by default if they fit in the range |
| 329 | return false; |
| 330 | char *endp = nullptr; |
| 331 | errno = 0; // strtoull will not set errno if valid |
| 332 | unsigned long long int n = strtoull(str.c_str(), &endp, 10); |
| 333 | if(out) *out = (uint64_t)n; |
| 334 | // Note that strtoull returns a *unsigned long long int*, so even if it doesn't report an over/underflow |
| 335 | // we still have to check that the returned value is within the range of an *uint64_t*. |
| 336 | return endp && *endp == 0 && !errno && |
| 337 | n <= std::numeric_limits<uint64_t>::max(); |
| 338 | } |
| 339 | |
| 340 | |
| 341 | bool ParseDouble(const std::string& str, double *out) |