mirror of
https://github.com/nlohmann/json.git
synced 2026-11-02 19:05:35 +00:00
Move the fraction only for a multibyte decimal point
For a one-byte decimal point, the std::copy() call had its destination at the start of its source range, which std::copy() does not allow. The bytes are now moved only when the decimal point is longer than the '.' it is replaced with. Also name the right place of get_decimal_point(). Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
2 files changed
+24
-14
No files matched your search
Generated
+12
-7
@@ -37343,8 +37343,9 @@ class serializer
|
||||
JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size());
|
||||
|
||||
// look up the locale's decimal point now, matching what
|
||||
// snprintf_float() just used (see lexer::get_decimal_point()); it is a
|
||||
// string, which can be longer than one byte (U+066B in ps_AF, #5993).
|
||||
// snprintf_float() just used (see get_decimal_point() in
|
||||
// number_parse.hpp); it is a string, which can be longer than one
|
||||
// byte (U+066B in ps_AF, #5993).
|
||||
// A thousands separator needs no handling: %g never groups digits.
|
||||
const auto* loc = std::localeconv();
|
||||
JSON_ASSERT(loc != nullptr);
|
||||
@@ -37361,11 +37362,15 @@ class serializer
|
||||
if (dec_pos != last)
|
||||
{
|
||||
*dec_pos = '.';
|
||||
// move the fraction and exponent behind the '.' (a no-op for a one-byte decimal point)
|
||||
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::copy returns an iterator, see https://github.com/nlohmann/json/issues/3081
|
||||
const auto end = std::copy(dec_pos + static_cast<std::ptrdiff_t>(decimal_point_len), last, dec_pos + 1);
|
||||
*end = '\0';
|
||||
len = end - first;
|
||||
if (decimal_point_len > 1)
|
||||
{
|
||||
// move the fraction and exponent behind the '.' (std::copy
|
||||
// allows the overlap, as the destination is before the source)
|
||||
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::copy returns an iterator, see https://github.com/nlohmann/json/issues/3081
|
||||
const auto end = std::copy(dec_pos + static_cast<std::ptrdiff_t>(decimal_point_len), last, dec_pos + 1);
|
||||
*end = '\0';
|
||||
len = end - first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user