Skip to content

Commit

Permalink
Merge branch 'nlohmann:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomerkm authored Nov 10, 2023
2 parents 83bf8dd + 6eab7a2 commit 0012f86
Show file tree
Hide file tree
Showing 110 changed files with 353 additions and 288 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ Checks: '*,
-misc-non-private-member-variables-in-classes,
-modernize-concat-nested-namespaces,
-modernize-type-traits,
-modernize-use-constraints,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-performance-enum-size,
-readability-function-cognitive-complexity,
-readability-function-size,
-readability-identifier-length,
Expand Down
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# JSON for Modern C++ has been originally written by Niels Lohmann.
# Since 2013 over 140 contributors have helped to improve the library.
# JSON for Modern C++ was originally written by Niels Lohmann.
# Since 2013, over 250 contributors have helped to improve the library.
# This CODEOWNERS file is only to make sure that @nlohmann is requested
# for a code review in case of a pull request.

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: c-cpp

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/publish_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ jobs:
- name: Install virtual environment
run: make install_venv -C docs/mkdocs

- name: Publish documentation
run: make publish -C docs/mkdocs
- name: Build documentation
run: make build -C docs/mkdocs

- name: Deploy documentation
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/mkdocs/site
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
uses: egor-tensin/setup-mingw@v2
with:
platform: ${{ matrix.architecture }}
version: 12.2.0 # https://github.com/egor-tensin/setup-mingw/issues/14
- name: Run CMake
run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
- name: Build
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@
/localhost.pem
/localhost-key.pem
/serve_header.yml

# Swift Package Manager build directory
/.build
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.1...3.14)

##
## PROJECT
Expand Down Expand Up @@ -122,7 +122,7 @@ target_include_directories(
${NLOHMANN_JSON_TARGET_NAME}
${NLOHMANN_JSON_SYSTEM_INCLUDE} INTERFACE
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}>
)

