mirror of
https://github.com/nlohmann/json.git
synced 2026-07-23 19:04:54 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c16615e5e0 |
@@ -1869,24 +1869,6 @@ class binary_reader
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief create the error message for a missing/invalid length-type marker
|
||||
|
||||
Used both when reading a UBJSON/BJData string and when reading an optimized
|
||||
container size. The accepted markers depend on the input format, and the
|
||||
size variant appends " after '#'" via @a infix.
|
||||
|
||||
@param[in] last_token the offending byte as returned by get_token_string()
|
||||
@param[in] infix extra context inserted after the marker list
|
||||
@return the formatted error message
|
||||
*/
|
||||
std::string unexpected_length_type_message(const std::string& last_token, const char* infix) const
|
||||
{
|
||||
return concat("expected length type specification (",
|
||||
input_format == input_format_t::bjdata ? "U, i, u, I, m, l, M, L" : "U, i, I, l, L",
|
||||
")", infix, "; last byte: 0x", last_token);
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief reads a UBJSON string
|
||||
|
||||
@@ -1979,8 +1961,17 @@ class binary_reader
|
||||
break;
|
||||
}
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
|
||||
exception_message(input_format, unexpected_length_type_message(last_token, ""), "string"), nullptr));
|
||||
std::string message;
|
||||
|
||||
if (input_format != input_format_t::bjdata)
|
||||
{
|
||||
message = "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
|
||||
}
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, "string"), nullptr));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -2259,8 +2250,17 @@ class binary_reader
|
||||
break;
|
||||
}
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
|
||||
exception_message(input_format, unexpected_length_type_message(last_token, " after '#'"), "size"), nullptr));
|
||||
std::string message;
|
||||
|
||||
if (input_format != input_format_t::bjdata)
|
||||
{
|
||||
message = "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
|
||||
}
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, "size"), nullptr));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -699,21 +699,35 @@ struct is_json_pointer_of<A, ::nlohmann::json_pointer<A>> : std::true_type {};
|
||||
template <typename A>
|
||||
struct is_json_pointer_of<A, ::nlohmann::json_pointer<A>&> : std::true_type {};
|
||||
|
||||
// checks if A and B are comparable using Compare functor
|
||||
// checks if A and B are comparable using Compare functor, assuming that
|
||||
// neither A nor B is a json_pointer type (that case is handled by
|
||||
// is_comparable below, which never instantiates this helper otherwise)
|
||||
template<typename Compare, typename A, typename B, typename = void>
|
||||
struct is_comparable : std::false_type {};
|
||||
struct is_comparable_no_json_pointer : std::false_type {};
|
||||
|
||||
// We exclude json_pointer here, because the checks using Compare(A, B) will
|
||||
// use json_pointer::operator string_t() which triggers a deprecation warning
|
||||
// for GCC. See https://github.com/nlohmann/json/issues/4621. The call to
|
||||
// is_json_pointer_of can be removed once the deprecated function has been
|
||||
// removed.
|
||||
template<typename Compare, typename A, typename B>
|
||||
struct is_comparable < Compare, A, B, enable_if_t < !is_json_pointer_of<A, B>::value
|
||||
&& std::is_constructible <decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>()))>::value
|
||||
struct is_comparable_no_json_pointer < Compare, A, B, enable_if_t <
|
||||
std::is_constructible <decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>()))>::value
|
||||
&& std::is_constructible <decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>::value
|
||||
>> : std::true_type {};
|
||||
|
||||
// checks if A and B are comparable using Compare functor
|
||||
// We dispatch on is_json_pointer_of as a plain bool (rather than folding it
|
||||
// into a single enable_if_t condition together with the checks below) so
|
||||
// that the Compare(A, B) checks are only ever written - and thus only ever
|
||||
// instantiated - when A/B are not a json_pointer/string pair. Those checks
|
||||
// use json_pointer::operator string_t() (GCC, see #4621) resp. the
|
||||
// deprecated json_pointer/string operator== (Clang, see #5288), and merely
|
||||
// naming them as later operands of a plain && chain is not sufficient to
|
||||
// avoid their instantiation on all compilers, even when the first operand
|
||||
// is false. The dispatch on is_json_pointer_of can be removed once the
|
||||
// deprecated json_pointer comparison operators have been removed.
|
||||
template<typename Compare, typename A, typename B, bool = is_json_pointer_of<A, B>::value>
|
||||
struct is_comparable : std::false_type {};
|
||||
|
||||
template<typename Compare, typename A, typename B>
|
||||
struct is_comparable<Compare, A, B, false> : is_comparable_no_json_pointer<Compare, A, B> {};
|
||||
|
||||
template<typename T>
|
||||
using detect_is_transparent = typename T::is_transparent;
|
||||
|
||||
|
||||
@@ -4462,21 +4462,35 @@ struct is_json_pointer_of<A, ::nlohmann::json_pointer<A>> : std::true_type {};
|
||||
template <typename A>
|
||||
struct is_json_pointer_of<A, ::nlohmann::json_pointer<A>&> : std::true_type {};
|
||||
|
||||
// checks if A and B are comparable using Compare functor
|
||||
// checks if A and B are comparable using Compare functor, assuming that
|
||||
// neither A nor B is a json_pointer type (that case is handled by
|
||||
// is_comparable below, which never instantiates this helper otherwise)
|
||||
template<typename Compare, typename A, typename B, typename = void>
|
||||
struct is_comparable : std::false_type {};
|
||||
struct is_comparable_no_json_pointer : std::false_type {};
|
||||
|
||||
// We exclude json_pointer here, because the checks using Compare(A, B) will
|
||||
// use json_pointer::operator string_t() which triggers a deprecation warning
|
||||
// for GCC. See https://github.com/nlohmann/json/issues/4621. The call to
|
||||
// is_json_pointer_of can be removed once the deprecated function has been
|
||||
// removed.
|
||||
template<typename Compare, typename A, typename B>
|
||||
struct is_comparable < Compare, A, B, enable_if_t < !is_json_pointer_of<A, B>::value
|
||||
&& std::is_constructible <decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>()))>::value
|
||||
struct is_comparable_no_json_pointer < Compare, A, B, enable_if_t <
|
||||
std::is_constructible <decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>()))>::value
|
||||
&& std::is_constructible <decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>::value
|
||||
>> : std::true_type {};
|
||||
|
||||
// checks if A and B are comparable using Compare functor
|
||||
// We dispatch on is_json_pointer_of as a plain bool (rather than folding it
|
||||
// into a single enable_if_t condition together with the checks below) so
|
||||
// that the Compare(A, B) checks are only ever written - and thus only ever
|
||||
// instantiated - when A/B are not a json_pointer/string pair. Those checks
|
||||
// use json_pointer::operator string_t() (GCC, see #4621) resp. the
|
||||
// deprecated json_pointer/string operator== (Clang, see #5288), and merely
|
||||
// naming them as later operands of a plain && chain is not sufficient to
|
||||
// avoid their instantiation on all compilers, even when the first operand
|
||||
// is false. The dispatch on is_json_pointer_of can be removed once the
|
||||
// deprecated json_pointer comparison operators have been removed.
|
||||
template<typename Compare, typename A, typename B, bool = is_json_pointer_of<A, B>::value>
|
||||
struct is_comparable : std::false_type {};
|
||||
|
||||
template<typename Compare, typename A, typename B>
|
||||
struct is_comparable<Compare, A, B, false> : is_comparable_no_json_pointer<Compare, A, B> {};
|
||||
|
||||
template<typename T>
|
||||
using detect_is_transparent = typename T::is_transparent;
|
||||
|
||||
@@ -12418,24 +12432,6 @@ class binary_reader
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief create the error message for a missing/invalid length-type marker
|
||||
|
||||
Used both when reading a UBJSON/BJData string and when reading an optimized
|
||||
container size. The accepted markers depend on the input format, and the
|
||||
size variant appends " after '#'" via @a infix.
|
||||
|
||||
@param[in] last_token the offending byte as returned by get_token_string()
|
||||
@param[in] infix extra context inserted after the marker list
|
||||
@return the formatted error message
|
||||
*/
|
||||
std::string unexpected_length_type_message(const std::string& last_token, const char* infix) const
|
||||
{
|
||||
return concat("expected length type specification (",
|
||||
input_format == input_format_t::bjdata ? "U, i, u, I, m, l, M, L" : "U, i, I, l, L",
|
||||
")", infix, "; last byte: 0x", last_token);
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief reads a UBJSON string
|
||||
|
||||
@@ -12528,8 +12524,17 @@ class binary_reader
|
||||
break;
|
||||
}
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
|
||||
exception_message(input_format, unexpected_length_type_message(last_token, ""), "string"), nullptr));
|
||||
std::string message;
|
||||
|
||||
if (input_format != input_format_t::bjdata)
|
||||
{
|
||||
message = "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
|
||||
}
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, "string"), nullptr));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -12808,8 +12813,17 @@ class binary_reader
|
||||
break;
|
||||
}
|
||||
auto last_token = get_token_string();
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
|
||||
exception_message(input_format, unexpected_length_type_message(last_token, " after '#'"), "size"), nullptr));
|
||||
std::string message;
|
||||
|
||||
if (input_format != input_format_t::bjdata)
|
||||
{
|
||||
message = "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
|
||||
}
|
||||
return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, "size"), nullptr));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user