mirror of
https://github.com/nlohmann/json.git
synced 2026-10-03 21:20:30 +00:00
Name JSON types without a basic_json value
basic_json::type_name() now calls detail::value_type_name(value_t), so that code which reports types without a basic_json value at hand, such as the zero-copy view, uses the same names in its exception messages. No change in behavior. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -67,6 +67,39 @@ enum class value_t : std::uint8_t
|
|||||||
discarded ///< discarded by the parser callback function
|
discarded ///< discarded by the parser callback function
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief the name of a JSON type, as returned by basic_json::type_name()
|
||||||
|
|
||||||
|
Used in exception messages; also by code that reports types without a
|
||||||
|
basic_json value at hand (such as the zero-copy view).
|
||||||
|
*/
|
||||||
|
inline const char* value_type_name(const value_t t) noexcept
|
||||||
|
{
|
||||||
|
switch (t)
|
||||||
|
{
|
||||||
|
case value_t::null:
|
||||||
|
return "null";
|
||||||
|
case value_t::object:
|
||||||
|
return "object";
|
||||||
|
case value_t::array:
|
||||||
|
return "array";
|
||||||
|
case value_t::string:
|
||||||
|
return "string";
|
||||||
|
case value_t::boolean:
|
||||||
|
return "boolean";
|
||||||
|
case value_t::binary:
|
||||||
|
return "binary";
|
||||||
|
case value_t::discarded:
|
||||||
|
return "discarded";
|
||||||
|
case value_t::number_integer:
|
||||||
|
case value_t::number_unsigned:
|
||||||
|
case value_t::number_float:
|
||||||
|
return "number";
|
||||||
|
default:
|
||||||
|
return "invalid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief comparison operator for JSON types
|
@brief comparison operator for JSON types
|
||||||
|
|
||||||
|
|||||||
@@ -5067,29 +5067,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
JSON_HEDLEY_RETURNS_NON_NULL
|
JSON_HEDLEY_RETURNS_NON_NULL
|
||||||
const char* type_name() const noexcept
|
const char* type_name() const noexcept
|
||||||
{
|
{
|
||||||
switch (m_data.m_type)
|
return detail::value_type_name(m_data.m_type);
|
||||||
{
|
|
||||||
case value_t::null:
|
|
||||||
return "null";
|
|
||||||
case value_t::object:
|
|
||||||
return "object";
|
|
||||||
case value_t::array:
|
|
||||||
return "array";
|
|
||||||
case value_t::string:
|
|
||||||
return "string";
|
|
||||||
case value_t::boolean:
|
|
||||||
return "boolean";
|
|
||||||
case value_t::binary:
|
|
||||||
return "binary";
|
|
||||||
case value_t::discarded:
|
|
||||||
return "discarded";
|
|
||||||
case value_t::number_integer:
|
|
||||||
case value_t::number_unsigned:
|
|
||||||
case value_t::number_float:
|
|
||||||
return "number";
|
|
||||||
default:
|
|
||||||
return "invalid";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED:
|
JSON_PRIVATE_UNLESS_TESTED:
|
||||||
|
|||||||
@@ -3381,6 +3381,39 @@ enum class value_t : std::uint8_t
|
|||||||
discarded ///< discarded by the parser callback function
|
discarded ///< discarded by the parser callback function
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief the name of a JSON type, as returned by basic_json::type_name()
|
||||||
|
|
||||||
|
Used in exception messages; also by code that reports types without a
|
||||||
|
basic_json value at hand (such as the zero-copy view).
|
||||||
|
*/
|
||||||
|
inline const char* value_type_name(const value_t t) noexcept
|
||||||
|
{
|
||||||
|
switch (t)
|
||||||
|
{
|
||||||
|
case value_t::null:
|
||||||
|
return "null";
|
||||||
|
case value_t::object:
|
||||||
|
return "object";
|
||||||
|
case value_t::array:
|
||||||
|
return "array";
|
||||||
|
case value_t::string:
|
||||||
|
return "string";
|
||||||
|
case value_t::boolean:
|
||||||
|
return "boolean";
|
||||||
|
case value_t::binary:
|
||||||
|
return "binary";
|
||||||
|
case value_t::discarded:
|
||||||
|
return "discarded";
|
||||||
|
case value_t::number_integer:
|
||||||
|
case value_t::number_unsigned:
|
||||||
|
case value_t::number_float:
|
||||||
|
return "number";
|
||||||
|
default:
|
||||||
|
return "invalid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief comparison operator for JSON types
|
@brief comparison operator for JSON types
|
||||||
|
|
||||||
@@ -32023,29 +32056,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
JSON_HEDLEY_RETURNS_NON_NULL
|
JSON_HEDLEY_RETURNS_NON_NULL
|
||||||
const char* type_name() const noexcept
|
const char* type_name() const noexcept
|
||||||
{
|
{
|
||||||
switch (m_data.m_type)
|
return detail::value_type_name(m_data.m_type);
|
||||||
{
|
|
||||||
case value_t::null:
|
|
||||||
return "null";
|
|
||||||
case value_t::object:
|
|
||||||
return "object";
|
|
||||||
case value_t::array:
|
|
||||||
return "array";
|
|
||||||
case value_t::string:
|
|
||||||
return "string";
|
|
||||||
case value_t::boolean:
|
|
||||||
return "boolean";
|
|
||||||
case value_t::binary:
|
|
||||||
return "binary";
|
|
||||||
case value_t::discarded:
|
|
||||||
return "discarded";
|
|
||||||
case value_t::number_integer:
|
|
||||||
case value_t::number_unsigned:
|
|
||||||
case value_t::number_float:
|
|
||||||
return "number";
|
|
||||||
default:
|
|
||||||
return "invalid";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED:
|
JSON_PRIVATE_UNLESS_TESTED:
|
||||||
|
|||||||
Reference in New Issue
Block a user