## add debug view definition file for msvc (natvis)
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ pretty:
--pad-header \
--align-pointer=type \
--align-reference=type \
--add-brackets \
--add-braces \
--squeeze-lines=2 \
--convert-tabs \
--close-templates \
--lineend=linux \
Expand Down
22 changes: 22 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "nlohmann-json",
platforms: [
.iOS(.v12), .macOS(.v10_13), .tvOS(.v12), .watchOS(.v4)
],
products: [
.library(name: "json", targets: ["json"])
],
targets: [
.target(
name: "json",
path: "single_include/nlohmann",
publicHeadersPath: "."
)
],
cxxLanguageStandard: .cxx11
)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,8 @@ If you are using [cget](https://cget.readthedocs.io/en/latest/), you can install

If you are using [CocoaPods](https://cocoapods.org), you can use the library by adding pod `"nlohmann_json", '~>3.1.2'` to your podfile (see [an example](https://bitbucket.org/benman/nlohmann_json-cocoapod/src/master/)). Please file issues [here](https://bitbucket.org/benman/nlohmann_json-cocoapod/issues?status=new&status=open).

If you are using [Swift Package Manager](https://swift.org/package-manager/), you can use the library by adding a package dependency to this repository. And target dependency as `.product(name: "nlohmann-json", package: "json")`.

If you are using [NuGet](https://www.nuget.org), you can use the package [nlohmann.json](https://www.nuget.org/packages/nlohmann.json/). Please check [this extensive description](https://github.com/nlohmann/json/issues/1132#issuecomment-452250255) on how to use the package. Please file issues [here](https://github.com/hnkb/nlohmann-json-nuget/issues).

If you are using [conda](https://conda.io/), you can use the package [nlohmann_json](https://github.com/conda-forge/nlohmann_json-feedstock) from [conda-forge](https://conda-forge.org) executing `conda install -c conda-forge nlohmann_json`. Please file issues [here](https://github.com/conda-forge/nlohmann_json-feedstock/issues).
Expand Down
13 changes: 6 additions & 7 deletions docs/examples/at__json_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ int main()
// output the changed array
std::cout << j["array"] << '\n';


// out_of_range.106
try
{
// try to use an array index with leading '0'
json::reference ref = j.at("/array/01"_json_pointer);
}
catch (json::parse_error& e)
catch (const json::parse_error& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -53,7 +52,7 @@ int main()
// try to use an array index that is not a number
json::reference ref = j.at("/array/one"_json_pointer);
}
catch (json::parse_error& e)
catch (const json::parse_error& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -64,7 +63,7 @@ int main()
// try to use an invalid array index
json::reference ref = j.at("/array/4"_json_pointer);
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -75,7 +74,7 @@ int main()
// try to use the array index '-'
json::reference ref = j.at("/array/-"_json_pointer);
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -86,7 +85,7 @@ int main()
// try to use a JSON pointer to a nonexistent object key
json::const_reference ref = j.at("/foo"_json_pointer);
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -97,7 +96,7 @@ int main()
// try to use a JSON pointer that cannot be resolved
json::reference ref = j.at("/number/foo"_json_pointer);
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand Down
10 changes: 5 additions & 5 deletions docs/examples/at__json_pointer_const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main()
// try to use an array index that is not a number
json::const_reference ref = j.at("/array/one"_json_pointer);
}
catch (json::parse_error& e)
catch (const json::parse_error& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -40,7 +40,7 @@ int main()
// try to use an invalid array index
json::const_reference ref = j.at("/array/4"_json_pointer);
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -51,7 +51,7 @@ int main()
// try to use the array index '-'
json::const_reference ref = j.at("/array/-"_json_pointer);
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -62,7 +62,7 @@ int main()
// try to use a JSON pointer to a nonexistent object key
json::const_reference ref = j.at("/foo"_json_pointer);
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -73,7 +73,7 @@ int main()
// try to use a JSON pointer that cannot be resolved
json::const_reference ref = j.at("/number/foo"_json_pointer);
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/at__keytype.c++17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ int main()
// output changed array
std::cout << object << '\n';


// exception type_error.304
try
{
// use at() with string_view on a non-object type
json str = "I am a string";
str.at("the good"sv) = "Another string";
}
catch (json::type_error& e)
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -43,7 +42,7 @@ int main()
// try to write at a nonexisting key using string_view
object.at("the fast"sv) = "il rapido";
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/at__keytype_const.c++17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ int main()
// output element with key "the ugly" using string_view
std::cout << object.at("the ugly"sv) << '\n';


// exception type_error.304
try
{
// use at() with string_view on a non-object type
const json str = "I am a string";
std::cout << str.at("the good"sv) << '\n';
}
catch (json::type_error& e)
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -37,7 +36,7 @@ int main()
// try to read from a nonexisting key using string_view
std::cout << object.at("the fast"sv) << '\n';
}
catch (json::out_of_range)
catch (const json::out_of_range)
{
std::cout << "out of range" << '\n';
}
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/at__object_t_key_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ int main()
// output changed array
std::cout << object << '\n';


// exception type_error.304
try
{
// use at() on a non-object type
json str = "I am a string";
str.at("the good") = "Another string";
}
catch (json::type_error& e)
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -41,7 +40,7 @@ int main()
// try to write at a nonexisting key
object.at("the fast") = "il rapido";
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/at__object_t_key_type_const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ int main()
// output element with key "the ugly"
std::cout << object.at("the ugly") << '\n';


// exception type_error.304
try
{
// use at() on a non-object type
const json str = "I am a string";
std::cout << str.at("the good") << '\n';
}
catch (json::type_error& e)
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -35,7 +34,7 @@ int main()
// try to read from a nonexisting key
std::cout << object.at("the fast") << '\n';
}
catch (json::out_of_range)
catch (const json::out_of_range)
{
std::cout << "out of range" << '\n';
}
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/at__size_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ int main()
// output changed array
std::cout << array << '\n';


// exception type_error.304
try
{
// use at() on a non-array type
json str = "I am a string";
str.at(0) = "Another string";
}
catch (json::type_error& e)
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -36,7 +35,7 @@ int main()
// try to write beyond the array limit
array.at(5) = "sixth";
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/at__size_type_const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ int main()
// output element at index 2 (third element)
std::cout << array.at(2) << '\n';


// exception type_error.304
try
{
// use at() on a non-array type
const json str = "I am a string";
std::cout << str.at(0) << '\n';
}
catch (json::type_error& e)
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
Expand All @@ -30,7 +29,7 @@ int main()
// try to read beyond the array limit
std::cout << array.at(5) << '\n';
}
catch (json::out_of_range& e)
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/back.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int main()
json j_null;
j_null.back();
}
catch (json::invalid_iterator& e)
catch (const json::invalid_iterator& e)
{
std::cout << e.what() << '\n';
}
Expand Down
Loading

0 comments on commit 0012f86

Please sign in to comment.