TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ array_index()

template<typename BasicJsonType >
static BasicJsonType::size_type nlohmann::json_pointer< BasicJsonType >::array_index ( const std::string &  s)
inlinestaticprivate
Parameters
[in]sreference token to be converted into an array index
Returns
integer representation of s
Exceptions
parse_error.106if an array index begins with '0'
parse_error.109if an array index begins not with a digit
out_of_range.404if string s could not be converted to an integer
out_of_range.410if an array index exceeds size_type

Definition at line 12878 of file json.hpp.

12879 {
12880 using size_type = typename BasicJsonType::size_type;
12881
12882 // error condition (cf. RFC 6901, Sect. 4)
12883 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0'))
12884 {
12885 JSON_THROW(detail::parse_error::create(106, 0, "array index '" + s + "' must not begin with '0'", BasicJsonType()));
12886 }
12887
12888 // error condition (cf. RFC 6901, Sect. 4)
12889 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9')))
12890 {
12891 JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number", BasicJsonType()));
12892 }
12893
12894 std::size_t processed_chars = 0;
12895 unsigned long long res = 0; // NOLINT(runtime/int)
12896 JSON_TRY
12897 {
12898 res = std::stoull(s, &processed_chars);
12899 }
12900 JSON_CATCH(std::out_of_range &)
12901 {
12902 JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
12903 }
12904
12905 // check if the string was completely read
12906 if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
12907 {
12908 JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
12909 }
12910
12911 // only triggered on special platforms (like 32bit), see also
12912 // https://github.com/nlohmann/json/pull/2203
12913 if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) // NOLINT(runtime/int)
12914 {
12915 JSON_THROW(detail::out_of_range::create(410, "array index " + s + " exceeds size_type", BasicJsonType())); // LCOV_EXCL_LINE
12916 }
12917
12918 return static_cast<size_type>(res);
12919 }
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, const BasicJsonType &context)
create a parse error exception
Definition: json.hpp:2800