1
0
mirror of https://github.com/nlohmann/json.git synced 2025-08-07 18:02:57 +03:00
* ✏️ 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

@@ -563,7 +563,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
(t == value_t::binary && binary == nullptr)
)
{
//not initialized (e.g. due to exception in the ctor)
//not initialized (e.g., due to exception in the ctor)
return;
}
if (t == value_t::array || t == value_t::object)
@@ -588,7 +588,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
while (!stack.empty())
{
// move the last item to local variable to be processed
// move the last item to a local variable to be processed
basic_json current_item(std::move(stack.back()));
stack.pop_back();
@@ -610,7 +610,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
current_item.m_data.m_value.object->clear();
}
// it's now safe that current_item get destructed
// it's now safe that current_item gets destructed
// since it doesn't have any children
}
}
@@ -918,20 +918,20 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
{
// The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int;
// (many string types can be constructed from 0 via its null-pointer guise, so we get a
// broken call to op[key_type], the wrong semantics and a 4804 warning on Windows)
// broken call to op[key_type], the wrong semantics, and a 4804 warning on Windows)
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
});
// adjust type if type deduction is not wanted
if (!type_deduction)
{
// if array is wanted, do not create an object though possible
// if an array is wanted, do not create an object though possible
if (manual_type == value_t::array)
{
is_an_object = false;
}
// if object is wanted but impossible, throw an exception
// if an object is wanted but impossible, throw an exception
if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
{
JSON_THROW(type_error::create(301, "cannot create object from initializer list", nullptr));
@@ -940,7 +940,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
if (is_an_object)
{
// the initializer list is a list of pairs -> create object
// the initializer list is a list of pairs -> create an object
m_data.m_type = value_t::object;
m_data.m_value = value_t::object;
@@ -954,7 +954,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
else
{
// the initializer list describes an array -> create array
// the initializer list describes an array -> create an array
m_data.m_type = value_t::array;
m_data.m_value.array = create<array_t>(init.begin(), init.end());
}
@@ -1042,16 +1042,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_ASSERT(first.m_object != nullptr);
JSON_ASSERT(last.m_object != nullptr);
// make sure iterator fits the current value
// make sure the iterator fits the current value
if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
{
JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", nullptr));
}
// copy type from first iterator
// copy type from the first iterator
m_data.m_type = first.m_object->m_data.m_type;
// check if iterator range is complete for primitive values
// check if the iterator range is complete for primitive values
switch (m_data.m_type)
{
case value_t::boolean:
@@ -1231,7 +1231,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
, end_position(other.end_position) // cppcheck-suppress[accessForwarded] TODO check
#endif
{
// check that passed value is valid
// check that the passed value is valid
other.assert_invariant(false); // cppcheck-suppress[accessForwarded]
// invalidate payload
@@ -1257,7 +1257,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
std::is_nothrow_move_assignable<json_base_class_t>::value
)
{
// check that passed value is valid
// check that the passed value is valid
other.assert_invariant();
using std::swap;
@@ -1973,7 +1973,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
JSON_CATCH (std::out_of_range&)
{
// create better exception explanation
// create a better exception explanation
JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this));
} // cppcheck-suppress[missingReturn]
}
@@ -1996,7 +1996,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
JSON_CATCH (std::out_of_range&)
{
// create better exception explanation
// create a better exception explanation
JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this));
} // cppcheck-suppress[missingReturn]
}
@@ -2086,7 +2086,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/
reference operator[](size_type idx)
{
// implicitly convert null value to an empty array
// implicitly convert a null value to an empty array
if (is_null())
{
m_data.m_type = value_t::array;
@@ -2097,7 +2097,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// operator[] only works for arrays
if (JSON_HEDLEY_LIKELY(is_array()))
{
// fill up array with null values if given idx is outside range
// fill up the array with null values if given idx is outside the range
if (idx >= m_data.m_value.array->size())
{
#if JSON_DIAGNOSTICS
@@ -2145,7 +2145,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/
reference operator[](typename object_t::key_type key) // NOLINT(performance-unnecessary-value-param)
{
// implicitly convert null value to an empty object
// implicitly convert a null value to an empty object
if (is_null())
{
m_data.m_type = value_t::object;
@@ -2198,7 +2198,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value, int > = 0 >
reference operator[](KeyType && key)
{
// implicitly convert null value to an empty object
// implicitly convert a null value to an empty object
if (is_null())
{
m_data.m_type = value_t::object;
@@ -2255,7 +2255,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// value only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if key is found, return value and given default value otherwise
// If 'key' is found, return its value. Otherwise, return `default_value'.
const auto it = find(key);
if (it != end())
{
@@ -2280,7 +2280,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// value only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if key is found, return value and given default value otherwise
// If 'key' is found, return its value. Otherwise, return `default_value'.
const auto it = find(key);
if (it != end())
{
@@ -2306,7 +2306,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// value only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if key is found, return value and given default value otherwise
// If 'key' is found, return its value. Otherwise, return `default_value'.
const auto it = find(std::forward<KeyType>(key));
if (it != end())
{
@@ -2333,7 +2333,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// value only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if key is found, return value and given default value otherwise
// If 'key' is found, return its value. Otherwise, return `default_value'.
const auto it = find(std::forward<KeyType>(key));
if (it != end())
{
@@ -2356,7 +2356,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// value only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if pointer resolves a value, return it or use default value
// If the pointer resolves to a value, return it. Otherwise, return
// 'default_value'.
JSON_TRY
{
return ptr.get_checked(this).template get<ValueType>();
@@ -2381,7 +2382,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// value only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
// if pointer resolves a value, return it or use default value
// If the pointer resolves to a value, return it. Otherwise, return
// 'default_value'.
JSON_TRY
{
return ptr.get_checked(this).template get<ReturnType>();
@@ -2455,7 +2457,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 >
IteratorType erase(IteratorType pos) // NOLINT(performance-unnecessary-value-param)
{
// make sure iterator fits the current value
// make sure the iterator fits the current value
if (JSON_HEDLEY_UNLIKELY(this != pos.m_object))
{
JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", this));
@@ -2525,7 +2527,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int > = 0 >
IteratorType erase(IteratorType first, IteratorType last) // NOLINT(performance-unnecessary-value-param)
{
// make sure iterator fits the current value
// make sure the iterator fits the current value
if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object))
{
JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", this));
@@ -3120,7 +3122,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this));
}
// transform null object into an array
// transform a null object into an array
if (is_null())
{
m_data.m_type = value_t::array;
@@ -3128,7 +3130,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
assert_invariant();
}
// add element to array (move semantics)
// add the element to the array (move semantics)
const auto old_capacity = m_data.m_value.array->capacity();
m_data.m_value.array->push_back(std::move(val));
set_parent(m_data.m_value.array->back(), old_capacity);
@@ -3153,7 +3155,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this));
}
// transform null object into an array
// transform a null object into an array
if (is_null())
{
m_data.m_type = value_t::array;
@@ -3161,7 +3163,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
assert_invariant();
}
// add element to array
// add the element to the array
const auto old_capacity = m_data.m_value.array->capacity();
m_data.m_value.array->push_back(val);
set_parent(m_data.m_value.array->back(), old_capacity);
@@ -3185,7 +3187,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(308, detail::concat("cannot use push_back() with ", type_name()), this));
}
// transform null object into an object
// transform a null object into an object
if (is_null())
{
m_data.m_type = value_t::object;
@@ -3193,7 +3195,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
assert_invariant();
}
// add element to object
// add the element to the object
auto res = m_data.m_value.object->insert(val);
set_parent(res.first->second);
}
@@ -3241,7 +3243,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(311, detail::concat("cannot use emplace_back() with ", type_name()), this));
}
// transform null object into an array
// transform a null object into an array
if (is_null())
{
m_data.m_type = value_t::array;
@@ -3249,7 +3251,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
assert_invariant();
}
// add element to array (perfect forwarding)
// add the element to the array (perfect forwarding)
const auto old_capacity = m_data.m_value.array->capacity();
m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
return set_parent(m_data.m_value.array->back(), old_capacity);
@@ -3266,7 +3268,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW(type_error::create(311, detail::concat("cannot use emplace() with ", type_name()), this));
}
// transform null object into an object
// transform a null object into an object
if (is_null())
{
m_data.m_type = value_t::object;
@@ -3274,11 +3276,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
assert_invariant();
}
// add element to array (perfect forwarding)
// add the element to the array (perfect forwarding)
auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...);
set_parent(res.first->second);
// create result iterator and set iterator to the result of emplace
// create a result iterator and set iterator to the result of emplace
auto it = begin();
it.m_it.object_iterator = res.first;
@@ -3442,7 +3444,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @sa https://json.nlohmann.me/api/basic_json/update/
void update(const_iterator first, const_iterator last, bool merge_objects = false) // NOLINT(performance-unnecessary-value-param)
{
// implicitly convert null value to an empty object
// implicitly convert a null value to an empty object
if (is_null())
{
m_data.m_type = value_t::object;
@@ -4002,7 +4004,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/
friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
{
// read width member and use it as indentation parameter if nonzero
// read width member and use it as the indentation parameter if nonzero
const bool pretty_print = o.width() > 0;
const auto indentation = pretty_print ? o.width() : 0;
@@ -4797,7 +4799,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
result.at(top_pointer);
}
// get reference to parent of JSON pointer ptr
// get reference to the parent of the JSON pointer ptr
const auto last_path = ptr.back();
ptr.pop_back();
// parent must exist when performing patch add per RFC6902 specs
@@ -4835,7 +4837,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
break;
}
// if there exists a parent it cannot be primitive
// if there exists a parent, it cannot be primitive
case value_t::string: // LCOV_EXCL_LINE
case value_t::boolean: // LCOV_EXCL_LINE
case value_t::number_integer: // LCOV_EXCL_LINE
@@ -4851,7 +4853,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// wrapper for "remove" operation; remove value at ptr
const auto operation_remove = [this, & result](json_pointer & ptr)
{
// get reference to parent of JSON pointer ptr
// get reference to the parent of the JSON pointer ptr
const auto last_path = ptr.back();
ptr.pop_back();
basic_json& parent = result.at(ptr);
@@ -4897,14 +4899,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// context-sensitive error message
const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); // NOLINT(bugprone-unused-local-non-trivial-variable)
// check if desired value is present
// check if the desired value is present
if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end()))
{
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg, " must have member '", member, "'"), &val));
}
// check if result is of type string
// check if the result is of type string
if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
{
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
@@ -4993,7 +4995,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// ignore out of range errors: success remains false
}
// throw an exception if test fails
// throw an exception if the test fails
if (JSON_HEDLEY_UNLIKELY(!success))
{
JSON_THROW(other_error::create(501, detail::concat("unsuccessful: ", val.dump()), &val));
@@ -5031,7 +5033,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// the patch
basic_json result(value_t::array);
// if the values are the same, return empty patch
// if the values are the same, return an empty patch
if (source == target)
{
return result;
@@ -5145,7 +5147,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
case value_t::discarded:
default:
{
// both primitive type: replace value
// both primitive types: replace value
result.push_back(
{
{"op", "replace"}, {"path", path}, {"value", target}