🚧 fixed an issue with ensure_ascii #1198

This commit is contained in:
Niels Lohmann 2018-10-22 15:53:36 +02:00
parent c7af027cbb
commit c51b1e6fab
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
3 changed files with 20 additions and 2 deletions

View file

@ -302,6 +302,7 @@ class serializer
// number of bytes written at the point of the last valid byte
std::size_t bytes_after_last_accept = 0;
std::size_t undumped_chars = 0;
for (std::size_t i = 0; i < s.size(); ++i)
{
@ -403,6 +404,7 @@ class serializer
// remember the byte position of this accept
bytes_after_last_accept = bytes;
undumped_chars = 0;
break;
}
@ -424,7 +426,7 @@ class serializer
// would like to read it again, because the byte
// may be OK for itself, but just not OK for the
// previous sequence
if (bytes_after_last_accept != bytes)
if (undumped_chars > 0)
{
--i;
}
@ -454,6 +456,8 @@ class serializer
bytes_after_last_accept = bytes;
}
undumped_chars = 0;
// continue processing the string
state = UTF8_ACCEPT;
continue;
@ -468,6 +472,7 @@ class serializer
// code point will not be escaped - copy byte to buffer
string_buffer[bytes++] = s[i];
}
++undumped_chars;
break;
}
}