| 278 | namespace { |
| 279 | template <typename T> |
| 280 | bool ParseIntegral(const std::string& str, T* out) |
| 281 | { |
| 282 | static_assert(std::is_integral<T>::value); |
| 283 | // Replicate the exact behavior of strtol/strtoll/strtoul/strtoull when |
| 284 | // handling leading +/- for backwards compatibility. |
| 285 | if (str.length() >= 2 && str[0] == '+' && str[1] == '-') { |
| 286 | return false; |
| 287 | } |
| 288 | const std::optional<T> opt_int = ToIntegral<T>((!str.empty() && str[0] == '+') ? str.substr(1) : str); |
| 289 | if (!opt_int) { |
| 290 | return false; |
| 291 | } |
| 292 | if (out != nullptr) { |
| 293 | *out = *opt_int; |
| 294 | } |
| 295 | return true; |
| 296 | } |
| 297 | }; // namespace |
| 298 | |
| 299 | bool ParseInt32(const std::string& str, int32_t* out) |