Return the value as well as the indication of whether the index/name is in range.
| 1967 | // in range. |
| 1968 | // |
| 1969 | static pair<value, bool> |
| 1970 | json_subscript_impl (const value& val, value* val_data, |
| 1971 | uint64_t i, const string& n, bool index) |
| 1972 | { |
| 1973 | const json_value& jv (val.as<json_value> ()); |
| 1974 | |
| 1975 | json_value jr; |
| 1976 | |
| 1977 | if (index) |
| 1978 | { |
| 1979 | if (i >= (jv.type == json_type::array ? jv.array.size () : |
| 1980 | jv.type == json_type::object ? jv.object.size () : |
| 1981 | jv.type == json_type::null ? 0 : 1)) |
| 1982 | return make_pair (value (), false); |
| 1983 | |
| 1984 | switch (jv.type) |
| 1985 | { |
| 1986 | case json_type::boolean: |
| 1987 | case json_type::signed_number: |
| 1988 | case json_type::hexadecimal_signed_number: |
| 1989 | case json_type::unsigned_number: |
| 1990 | case json_type::hexadecimal_unsigned_number: |
| 1991 | case json_type::string: |
| 1992 | { |
| 1993 | // Steal the value if possible. |
| 1994 | // |
| 1995 | jr = (&val == val_data |
| 1996 | ? json_value (move (const_cast<json_value&> (jv))) |
| 1997 | : json_value (jv)); |
| 1998 | break; |
| 1999 | } |
| 2000 | case json_type::array: |
| 2001 | { |
| 2002 | // Steal the value if possible. |
| 2003 | // |
| 2004 | const json_value& r (jv.array[i]); |
| 2005 | jr = (&val == val_data |
| 2006 | ? json_value (move (const_cast<json_value&> (r))) |
| 2007 | : json_value (r)); |
| 2008 | break; |
| 2009 | } |
| 2010 | case json_type::object: |
| 2011 | { |
| 2012 | // Represent as an object with one member. |
| 2013 | // |
| 2014 | new (&jr.object) json_value::object_type (); |
| 2015 | jr.type = json_type::object; |
| 2016 | |
| 2017 | // Steal the member if possible. |
| 2018 | // |
| 2019 | const json_member& m (jv.object[i]); |
| 2020 | jr.object.push_back (&val == val_data |
| 2021 | ? json_member (move (const_cast<json_member&> (m))) |
| 2022 | : json_member (m)); |
| 2023 | break; |
| 2024 | } |
| 2025 | case json_type::null: |
| 2026 | assert (false); |
no outgoing calls
no test coverage detected