From a9b0e6b843bf685c8045d3e16fc1ad35af3c4e49 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 13 Oct 2026 19:06:19 +0200 Subject: [PATCH] Address review: std::any_of in has_nonzero_digit, comment punctuation Signed-off-by: Niels Lohmann --- include/nlohmann/detail/input/lexer.hpp | 4 ++-- include/nlohmann/detail/input/number_parse.hpp | 11 ++++------- single_include/nlohmann/json.hpp | 15 ++++++--------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 2ded0ea4e..d0e90d32b 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -239,9 +239,9 @@ class lexer : public lexer_base /// calls would (bulk_scan implies lazy_position, so there are no position /// counters to advance) and leaves @a current holding the last of /// the 4 digits, just as the last such get() would; the codepoint is - /// written to @a out. Makes no state change and returns false - for a + /// written to @a out. Makes no state change and returns false for a /// pending unget, fewer than 4 remaining bytes, or any of the 4 bytes not - /// being a hex digit - so the caller falls back unchanged to the + /// being a hex digit, so the caller falls back unchanged to the /// per-character loop, which then reports the same diagnostic (stopping /// at the first invalid digit) as before this optimization. bool get_codepoint_bulk(std::true_type /*bulk*/, int& out) diff --git a/include/nlohmann/detail/input/number_parse.hpp b/include/nlohmann/detail/input/number_parse.hpp index e12f5bcf7..835e623d2 100644 --- a/include/nlohmann/detail/input/number_parse.hpp +++ b/include/nlohmann/detail/input/number_parse.hpp @@ -9,6 +9,7 @@ #pragma once +#include // any_of #include // array #include // FLT_EVAL_METHOD #include // localeconv @@ -260,14 +261,10 @@ inline std::uint32_t parse_eight_digits(std::uint64_t v) noexcept /// whether [first, last) contains a digit other than '0' inline bool has_nonzero_digit(const char* first, const char* last) noexcept { - for (; first != last; ++first) + return std::any_of(first, last, [](char c) noexcept { - if (*first != '0') - { - return true; - } - } - return false; + return c != '0'; + }); } /// the value of the validated exponent digits [+-]?[0-9]+ in [first, last), diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 5780d57f0..7f83650f7 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -9076,6 +9076,7 @@ NLOHMANN_JSON_NAMESPACE_END +#include // any_of #include // array #include // FLT_EVAL_METHOD #include // localeconv @@ -9706,14 +9707,10 @@ inline std::uint32_t parse_eight_digits(std::uint64_t v) noexcept /// whether [first, last) contains a digit other than '0' inline bool has_nonzero_digit(const char* first, const char* last) noexcept { - for (; first != last; ++first) + return std::any_of(first, last, [](char c) noexcept { - if (*first != '0') - { - return true; - } - } - return false; + return c != '0'; + }); } /// the value of the validated exponent digits [+-]?[0-9]+ in [first, last), @@ -11076,9 +11073,9 @@ class lexer : public lexer_base /// calls would (bulk_scan implies lazy_position, so there are no position /// counters to advance) and leaves @a current holding the last of /// the 4 digits, just as the last such get() would; the codepoint is - /// written to @a out. Makes no state change and returns false - for a + /// written to @a out. Makes no state change and returns false for a /// pending unget, fewer than 4 remaining bytes, or any of the 4 bytes not - /// being a hex digit - so the caller falls back unchanged to the + /// being a hex digit, so the caller falls back unchanged to the /// per-character loop, which then reports the same diagnostic (stopping /// at the first invalid digit) as before this optimization. bool get_codepoint_bulk(std::true_type /*bulk*/, int& out)