* ✏️ fix typos

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* ✏️ address review comments

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* ✏️ address review comments

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2025-05-04 10:28:24 +02:00
committed by GitHub
parent 0a8b48ac6a
commit 9110918cf8
42 changed files with 329 additions and 325 deletions

View File

@@ -398,7 +398,7 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
}
// overload for arithmetic types, not chosen for basic_json template arguments
// (BooleanType, etc..); note: Is it really necessary to provide explicit
// (BooleanType, etc.); note: Is it really necessary to provide explicit
// overloads for boolean_t etc. in case of a custom BooleanType which is not
// an arithmetic type?
template < typename BasicJsonType, typename ArithmeticType,

View File

@@ -130,7 +130,7 @@ struct diyfp // f * 2^e
// p_lo = p0_lo + (Q << 32)
//
// But in this particular case here, the full p_lo is not required.
// Effectively we only need to add the highest bit in p_lo to p_hi (and
// Effectively, we only need to add the highest bit in p_lo to p_hi (and
// Q_hi + 1 does not overflow).
Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up
@@ -220,7 +220,7 @@ boundaries compute_boundaries(FloatType value)
// Compute the boundaries m- and m+ of the floating-point value
// v = f * 2^e.
//
// Determine v- and v+, the floating-point predecessor and successor if v,
// Determine v- and v+, the floating-point predecessor and successor of v,
// respectively.
//
// v- = v - 2^e if f != 2^(p-1) or e == e_min (A)
@@ -375,7 +375,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e)
// (A smaller distance gamma-alpha would require a larger table.)
// NB:
// Actually this function returns c, such that -60 <= e_c + e + 64 <= -34.
// Actually, this function returns c, such that -60 <= e_c + e + 64 <= -34.
constexpr int kCachedPowersMinDecExp = -300;
constexpr int kCachedPowersDecStep = 8;
@@ -687,8 +687,8 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,
decimal_exponent += n;
// We may now just stop. But instead look if the buffer could be
// decremented to bring V closer to w.
// We may now just stop. But instead, it looks as if the buffer
// could be decremented to bring V closer to w.
//
// pow10 = 10^n is now 1 ulp in the decimal representation V.
// The rounding procedure works with diyfp's with an implicit
@@ -1095,7 +1095,7 @@ char* to_chars(char* first, const char* last, FloatType value)
// Compute v = buffer * 10^decimal_exponent.
// The decimal digits are stored in the buffer, which needs to be interpreted
// as an unsigned decimal integer.
// len is the length of the buffer, i.e. the number of decimal digits.
// len is the length of the buffer, i.e., the number of decimal digits.
int len = 0;
int decimal_exponent = 0;
dtoa_impl::grisu2(first, len, decimal_exponent, value);

View File

@@ -30,7 +30,7 @@
// emitted in every translation unit. This issue cannot be fixed with a
// header-only library as there is no implementation file to move these
// functions to. As a result, we suppress this warning here to avoid client
// code to stumble over this. See https://github.com/nlohmann/json/issues/4087
// code stumbling over this. See https://github.com/nlohmann/json/issues/4087
// for a discussion.
#if defined(__clang__)
#pragma clang diagnostic push

View File

@@ -334,7 +334,7 @@ class binary_reader
return get_number<std::uint64_t, true>(input_format_t::bson, value) && sax->number_unsigned(value);
}
default: // anything else not supported (yet)
default: // anything else is not supported (yet)
{
std::array<char, 3> cr{{}};
static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
@@ -731,7 +731,7 @@ class binary_reader
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD8: // tagged item (1 bytes follow)
case 0xD8: // tagged item (1 byte follows)
case 0xD9: // tagged item (2 bytes follow)
case 0xDA: // tagged item (4 bytes follow)
case 0xDB: // tagged item (8 bytes follow)
@@ -783,7 +783,7 @@ class binary_reader
case cbor_tag_handler_t::store:
{
binary_t b;
// use binary subtype and store in binary container
// use binary subtype and store in a binary container
switch (current)
{
case 0xD8:
@@ -852,7 +852,7 @@ class binary_reader
const auto byte1 = static_cast<unsigned char>(byte1_raw);
const auto byte2 = static_cast<unsigned char>(byte2_raw);
// code from RFC 7049, Appendix D, Figure 3:
// Code from RFC 7049, Appendix D, Figure 3:
// As half-precision floating-point numbers were only added
// to IEEE 754 in 2008, today's programming platforms often
// still only have limited support for them. It is very
@@ -2159,7 +2159,7 @@ class binary_reader
{
break;
}
if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array
if (is_ndarray) // ndarray dimensional vector can only contain integers and cannot embed another array
{
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr));
}
@@ -2417,7 +2417,7 @@ class binary_reader
const auto byte1 = static_cast<unsigned char>(byte1_raw);
const auto byte2 = static_cast<unsigned char>(byte2_raw);
// code from RFC 7049, Appendix D, Figure 3:
// Code from RFC 7049, Appendix D, Figure 3:
// As half-precision floating-point numbers were only added
// to IEEE 754 in 2008, today's programming platforms often
// still only have limited support for them. It is very
@@ -2705,7 +2705,7 @@ class binary_reader
bool get_ubjson_high_precision_number()
{
// get size of following number string
// get the size of the following number string
std::size_t size{};
bool no_ndarray = true;
auto res = get_ubjson_size_value(size, no_ndarray);
@@ -2803,7 +2803,7 @@ class binary_reader
chars_read += new_chars_read;
if (JSON_HEDLEY_UNLIKELY(new_chars_read < sizeof(T)))
{
// in case of failure, advance position by 1 to report failing location
// in case of failure, advance position by 1 to report the failing location
++chars_read;
sax->parse_error(chars_read, "<end of file>", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
return false;

View File

@@ -108,7 +108,7 @@ class input_stream_adapter
: is(&i), sb(i.rdbuf())
{}
// delete because of pointer members
// deleted because of pointer members
input_stream_adapter(const input_stream_adapter&) = delete;
input_stream_adapter& operator=(input_stream_adapter&) = delete;
input_stream_adapter& operator=(input_stream_adapter&&) = delete;
@@ -122,7 +122,7 @@ class input_stream_adapter
// std::istream/std::streambuf use std::char_traits<char>::to_int_type, to
// ensure that std::char_traits<char>::eof() and the character 0xFF do not
// end up as the same value, e.g. 0xFFFFFFFF.
// end up as the same value, e.g., 0xFFFFFFFF.
std::char_traits<char>::int_type get_character()
{
auto res = sb->sbumpc();
@@ -344,7 +344,7 @@ class wide_string_input_adapter
typename std::char_traits<char>::int_type get_character() noexcept
{
// check if buffer needs to be filled
// check if the buffer needs to be filled
if (utf8_bytes_index == utf8_bytes_filled)
{
fill_buffer<sizeof(WideCharType)>();

View File

@@ -260,7 +260,7 @@ class json_sax_dom_parser
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_object());
// add null at given key and store the reference for later
// add null at the given key and store the reference for later
object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));
return true;
}
@@ -576,11 +576,11 @@ class json_sax_dom_callback_parser
{
BasicJsonType k = BasicJsonType(val);
// check callback for key
// check callback for the key
const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k);
key_keep_stack.push_back(keep);
// add discarded value at given key and store the reference for later
// add discarded value at the given key and store the reference for later
if (keep && ref_stack.back())
{
object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded);

View File

@@ -127,7 +127,7 @@ class lexer : public lexer_base<BasicJsonType>
, decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
{}
// delete because of pointer members
// deleted because of pointer members
lexer(const lexer&) = delete;
lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
lexer& operator=(lexer&) = delete;
@@ -262,10 +262,10 @@ class lexer : public lexer_base<BasicJsonType>
while (true)
{
// get next character
// get the next character
switch (get())
{
// end of file while parsing string
// end of file while parsing the string
case char_traits<char_type>::eof():
{
error_message = "invalid string: missing closing quote";
@@ -351,7 +351,7 @@ class lexer : public lexer_base<BasicJsonType>
(static_cast<unsigned int>(codepoint1) << 10u)
// low surrogate occupies the least significant 15 bits
+ static_cast<unsigned int>(codepoint2)
// there is still the 0xD800, 0xDC00 and 0x10000 noise
// there is still the 0xD800, 0xDC00, and 0x10000 noise
// in the result, so we have to subtract with:
// (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
- 0x35FDC00u);
@@ -377,7 +377,7 @@ class lexer : public lexer_base<BasicJsonType>
}
}
// result of the above calculation yields a proper codepoint
// the result of the above calculation yields a proper codepoint
JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
// translate codepoint into bytes
@@ -828,7 +828,7 @@ class lexer : public lexer_base<BasicJsonType>
break;
}
// remaining bytes (80..C1 and F5..FF) are ill-formed
// the remaining bytes (80..C1 and F5..FF) are ill-formed
default:
{
error_message = "invalid string: ill-formed UTF-8 byte";
@@ -973,7 +973,7 @@ class lexer : public lexer_base<BasicJsonType>
reset();
// the type of the parsed number; initially set to unsigned; will be
// changed if minus sign, decimal point or exponent is read
// changed if minus sign, decimal point, or exponent is read
token_type number_type = token_type::value_unsigned;
// state (init): we just found out we need to scan a number
@@ -1345,7 +1345,7 @@ scan_number_done:
if (next_unget)
{
// just reset the next_unget variable and work with current
// only reset the next_unget variable and work with current
next_unget = false;
}
else
@@ -1524,7 +1524,7 @@ scan_number_done:
return token_type::parse_error;
}
// read next character and ignore whitespace
// read the next character and ignore whitespace
skip_whitespace();
// ignore comments

View File

@@ -106,7 +106,7 @@ class parser
exception_message(token_type::end_of_input, "value"), nullptr));
}
// in case of an error, return discarded value
// in case of an error, return a discarded value
if (sdp.is_errored())
{
result = value_t::discarded;
@@ -133,7 +133,7 @@ class parser
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr));
}
// in case of an error, return discarded value
// in case of an error, return a discarded value
if (sdp.is_errored())
{
result = value_t::discarded;
@@ -336,7 +336,7 @@ class parser
case token_type::parse_error:
{
// using "uninitialized" to avoid "expected" message
// using "uninitialized" to avoid an "expected" message
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), nullptr));

View File

@@ -23,7 +23,7 @@ NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
// forward declare, to be able to friend it later on
// forward declare to be able to friend it later on
template<typename IteratorType> class iteration_proxy;
template<typename IteratorType> class iteration_proxy_value;

View File

@@ -21,9 +21,9 @@ namespace detail
@brief an iterator for primitive JSON types
This class models an iterator for primitive JSON types (boolean, number,
string). It's only purpose is to allow the iterator/const_iterator classes
string). Its only purpose is to allow the iterator/const_iterator classes
to "iterate" over primitive values. Internally, the iterator is modeled by
a `difference_type` variable. Value begin_value (`0`) models the begin,
a `difference_type` variable. Value begin_value (`0`) models the begin and
end_value (`1`) models past the end.
*/
class primitive_iterator_t

View File

@@ -285,7 +285,7 @@ class json_pointer
{
if (reference_token == "0")
{
// start a new array if reference token is 0
// start a new array if the reference token is 0
result = &result->operator[](0);
}
else
@@ -314,7 +314,7 @@ class json_pointer
The following code is only reached if there exists a reference
token _and_ the current value is primitive. In this case, we have
an error situation, because primitive values may only occur as
single value; that is, with an empty list of reference tokens.
a single value; that is, with an empty list of reference tokens.
*/
case detail::value_t::string:
case detail::value_t::boolean:
@@ -358,7 +358,7 @@ class json_pointer
// convert null values to arrays or objects before continuing
if (ptr->is_null())
{
// check if reference token is a number
// check if the reference token is a number
const bool nums =
std::all_of(reference_token.begin(), reference_token.end(),
[](const unsigned char x)
@@ -366,7 +366,7 @@ class json_pointer
return std::isdigit(x);
});
// change value to array for numbers or "-" or to object otherwise
// change value to an array for numbers or "-" or to object otherwise
*ptr = (nums || reference_token == "-")
? detail::value_t::array
: detail::value_t::object;
@@ -609,7 +609,7 @@ class json_pointer
{
if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9')))
{
// first char should be between '1' and '9'
// the first char should be between '1' and '9'
return false;
}
for (std::size_t i = 1; i < reference_token.size(); i++)
@@ -673,7 +673,7 @@ class json_pointer
return result;
}
// check if nonempty reference string begins with slash
// check if a nonempty reference string begins with slash
if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
{
JSON_THROW(detail::parse_error::create(107, 1, detail::concat("JSON pointer must be empty or begin with '/' - was: '", reference_string, "'"), nullptr));
@@ -747,7 +747,7 @@ class json_pointer
}
else
{
// iterate array and use index as reference string
// iterate array and use index as a reference string
for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
{
flatten(detail::concat<string_t>(reference_string, '/', std::to_string(i)),
@@ -785,7 +785,7 @@ class json_pointer
case detail::value_t::discarded:
default:
{
// add primitive value with its reference string
// add a primitive value with its reference string
result[reference_string] = value;
break;
}
@@ -821,17 +821,17 @@ class json_pointer
JSON_THROW(detail::type_error::create(315, "values in object must be primitive", &element.second));
}
// assign value to reference pointed to by JSON pointer; Note that if
// the JSON pointer is "" (i.e., points to the whole value), function
// get_and_create returns a reference to result itself. An assignment
// will then create a primitive value.
// Assign the value to the reference pointed to by JSON pointer. Note
// that if the JSON pointer is "" (i.e., points to the whole value),
// function get_and_create returns a reference to the result itself.
// An assignment will then create a primitive value.
json_pointer(element.first).get_and_create(result) = element.second;
}
return result;
}
// can't use conversion operator because of ambiguity
// can't use the conversion operator because of ambiguity
json_pointer<string_t> convert() const&
{
json_pointer<string_t> result;
@@ -926,7 +926,7 @@ class json_pointer
};
#if !JSON_HAS_THREE_WAY_COMPARISON
// functions cannot be defined inside class due to ODR violations
// functions cannot be defined inside the class due to ODR violations
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
inline bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
const json_pointer<RefStringTypeRhs>& rhs) noexcept

View File

@@ -31,7 +31,7 @@
#endif
// C++ language standard detection
// if the user manually specified the used c++ version this is skipped
// if the user manually specified the used C++ version, this is skipped
#if !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
#if (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
#define JSON_HAS_CPP_23
@@ -128,7 +128,7 @@
#endif
#ifndef JSON_HAS_RANGES
// ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error
// ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error
#if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
#define JSON_HAS_RANGES 0
#elif defined(__cpp_lib_ranges)
@@ -205,7 +205,7 @@
#define JSON_ASSERT(x) assert(x)
#endif
// allow to access some private functions (needed by the test suite)
// allow accessing some private functions (needed by the test suite)
#if defined(JSON_TESTS_PRIVATE)
#define JSON_PRIVATE_UNLESS_TESTED public
#else

View File

@@ -42,12 +42,12 @@ namespace detail
// Note to maintainers:
//
// Every trait in this file expects a non CV-qualified type.
// Every trait in this file expects a non-CV-qualified type.
// The only exceptions are in the 'aliases for detected' section
// (i.e. those of the form: decltype(T::member_function(std::declval<T>())))
// (i.e., those of the form: decltype(T::member_function(std::declval<T>())))
//
// In this case, T has to be properly CV-qualified to constraint the function arguments
// (e.g. to_json(BasicJsonType&, const T&))
// (e.g., to_json(BasicJsonType&, const T&))
template<typename> struct is_basic_json : std::false_type {};
@@ -55,7 +55,7 @@ NLOHMANN_BASIC_JSON_TPL_DECLARATION
struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
// used by exceptions create() member functions
// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t
// true_type for the pointer to possibly cv-qualified basic_json or std::nullptr_t
// false_type otherwise
template<typename BasicJsonContext>
struct is_basic_json_context :
@@ -281,7 +281,7 @@ template<class B> struct negation : std::integral_constant < bool, !B::value > {
// Reimplementation of is_constructible and is_default_constructible, due to them being broken for
// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367).
// This causes compile errors in e.g. clang 3.5 or gcc 4.9.
// This causes compile errors in e.g., Clang 3.5 or GCC 4.9.
template <typename T>
struct is_default_constructible : std::is_default_constructible<T> {};
@@ -361,7 +361,7 @@ using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
// The following implementation of is_complete_type is taken from
// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/
// and is written by Xiang Fan who agreed to using it in this library.
// and is written by Xiang Fan who agreed to use it in this library.
template<typename T, typename = void>
struct is_complete_type : std::false_type {};
@@ -598,7 +598,7 @@ decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
template<typename T>
using detect_is_transparent = typename T::is_transparent;
// type trait to check if KeyType can be used as object key (without a BasicJsonType)
// type trait to check if KeyType can be used as an object key (without a BasicJsonType)
// see is_usable_as_basic_json_key_type below
template<typename Comparator, typename ObjectKeyType, typename KeyTypeCVRef, bool RequireTransparentComparator = true,
bool ExcludeObjectKeyType = RequireTransparentComparator, typename KeyType = uncvref_t<KeyTypeCVRef>>
@@ -612,7 +612,7 @@ using is_usable_as_key_type = typename std::conditional <
std::true_type,
std::false_type >::type;
// type trait to check if KeyType can be used as object key
// type trait to check if KeyType can be used as an object key
// true if:
// - KeyType is comparable with BasicJsonType::object_t::key_type
// - if ExcludeObjectKeyType is true, KeyType is not BasicJsonType::object_t::key_type

View File

@@ -1552,7 +1552,7 @@ class binary_writer
{
return 'L';
}
// anything else is treated as high-precision number
// anything else is treated as a high-precision number
return 'H'; // LCOV_EXCL_LINE
}
@@ -1590,7 +1590,7 @@ class binary_writer
{
return 'M';
}
// anything else is treated as high-precision number
// anything else is treated as a high-precision number
return 'H'; // LCOV_EXCL_LINE
}
@@ -1756,11 +1756,11 @@ class binary_writer
template<typename NumberType>
void write_number(const NumberType n, const bool OutputIsLittleEndian = false)
{
// step 1: write number to array of length NumberType
// step 1: write the number to an array of length NumberType
std::array<CharType, sizeof(NumberType)> vec{};
std::memcpy(vec.data(), &n, sizeof(NumberType));
// step 2: write array to output (with possible reordering)
// step 2: write the array to output (with possible reordering)
if (is_little_endian != OutputIsLittleEndian)
{
// reverse byte order prior to conversion if necessary

View File

@@ -75,7 +75,7 @@ class serializer
, error_handler(error_handler_)
{}
// delete because of pointer members
// deleted because of pointer members
serializer(const serializer&) = delete;
serializer& operator=(const serializer&) = delete;
serializer(serializer&&) = delete;
@@ -573,7 +573,7 @@ class serializer
break;
}
default: // decode found yet incomplete multi-byte code point
default: // decode found yet incomplete multibyte code point
{
if (!ensure_ascii)
{
@@ -827,7 +827,7 @@ class serializer
void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/)
{
// get number of digits for a float -> text -> float round-trip
// get the number of digits for a float -> text -> float round-trip
static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
// the actual conversion
@@ -836,10 +836,10 @@ class serializer
// negative value indicates an error
JSON_ASSERT(len > 0);
// check if buffer was large enough
// check if the buffer was large enough
JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size());
// erase thousands separator
// erase thousands separators
if (thousands_sep != '\0')
{
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081
@@ -947,8 +947,8 @@ class serializer
* Helper function for dump_integer
*
* This function takes a negative signed integer and returns its absolute
* value as unsigned integer. The plus/minus shuffling is necessary as we can
* not directly remove the sign of an arbitrary signed integer as the
* value as an unsigned integer. The plus/minus shuffling is necessary as we
* cannot directly remove the sign of an arbitrary signed integer as the
* absolute values of INT_MIN and INT_MAX are usually not the same. See
* #1708 for details.
*/

View File

@@ -32,10 +32,10 @@ inline void replace_substring(StringType& s, const StringType& f,
const StringType& t)
{
JSON_ASSERT(!f.empty());
for (auto pos = s.find(f); // find first occurrence of f
for (auto pos = s.find(f); // find the first occurrence of f
pos != StringType::npos; // make sure f was found
s.replace(pos, f.size(), t), // replace with t, and
pos = s.find(f, pos + t.size())) // find next occurrence of f
pos = s.find(f, pos + t.size())) // find the next occurrence of f
{}
}