MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / array_index

Method array_index

Source/Utils/json.hpp:11867–11890  ·  view source on GitHub ↗

! @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 e

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

createFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected