mirror of
https://github.com/nlohmann/json.git
synced 2026-06-19 02:44:20 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fd3913e4e | |||
| 2030ba3944 | |||
| c51c9cefea |
@@ -11,7 +11,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ jobs:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
pull-requests: write
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: 'Checkout Repository'
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: 'Dependency Review'
|
||||
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
|
||||
uses: actions/dependency-review-action@2031cfc080254a8a887f58cffee85186f0e49e48 # v4.9.0
|
||||
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
security-events: write
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
@@ -40,7 +40,7 @@ jobs:
|
||||
run: make build -C docs/mkdocs
|
||||
|
||||
- name: Deploy documentation
|
||||
uses: peaceiris/actions-gh-pages@84c30a85c19949d7eee79c4ff27748b70285e453 # v4.1.0
|
||||
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./docs/mkdocs/site
|
||||
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
target: [ci_test_amalgamation, ci_test_single_header, ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance, ci_test_valgrind]
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
@@ -98,7 +98,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
@@ -251,7 +251,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
@@ -272,7 +272,7 @@ jobs:
|
||||
target: [ci_test_examples, ci_test_build_documentation]
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@9ca718d3bf646d6534007c269a635b3e54cadf99 # v2.19.2
|
||||
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
cppcheck==1.5.1
|
||||
cppcheck==1.5.0
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
# <small>nlohmann::json_pointer::</small>front
|
||||
|
||||
```cpp
|
||||
const string_t& front() const;
|
||||
```
|
||||
|
||||
Return the first reference token.
|
||||
|
||||
## Return value
|
||||
|
||||
First reference token.
|
||||
|
||||
## Exceptions
|
||||
|
||||
Throws [out_of_range.405](../../home/exceptions.md#jsonexceptionout_of_range405) if the JSON pointer has no parent.
|
||||
|
||||
## Complexity
|
||||
|
||||
Constant.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
The example shows the usage of `front`.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/json_pointer__front.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/json_pointer__front.output"
|
||||
```
|
||||
|
||||
## Version history
|
||||
@@ -37,9 +37,6 @@ are the base for JSON patches.
|
||||
- [**pop_back**](pop_back.md) - remove the last reference token
|
||||
- [**back**](back.md) - return last reference token
|
||||
- [**push_back**](push_back.md) - append an unescaped token at the end of the pointer
|
||||
- [**pop_front**](pop_front.md) - remove the first reference token
|
||||
- [**front**](front.md) - return first reference token
|
||||
- [**push_front**](push_front.md) - append an unescaped token at the start of the pointer
|
||||
- [**empty**](empty.md) - return whether the pointer points to the root document
|
||||
|
||||
## Literals
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
# <small>nlohmann::json_pointer::</small>pop_front
|
||||
|
||||
```cpp
|
||||
void pop_front();
|
||||
```
|
||||
|
||||
Remove the first reference token.
|
||||
|
||||
## Exceptions
|
||||
|
||||
Throws [out_of_range.405](../../home/exceptions.md#jsonexceptionout_of_range405) if the JSON pointer has no parent.
|
||||
|
||||
## Complexity
|
||||
|
||||
Linear in the number of reference tokens in the `json_pointer`.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
The example shows the usage of `pop_front`.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/json_pointer__pop_front.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/json_pointer__pop_front.output"
|
||||
```
|
||||
|
||||
## Version history
|
||||
@@ -1,36 +0,0 @@
|
||||
# <small>nlohmann::json_pointer::</small>push_front
|
||||
|
||||
```cpp
|
||||
void push_front(const string_t& token);
|
||||
|
||||
void push_front(string_t&& token);
|
||||
```
|
||||
|
||||
Append an unescaped token at the start of the reference pointer.
|
||||
|
||||
## Parameters
|
||||
|
||||
`token` (in)
|
||||
: token to add
|
||||
|
||||
## Complexity
|
||||
|
||||
Linear in the number of reference tokens in the `json_pointer`.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
The example shows the result of `push_front` for different JSON Pointers.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/json_pointer__push_front.cpp"
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/json_pointer__push_front.output"
|
||||
```
|
||||
|
||||
## Version history
|
||||
@@ -1,15 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// different JSON Pointers
|
||||
json::json_pointer ptr1("/foo");
|
||||
json::json_pointer ptr2("/foo/0");
|
||||
|
||||
// call empty()
|
||||
std::cout << "first reference token of \"" << ptr1 << "\" is \"" << ptr1.front() << "\"\n"
|
||||
<< "first reference token of \"" << ptr2 << "\" is \"" << ptr2.front() << "\"" << std::endl;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
first reference token of "/foo" is "foo"
|
||||
first reference token of "/foo/0" is "foo"
|
||||
@@ -1,21 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create empty JSON Pointer
|
||||
json::json_pointer ptr("/foo/bar/baz");
|
||||
std::cout << "\"" << ptr << "\"\n";
|
||||
|
||||
// call pop_front()
|
||||
ptr.pop_front();
|
||||
std::cout << "\"" << ptr << "\"\n";
|
||||
|
||||
ptr.pop_front();
|
||||
std::cout << "\"" << ptr << "\"\n";
|
||||
|
||||
ptr.pop_front();
|
||||
std::cout << "\"" << ptr << "\"\n";
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
"/foo/bar/baz"
|
||||
"/bar/baz"
|
||||
"/baz"
|
||||
""
|
||||
@@ -1,21 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create empty JSON Pointer
|
||||
json::json_pointer ptr;
|
||||
std::cout << "\"" << ptr << "\"\n";
|
||||
|
||||
// call push_front()
|
||||
ptr.push_front("foo");
|
||||
std::cout << "\"" << ptr << "\"\n";
|
||||
|
||||
ptr.push_front("0");
|
||||
std::cout << "\"" << ptr << "\"\n";
|
||||
|
||||
ptr.push_front("bar");
|
||||
std::cout << "\"" << ptr << "\"\n";
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
""
|
||||
"/foo"
|
||||
"/0/foo"
|
||||
"/bar/0/foo"
|
||||
@@ -233,7 +233,6 @@ nav:
|
||||
- '(Constructor)': api/json_pointer/json_pointer.md
|
||||
- 'back': api/json_pointer/back.md
|
||||
- 'empty': api/json_pointer/empty.md
|
||||
- 'front': api/json_pointer/front.md
|
||||
- 'operator string_t': api/json_pointer/operator_string_t.md
|
||||
- 'operator==': api/json_pointer/operator_eq.md
|
||||
- 'operator!=': api/json_pointer/operator_ne.md
|
||||
@@ -241,9 +240,7 @@ nav:
|
||||
- 'operator/=': api/json_pointer/operator_slasheq.md
|
||||
- 'parent_pointer': api/json_pointer/parent_pointer.md
|
||||
- 'pop_back': api/json_pointer/pop_back.md
|
||||
- 'pop_front': api/json_pointer/pop_front.md
|
||||
- 'push_back': api/json_pointer/push_back.md
|
||||
- 'push_front': api/json_pointer/push_front.md
|
||||
- 'string_t': api/json_pointer/string_t.md
|
||||
- 'to_string': api/json_pointer/to_string.md
|
||||
- json_sax:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
wheel==0.47.0
|
||||
|
||||
mkdocs==1.6.1 # documentation framework
|
||||
mkdocs-git-revision-date-localized-plugin==1.5.2 # plugin "git-revision-date-localized"
|
||||
mkdocs-git-revision-date-localized-plugin==1.5.1 # plugin "git-revision-date-localized"
|
||||
mkdocs-material==9.7.6 # theme for mkdocs
|
||||
mkdocs-material-extensions==1.3.1 # extensions
|
||||
mkdocs-minify-plugin==0.8.0 # plugin "minify"
|
||||
|
||||
@@ -388,10 +388,14 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||
|
||||
ConstructibleObjectType ret;
|
||||
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
|
||||
for (const auto& p : *inner_object)
|
||||
using value_type = typename ConstructibleObjectType::value_type;
|
||||
std::transform(
|
||||
inner_object->begin(), inner_object->end(),
|
||||
std::inserter(ret, ret.begin()),
|
||||
[](typename BasicJsonType::object_t::value_type const & p)
|
||||
{
|
||||
ret.emplace(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
}
|
||||
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
});
|
||||
obj = std::move(ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,10 @@ struct external_constructor<value_t::array>
|
||||
j.m_data.m_type = value_t::array;
|
||||
j.m_data.m_value = value_t::array;
|
||||
j.m_data.m_value.array->resize(arr.size());
|
||||
std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
|
||||
if (arr.size() > 0)
|
||||
{
|
||||
std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
|
||||
}
|
||||
j.set_parents();
|
||||
j.assert_invariant();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ This class implements a both iterators (iterator and const_iterator) for the
|
||||
been set (e.g., by a constructor or a copy assignment). If the iterator is
|
||||
default-constructed, it is *uninitialized* and most methods are undefined.
|
||||
**The library uses assertions to detect calls on uninitialized iterators.**
|
||||
@requirement REQ-JSON-01 The class satisfies the following concept requirements:
|
||||
@requirement The class satisfies the following concept requirements:
|
||||
-
|
||||
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):
|
||||
The iterator that can be moved can be moved in both directions (i.e.
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace detail
|
||||
iterator (to create @ref reverse_iterator) and @ref const_iterator (to
|
||||
create @ref const_reverse_iterator).
|
||||
|
||||
@requirement REQ-JSON-02 The class satisfies the following concept requirements:
|
||||
@requirement The class satisfies the following concept requirements:
|
||||
-
|
||||
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):
|
||||
The iterator that can be moved can be moved in both directions (i.e.
|
||||
|
||||
@@ -154,44 +154,6 @@ class json_pointer
|
||||
return res;
|
||||
}
|
||||
|
||||
/// @brief remove first reference token
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/pop_front/
|
||||
void pop_front()
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr));
|
||||
}
|
||||
|
||||
reference_tokens.erase(reference_tokens.begin());
|
||||
}
|
||||
|
||||
/// @brief return first reference token
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/front/
|
||||
const string_t& front() const
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr));
|
||||
}
|
||||
|
||||
return reference_tokens.front();
|
||||
}
|
||||
|
||||
/// @brief append an unescaped token at the start of the reference pointer
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/push_front/
|
||||
void push_front(const string_t& token)
|
||||
{
|
||||
reference_tokens.insert(reference_tokens.begin(), token);
|
||||
}
|
||||
|
||||
/// @brief append an unescaped token at the start of the reference pointer
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/push_front/
|
||||
void push_front(string_t&& token)
|
||||
{
|
||||
reference_tokens.insert(reference_tokens.begin(), std::move(token));
|
||||
}
|
||||
|
||||
/// @brief remove last reference token
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/pop_back/
|
||||
void pop_back()
|
||||
|
||||
@@ -137,6 +137,15 @@
|
||||
// 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
|
||||
// libstdc++ < 11 has incomplete C++20 ranges (issue #4440)
|
||||
#elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11
|
||||
#define JSON_HAS_RANGES 0
|
||||
// libc++ < 16 has incomplete C++20 ranges (issue #4440)
|
||||
#elif defined(__clang__) && !defined(__apple_build_version__) \
|
||||
&& __clang_major__ < 16 && defined(__GLIBCXX__)
|
||||
#define JSON_HAS_RANGES 0
|
||||
#elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000
|
||||
#define JSON_HAS_RANGES 0
|
||||
#elif defined(__cpp_lib_ranges)
|
||||
#define JSON_HAS_RANGES 1
|
||||
#else
|
||||
|
||||
@@ -825,27 +825,14 @@ class serializer
|
||||
o->write_characters(begin, static_cast<size_t>(end - begin));
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
static int snprintf_float(char* buf, std::size_t size, int d, double x)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
return (std::snprintf)(buf, size, "%.*g", d, x);
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
static int snprintf_float(char* buf, std::size_t size, int d, long double x)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
return (std::snprintf)(buf, size, "%.*lg", d, x);
|
||||
}
|
||||
|
||||
void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/)
|
||||
{
|
||||
// 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
|
||||
std::ptrdiff_t len = snprintf_float(number_buffer.data(), number_buffer.size(), d, x);
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
|
||||
|
||||
// negative value indicates an error
|
||||
JSON_ASSERT(len > 0);
|
||||
|
||||
@@ -741,10 +741,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
#endif
|
||||
}
|
||||
|
||||
iterator set_parents(iterator it, std::ptrdiff_t count_set_parents)
|
||||
iterator set_parents(iterator it, typename iterator::difference_type count_set_parents)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
for (std::ptrdiff_t i = 0; i < count_set_parents; ++i)
|
||||
for (typename iterator::difference_type i = 0; i < count_set_parents; ++i)
|
||||
{
|
||||
(it + i)->m_parent = this;
|
||||
}
|
||||
|
||||
@@ -50,25 +50,6 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
||||
: Container{first, last, alloc} {}
|
||||
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator() )
|
||||
: Container{init, alloc} {}
|
||||
ordered_map(const ordered_map&) = default;
|
||||
ordered_map(ordered_map&&) noexcept(std::is_nothrow_move_constructible<Container>::value) = default;
|
||||
~ordered_map() = default;
|
||||
|
||||
ordered_map& operator=(const ordered_map& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
ordered_map tmp(other);
|
||||
Container::operator=(std::move(static_cast<Container&>(tmp)));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ordered_map& operator=(ordered_map&& other) noexcept(std::is_nothrow_move_assignable<Container>::value)
|
||||
{
|
||||
Container::operator=(std::move(static_cast<Container&>(other)));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
|
||||
{
|
||||
|
||||
@@ -2501,6 +2501,15 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
||||
// 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
|
||||
// libstdc++ < 11 has incomplete C++20 ranges (issue #4440)
|
||||
#elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11
|
||||
#define JSON_HAS_RANGES 0
|
||||
// libc++ < 16 has incomplete C++20 ranges (issue #4440)
|
||||
#elif defined(__clang__) && !defined(__apple_build_version__) \
|
||||
&& __clang_major__ < 16 && defined(__GLIBCXX__)
|
||||
#define JSON_HAS_RANGES 0
|
||||
#elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000
|
||||
#define JSON_HAS_RANGES 0
|
||||
#elif defined(__cpp_lib_ranges)
|
||||
#define JSON_HAS_RANGES 1
|
||||
#else
|
||||
@@ -5306,10 +5315,14 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||
|
||||
ConstructibleObjectType ret;
|
||||
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
|
||||
for (const auto& p : *inner_object)
|
||||
using value_type = typename ConstructibleObjectType::value_type;
|
||||
std::transform(
|
||||
inner_object->begin(), inner_object->end(),
|
||||
std::inserter(ret, ret.begin()),
|
||||
[](typename BasicJsonType::object_t::value_type const & p)
|
||||
{
|
||||
ret.emplace(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
}
|
||||
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
});
|
||||
obj = std::move(ret);
|
||||
}
|
||||
|
||||
@@ -6023,7 +6036,10 @@ struct external_constructor<value_t::array>
|
||||
j.m_data.m_type = value_t::array;
|
||||
j.m_data.m_value = value_t::array;
|
||||
j.m_data.m_value.array->resize(arr.size());
|
||||
std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
|
||||
if (arr.size() > 0)
|
||||
{
|
||||
std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
|
||||
}
|
||||
j.set_parents();
|
||||
j.assert_invariant();
|
||||
}
|
||||
@@ -13800,7 +13816,7 @@ This class implements a both iterators (iterator and const_iterator) for the
|
||||
been set (e.g., by a constructor or a copy assignment). If the iterator is
|
||||
default-constructed, it is *uninitialized* and most methods are undefined.
|
||||
**The library uses assertions to detect calls on uninitialized iterators.**
|
||||
@requirement REQ-JSON-01 The class satisfies the following concept requirements:
|
||||
@requirement The class satisfies the following concept requirements:
|
||||
-
|
||||
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):
|
||||
The iterator that can be moved can be moved in both directions (i.e.
|
||||
@@ -14559,7 +14575,7 @@ namespace detail
|
||||
iterator (to create @ref reverse_iterator) and @ref const_iterator (to
|
||||
create @ref const_reverse_iterator).
|
||||
|
||||
@requirement REQ-JSON-02 The class satisfies the following concept requirements:
|
||||
@requirement The class satisfies the following concept requirements:
|
||||
-
|
||||
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):
|
||||
The iterator that can be moved can be moved in both directions (i.e.
|
||||
@@ -14865,44 +14881,6 @@ class json_pointer
|
||||
return res;
|
||||
}
|
||||
|
||||
/// @brief remove first reference token
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/pop_front/
|
||||
void pop_front()
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr));
|
||||
}
|
||||
|
||||
reference_tokens.erase(reference_tokens.begin());
|
||||
}
|
||||
|
||||
/// @brief return first reference token
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/front/
|
||||
const string_t& front() const
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr));
|
||||
}
|
||||
|
||||
return reference_tokens.front();
|
||||
}
|
||||
|
||||
/// @brief append an unescaped token at the start of the reference pointer
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/push_front/
|
||||
void push_front(const string_t& token)
|
||||
{
|
||||
reference_tokens.insert(reference_tokens.begin(), token);
|
||||
}
|
||||
|
||||
/// @brief append an unescaped token at the start of the reference pointer
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/push_front/
|
||||
void push_front(string_t&& token)
|
||||
{
|
||||
reference_tokens.insert(reference_tokens.begin(), std::move(token));
|
||||
}
|
||||
|
||||
/// @brief remove last reference token
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/pop_back/
|
||||
void pop_back()
|
||||
@@ -19804,27 +19782,14 @@ class serializer
|
||||
o->write_characters(begin, static_cast<size_t>(end - begin));
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
static int snprintf_float(char* buf, std::size_t size, int d, double x)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
return (std::snprintf)(buf, size, "%.*g", d, x);
|
||||
}
|
||||
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
static int snprintf_float(char* buf, std::size_t size, int d, long double x)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
return (std::snprintf)(buf, size, "%.*lg", d, x);
|
||||
}
|
||||
|
||||
void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/)
|
||||
{
|
||||
// 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
|
||||
std::ptrdiff_t len = snprintf_float(number_buffer.data(), number_buffer.size(), d, x);
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
|
||||
|
||||
// negative value indicates an error
|
||||
JSON_ASSERT(len > 0);
|
||||
@@ -20038,25 +20003,6 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
||||
: Container{first, last, alloc} {}
|
||||
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator() )
|
||||
: Container{init, alloc} {}
|
||||
ordered_map(const ordered_map&) = default;
|
||||
ordered_map(ordered_map&&) noexcept(std::is_nothrow_move_constructible<Container>::value) = default;
|
||||
~ordered_map() = default;
|
||||
|
||||
ordered_map& operator=(const ordered_map& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
ordered_map tmp(other);
|
||||
Container::operator=(std::move(static_cast<Container&>(tmp)));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ordered_map& operator=(ordered_map&& other) noexcept(std::is_nothrow_move_assignable<Container>::value)
|
||||
{
|
||||
Container::operator=(std::move(static_cast<Container&>(other)));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
|
||||
{
|
||||
@@ -21045,10 +20991,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
#endif
|
||||
}
|
||||
|
||||
iterator set_parents(iterator it, std::ptrdiff_t count_set_parents)
|
||||
iterator set_parents(iterator it, typename iterator::difference_type count_set_parents)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
for (std::ptrdiff_t i = 0; i < count_set_parents; ++i)
|
||||
for (typename iterator::difference_type i = 0; i < count_set_parents; ++i)
|
||||
{
|
||||
(it + i)->m_parent = this;
|
||||
}
|
||||
|
||||
@@ -564,14 +564,6 @@ TEST_CASE("JSON pointers")
|
||||
CHECK(!ptr.empty());
|
||||
CHECK(j[ptr] == j["answer"]["everything"]);
|
||||
|
||||
ptr.pop_front();
|
||||
CHECK(ptr.front() == "everything");
|
||||
ptr.pop_front();
|
||||
CHECK(ptr.empty());
|
||||
ptr.push_front("everything");
|
||||
ptr.push_front(answer);
|
||||
CHECK(j[ptr] == j["answer"]["everything"]);
|
||||
|
||||
// check access via const pointer
|
||||
const auto cptr = ptr;
|
||||
CHECK(cptr.back() == "everything");
|
||||
@@ -596,17 +588,8 @@ TEST_CASE("JSON pointers")
|
||||
CHECK(ptr.empty());
|
||||
CHECK(j[ptr] == j);
|
||||
|
||||
CHECK_THROWS_WITH_AS(ptr.pop_back(),
|
||||
"[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(ptr.back(),
|
||||
"[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(ptr.pop_front(),
|
||||
"[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(ptr.front(),
|
||||
"[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
|
||||
CHECK_THROWS_WITH(ptr.pop_back(),
|
||||
"[json.exception.out_of_range.405] JSON pointer has no parent");
|
||||
}
|
||||
|
||||
SECTION("operators")
|
||||
|
||||
@@ -69,15 +69,3 @@ TEST_CASE("ordered_json")
|
||||
CHECK(oj1.size() == 4);
|
||||
CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}");
|
||||
}
|
||||
|
||||
TEST_CASE("regression test for issue #3732 - iteration_proxy_value<iter_impl<ordered_json>>")
|
||||
{
|
||||
// Naming the proxy type in a function-parameter position forces eager
|
||||
// instantiation of basic_json<ordered_map>; previously this hit an
|
||||
// incomplete-type error in set_parents().
|
||||
auto fn = [](nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::ordered_json>> const & val)
|
||||
{
|
||||
return val.value();
|
||||
};
|
||||
static_cast<void>(fn);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,11 @@ using ordered_json = nlohmann::ordered_json;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// for #4440
|
||||
#if JSON_HAS_RANGES == 1
|
||||
#include <ranges>
|
||||
#endif
|
||||
|
||||
// NLOHMANN_JSON_SERIALIZE_ENUM uses a static std::pair
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
|
||||
@@ -1134,6 +1139,20 @@ TEST_CASE("regression tests 2")
|
||||
CHECK(!result.has_value());
|
||||
}
|
||||
#endif
|
||||
|
||||
#if JSON_HAS_RANGES == 1
|
||||
SECTION("issue #4440 - assert when using std::views::filter and GCC 10")
|
||||
{
|
||||
auto noOpFilter = std::views::filter([](auto&&) noexcept
|
||||
{
|
||||
return true;
|
||||
});
|
||||
json j = {1, 2, 3};
|
||||
auto filtered = j | noOpFilter;
|
||||
CHECK(*filtered.begin() == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("issue #4798 - nlohmann::json::to_msgpack() encode float NaN as double", T, double, float) // NOLINT(readability-math-missing-parentheses, bugprone-throwing-static-initialization)
|
||||
@@ -1240,93 +1259,4 @@ TEST_CASE("regression test #5074 - single-element brace init with JSON_BRACE_INI
|
||||
}
|
||||
#endif
|
||||
|
||||
struct Example_5122
|
||||
{
|
||||
float b = 2;
|
||||
nlohmann::ordered_map<std::string, std::string> c{}; // NOLINT(readability-redundant-member-init): needed for GCC -Weffc++
|
||||
int a = 1;
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Example_5122, b, c, a)
|
||||
};
|
||||
|
||||
TEST_CASE("regression test #5122 - from_json into types holding nlohmann::ordered_map")
|
||||
{
|
||||
Example_5122 src;
|
||||
src.c.emplace("first", "1");
|
||||
src.c.emplace("second", "2");
|
||||
|
||||
ordered_json const j = src;
|
||||
Example_5122 const dst = j.get<Example_5122>();
|
||||
|
||||
CHECK(dst.b == src.b);
|
||||
CHECK(dst.a == src.a);
|
||||
REQUIRE(dst.c.size() == src.c.size());
|
||||
auto src_it = src.c.begin();
|
||||
auto dst_it = dst.c.begin();
|
||||
for (; src_it != src.c.end(); ++src_it, ++dst_it)
|
||||
{
|
||||
CHECK(dst_it->first == src_it->first);
|
||||
CHECK(dst_it->second == src_it->second);
|
||||
}
|
||||
}
|
||||
|
||||
// -Wself-assign-overloaded was introduced in Clang 7. Gate the pragma on
|
||||
// __has_warning so older Clang versions do not error with "unknown warning
|
||||
// group". The __has_warning check has to stay inside the __clang__ branch
|
||||
// because GCC does not provide it and would tokenize-error on the argument.
|
||||
#if defined(__clang__) && defined(__has_warning)
|
||||
#if __has_warning("-Wself-assign-overloaded")
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wself-assign-overloaded")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TEST_CASE("regression test #5122 - nlohmann::ordered_map copy-assignment is self-assignment safe")
|
||||
{
|
||||
nlohmann::ordered_map<std::string, std::string> m;
|
||||
m.emplace("first", "1");
|
||||
m.emplace("second", "2");
|
||||
|
||||
// Insertion order is preserved by ordered_map, so we can check it directly.
|
||||
m = m;
|
||||
|
||||
REQUIRE(m.size() == 2);
|
||||
auto it = m.begin();
|
||||
CHECK(it->first == "first");
|
||||
CHECK(it->second == "1");
|
||||
++it;
|
||||
CHECK(it->first == "second");
|
||||
CHECK(it->second == "2");
|
||||
}
|
||||
|
||||
#if defined(__clang__) && defined(__has_warning)
|
||||
#if __has_warning("-Wself-assign-overloaded")
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TEST_CASE("regression test #5122 - nlohmann::ordered_map move-assignment transfers contents")
|
||||
{
|
||||
nlohmann::ordered_map<std::string, std::string> src;
|
||||
src.emplace("first", "1");
|
||||
src.emplace("second", "2");
|
||||
|
||||
nlohmann::ordered_map<std::string, std::string> dst;
|
||||
dst.emplace("stale", "x");
|
||||
dst = std::move(src);
|
||||
|
||||
REQUIRE(dst.size() == 2);
|
||||
auto it = dst.begin();
|
||||
CHECK(it->first == "first");
|
||||
CHECK(it->second == "1");
|
||||
++it;
|
||||
CHECK(it->first == "second");
|
||||
CHECK(it->second == "2");
|
||||
|
||||
// Re-assigning into the moved-from object must leave it in a usable state.
|
||||
src = nlohmann::ordered_map<std::string, std::string> {};
|
||||
src.emplace("after-move", "3");
|
||||
REQUIRE(src.size() == 1);
|
||||
CHECK(src.begin()->first == "after-move");
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
Reference in New Issue
Block a user