| 532 | } |
| 533 | |
| 534 | int64_t parseInt64(const std::string& s, bool& ok) { |
| 535 | auto ret = stringTo<int64_t>(s, ok); |
| 536 | if (ok) |
| 537 | return ret; |
| 538 | |
| 539 | auto f = stringTo<float>(s, ok); |
| 540 | if (ok) |
| 541 | return static_cast<int64_t>(f); |
| 542 | |
| 543 | auto [r, st] = stringTo<Rational>(s, ok); |
| 544 | if (ok) { |
| 545 | if (st <= 0) { |
| 546 | ok = false; |
| 547 | return 0; |
| 548 | } |
| 549 | return static_cast<int64_t>(static_cast<float>(r) / st); |
| 550 | } |
| 551 | |
| 552 | bool b = stringTo<bool>(s, ok); |
| 553 | if (ok) |
| 554 | return b ? 1 : 0; |
| 555 | |
| 556 | // everything failed, return from stringTo<int64_t> is probably the best fit |
| 557 | return ret; |
| 558 | } |
| 559 | |
| 560 | uint32_t parseUint32(const std::string& s, bool& ok) { |
| 561 | if (auto x = parseInt64(s, ok); ok && 0 <= x && x <= std::numeric_limits<uint32_t>::max()) { |
no outgoing calls