mirror of
https://github.com/nlohmann/json.git
synced 2025-08-06 19:16:31 +08:00
♻️ simplify code
This commit is contained in:
parent
a83404525e
commit
1d6ba22f15
@ -30,6 +30,7 @@ class binary_writer
|
||||
using string_t = typename BasicJsonType::string_t;
|
||||
using binary_t = typename BasicJsonType::binary_t;
|
||||
using number_float_t = typename BasicJsonType::number_float_t;
|
||||
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
|
||||
|
||||
public:
|
||||
/*!
|
||||
@ -58,7 +59,7 @@ class binary_writer
|
||||
|
||||
default:
|
||||
{
|
||||
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j)));;
|
||||
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)));;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -907,7 +908,7 @@ class binary_writer
|
||||
const auto it = name.find(static_cast<typename string_t::value_type>(0));
|
||||
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) + ")", detail::diagnostics_t<BasicJsonType>(j)));
|
||||
JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", diagnostics_t(j)));
|
||||
}
|
||||
|
||||
return /*id*/ 1ul + name.size() + /*zero-terminator*/1u;
|
||||
@ -1031,7 +1032,7 @@ class binary_writer
|
||||
}
|
||||
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", detail::diagnostics_t<BasicJsonType>(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", diagnostics_t(j)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ class serializer
|
||||
using number_integer_t = typename BasicJsonType::number_integer_t;
|
||||
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
|
||||
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_REJECT = 1;
|
||||
|
||||
@ -500,7 +501,7 @@ class serializer
|
||||
{
|
||||
std::string sn(3, '\0');
|
||||
(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, detail::diagnostics_t<BasicJsonType>()));
|
||||
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, diagnostics_t()));
|
||||
}
|
||||
|
||||
case error_handler_t::ignore:
|
||||
@ -594,7 +595,7 @@ class serializer
|
||||
{
|
||||
std::string sn(3, '\0');
|
||||
(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, detail::diagnostics_t<BasicJsonType>()));
|
||||
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, diagnostics_t()));
|
||||
}
|
||||
|
||||
case error_handler_t::ignore:
|
||||
|
@ -12992,6 +12992,7 @@ class binary_writer
|
||||
using string_t = typename BasicJsonType::string_t;
|
||||
using binary_t = typename BasicJsonType::binary_t;
|
||||
using number_float_t = typename BasicJsonType::number_float_t;
|
||||
using diagnostics_t = detail::diagnostics_t<BasicJsonType>;
|
||||
|
||||
public:
|
||||
/*!
|
||||
@ -13020,7 +13021,7 @@ class binary_writer
|
||||
|
||||
default:
|
||||
{
|
||||
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), detail::diagnostics_t<BasicJsonType>(j)));;
|
||||
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)));;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13869,7 +13870,7 @@ class binary_writer
|
||||
const auto it = name.find(static_cast<typename string_t::value_type>(0));
|
||||
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) + ")", detail::diagnostics_t<BasicJsonType>(j)));
|
||||
JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", diagnostics_t(j)));
|
||||
}
|
||||
|
||||
return /*id*/ 1ul + name.size() + /*zero-terminator*/1u;
|
||||
@ -13993,7 +13994,7 @@ class binary_writer
|
||||
}
|
||||
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", detail::diagnostics_t<BasicJsonType>(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", diagnostics_t(j)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -15720,6 +15721,7 @@ class serializer
|
||||
using number_integer_t = typename BasicJsonType::number_integer_t;
|
||||
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
|
||||
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_REJECT = 1;
|
||||
|
||||
@ -16175,7 +16177,7 @@ class serializer
|
||||
{
|
||||
std::string sn(3, '\0');
|
||||
(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, detail::diagnostics_t<BasicJsonType>()));
|
||||
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, diagnostics_t()));
|
||||
}
|
||||
|
||||
case error_handler_t::ignore:
|
||||
@ -16269,7 +16271,7 @@ class serializer
|
||||
{
|
||||
std::string sn(3, '\0');
|
||||
(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, detail::diagnostics_t<BasicJsonType>()));
|
||||
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, diagnostics_t()));
|
||||
}
|
||||
|
||||
case error_handler_t::ignore:
|
||||
|
Loading…
Reference in New Issue
Block a user