👌 remove unused template parameter

parent 74cc0ab4
...@@ -114,9 +114,9 @@ class exception : public std::exception ...@@ -114,9 +114,9 @@ class exception : public std::exception
return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
[](const std::string & a, const std::string & b) [](const std::string & a, const std::string & b)
{ {
return a + "/" + detail::escape(b); return a + "/" + detail::escape(b);
}) + ") "; }) + ") ";
#else #else
return ""; return "";
#endif #endif
...@@ -188,7 +188,7 @@ class parse_error : public exception ...@@ -188,7 +188,7 @@ class parse_error : public exception
static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context) static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = exception::name("parse_error", id_) + "parse error" +
position_string(pos) + ": " + exception::diagnostics<BasicJsonType>(context) + what_arg; position_string(pos) + ": " + exception::diagnostics(context) + what_arg;
return parse_error(id_, pos.chars_read_total, w.c_str()); return parse_error(id_, pos.chars_read_total, w.c_str());
} }
...@@ -197,7 +197,7 @@ class parse_error : public exception ...@@ -197,7 +197,7 @@ class parse_error : public exception
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = exception::name("parse_error", id_) + "parse error" +
(byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
": " + exception::diagnostics<BasicJsonType>(context) + what_arg; ": " + exception::diagnostics(context) + what_arg;
return parse_error(id_, byte_, w.c_str()); return parse_error(id_, byte_, w.c_str());
} }
...@@ -321,7 +321,7 @@ class type_error : public exception ...@@ -321,7 +321,7 @@ class type_error : public exception
template<typename BasicJsonType> template<typename BasicJsonType>
static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context) static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("type_error", id_) + exception::diagnostics<BasicJsonType>(context) + what_arg; std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg;
return type_error(id_, w.c_str()); return type_error(id_, w.c_str());
} }
...@@ -369,7 +369,7 @@ class out_of_range : public exception ...@@ -369,7 +369,7 @@ class out_of_range : public exception
template<typename BasicJsonType> template<typename BasicJsonType>
static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context) static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("out_of_range", id_) + exception::diagnostics<BasicJsonType>(context) + what_arg; std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg;
return out_of_range(id_, w.c_str()); return out_of_range(id_, w.c_str());
} }
...@@ -408,7 +408,7 @@ class other_error : public exception ...@@ -408,7 +408,7 @@ class other_error : public exception
template<typename BasicJsonType> template<typename BasicJsonType>
static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context) static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("other_error", id_) + exception::diagnostics<BasicJsonType>(context) + what_arg; std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg;
return other_error(id_, w.c_str()); return other_error(id_, w.c_str());
} }
......
...@@ -73,11 +73,6 @@ SOFTWARE. ...@@ -73,11 +73,6 @@ SOFTWARE.
#include <stdexcept> // runtime_error #include <stdexcept> // runtime_error
#include <string> // to_string #include <string> // to_string
// #include <nlohmann/detail/diagnostics_t.hpp>
#include <string>
#include <vector>
// #include <nlohmann/detail/value_t.hpp> // #include <nlohmann/detail/value_t.hpp>
...@@ -2502,87 +2497,6 @@ static void unescape(std::string& s) ...@@ -2502,87 +2497,6 @@ static void unescape(std::string& s)
} // namespace detail } // namespace detail
} // namespace nlohmann } // namespace nlohmann
namespace nlohmann
{
namespace detail
{
template<typename BasicJsonType>
class diagnostics_t
{
public:
diagnostics_t() noexcept = default;
diagnostics_t(const BasicJsonType& j) noexcept
: m_j(&j)
{}
std::string diagnostics() const
{
#if JSON_DIAGNOSTICS
if (m_j == nullptr)
{
return "";
}
std::vector<std::string> tokens;
for (const auto* current = m_j; current->m_parent != nullptr; current = current->m_parent)
{
switch (current->m_parent->type())
{
case value_t::array:
{
for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
{
if (&current->m_parent->m_value.array->operator[](i) == current)
{
tokens.emplace_back(std::to_string(i));
break;
}
}
break;
}
case value_t::object:
{
for (const auto& element : *current->m_parent->m_value.object)
{
if (&element.second == current)
{
tokens.emplace_back(element.first.c_str());
break;
}
}
break;
}
default: // LCOV_EXCL_LINE
break; // LCOV_EXCL_LINE
}
}
if (tokens.empty())
{
return ""; // LCOV_EXCL_LINE
}
return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
[](const std::string & a, const std::string & b)
{
return a + "/" + detail::escape(b);
}) + ") ";
#else
return "";
#endif
}
private:
const BasicJsonType* m_j = nullptr;
};
} // namespace detail
} // namespace nlohmann
// #include <nlohmann/detail/input/position_t.hpp> // #include <nlohmann/detail/input/position_t.hpp>
...@@ -2673,6 +2587,61 @@ class exception : public std::exception ...@@ -2673,6 +2587,61 @@ class exception : public std::exception
return "[json.exception." + ename + "." + std::to_string(id_) + "] "; return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
} }
template<typename BasicJsonType>
static std::string diagnostics(const BasicJsonType& leaf_element)
{
#if JSON_DIAGNOSTICS
std::vector<std::string> tokens;
for (const auto* current = &leaf_element; current->m_parent != nullptr; current = current->m_parent)
{
switch (current->m_parent->type())
{
case value_t::array:
{
for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
{
if (&current->m_parent->m_value.array->operator[](i) == current)
{
tokens.emplace_back(std::to_string(i));
break;
}
}
break;
}
case value_t::object:
{
for (const auto& element : *current->m_parent->m_value.object)
{
if (&element.second == current)
{
tokens.emplace_back(element.first.c_str());
break;
}
}
break;
}
default: // LCOV_EXCL_LINE
break; // LCOV_EXCL_LINE
}
}
if (tokens.empty())
{
return "";
}
return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
[](const std::string & a, const std::string & b)
{
return a + "/" + detail::escape(b);
}) + ") ";
#else
return "";
#endif
}
private: private:
/// an exception object as storage for error messages /// an exception object as storage for error messages
std::runtime_error m; std::runtime_error m;
...@@ -2736,19 +2705,19 @@ class parse_error : public exception ...@@ -2736,19 +2705,19 @@ class parse_error : public exception
@return parse_error object @return parse_error object
*/ */
template<typename BasicJsonType> template<typename BasicJsonType>
static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = exception::name("parse_error", id_) + "parse error" +
position_string(pos) + ": " + diagnostics.diagnostics() + what_arg; position_string(pos) + ": " + exception::diagnostics(context) + what_arg;
return parse_error(id_, pos.chars_read_total, w.c_str()); return parse_error(id_, pos.chars_read_total, w.c_str());
} }
template<typename BasicJsonType> template<typename BasicJsonType>
static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("parse_error", id_) + "parse error" + std::string w = exception::name("parse_error", id_) + "parse error" +
(byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
": " + diagnostics.diagnostics() + what_arg; ": " + exception::diagnostics(context) + what_arg;
return parse_error(id_, byte_, w.c_str()); return parse_error(id_, byte_, w.c_str());
} }
...@@ -2815,9 +2784,9 @@ class invalid_iterator : public exception ...@@ -2815,9 +2784,9 @@ class invalid_iterator : public exception
{ {
public: public:
template<typename BasicJsonType> template<typename BasicJsonType>
static invalid_iterator create(int id_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("invalid_iterator", id_) + diagnostics.diagnostics() + what_arg; std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
return invalid_iterator(id_, w.c_str()); return invalid_iterator(id_, w.c_str());
} }
...@@ -2870,9 +2839,9 @@ class type_error : public exception ...@@ -2870,9 +2839,9 @@ class type_error : public exception
{ {
public: public:
template<typename BasicJsonType> template<typename BasicJsonType>
static type_error create(int id_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("type_error", id_) + diagnostics.diagnostics() + what_arg; std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg;
return type_error(id_, w.c_str()); return type_error(id_, w.c_str());
} }
...@@ -2918,9 +2887,9 @@ class out_of_range : public exception ...@@ -2918,9 +2887,9 @@ class out_of_range : public exception
{ {
public: public:
template<typename BasicJsonType> template<typename BasicJsonType>
static out_of_range create(int id_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("out_of_range", id_) + diagnostics.diagnostics() + what_arg; std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg;
return out_of_range(id_, w.c_str()); return out_of_range(id_, w.c_str());
} }
...@@ -2957,9 +2926,9 @@ class other_error : public exception ...@@ -2957,9 +2926,9 @@ class other_error : public exception
{ {
public: public:
template<typename BasicJsonType> template<typename BasicJsonType>
static other_error create(int id_, const std::string& what_arg, const detail::diagnostics_t<BasicJsonType>& diagnostics) static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
{ {
std::string w = exception::name("other_error", id_) + diagnostics.diagnostics() + what_arg; std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg;
return other_error(id_, w.c_str()); return other_error(id_, w.c_str());
} }
...@@ -2970,8 +2939,6 @@ class other_error : public exception ...@@ -2970,8 +2939,6 @@ class other_error : public exception
} // namespace detail } // namespace detail
} // namespace nlohmann } // namespace nlohmann
// #include <nlohmann/detail/diagnostics_t.hpp>
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/macro_scope.hpp>
// #include <nlohmann/detail/meta/cpp_future.hpp> // #include <nlohmann/detail/meta/cpp_future.hpp>
...@@ -3675,7 +3642,7 @@ void from_json(const BasicJsonType& j, typename std::nullptr_t& n) ...@@ -3675,7 +3642,7 @@ void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_null())) if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
{ {
JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name()), j));
} }
n = nullptr; n = nullptr;
} }
...@@ -3706,7 +3673,7 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) ...@@ -3706,7 +3673,7 @@ void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
} }
default: default:
JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
} }
} }
...@@ -3715,7 +3682,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) ...@@ -3715,7 +3682,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_boolean())) if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
{ {
JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()), j));
} }
b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>(); b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
} }
...@@ -3725,7 +3692,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) ...@@ -3725,7 +3692,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_string())) if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
{ {
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
} }
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
} }
...@@ -3741,7 +3708,7 @@ void from_json(const BasicJsonType& j, ConstructibleStringType& s) ...@@ -3741,7 +3708,7 @@ void from_json(const BasicJsonType& j, ConstructibleStringType& s)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_string())) if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
{ {
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
} }
s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
...@@ -3781,7 +3748,7 @@ void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l) ...@@ -3781,7 +3748,7 @@ void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
l.clear(); l.clear();
std::transform(j.rbegin(), j.rend(), std::transform(j.rbegin(), j.rend(),
...@@ -3798,7 +3765,7 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l) ...@@ -3798,7 +3765,7 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
l.resize(j.size()); l.resize(j.size());
std::transform(j.begin(), j.end(), std::begin(l), std::transform(j.begin(), j.end(), std::begin(l),
...@@ -3889,7 +3856,7 @@ void()) ...@@ -3889,7 +3856,7 @@ void())
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
from_json_array_impl(j, arr, priority_tag<3> {}); from_json_array_impl(j, arr, priority_tag<3> {});
...@@ -3900,7 +3867,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin) ...@@ -3900,7 +3867,7 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_binary())) if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
{ {
JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name()), j));
} }
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>(); bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
...@@ -3912,7 +3879,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) ...@@ -3912,7 +3879,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_object())) if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
{ {
JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()), j));
} }
ConstructibleObjectType ret; ConstructibleObjectType ret;
...@@ -3966,7 +3933,7 @@ void from_json(const BasicJsonType& j, ArithmeticType& val) ...@@ -3966,7 +3933,7 @@ void from_json(const BasicJsonType& j, ArithmeticType& val)
} }
default: default:
JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
} }
} }
...@@ -3995,14 +3962,14 @@ void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& ...@@ -3995,14 +3962,14 @@ void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>&
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
m.clear(); m.clear();
for (const auto& p : j) for (const auto& p : j)
{ {
if (JSON_HEDLEY_UNLIKELY(!p.is_array())) if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
} }
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
} }
...@@ -4015,14 +3982,14 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE ...@@ -4015,14 +3982,14 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
{ {
if (JSON_HEDLEY_UNLIKELY(!j.is_array())) if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
} }
m.clear(); m.clear();
for (const auto& p : j) for (const auto& p : j)
{ {
if (JSON_HEDLEY_UNLIKELY(!p.is_array())) if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
{ {
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), detail::diagnostics_t<BasicJsonType>(j))); JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
} }
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>()); m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
} }
...@@ -4835,8 +4802,6 @@ class byte_container_with_subtype : public BinaryType ...@@ -4835,8 +4802,6 @@ class byte_container_with_subtype : public BinaryType
// #include <nlohmann/detail/exceptions.hpp> // #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/diagnostics_t.hpp>
// #include <nlohmann/detail/hash.hpp> // #include <nlohmann/detail/hash.hpp>
...@@ -4976,8 +4941,6 @@ std::size_t hash(const BasicJsonType& j) ...@@ -4976,8 +4941,6 @@ std::size_t hash(const BasicJsonType& j)
#include <utility> // make_pair, move #include <utility> // make_pair, move
#include <vector> // vector #include <vector> // vector
// #include <nlohmann/detail/diagnostics_t.hpp>
// #include <nlohmann/detail/exceptions.hpp> // #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/input/input_adapters.hpp> // #include <nlohmann/detail/input/input_adapters.hpp>
...@@ -5468,8 +5431,6 @@ class span_input_adapter ...@@ -5468,8 +5431,6 @@ class span_input_adapter
#include <utility> // move #include <utility> // move
#include <vector> // vector #include <vector> // vector
// #include <nlohmann/detail/diagnostics_t.hpp>
// #include <nlohmann/detail/exceptions.hpp> // #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/macro_scope.hpp>
...@@ -5621,7 +5582,6 @@ class json_sax_dom_parser ...@@ -5621,7 +5582,6 @@ class json_sax_dom_parser
using number_float_t = typename BasicJsonType::number_float_t; using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using binary_t = typename BasicJsonType::binary_t; using binary_t = typename BasicJsonType::binary_t;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
/*! /*!
@param[in, out] r reference to a JSON value that is manipulated while @param[in, out] r reference to a JSON value that is manipulated while
...@@ -5687,7 +5647,7 @@ class json_sax_dom_parser ...@@ -5687,7 +5647,7 @@ class json_sax_dom_parser
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), diagnostics_t(*ref_stack.back()))); JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
} }
return true; return true;
...@@ -5713,7 +5673,7 @@ class json_sax_dom_parser ...@@ -5713,7 +5673,7 @@ class json_sax_dom_parser
if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), diagnostics_t(*ref_stack.back()))); JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
} }
return true; return true;
...@@ -5798,7 +5758,6 @@ class json_sax_dom_callback_parser ...@@ -5798,7 +5758,6 @@ class json_sax_dom_callback_parser
using binary_t = typename BasicJsonType::binary_t; using binary_t = typename BasicJsonType::binary_t;
using parser_callback_t = typename BasicJsonType::parser_callback_t; using parser_callback_t = typename BasicJsonType::parser_callback_t;
using parse_event_t = typename BasicJsonType::parse_event_t; using parse_event_t = typename BasicJsonType::parse_event_t;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
json_sax_dom_callback_parser(BasicJsonType& r, json_sax_dom_callback_parser(BasicJsonType& r,
const parser_callback_t cb, const parser_callback_t cb,
...@@ -5869,7 +5828,7 @@ class json_sax_dom_callback_parser ...@@ -5869,7 +5828,7 @@ class json_sax_dom_callback_parser
// check object limit // check object limit
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), diagnostics_t(*ref_stack.back()))); JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
} }
return true; return true;
...@@ -5939,7 +5898,7 @@ class json_sax_dom_callback_parser ...@@ -5939,7 +5898,7 @@ class json_sax_dom_callback_parser
// check array limit // check array limit
if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
{ {
JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), diagnostics_t(*ref_stack.back()))); JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
} }
return true; return true;
...@@ -8003,7 +7962,6 @@ class binary_reader ...@@ -8003,7 +7962,6 @@ class binary_reader
using json_sax_t = SAX; using json_sax_t = SAX;
using char_type = typename InputAdapterType::char_type; using char_type = typename InputAdapterType::char_type;
using char_int_type = typename std::char_traits<char_type>::int_type; using char_int_type = typename std::char_traits<char_type>::int_type;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
public: public:
/*! /*!
...@@ -8077,7 +8035,7 @@ class binary_reader ...@@ -8077,7 +8035,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof())) if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
{ {
return sax->parse_error(chars_read, get_token_string(), return sax->parse_error(chars_read, get_token_string(),
parse_error::create(110, chars_read, exception_message(format, "expected end of input; last byte: 0x" + get_token_string(), "value"), diagnostics_t())); parse_error::create(110, chars_read, exception_message(format, "expected end of input; last byte: 0x" + get_token_string(), "value"), BasicJsonType()));
} }
} }
...@@ -8153,7 +8111,7 @@ class binary_reader ...@@ -8153,7 +8111,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(len < 1)) if (JSON_HEDLEY_UNLIKELY(len < 1))
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "string length must be at least 1, is " + std::to_string(len), "string"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "string length must be at least 1, is " + std::to_string(len), "string"), BasicJsonType()));
} }
return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != std::char_traits<char_type>::eof(); return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != std::char_traits<char_type>::eof();
...@@ -8174,7 +8132,7 @@ class binary_reader ...@@ -8174,7 +8132,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(len < 0)) if (JSON_HEDLEY_UNLIKELY(len < 0))
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "byte array length cannot be negative, is " + std::to_string(len), "binary"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "byte array length cannot be negative, is " + std::to_string(len), "binary"), BasicJsonType()));
} }
// All BSON binary values have a subtype // All BSON binary values have a subtype
...@@ -8256,7 +8214,7 @@ class binary_reader ...@@ -8256,7 +8214,7 @@ class binary_reader
{ {
std::array<char, 3> cr{{}}; std::array<char, 3> cr{{}};
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type)); (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type));
return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr.data()), diagnostics_t())); return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr.data()), BasicJsonType()));
} }
} }
} }
...@@ -8656,7 +8614,7 @@ class binary_reader ...@@ -8656,7 +8614,7 @@ class binary_reader
case cbor_tag_handler_t::error: case cbor_tag_handler_t::error:
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
} }
case cbor_tag_handler_t::ignore: case cbor_tag_handler_t::ignore:
...@@ -8771,7 +8729,7 @@ class binary_reader ...@@ -8771,7 +8729,7 @@ class binary_reader
default: // anything else (0xFF is handled inside the other types) default: // anything else (0xFF is handled inside the other types)
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
} }
} }
} }
...@@ -8866,7 +8824,7 @@ class binary_reader ...@@ -8866,7 +8824,7 @@ class binary_reader
default: default:
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x" + last_token, "string"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x" + last_token, "string"), BasicJsonType()));
} }
} }
} }
...@@ -8965,7 +8923,7 @@ class binary_reader ...@@ -8965,7 +8923,7 @@ class binary_reader
default: default:
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x" + last_token, "binary"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x" + last_token, "binary"), BasicJsonType()));
} }
} }
} }
...@@ -9432,7 +9390,7 @@ class binary_reader ...@@ -9432,7 +9390,7 @@ class binary_reader
default: // anything else default: // anything else
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack, "invalid byte: 0x" + last_token, "value"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
} }
} }
} }
...@@ -9514,7 +9472,7 @@ class binary_reader ...@@ -9514,7 +9472,7 @@ class binary_reader
default: default:
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack, "expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x" + last_token, "string"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack, "expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x" + last_token, "string"), BasicJsonType()));
} }
} }
} }
...@@ -9764,7 +9722,7 @@ class binary_reader ...@@ -9764,7 +9722,7 @@ class binary_reader
default: default:
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token, "string"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token, "string"), BasicJsonType()));
} }
} }
...@@ -9834,7 +9792,7 @@ class binary_reader ...@@ -9834,7 +9792,7 @@ class binary_reader
default: default:
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token, "size"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token, "size"), BasicJsonType()));
} }
} }
} }
...@@ -9872,7 +9830,7 @@ class binary_reader ...@@ -9872,7 +9830,7 @@ class binary_reader
return false; return false;
} }
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "expected '#' after type information; last byte: 0x" + last_token, "size"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "expected '#' after type information; last byte: 0x" + last_token, "size"), BasicJsonType()));
} }
return get_ubjson_size_value(result.first); return get_ubjson_size_value(result.first);
...@@ -9962,7 +9920,7 @@ class binary_reader ...@@ -9962,7 +9920,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(current > 127)) if (JSON_HEDLEY_UNLIKELY(current > 127))
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "byte after 'C' must be in range 0x00..0x7F; last byte: 0x" + last_token, "char"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "byte after 'C' must be in range 0x00..0x7F; last byte: 0x" + last_token, "char"), BasicJsonType()));
} }
string_t s(1, static_cast<typename string_t::value_type>(current)); string_t s(1, static_cast<typename string_t::value_type>(current));
return sax->string(s); return sax->string(s);
...@@ -9983,7 +9941,7 @@ class binary_reader ...@@ -9983,7 +9941,7 @@ class binary_reader
default: // anything else default: // anything else
{ {
auto last_token = get_token_string(); auto last_token = get_token_string();
return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "invalid byte: 0x" + last_token, "value"), diagnostics_t())); return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
} }
} }
} }
...@@ -10161,7 +10119,7 @@ class binary_reader ...@@ -10161,7 +10119,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
{ {
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), diagnostics_t())); return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), BasicJsonType()));
} }
switch (result_number) switch (result_number)
...@@ -10173,7 +10131,7 @@ class binary_reader ...@@ -10173,7 +10131,7 @@ class binary_reader
case token_type::value_float: case token_type::value_float:
return sax->number_float(number_lexer.get_number_float(), std::move(number_string)); return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
default: default:
return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), diagnostics_t())); return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), BasicJsonType()));
} }
} }
...@@ -10329,7 +10287,7 @@ class binary_reader ...@@ -10329,7 +10287,7 @@ class binary_reader
if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof())) if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
{ {
return sax->parse_error(chars_read, "<end of file>", return sax->parse_error(chars_read, "<end of file>",
parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), diagnostics_t())); parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), BasicJsonType()));
} }
return true; return true;
} }
...@@ -10416,8 +10374,6 @@ class binary_reader ...@@ -10416,8 +10374,6 @@ class binary_reader
// #include <nlohmann/detail/exceptions.hpp> // #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/diagnostics_t.hpp>
// #include <nlohmann/detail/input/input_adapters.hpp> // #include <nlohmann/detail/input/input_adapters.hpp>
// #include <nlohmann/detail/input/json_sax.hpp> // #include <nlohmann/detail/input/json_sax.hpp>
...@@ -10473,7 +10429,6 @@ class parser ...@@ -10473,7 +10429,6 @@ class parser
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using lexer_t = lexer<BasicJsonType, InputAdapterType>; using lexer_t = lexer<BasicJsonType, InputAdapterType>;
using token_type = typename lexer_t::token_type; using token_type = typename lexer_t::token_type;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
public: public:
/// a parser reading from an input adapter /// a parser reading from an input adapter
...@@ -10512,7 +10467,7 @@ class parser ...@@ -10512,7 +10467,7 @@ class parser
sdp.parse_error(m_lexer.get_position(), sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_of_input, "value"), diagnostics_t())); exception_message(token_type::end_of_input, "value"), BasicJsonType()));
} }
// in case of an error, return discarded value // in case of an error, return discarded value
...@@ -10539,8 +10494,7 @@ class parser ...@@ -10539,8 +10494,7 @@ class parser
{ {
sdp.parse_error(m_lexer.get_position(), sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
exception_message(token_type::end_of_input, "value"), diagnostics_t()));
} }
// in case of an error, return discarded value // in case of an error, return discarded value
...@@ -10578,8 +10532,7 @@ class parser ...@@ -10578,8 +10532,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
exception_message(token_type::end_of_input, "value"), diagnostics_t()));
} }
return result; return result;
...@@ -10625,8 +10578,7 @@ class parser ...@@ -10625,8 +10578,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
exception_message(token_type::value_string, "object key"), diagnostics_t()));
} }
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{ {
...@@ -10638,8 +10590,7 @@ class parser ...@@ -10638,8 +10590,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
exception_message(token_type::name_separator, "object separator"), diagnostics_t()));
} }
// remember we are now inside an object // remember we are now inside an object
...@@ -10682,7 +10633,7 @@ class parser ...@@ -10682,7 +10633,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'", diagnostics_t())); out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'", BasicJsonType()));
} }
if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string()))) if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
...@@ -10752,16 +10703,14 @@ class parser ...@@ -10752,16 +10703,14 @@ class parser
// using "uninitialized" to avoid "expected" message // using "uninitialized" to avoid "expected" message
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), BasicJsonType()));
exception_message(token_type::uninitialized, "value"), diagnostics_t()));
} }
default: // the last token was unexpected default: // the last token was unexpected
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), BasicJsonType()));
exception_message(token_type::literal_or_value, "value"), diagnostics_t()));
} }
} }
} }
...@@ -10807,8 +10756,7 @@ class parser ...@@ -10807,8 +10756,7 @@ class parser
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array, "array"), BasicJsonType()));
exception_message(token_type::end_array, "array"), diagnostics_t()));
} }
else // object else // object
{ {
...@@ -10820,8 +10768,7 @@ class parser ...@@ -10820,8 +10768,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
exception_message(token_type::value_string, "object key"), diagnostics_t()));
} }
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
...@@ -10834,8 +10781,7 @@ class parser ...@@ -10834,8 +10781,7 @@ class parser
{ {
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
exception_message(token_type::name_separator, "object separator"), diagnostics_t()));
} }
// parse values // parse values
...@@ -10863,8 +10809,7 @@ class parser ...@@ -10863,8 +10809,7 @@ class parser
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object, "object"), BasicJsonType()));
exception_message(token_type::end_object, "object"), diagnostics_t()));
} }
} }
} }
...@@ -11075,8 +11020,6 @@ template<typename BasicJsonType> struct internal_iterator ...@@ -11075,8 +11020,6 @@ template<typename BasicJsonType> struct internal_iterator
#include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next #include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next
#include <type_traits> // conditional, is_const, remove_const #include <type_traits> // conditional, is_const, remove_const
// #include <nlohmann/detail/diagnostics_t.hpp>
// #include <nlohmann/detail/exceptions.hpp> // #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/iterators/internal_iterator.hpp> // #include <nlohmann/detail/iterators/internal_iterator.hpp>
...@@ -11132,7 +11075,6 @@ class iter_impl ...@@ -11132,7 +11075,6 @@ class iter_impl
// make sure BasicJsonType is basic_json or const basic_json // make sure BasicJsonType is basic_json or const basic_json
static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value, static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,
"iter_impl only accepts (const) basic_json"); "iter_impl only accepts (const) basic_json");
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
public: public:
...@@ -11339,7 +11281,7 @@ class iter_impl ...@@ -11339,7 +11281,7 @@ class iter_impl
} }
case value_t::null: case value_t::null:
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
default: default:
{ {
...@@ -11348,7 +11290,7 @@ class iter_impl ...@@ -11348,7 +11290,7 @@ class iter_impl
return *m_object; return *m_object;
} }
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
} }
} }
} }
...@@ -11382,7 +11324,7 @@ class iter_impl ...@@ -11382,7 +11324,7 @@ class iter_impl
return m_object; return m_object;
} }
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
} }
} }
} }
...@@ -11483,7 +11425,7 @@ class iter_impl ...@@ -11483,7 +11425,7 @@ class iter_impl
// if objects are not the same, the comparison is undefined // if objects are not the same, the comparison is undefined
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
{ {
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
} }
JSON_ASSERT(m_object != nullptr); JSON_ASSERT(m_object != nullptr);
...@@ -11520,7 +11462,7 @@ class iter_impl ...@@ -11520,7 +11462,7 @@ class iter_impl
// if objects are not the same, the comparison is undefined // if objects are not the same, the comparison is undefined
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
{ {
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
} }
JSON_ASSERT(m_object != nullptr); JSON_ASSERT(m_object != nullptr);
...@@ -11528,7 +11470,7 @@ class iter_impl ...@@ -11528,7 +11470,7 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", *m_object));
case value_t::array: case value_t::array:
return (m_it.array_iterator < other.m_it.array_iterator); return (m_it.array_iterator < other.m_it.array_iterator);
...@@ -11576,7 +11518,7 @@ class iter_impl ...@@ -11576,7 +11518,7 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
case value_t::array: case value_t::array:
{ {
...@@ -11647,7 +11589,7 @@ class iter_impl ...@@ -11647,7 +11589,7 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
case value_t::array: case value_t::array:
return m_it.array_iterator - other.m_it.array_iterator; return m_it.array_iterator - other.m_it.array_iterator;
...@@ -11668,13 +11610,13 @@ class iter_impl ...@@ -11668,13 +11610,13 @@ class iter_impl
switch (m_object->m_type) switch (m_object->m_type)
{ {
case value_t::object: case value_t::object:
JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", *m_object));
case value_t::array: case value_t::array:
return *std::next(m_it.array_iterator, n); return *std::next(m_it.array_iterator, n);
case value_t::null: case value_t::null:
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
default: default:
{ {
...@@ -11683,7 +11625,7 @@ class iter_impl ...@@ -11683,7 +11625,7 @@ class iter_impl
return *m_object; return *m_object;
} }
JSON_THROW(invalid_iterator::create(214, "cannot get value", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
} }
} }
} }
...@@ -11701,7 +11643,7 @@ class iter_impl ...@@ -11701,7 +11643,7 @@ class iter_impl
return m_it.object_iterator->first; return m_it.object_iterator->first;
} }
JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", diagnostics_t(*m_object))); JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", *m_object));
} }
/*! /*!
...@@ -11858,8 +11800,6 @@ class json_reverse_iterator : public std::reverse_iterator<Base> ...@@ -11858,8 +11800,6 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
#include <utility> // move #include <utility> // move
#include <vector> // vector #include <vector> // vector
// #include <nlohmann/detail/diagnostics_t.hpp>
// #include <nlohmann/detail/exceptions.hpp> // #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/macro_scope.hpp>
...@@ -11878,8 +11818,6 @@ class json_pointer ...@@ -11878,8 +11818,6 @@ class json_pointer
NLOHMANN_BASIC_JSON_TPL_DECLARATION NLOHMANN_BASIC_JSON_TPL_DECLARATION
friend class basic_json; friend class basic_json;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
public: public:
/*! /*!
@brief create JSON pointer @brief create JSON pointer
...@@ -12106,7 +12044,7 @@ class json_pointer ...@@ -12106,7 +12044,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(empty())) if (JSON_HEDLEY_UNLIKELY(empty()))
{ {
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", diagnostics_t())); JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
} }
reference_tokens.pop_back(); reference_tokens.pop_back();
...@@ -12130,7 +12068,7 @@ class json_pointer ...@@ -12130,7 +12068,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(empty())) if (JSON_HEDLEY_UNLIKELY(empty()))
{ {
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", diagnostics_t())); JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
} }
return reference_tokens.back(); return reference_tokens.back();
...@@ -12196,13 +12134,13 @@ class json_pointer ...@@ -12196,13 +12134,13 @@ class json_pointer
// error condition (cf. RFC 6901, Sect. 4) // error condition (cf. RFC 6901, Sect. 4)
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0')) if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0'))
{ {
JSON_THROW(detail::parse_error::create(106, 0, "array index '" + s + "' must not begin with '0'", diagnostics_t())); JSON_THROW(detail::parse_error::create(106, 0, "array index '" + s + "' must not begin with '0'", BasicJsonType()));
} }
// error condition (cf. RFC 6901, Sect. 4) // error condition (cf. RFC 6901, Sect. 4)
if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9'))) if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9')))
{ {
JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number", diagnostics_t())); JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number", BasicJsonType()));
} }
std::size_t processed_chars = 0; std::size_t processed_chars = 0;
...@@ -12213,20 +12151,20 @@ class json_pointer ...@@ -12213,20 +12151,20 @@ class json_pointer
} }
JSON_CATCH(std::out_of_range&) JSON_CATCH(std::out_of_range&)
{ {
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", diagnostics_t())); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
} }
// check if the string was completely read // check if the string was completely read
if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size())) if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
{ {
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", diagnostics_t())); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
} }
// only triggered on special platforms (like 32bit), see also // only triggered on special platforms (like 32bit), see also
// https://github.com/nlohmann/json/pull/2203 // https://github.com/nlohmann/json/pull/2203
if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
{ {
JSON_THROW(detail::out_of_range::create(410, "array index " + s + " exceeds size_type", diagnostics_t())); // LCOV_EXCL_LINE JSON_THROW(detail::out_of_range::create(410, "array index " + s + " exceeds size_type", BasicJsonType())); // LCOV_EXCL_LINE
} }
return static_cast<size_type>(res); return static_cast<size_type>(res);
...@@ -12237,7 +12175,7 @@ class json_pointer ...@@ -12237,7 +12175,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(empty())) if (JSON_HEDLEY_UNLIKELY(empty()))
{ {
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", diagnostics_t())); JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
} }
json_pointer result = *this; json_pointer result = *this;
...@@ -12300,7 +12238,7 @@ class json_pointer ...@@ -12300,7 +12238,7 @@ class json_pointer
single value; that is, with an empty list of reference tokens. single value; that is, with an empty list of reference tokens.
*/ */
default: default:
JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", diagnostics_t(j))); JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", j));
} }
} }
...@@ -12372,7 +12310,7 @@ class json_pointer ...@@ -12372,7 +12310,7 @@ class json_pointer
} }
default: default:
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
} }
} }
...@@ -12405,7 +12343,7 @@ class json_pointer ...@@ -12405,7 +12343,7 @@ class json_pointer
// "-" always fails the range check // "-" always fails the range check
JSON_THROW(detail::out_of_range::create(402, JSON_THROW(detail::out_of_range::create(402,
"array index '-' (" + std::to_string(ptr->m_value.array->size()) + "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
") is out of range", diagnostics_t(*ptr))); ") is out of range", *ptr));
} }
// note: at performs range check // note: at performs range check
...@@ -12414,7 +12352,7 @@ class json_pointer ...@@ -12414,7 +12352,7 @@ class json_pointer
} }
default: default:
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
} }
} }
...@@ -12452,7 +12390,7 @@ class json_pointer ...@@ -12452,7 +12390,7 @@ class json_pointer
if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
{ {
// "-" cannot be used for const access // "-" cannot be used for const access
JSON_THROW(detail::out_of_range::create(402, "array index '-' (" + std::to_string(ptr->m_value.array->size()) + ") is out of range", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(402, "array index '-' (" + std::to_string(ptr->m_value.array->size()) + ") is out of range", *ptr));
} }
// use unchecked array access // use unchecked array access
...@@ -12461,7 +12399,7 @@ class json_pointer ...@@ -12461,7 +12399,7 @@ class json_pointer
} }
default: default:
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
} }
} }
...@@ -12494,7 +12432,7 @@ class json_pointer ...@@ -12494,7 +12432,7 @@ class json_pointer
// "-" always fails the range check // "-" always fails the range check
JSON_THROW(detail::out_of_range::create(402, JSON_THROW(detail::out_of_range::create(402,
"array index '-' (" + std::to_string(ptr->m_value.array->size()) + "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
") is out of range", diagnostics_t(*ptr))); ") is out of range", *ptr));
} }
// note: at performs range check // note: at performs range check
...@@ -12503,7 +12441,7 @@ class json_pointer ...@@ -12503,7 +12441,7 @@ class json_pointer
} }
default: default:
JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", diagnostics_t(*ptr))); JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
} }
} }
...@@ -12607,7 +12545,7 @@ class json_pointer ...@@ -12607,7 +12545,7 @@ class json_pointer
// check if nonempty reference string begins with slash // check if nonempty reference string begins with slash
if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/')) if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
{ {
JSON_THROW(detail::parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'", diagnostics_t())); JSON_THROW(detail::parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'", BasicJsonType()));
} }
// extract the reference tokens: // extract the reference tokens:
...@@ -12642,7 +12580,7 @@ class json_pointer ...@@ -12642,7 +12580,7 @@ class json_pointer
(reference_token[pos + 1] != '0' && (reference_token[pos + 1] != '0' &&
reference_token[pos + 1] != '1'))) reference_token[pos + 1] != '1')))
{ {
JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", diagnostics_t())); JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", BasicJsonType()));
} }
} }
...@@ -12729,7 +12667,7 @@ class json_pointer ...@@ -12729,7 +12667,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(!value.is_object())) if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
{ {
JSON_THROW(detail::type_error::create(314, "only objects can be unflattened", diagnostics_t(value))); JSON_THROW(detail::type_error::create(314, "only objects can be unflattened", value));
} }
BasicJsonType result; BasicJsonType result;
...@@ -12739,7 +12677,7 @@ class json_pointer ...@@ -12739,7 +12677,7 @@ class json_pointer
{ {
if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive())) if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
{ {
JSON_THROW(detail::type_error::create(315, "values in object must be primitive", diagnostics_t(element.second))); JSON_THROW(detail::type_error::create(315, "values in object must be primitive", element.second));
} }
// assign value to reference pointed to by JSON pointer; Note that if // assign value to reference pointed to by JSON pointer; Note that if
...@@ -12879,8 +12817,6 @@ class json_ref ...@@ -12879,8 +12817,6 @@ class json_ref
#include <string> // string #include <string> // string
#include <cmath> // isnan, isinf #include <cmath> // isnan, isinf
// #include <nlohmann/detail/diagnostics_t.hpp>
// #include <nlohmann/detail/input/binary_reader.hpp> // #include <nlohmann/detail/input/binary_reader.hpp>
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/macro_scope.hpp>
...@@ -13029,7 +12965,6 @@ class binary_writer ...@@ -13029,7 +12965,6 @@ class binary_writer
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using binary_t = typename BasicJsonType::binary_t; using binary_t = typename BasicJsonType::binary_t;
using number_float_t = typename BasicJsonType::number_float_t; using number_float_t = typename BasicJsonType::number_float_t;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
public: public:
/*! /*!
...@@ -13058,7 +12993,7 @@ class binary_writer ...@@ -13058,7 +12993,7 @@ class binary_writer
default: default:
{ {
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), diagnostics_t(j)));; JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));;
} }
} }
} }
...@@ -13907,7 +13842,7 @@ class binary_writer ...@@ -13907,7 +13842,7 @@ class binary_writer
const auto it = name.find(static_cast<typename string_t::value_type>(0)); const auto it = name.find(static_cast<typename string_t::value_type>(0));
if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
{ {
JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", diagnostics_t(j))); JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", j));
} }
return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; return /*id*/ 1ul + name.size() + /*zero-terminator*/1u;
...@@ -14031,7 +13966,7 @@ class binary_writer ...@@ -14031,7 +13966,7 @@ class binary_writer
} }
else else
{ {
JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BSON as it does not fit int64", diagnostics_t(j))); JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BSON as it does not fit int64", j));
} }
} }
...@@ -15719,8 +15654,6 @@ char* to_chars(char* first, const char* last, FloatType value) ...@@ -15719,8 +15654,6 @@ char* to_chars(char* first, const char* last, FloatType value)
} // namespace detail } // namespace detail
} // namespace nlohmann } // namespace nlohmann
// #include <nlohmann/detail/diagnostics_t.hpp>
// #include <nlohmann/detail/exceptions.hpp> // #include <nlohmann/detail/exceptions.hpp>
// #include <nlohmann/detail/macro_scope.hpp> // #include <nlohmann/detail/macro_scope.hpp>
...@@ -15758,7 +15691,6 @@ class serializer ...@@ -15758,7 +15691,6 @@ class serializer
using number_integer_t = typename BasicJsonType::number_integer_t; using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using binary_char_t = typename BasicJsonType::binary_t::value_type; using binary_char_t = typename BasicJsonType::binary_t::value_type;
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
static constexpr std::uint8_t UTF8_ACCEPT = 0; static constexpr std::uint8_t UTF8_ACCEPT = 0;
static constexpr std::uint8_t UTF8_REJECT = 1; static constexpr std::uint8_t UTF8_REJECT = 1;
...@@ -16214,7 +16146,7 @@ class serializer ...@@ -16214,7 +16146,7 @@ class serializer
{ {
std::string sn(3, '\0'); std::string sn(3, '\0');
(std::snprintf)(&sn[0], sn.size(), "%.2X", byte); (std::snprintf)(&sn[0], sn.size(), "%.2X", byte);
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, diagnostics_t())); JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, BasicJsonType()));
} }
case error_handler_t::ignore: case error_handler_t::ignore:
...@@ -16308,7 +16240,7 @@ class serializer ...@@ -16308,7 +16240,7 @@ class serializer
{ {
std::string sn(3, '\0'); std::string sn(3, '\0');
(std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast<std::uint8_t>(s.back())); (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast<std::uint8_t>(s.back()));
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, diagnostics_t())); JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
} }
case error_handler_t::ignore: case error_handler_t::ignore:
...@@ -16973,15 +16905,11 @@ class basic_json ...@@ -16973,15 +16905,11 @@ class basic_json
friend class ::nlohmann::detail::json_sax_dom_parser; friend class ::nlohmann::detail::json_sax_dom_parser;
template<typename BasicJsonType> template<typename BasicJsonType>
friend class ::nlohmann::detail::json_sax_dom_callback_parser; friend class ::nlohmann::detail::json_sax_dom_callback_parser;
template<typename BasicJsonType> friend class ::nlohmann::detail::exception;
friend class ::nlohmann::detail::diagnostics_t;
/// workaround type for MSVC /// workaround type for MSVC
using basic_json_t = NLOHMANN_BASIC_JSON_TPL; using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
/// shortcut
using diagnostics_t = ::nlohmann::detail::diagnostics_t<basic_json>;
JSON_PRIVATE_UNLESS_TESTED: JSON_PRIVATE_UNLESS_TESTED:
// convenience aliases for types residing in namespace detail; // convenience aliases for types residing in namespace detail;
using lexer = ::nlohmann::detail::lexer_base<basic_json>; using lexer = ::nlohmann::detail::lexer_base<basic_json>;
...@@ -17849,7 +17777,7 @@ class basic_json ...@@ -17849,7 +17777,7 @@ class basic_json
object = nullptr; // silence warning, see #821 object = nullptr; // silence warning, see #821
if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
{ {
JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.9.1", diagnostics_t())); // LCOV_EXCL_LINE JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.9.1", basic_json())); // LCOV_EXCL_LINE
} }
break; break;
} }
...@@ -18490,7 +18418,7 @@ class basic_json ...@@ -18490,7 +18418,7 @@ class basic_json
// if object is wanted but impossible, throw an exception // if object is wanted but impossible, throw an exception
if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object)) if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
{ {
JSON_THROW(type_error::create(301, "cannot create object from initializer list", diagnostics_t())); JSON_THROW(type_error::create(301, "cannot create object from initializer list", basic_json()));
} }
} }
...@@ -18795,7 +18723,7 @@ class basic_json ...@@ -18795,7 +18723,7 @@ class basic_json
// make sure iterator fits the current value // make sure iterator fits the current value
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
{ {
JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", diagnostics_t())); JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", basic_json()));
} }
// copy type from first iterator // copy type from first iterator
...@@ -18813,7 +18741,7 @@ class basic_json ...@@ -18813,7 +18741,7 @@ class basic_json
if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin() if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
|| !last.m_it.primitive_iterator.is_end())) || !last.m_it.primitive_iterator.is_end()))
{ {
JSON_THROW(invalid_iterator::create(204, "iterators out of range", diagnostics_t())); JSON_THROW(invalid_iterator::create(204, "iterators out of range", *first.m_object));
} }
break; break;
} }
...@@ -18875,7 +18803,7 @@ class basic_json ...@@ -18875,7 +18803,7 @@ class basic_json
} }
default: default:
JSON_THROW(invalid_iterator::create(206, "cannot construct with iterators from " + std::string(first.m_object->type_name()), diagnostics_t())); JSON_THROW(invalid_iterator::create(206, "cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
} }
set_parents(); set_parents();
...@@ -19574,7 +19502,7 @@ class basic_json ...@@ -19574,7 +19502,7 @@ class basic_json
return m_value.boolean; return m_value.boolean;
} }
JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(type_name()), *this));
} }
/// get a pointer to the value (object) /// get a pointer to the value (object)
...@@ -19695,7 +19623,7 @@ class basic_json ...@@ -19695,7 +19623,7 @@ class basic_json
return *ptr; return *ptr;
} }
JSON_THROW(type_error::create(303, "incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), diagnostics_t(obj))); JSON_THROW(type_error::create(303, "incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
} }
public: public:
...@@ -20123,7 +20051,7 @@ class basic_json ...@@ -20123,7 +20051,7 @@ class basic_json
{ {
if (!is_binary()) if (!is_binary())
{ {
JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this));
} }
return *get_ptr<binary_t*>(); return *get_ptr<binary_t*>();
...@@ -20134,7 +20062,7 @@ class basic_json ...@@ -20134,7 +20062,7 @@ class basic_json
{ {
if (!is_binary()) if (!is_binary())
{ {
JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this));
} }
return *get_ptr<const binary_t*>(); return *get_ptr<const binary_t*>();
...@@ -20189,12 +20117,12 @@ class basic_json ...@@ -20189,12 +20117,12 @@ class basic_json
JSON_CATCH (std::out_of_range&) JSON_CATCH (std::out_of_range&)
{ {
// create better exception explanation // create better exception explanation
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", diagnostics_t(*this))); JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
} }
} }
else else
{ {
JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
} }
} }
...@@ -20236,12 +20164,12 @@ class basic_json ...@@ -20236,12 +20164,12 @@ class basic_json
JSON_CATCH (std::out_of_range&) JSON_CATCH (std::out_of_range&)
{ {
// create better exception explanation // create better exception explanation
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", diagnostics_t(*this))); JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
} }
} }
else else
{ {
JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
} }
} }
...@@ -20287,12 +20215,12 @@ class basic_json ...@@ -20287,12 +20215,12 @@ class basic_json
JSON_CATCH (std::out_of_range&) JSON_CATCH (std::out_of_range&)
{ {
// create better exception explanation // create better exception explanation
JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", diagnostics_t(*this))); JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this));
} }
} }
else else
{ {
JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
} }
} }
...@@ -20338,12 +20266,12 @@ class basic_json ...@@ -20338,12 +20266,12 @@ class basic_json
JSON_CATCH (std::out_of_range&) JSON_CATCH (std::out_of_range&)
{ {
// create better exception explanation // create better exception explanation
JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", diagnostics_t(*this))); JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this));
} }
} }
else else
{ {
JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
} }
} }
...@@ -20403,7 +20331,7 @@ class basic_json ...@@ -20403,7 +20331,7 @@ class basic_json
return m_value.array->operator[](idx); return m_value.array->operator[](idx);
} }
JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -20433,7 +20361,7 @@ class basic_json ...@@ -20433,7 +20361,7 @@ class basic_json
return m_value.array->operator[](idx); return m_value.array->operator[](idx);
} }
JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -20479,7 +20407,7 @@ class basic_json ...@@ -20479,7 +20407,7 @@ class basic_json
return set_parent(m_value.object->operator[](key)); return set_parent(m_value.object->operator[](key));
} }
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -20521,7 +20449,7 @@ class basic_json ...@@ -20521,7 +20449,7 @@ class basic_json
return m_value.object->find(key)->second; return m_value.object->find(key)->second;
} }
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -20569,7 +20497,7 @@ class basic_json ...@@ -20569,7 +20497,7 @@ class basic_json
return set_parent(m_value.object->operator[](key)); return set_parent(m_value.object->operator[](key));
} }
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -20613,7 +20541,7 @@ class basic_json ...@@ -20613,7 +20541,7 @@ class basic_json
return m_value.object->find(key)->second; return m_value.object->find(key)->second;
} }
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -20685,7 +20613,7 @@ class basic_json ...@@ -20685,7 +20613,7 @@ class basic_json
return default_value; return default_value;
} }
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -20758,7 +20686,7 @@ class basic_json ...@@ -20758,7 +20686,7 @@ class basic_json
} }
} }
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -20912,7 +20840,7 @@ class basic_json ...@@ -20912,7 +20840,7 @@ class basic_json
// make sure iterator fits the current value // make sure iterator fits the current value
if (JSON_HEDLEY_UNLIKELY(this != pos.m_object)) if (JSON_HEDLEY_UNLIKELY(this != pos.m_object))
{ {
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
} }
IteratorType result = end(); IteratorType result = end();
...@@ -20928,7 +20856,7 @@ class basic_json ...@@ -20928,7 +20856,7 @@ class basic_json
{ {
if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin())) if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
{ {
JSON_THROW(invalid_iterator::create(205, "iterator out of range", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(205, "iterator out of range", *this));
} }
if (is_string()) if (is_string())
...@@ -20964,7 +20892,7 @@ class basic_json ...@@ -20964,7 +20892,7 @@ class basic_json
} }
default: default:
JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
} }
return result; return result;
...@@ -21025,7 +20953,7 @@ class basic_json ...@@ -21025,7 +20953,7 @@ class basic_json
// make sure iterator fits the current value // make sure iterator fits the current value
if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object)) if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object))
{ {
JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", *this));
} }
IteratorType result = end(); IteratorType result = end();
...@@ -21042,7 +20970,7 @@ class basic_json ...@@ -21042,7 +20970,7 @@ class basic_json
if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin() if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
|| !last.m_it.primitive_iterator.is_end())) || !last.m_it.primitive_iterator.is_end()))
{ {
JSON_THROW(invalid_iterator::create(204, "iterators out of range", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(204, "iterators out of range", *this));
} }
if (is_string()) if (is_string())
...@@ -21080,7 +21008,7 @@ class basic_json ...@@ -21080,7 +21008,7 @@ class basic_json
} }
default: default:
JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
} }
return result; return result;
...@@ -21123,7 +21051,7 @@ class basic_json ...@@ -21123,7 +21051,7 @@ class basic_json
return m_value.object->erase(key); return m_value.object->erase(key);
} }
JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -21157,14 +21085,14 @@ class basic_json ...@@ -21157,14 +21085,14 @@ class basic_json
{ {
if (JSON_HEDLEY_UNLIKELY(idx >= size())) if (JSON_HEDLEY_UNLIKELY(idx >= size()))
{ {
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", diagnostics_t(*this))); JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
} }
m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx)); m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
} }
else else
{ {
JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
} }
} }
...@@ -22109,7 +22037,7 @@ class basic_json ...@@ -22109,7 +22037,7 @@ class basic_json
// push_back only works for null objects or arrays // push_back only works for null objects or arrays
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
{ {
JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
} }
// transform null object into an array // transform null object into an array
...@@ -22145,7 +22073,7 @@ class basic_json ...@@ -22145,7 +22073,7 @@ class basic_json
// push_back only works for null objects or arrays // push_back only works for null objects or arrays
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
{ {
JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
} }
// transform null object into an array // transform null object into an array
...@@ -22196,7 +22124,7 @@ class basic_json ...@@ -22196,7 +22124,7 @@ class basic_json
// push_back only works for null objects or objects // push_back only works for null objects or objects
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object()))) if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
{ {
JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
} }
// transform null object into an object // transform null object into an object
...@@ -22300,7 +22228,7 @@ class basic_json ...@@ -22300,7 +22228,7 @@ class basic_json
// emplace_back only works for null objects or arrays // emplace_back only works for null objects or arrays
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
{ {
JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + std::string(type_name()), *this));
} }
// transform null object into an array // transform null object into an array
...@@ -22353,7 +22281,7 @@ class basic_json ...@@ -22353,7 +22281,7 @@ class basic_json
// emplace only works for null objects or arrays // emplace only works for null objects or arrays
if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object()))) if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
{ {
JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name()), *this));
} }
// transform null object into an object // transform null object into an object
...@@ -22426,14 +22354,14 @@ class basic_json ...@@ -22426,14 +22354,14 @@ class basic_json
// check if iterator pos fits to this JSON value // check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{ {
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
} }
// insert to array and return iterator // insert to array and return iterator
return set_parents(insert_iterator(pos, val), static_cast<typename iterator::difference_type>(1)); return set_parents(insert_iterator(pos, val), static_cast<typename iterator::difference_type>(1));
} }
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -22477,14 +22405,14 @@ class basic_json ...@@ -22477,14 +22405,14 @@ class basic_json
// check if iterator pos fits to this JSON value // check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{ {
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
} }
// insert to array and return iterator // insert to array and return iterator
return set_parents(insert_iterator(pos, cnt, val), static_cast<typename iterator::difference_type>(cnt)); return set_parents(insert_iterator(pos, cnt, val), static_cast<typename iterator::difference_type>(cnt));
} }
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
} }
/*! /*!
...@@ -22522,24 +22450,24 @@ class basic_json ...@@ -22522,24 +22450,24 @@ class basic_json
// insert only works for arrays // insert only works for arrays
if (JSON_HEDLEY_UNLIKELY(!is_array())) if (JSON_HEDLEY_UNLIKELY(!is_array()))
{ {
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
} }
// check if iterator pos fits to this JSON value // check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{ {
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
} }
// check if range iterators belong to the same JSON object // check if range iterators belong to the same JSON object
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
{ {
JSON_THROW(invalid_iterator::create(210, "iterators do not fit", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
} }
if (JSON_HEDLEY_UNLIKELY(first.m_object == this)) if (JSON_HEDLEY_UNLIKELY(first.m_object == this))
{ {
JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container", *this));
} }
// insert to array and return iterator // insert to array and return iterator
...@@ -22575,13 +22503,13 @@ class basic_json ...@@ -22575,13 +22503,13 @@ class basic_json
// insert only works for arrays // insert only works for arrays
if (JSON_HEDLEY_UNLIKELY(!is_array())) if (JSON_HEDLEY_UNLIKELY(!is_array()))
{ {
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
} }
// check if iterator pos fits to this JSON value // check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{ {
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
} }
// insert to array and return iterator // insert to array and return iterator
...@@ -22616,19 +22544,19 @@ class basic_json ...@@ -22616,19 +22544,19 @@ class basic_json
// insert only works for objects // insert only works for objects
if (JSON_HEDLEY_UNLIKELY(!is_object())) if (JSON_HEDLEY_UNLIKELY(!is_object()))
{ {
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
} }
// check if range iterators belong to the same JSON object // check if range iterators belong to the same JSON object
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
{ {
JSON_THROW(invalid_iterator::create(210, "iterators do not fit", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
} }
// passed iterators must belong to objects // passed iterators must belong to objects
if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object())) if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
{ {
JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
} }
m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator); m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
...@@ -22665,11 +22593,11 @@ class basic_json ...@@ -22665,11 +22593,11 @@ class basic_json
if (JSON_HEDLEY_UNLIKELY(!is_object())) if (JSON_HEDLEY_UNLIKELY(!is_object()))
{ {
JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
} }
if (JSON_HEDLEY_UNLIKELY(!j.is_object())) if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
{ {
JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), *this));
} }
for (auto it = j.cbegin(); it != j.cend(); ++it) for (auto it = j.cbegin(); it != j.cend(); ++it)
...@@ -22716,20 +22644,20 @@ class basic_json ...@@ -22716,20 +22644,20 @@ class basic_json
if (JSON_HEDLEY_UNLIKELY(!is_object())) if (JSON_HEDLEY_UNLIKELY(!is_object()))
{ {
JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
} }
// check if range iterators belong to the same JSON object // check if range iterators belong to the same JSON object
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
{ {
JSON_THROW(invalid_iterator::create(210, "iterators do not fit", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
} }
// passed iterators must belong to objects // passed iterators must belong to objects
if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object() if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
|| !last.m_object->is_object())) || !last.m_object->is_object()))
{ {
JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", diagnostics_t(*this))); JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
} }
for (auto it = first; it != last; ++it) for (auto it = first; it != last; ++it)
...@@ -22827,7 +22755,7 @@ class basic_json ...@@ -22827,7 +22755,7 @@ class basic_json
} }
else else
{ {
JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
} }
} }
...@@ -22860,7 +22788,7 @@ class basic_json ...@@ -22860,7 +22788,7 @@ class basic_json
} }
else else
{ {
JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
} }
} }
...@@ -22893,7 +22821,7 @@ class basic_json ...@@ -22893,7 +22821,7 @@ class basic_json
} }
else else
{ {
JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
} }
} }
...@@ -22926,7 +22854,7 @@ class basic_json ...@@ -22926,7 +22854,7 @@ class basic_json
} }
else else
{ {
JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
} }
} }
...@@ -22940,7 +22868,7 @@ class basic_json ...@@ -22940,7 +22868,7 @@ class basic_json
} }
else else
{ {
JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), diagnostics_t(*this))); JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
} }
} }
...@@ -25149,7 +25077,7 @@ class basic_json ...@@ -25149,7 +25077,7 @@ class basic_json
if (JSON_HEDLEY_UNLIKELY(idx > parent.size())) if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))
{ {
// avoid undefined behavior // avoid undefined behavior
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", diagnostics_t(parent))); JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", parent));
} }
// default case: insert add offset // default case: insert add offset
...@@ -25183,7 +25111,7 @@ class basic_json ...@@ -25183,7 +25111,7 @@ class basic_json
} }
else else
{ {
JSON_THROW(out_of_range::create(403, "key '" + last_path + "' not found", diagnostics_t(*this))); JSON_THROW(out_of_range::create(403, "key '" + last_path + "' not found", *this));
} }
} }
else if (parent.is_array()) else if (parent.is_array())
...@@ -25196,7 +25124,7 @@ class basic_json ...@@ -25196,7 +25124,7 @@ class basic_json
// type check: top level value must be an array // type check: top level value must be an array
if (JSON_HEDLEY_UNLIKELY(!json_patch.is_array())) if (JSON_HEDLEY_UNLIKELY(!json_patch.is_array()))
{ {
JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", diagnostics_t(json_patch))); JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", json_patch));
} }
// iterate and apply the operations // iterate and apply the operations
...@@ -25216,13 +25144,13 @@ class basic_json ...@@ -25216,13 +25144,13 @@ class basic_json
// check if desired value is present // check if desired value is present
if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end())) if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
{ {
JSON_THROW(parse_error::create(105, 0, error_msg + " must have member '" + member + "'", diagnostics_t(val))); JSON_THROW(parse_error::create(105, 0, error_msg + " must have member '" + member + "'", val));
} }
// check if result is of type string // check if result is of type string
if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string())) if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
{ {
JSON_THROW(parse_error::create(105, 0, error_msg + " must have string member '" + member + "'", diagnostics_t(val))); JSON_THROW(parse_error::create(105, 0, error_msg + " must have string member '" + member + "'", val));
} }
// no error: return value // no error: return value
...@@ -25232,7 +25160,7 @@ class basic_json ...@@ -25232,7 +25160,7 @@ class basic_json
// type check: every element of the array must be an object // type check: every element of the array must be an object
if (JSON_HEDLEY_UNLIKELY(!val.is_object())) if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
{ {
JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", diagnostics_t(val))); JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", val));
} }
// collect mandatory members // collect mandatory members
...@@ -25310,7 +25238,7 @@ class basic_json ...@@ -25310,7 +25238,7 @@ class basic_json
// throw an exception if test fails // throw an exception if test fails
if (JSON_HEDLEY_UNLIKELY(!success)) if (JSON_HEDLEY_UNLIKELY(!success))
{ {
JSON_THROW(other_error::create(501, "unsuccessful: " + val.dump(), diagnostics_t(val))); JSON_THROW(other_error::create(501, "unsuccessful: " + val.dump(), val));
} }
break; break;
...@@ -25320,7 +25248,7 @@ class basic_json ...@@ -25320,7 +25248,7 @@ class basic_json
{ {
// op must be "add", "remove", "replace", "move", "copy", or // op must be "add", "remove", "replace", "move", "copy", or
// "test" // "test"
JSON_THROW(parse_error::create(105, 0, "operation value '" + op + "' is invalid", diagnostics_t(val))); JSON_THROW(parse_error::create(105, 0, "operation value '" + op + "' is invalid", val));
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment