mirror of
https://github.com/nlohmann/json.git
synced 2026-10-03 05:00:30 +00:00
Under a locale whose decimal point is longer than one byte (e.g. U+066B in fa_IR.UTF-8 or ar_EG.UTF-8), every float that reached the strtod fallback was truncated at the decimal point: "3.14159265358979323846" became 3.0, and "1.5e400" became 1.0 instead of throwing. With libc++ and in C++11/14, that fallback was taken for most floats. The lexer now converts floats in this order: 1. std::from_chars, now also for float and double with libc++ 20 or later, which does not define __cpp_lib_to_chars (on Apple platforms only if the deployment target provides it); 2. Clinger's fast path (double only); 3. strtof_l/strtod_l/strtold_l with a "C" locale created once, on glibc, Apple platforms, and MSVC; 4. strtof/strtod/strtold with the decimal point of the current locale, which now puts a multi-byte decimal point into a copy of the token. If std::from_chars reports a value out of range, the result is derived from the token (+-infinity or +-0) instead of calling strtod, because implementations disagree on the stored value (P4168). Values that may be subnormal are left to the next step, because libstdc++ before GCC 13 reports some of them as out of range. The conversion helpers moved from the lexer to number_parse.hpp, so the last-resort path can be tested directly. Fixes #5660. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
55 lines
1.5 KiB
C++
55 lines
1.5 KiB
C++
// __ _____ _____ _____
|
|
// __| | __| | | | JSON for Modern C++
|
|
// | | |__ | | | | | | version 3.12.0
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
//
|
|
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
// restore clang diagnostic settings
|
|
#if defined(__clang__)
|
|
#pragma clang diagnostic pop
|
|
#endif
|
|
|
|
// clean up
|
|
#undef JSON_ASSERT
|
|
#undef JSON_INTERNAL_CATCH
|
|
#undef JSON_THROW
|
|
#undef JSON_PRIVATE_UNLESS_TESTED
|
|
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
|
#undef NLOHMANN_BASIC_JSON_TPL
|
|
#undef JSON_EXPLICIT
|
|
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
|
|
#undef JSON_INLINE_VARIABLE
|
|
#undef JSON_NO_UNIQUE_ADDRESS
|
|
#undef JSON_DISABLE_ENUM_SERIALIZATION
|
|
#undef JSON_USE_GLOBAL_UDLS
|
|
|
|
#ifndef JSON_TEST_KEEP_MACROS
|
|
#undef JSON_CATCH
|
|
#undef JSON_TRY
|
|
#undef JSON_HAS_CPP_11
|
|
#undef JSON_HAS_CPP_14
|
|
#undef JSON_HAS_CPP_17
|
|
#undef JSON_HAS_CPP_20
|
|
#undef JSON_HAS_CPP_23
|
|
#undef JSON_HAS_CPP_26
|
|
#undef JSON_HAS_FILESYSTEM
|
|
#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
|
|
#undef JSON_HAS_THREE_WAY_COMPARISON
|
|
#undef JSON_HAS_RANGES
|
|
#undef JSON_HAS_STD_FORMAT
|
|
#undef JSON_HAS_STATIC_RTTI
|
|
#undef JSON_HAS_FLOAT_FROM_CHARS
|
|
#undef JSON_HAS_LONG_DOUBLE_FROM_CHARS
|
|
#undef JSON_HAS_C_LOCALE_STRTOD
|
|
#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
|
|
#undef JSON_BRACE_INIT_COPY_SEMANTICS
|
|
#undef JSON_PRECISE_STREAM_POSITION
|
|
#undef JSON_STRICT_NUL_HANDLING
|
|
#endif
|
|
|
|
#include <nlohmann/thirdparty/hedley/hedley_undef.hpp>
|