| 444 | } |
| 445 | |
| 446 | bool ParseInt64(const std::string& str, int64_t *out) |
| 447 | { |
| 448 | if (!ParsePrechecks(str)) |
| 449 | return false; |
| 450 | char *endp = NULL; |
| 451 | errno = 0; // strtoll will not set errno if valid |
| 452 | long long int n = strtoll(str.c_str(), &endp, 10); |
| 453 | if(out) *out = (int64_t)n; |
| 454 | // Note that strtoll returns a *long long int*, so even if strtol doesn't report a over/underflow |
| 455 | // we still have to check that the returned value is within the range of an *int64_t*. |
| 456 | return endp && *endp == 0 && !errno && |
| 457 | n >= std::numeric_limits<int64_t>::min() && |
| 458 | n <= std::numeric_limits<int64_t>::max(); |
| 459 | } |
| 460 | |
| 461 | bool ParseDouble(const std::string& str, double *out) |
| 462 | { |