! @param[in] s reference token to be converted into an array index @return integer representation of @a s @throw parse_error.106 if an array index begins with '0' @throw parse_error.109 if an array index begins not with a digit @throw out_of_range.404 if string @a s could not be converted to an integer @throw out_of_range.410 if an array index exceeds size_type */
| 11867 | @throw out_of_range.410 if an array index exceeds size_type |
| 11868 | */ |
| 11869 | static typename BasicJsonType::size_type array_index(const std::string& s) |
| 11870 | { |
| 11871 | using size_type = typename BasicJsonType::size_type; |
| 11872 | |
| 11873 | // error condition (cf. RFC 6901, Sect. 4) |
| 11874 | if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0')) |
| 11875 | { |
| 11876 | JSON_THROW(detail::parse_error::create(106, 0, |
| 11877 | "array index '" + s + |
| 11878 | "' must not begin with '0'")); |
| 11879 | } |
| 11880 | |
| 11881 | // error condition (cf. RFC 6901, Sect. 4) |
| 11882 | if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9'))) |
| 11883 | { |
| 11884 | JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number")); |
| 11885 | } |
| 11886 | |
| 11887 | std::size_t processed_chars = 0; |
| 11888 | unsigned long long res = 0; |
| 11889 | JSON_TRY |
| 11890 | { |
| 11891 | res = std::stoull(s, &processed_chars); |
| 11892 | } |
| 11893 | JSON_CATCH(std::out_of_range&) |
| 11894 | { |
| 11895 | JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'")); |