mirror of
https://github.com/nlohmann/json.git
synced 2026-04-15 12:38:54 +00:00
🚧 first implementation for keep
This commit is contained in:
@@ -44,7 +44,8 @@ enum class error_handler_t
|
||||
{
|
||||
strict, ///< throw a type_error exception in case of invalid UTF-8
|
||||
replace, ///< replace invalid UTF-8 sequences with U+FFFD
|
||||
ignore ///< ignore invalid UTF-8 sequences
|
||||
ignore, ///< ignore invalid UTF-8 sequences
|
||||
keep ///< keep invalid UTF-8 sequences
|
||||
};
|
||||
|
||||
template<typename BasicJsonType>
|
||||
@@ -398,6 +399,13 @@ class serializer
|
||||
std::size_t bytes_after_last_accept = 0;
|
||||
std::size_t undumped_chars = 0;
|
||||
|
||||
// copy string as-is if error handler is set to keep
|
||||
if (error_handler == error_handler_t::keep)
|
||||
{
|
||||
o->write_characters(s.data(), s.size());
|
||||
return;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < s.size(); ++i)
|
||||
{
|
||||
const auto byte = static_cast<std::uint8_t>(s[i]);
|
||||
@@ -529,12 +537,6 @@ class serializer
|
||||
// thus removing/ignoring the invalid characters
|
||||
bytes = bytes_after_last_accept;
|
||||
|
||||
// fix for #4552
|
||||
if (error_handler == error_handler_t::ignore)
|
||||
{
|
||||
bytes += undumped_chars;
|
||||
}
|
||||
|
||||
if (error_handler == error_handler_t::replace)
|
||||
{
|
||||
// add a replacement character
|
||||
|
||||
Reference in New Issue
Block a user