From 31b51c95db1c7514c32923f4a4cea1444b5e29e7 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 17 Nov 2026 16:43:55 +0100 Subject: [PATCH] Name the UTF-8 cut helpers after what they do to the buffer Signed-off-by: Niels Lohmann --- include/nlohmann/detail/input/lexer.hpp | 10 +++++----- single_include/nlohmann/json.hpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index a67af2712..90c5079c4 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -2282,11 +2282,11 @@ scan_number_done: // the lexer reads bytes (wide characters arrive as UTF-8), so // move both cuts to character boundaries to keep the message // valid UTF-8; this only shortens the two parts - const auto head_end = chars.begin() + static_cast(utf8_head_cut(chars.data(), shown)); + const auto head_end = chars.begin() + static_cast(length_without_partial_utf8_at_end(chars.data(), shown)); const auto tail_begin = chars.end() - static_cast(shown); append_escaped(result, chars.begin(), head_end); result += "..."; - append_escaped(result, tail_begin + static_cast(utf8_tail_skip(&*tail_begin)), chars.end()); + append_escaped(result, tail_begin + static_cast(partial_utf8_length_at_start(&*tail_begin)), chars.end()); } else { @@ -2309,7 +2309,7 @@ scan_number_done: Looks only at the last 4 of these characters: in valid UTF-8, at most 3 bytes of a character can be before the cut. */ - static std::size_t utf8_head_cut(const char_type* data, const std::size_t n) noexcept + static std::size_t length_without_partial_utf8_at_end(const char_type* data, const std::size_t n) noexcept { std::size_t lead = n - 1; while (lead > n - 4 && is_utf8_continuation(data[lead])) @@ -2333,9 +2333,9 @@ scan_number_done: return lead + length > n ? lead : n; } - /// the number of UTF-8 continuation bytes (at most 3) at @a data, which + /// the number of UTF-8 continuation bytes (at most 3) at the start of @a data, which /// belong to a character that begins before it - static std::size_t utf8_tail_skip(const char_type* data) noexcept + static std::size_t partial_utf8_length_at_start(const char_type* data) noexcept { std::size_t skip = 0; while (skip < 3 && is_utf8_continuation(data[skip])) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 5a18ec9e3..9d5a31102 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15785,11 +15785,11 @@ scan_number_done: // the lexer reads bytes (wide characters arrive as UTF-8), so // move both cuts to character boundaries to keep the message // valid UTF-8; this only shortens the two parts - const auto head_end = chars.begin() + static_cast(utf8_head_cut(chars.data(), shown)); + const auto head_end = chars.begin() + static_cast(length_without_partial_utf8_at_end(chars.data(), shown)); const auto tail_begin = chars.end() - static_cast(shown); append_escaped(result, chars.begin(), head_end); result += "..."; - append_escaped(result, tail_begin + static_cast(utf8_tail_skip(&*tail_begin)), chars.end()); + append_escaped(result, tail_begin + static_cast(partial_utf8_length_at_start(&*tail_begin)), chars.end()); } else { @@ -15812,7 +15812,7 @@ scan_number_done: Looks only at the last 4 of these characters: in valid UTF-8, at most 3 bytes of a character can be before the cut. */ - static std::size_t utf8_head_cut(const char_type* data, const std::size_t n) noexcept + static std::size_t length_without_partial_utf8_at_end(const char_type* data, const std::size_t n) noexcept { std::size_t lead = n - 1; while (lead > n - 4 && is_utf8_continuation(data[lead])) @@ -15836,9 +15836,9 @@ scan_number_done: return lead + length > n ? lead : n; } - /// the number of UTF-8 continuation bytes (at most 3) at @a data, which + /// the number of UTF-8 continuation bytes (at most 3) at the start of @a data, which /// belong to a character that begins before it - static std::size_t utf8_tail_skip(const char_type* data) noexcept + static std::size_t partial_utf8_length_at_start(const char_type* data) noexcept { std::size_t skip = 0; while (skip < 3 && is_utf8_continuation(data[skip]))