| 32 | } |
| 33 | return out; |
| 34 | } |
| 35 | |
| 36 | uint32_t parse_u32_value(const std::string & value, std::string_view key) { |
| 37 | if (!value.empty() && value.front() == '-') { |
| 38 | throw std::runtime_error(std::string(key) + " must be an unsigned integer"); |
| 39 | } |
| 40 | size_t parsed = 0; |
| 41 | const unsigned long out = std::stoul(value, &parsed); |
| 42 | if (parsed != value.size()) { |
| 43 | throw std::runtime_error(std::string(key) + " must be an unsigned integer"); |
| 44 | } |
| 45 | if (out > std::numeric_limits<uint32_t>::max()) { |
| 46 | throw std::runtime_error(std::string(key) + " is outside uint32 range"); |
| 47 | } |
| 48 | return static_cast<uint32_t>(out); |
| 49 | } |
| 50 |
no test coverage detected