mirror of
https://github.com/nlohmann/json.git
synced 2026-10-05 14:10:31 +00:00
Merge #5741 and make keep the default error_handler of the binary writers
Merges claude/binary-utf8-roundtrip-5651, where the writers now only check UTF-8 if JSON_STRICT_BINARY_UTF8 is enabled, and applies the same rule to the error_handler parameter added here: to_cbor(), to_ubjson(), to_bjdata(), and to_bson() default to error_handler_t::keep, the behavior of 3.12.0, or to error_handler_t::strict if JSON_STRICT_BINARY_UTF8 is enabled (detail::binary_writer_default_error_handler()). Passing a handler explicitly always takes precedence. - Conflicts in binary_writer.hpp resolved in favor of this branch's error_handler, which replaces #5741's check_text_utf8(). - Tests: the "default parameters" section checks that the default equals keep; unit-binary_utf8_strict.cpp checks that an explicit handler overrides the macro's default. - Docs: signatures show keep; parameter, exception, and format pages describe keep as the default and the macro; the two 3.13.0 version history entries of each writer are merged into one. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -34,5 +34,17 @@ enum class error_handler_t
|
||||
keep ///< keep invalid UTF-8 sequences unchanged
|
||||
};
|
||||
|
||||
/// the default error handler of the CBOR, UBJSON, BJData, and BSON writers:
|
||||
/// error_handler_t::strict if JSON_STRICT_BINARY_UTF8 is enabled, otherwise
|
||||
/// error_handler_t::keep (the behavior before version 3.13.0)
|
||||
constexpr error_handler_t binary_writer_default_error_handler() noexcept
|
||||
{
|
||||
#if JSON_STRICT_BINARY_UTF8
|
||||
return error_handler_t::strict;
|
||||
#else
|
||||
return error_handler_t::keep;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
Reference in New Issue
Block a user