mirror of
https://github.com/nlohmann/json.git
synced 2026-10-23 22:38:55 +00:00
Add shared detail helpers for the #5891 cleanup
Add detail::is_primitive(value_t), detail::hex4_lower(), detail::utf8_shape(), detail::input_format_name(), detail::empty_input_message(), the exception ids 116, 319, 320 and 416 to detail::exception_id, and make detail::is_ascii_copyable() constexpr. Later commits switch the duplicated code over to them. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
5 files changed
+142
-1
No files matched your search
@@ -67,6 +67,36 @@ namespace detail
|
||||
/// the supported input formats
|
||||
enum class input_format_t { json, cbor, msgpack, ubjson, bson, bjdata, bon8 };
|
||||
|
||||
/// @return the name of a binary input format, as used in exception messages
|
||||
inline const char* input_format_name(const input_format_t format) noexcept
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case input_format_t::cbor:
|
||||
return "CBOR";
|
||||
case input_format_t::msgpack:
|
||||
return "MessagePack";
|
||||
case input_format_t::ubjson:
|
||||
return "UBJSON";
|
||||
case input_format_t::bson:
|
||||
return "BSON";
|
||||
case input_format_t::bjdata:
|
||||
return "BJData";
|
||||
case input_format_t::bon8:
|
||||
return "BON8";
|
||||
case input_format_t::json: // LCOV_EXCL_LINE
|
||||
default: // LCOV_EXCL_LINE
|
||||
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
||||
return ""; // LCOV_EXCL_LINE
|
||||
}
|
||||
}
|
||||
|
||||
/// @return the message of the parse_error thrown or reported for an empty input
|
||||
inline const char* empty_input_message() noexcept
|
||||
{
|
||||
return "attempting to parse an empty input; check that your input string or stream contains the expected JSON";
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// input adapters //
|
||||
////////////////////
|
||||
|
||||
@@ -96,7 +96,7 @@ JSON_HEDLEY_ALWAYS_INLINE std::size_t find_string_special(const unsigned char* d
|
||||
// printable ASCII except '"' and '\\' - is emitted unchanged. Note this differs
|
||||
// from is_string_special() only in that 0x7F is also a stop (it is escaped as
|
||||
// \u007f under ensure_ascii).
|
||||
inline bool is_ascii_copyable(unsigned char c) noexcept
|
||||
constexpr bool is_ascii_copyable(unsigned char c) noexcept
|
||||
{
|
||||
return c >= 0x20u && c < 0x7Fu && c != '"' && c != '\\';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user