mirror of
https://github.com/nlohmann/json.git
synced 2026-10-01 20:20:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc9370c291 | ||
|
|
666801a2c6 |
+17
@@ -0,0 +1,17 @@
|
|||||||
|
arm_container:
|
||||||
|
image: gcc:latest
|
||||||
|
|
||||||
|
check_task:
|
||||||
|
check_script:
|
||||||
|
# the gcc image ships an outdated CMake, so fetch a recent prebuilt binary
|
||||||
|
# instead of compiling CMake from source
|
||||||
|
- wget -q https://github.com/Kitware/CMake/releases/download/v4.3.4/cmake-4.3.4-linux-aarch64.tar.gz
|
||||||
|
- tar xfz cmake-4.3.4-linux-aarch64.tar.gz
|
||||||
|
- export PATH="$(pwd)/cmake-4.3.4-linux-aarch64/bin:$PATH"
|
||||||
|
- cmake --version
|
||||||
|
- mkdir build
|
||||||
|
- cd build
|
||||||
|
- cmake .. -DJSON_FastTests=ON
|
||||||
|
- make -j4
|
||||||
|
- cd tests
|
||||||
|
- ctest -j4
|
||||||
+5
-10
@@ -1,15 +1,9 @@
|
|||||||
# bugprone-use-after-move (hicpp-invalid-access-moved is its alias) still flags
|
# TODO: The first three checks are only removed to get the CI going. They have to be addressed at some point.
|
||||||
# the basic_json move constructor, which forwards the whole object to its base
|
# TODO: portability-avoid-pragma-once: should be fixed eventually
|
||||||
# class (#5724), and two forwards in the error-message construction of
|
|
||||||
# at(KeyType&&) (json.hpp, both overloads: find(std::forward<KeyType>(key))
|
|
||||||
# followed by string_t(std::forward<KeyType>(key)) in the throw), which #5689
|
|
||||||
# rewrites. Re-enable both checks once those changes have landed.
|
|
||||||
# portability-avoid-pragma-once: kept disabled on purpose. #pragma once is accepted
|
|
||||||
# by every supported compiler, and tools/amalgamate/amalgamate.py strips it from
|
|
||||||
# single_include, so there is nothing left to fix here.
|
|
||||||
|
|
||||||
Checks: '*,
|
Checks: '*,
|
||||||
|
|
||||||
|
-portability-template-virtual-member-function,
|
||||||
-bugprone-use-after-move,
|
-bugprone-use-after-move,
|
||||||
-hicpp-invalid-access-moved,
|
-hicpp-invalid-access-moved,
|
||||||
|
|
||||||
@@ -43,6 +37,7 @@ Checks: '*,
|
|||||||
-google-readability-function-size,
|
-google-readability-function-size,
|
||||||
-google-runtime-float,
|
-google-runtime-float,
|
||||||
-google-runtime-int,
|
-google-runtime-int,
|
||||||
|
-google-runtime-references,
|
||||||
-hicpp-avoid-goto,
|
-hicpp-avoid-goto,
|
||||||
-hicpp-explicit-conversions,
|
-hicpp-explicit-conversions,
|
||||||
-hicpp-function-size,
|
-hicpp-function-size,
|
||||||
@@ -76,7 +71,6 @@ Checks: '*,
|
|||||||
-readability-magic-numbers,
|
-readability-magic-numbers,
|
||||||
-readability-redundant-access-specifiers,
|
-readability-redundant-access-specifiers,
|
||||||
-readability-redundant-parentheses,
|
-readability-redundant-parentheses,
|
||||||
-readability-redundant-typename,
|
|
||||||
-readability-simplify-boolean-expr,
|
-readability-simplify-boolean-expr,
|
||||||
-readability-uppercase-literal-suffix,
|
-readability-uppercase-literal-suffix,
|
||||||
-readability-use-concise-preprocessor-directives'
|
-readability-use-concise-preprocessor-directives'
|
||||||
@@ -87,4 +81,5 @@ CheckOptions:
|
|||||||
|
|
||||||
WarningsAsErrors: '*'
|
WarningsAsErrors: '*'
|
||||||
|
|
||||||
|
#HeaderFilterRegex: '.*nlohmann.*'
|
||||||
HeaderFilterRegex: '.*hpp$'
|
HeaderFilterRegex: '.*hpp$'
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ updates:
|
|||||||
interval: daily
|
interval: daily
|
||||||
cooldown:
|
cooldown:
|
||||||
default-days: 7
|
default-days: 7
|
||||||
ignore:
|
|
||||||
# astyle is deliberately pinned (see tools/astyle/requirements.txt): newer versions
|
|
||||||
# reformat the code, and the pinned version defines the formatting CI enforces
|
|
||||||
- dependency-name: astyle
|
|
||||||
|
|
||||||
- package-ecosystem: pip
|
- package-ecosystem: pip
|
||||||
directory: /tools/generate_natvis
|
directory: /tools/generate_natvis
|
||||||
|
|||||||
@@ -30,6 +30,14 @@ environment:
|
|||||||
CMAKE_OPTIONS: ""
|
CMAKE_OPTIONS: ""
|
||||||
GENERATOR: Visual Studio 14 2015
|
GENERATOR: Visual Studio 14 2015
|
||||||
|
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||||
|
configuration: Release
|
||||||
|
platform: x86
|
||||||
|
name: with_win_header
|
||||||
|
CXX_FLAGS: "/W4 /WX"
|
||||||
|
CMAKE_OPTIONS: ""
|
||||||
|
GENERATOR: Visual Studio 14 2015
|
||||||
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||||
configuration: Release
|
configuration: Release
|
||||||
platform: x86
|
platform: x86
|
||||||
@@ -66,6 +74,9 @@ install:
|
|||||||
- if "%platform%"=="x86" set GENERATOR_PLATFORM=Win32
|
- if "%platform%"=="x86" set GENERATOR_PLATFORM=Win32
|
||||||
|
|
||||||
before_build:
|
before_build:
|
||||||
|
# for with_win_header build, inject the inclusion of Windows.h to the single-header library
|
||||||
|
- ps: if ($env:name -Eq "with_win_header") { $header_path = "single_include\nlohmann\json.hpp" }
|
||||||
|
- ps: if ($env:name -Eq "with_win_header") { "#include <Windows.h>`n" + (Get-Content $header_path | Out-String) | Set-Content $header_path }
|
||||||
- cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%"
|
- cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%"
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ jobs:
|
|||||||
MAIN_DIR: ${{ github.workspace }}/main
|
MAIN_DIR: ${{ github.workspace }}/main
|
||||||
INCLUDE_DIR: ${{ github.workspace }}/main/single_include/nlohmann
|
INCLUDE_DIR: ${{ github.workspace }}/main/single_include/nlohmann
|
||||||
TOOL_DIR: ${{ github.workspace }}/tools/tools/amalgamate
|
TOOL_DIR: ${{ github.workspace }}/tools/tools/amalgamate
|
||||||
NATVIS_TOOL_DIR: ${{ github.workspace }}/tools/tools/generate_natvis
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
@@ -62,48 +61,6 @@ jobs:
|
|||||||
python3 -mvenv venv
|
python3 -mvenv venv
|
||||||
venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
|
venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
|
||||||
|
|
||||||
- name: Install generate_natvis dependencies
|
|
||||||
run: pip3 install -r $NATVIS_TOOL_DIR/requirements.txt
|
|
||||||
|
|
||||||
- name: Regenerate the tools/macro_builder tables in macro_scope.hpp
|
|
||||||
run: |
|
|
||||||
cd $MAIN_DIR
|
|
||||||
|
|
||||||
# Built from this PR's own tools/macro_builder/main.cpp, not a
|
|
||||||
# develop checkout: unlike amalgamate.py and generate_natvis.py,
|
|
||||||
# this tool has no other source of truth to check against (its
|
|
||||||
# own README documents that it must reproduce macro_scope.hpp
|
|
||||||
# byte for byte), so there is nothing to gain from checking out a
|
|
||||||
# separate copy, and doing so would make this step fail on a PR
|
|
||||||
# that adds support for a new dispatch table until that PR itself
|
|
||||||
# merges to develop, the same way generate_natvis.py's --version
|
|
||||||
# requirement briefly did.
|
|
||||||
TMPDIR=$(mktemp -d ./macro_builder_check.XXXXXX)
|
|
||||||
c++ -std=c++11 tools/macro_builder/main.cpp -o "$TMPDIR/macro_builder"
|
|
||||||
"$TMPDIR/macro_builder" > "$TMPDIR/paste.hpp"
|
|
||||||
"$TMPDIR/macro_builder" type_body > "$TMPDIR/type_body.hpp"
|
|
||||||
|
|
||||||
# Splice the (still unindented) generated blocks back into
|
|
||||||
# macro_scope.hpp; the astyle pass below indents their
|
|
||||||
# continuation lines the same way it does for the rest of
|
|
||||||
# include/, so a correctly regenerated file comes out unchanged.
|
|
||||||
awk -v newfile="$TMPDIR/paste.hpp" '
|
|
||||||
BEGIN { while ((getline line < newfile) > 0) { new = new line "\n" } }
|
|
||||||
/^#define NLOHMANN_JSON_EXPAND\( x \) x$/ { printf "%s", new; skip=1 }
|
|
||||||
skip && /^#define NLOHMANN_JSON_DOUBLE_PASTE63\(/ { skip=0; next }
|
|
||||||
skip { next }
|
|
||||||
{ print }
|
|
||||||
' include/nlohmann/detail/macro_scope.hpp > "$TMPDIR/macro_scope_1.hpp"
|
|
||||||
awk -v newfile="$TMPDIR/type_body.hpp" '
|
|
||||||
BEGIN { while ((getline line < newfile) > 0) { new = new line "\n" } }
|
|
||||||
/^#define NLOHMANN_JSON_TYPE_BODY\(Prefix, \.\.\.\)/ { printf "%s", new; skip=1 }
|
|
||||||
skip && /^[[:space:]]*NLOHMANN_JSON_TYPE_BODY_SENTINEL\)\)$/ { skip=0; next }
|
|
||||||
skip { next }
|
|
||||||
{ print }
|
|
||||||
' "$TMPDIR/macro_scope_1.hpp" > "$TMPDIR/macro_scope_2.hpp"
|
|
||||||
mv "$TMPDIR/macro_scope_2.hpp" include/nlohmann/detail/macro_scope.hpp
|
|
||||||
rm -rf "$TMPDIR"
|
|
||||||
|
|
||||||
- name: Regenerate amalgamation, formatting, and BUILD.bazel
|
- name: Regenerate amalgamation, formatting, and BUILD.bazel
|
||||||
run: |
|
run: |
|
||||||
cd $MAIN_DIR
|
cd $MAIN_DIR
|
||||||
@@ -131,19 +88,6 @@ jobs:
|
|||||||
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
||||||
$(find $SOURCE_DIRS -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
|
$(find $SOURCE_DIRS -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
|
||||||
|
|
||||||
- name: Regenerate nlohmann_json.natvis
|
|
||||||
run: |
|
|
||||||
cd $MAIN_DIR
|
|
||||||
# Pass --version explicitly so this step also works with the tool
|
|
||||||
# copy from develop before this repository's own generate_natvis.py
|
|
||||||
# learns to derive the version itself: the older script requires
|
|
||||||
# --version, and the newer one accepts it as an explicit override.
|
|
||||||
ABI_MACROS=include/nlohmann/detail/abi_macros.hpp
|
|
||||||
VERSION_MAJOR=$(grep -m1 'define NLOHMANN_JSON_VERSION_MAJOR' $ABI_MACROS | grep -o '[0-9]\+')
|
|
||||||
VERSION_MINOR=$(grep -m1 'define NLOHMANN_JSON_VERSION_MINOR' $ABI_MACROS | grep -o '[0-9]\+')
|
|
||||||
VERSION_PATCH=$(grep -m1 'define NLOHMANN_JSON_VERSION_PATCH' $ABI_MACROS | grep -o '[0-9]\+')
|
|
||||||
python3 $NATVIS_TOOL_DIR/generate_natvis.py --version "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" $MAIN_DIR
|
|
||||||
|
|
||||||
- name: Build patch and check for differences
|
- name: Build patch and check for differences
|
||||||
id: diff
|
id: diff
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -7,16 +7,6 @@ on:
|
|||||||
- develop
|
- develop
|
||||||
paths:
|
paths:
|
||||||
- docs/mkdocs/**
|
- docs/mkdocs/**
|
||||||
# the site also embeds these files via pymdownx.snippets
|
|
||||||
# (mkdocs.yml sets restrict_base_path: false for this)
|
|
||||||
- .clang-tidy
|
|
||||||
- .github/CODE_OF_CONDUCT.md
|
|
||||||
- .github/CONTRIBUTING.md
|
|
||||||
- .github/SECURITY.md
|
|
||||||
- cmake/clang_flags.cmake
|
|
||||||
- cmake/gcc_flags.cmake
|
|
||||||
- tests/fmt_formatter/project/main.cpp
|
|
||||||
- tools/astyle/.astylerc
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
# we don't want to have concurrent jobs, and we don't want to cancel running jobs to avoid broken publications
|
# we don't want to have concurrent jobs, and we don't want to cancel running jobs to avoid broken publications
|
||||||
@@ -33,7 +23,7 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
if: github.repository == 'nlohmann/json'
|
if: github.repository == 'nlohmann/json'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||||
@@ -41,8 +31,6 @@ jobs:
|
|||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: Install virtual environment
|
- name: Install virtual environment
|
||||||
run: make install_venv -C docs/mkdocs
|
run: make install_venv -C docs/mkdocs
|
||||||
|
|||||||
@@ -52,13 +52,6 @@ jobs:
|
|||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --target ci_infer
|
run: cmake --build build --target ci_infer
|
||||||
- name: Archive Infer report
|
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
||||||
with:
|
|
||||||
name: infer-report
|
|
||||||
path: ${{ github.workspace }}/build/build_infer/infer-out/report.txt
|
|
||||||
if-no-files-found: ignore
|
|
||||||
|
|
||||||
ci_static_analysis_ubuntu:
|
ci_static_analysis_ubuntu:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -85,7 +78,7 @@ jobs:
|
|||||||
|
|
||||||
ci_static_analysis_clang:
|
ci_static_analysis_clang:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: silkeh/clang:22
|
container: silkeh/clang:dev
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
target: [ci_test_clang, ci_clang_tidy, ci_test_clang_sanitizer, ci_clang_analyze, ci_single_binaries]
|
target: [ci_test_clang, ci_clang_tidy, ci_test_clang_sanitizer, ci_clang_analyze, ci_single_binaries]
|
||||||
@@ -104,13 +97,13 @@ jobs:
|
|||||||
|
|
||||||
ci_cmake_options:
|
ci_cmake_options:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ubuntu:24.04
|
container: ubuntu:focal
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
target: [ci_cmake_flags, ci_test_diagnostics, ci_test_diagnostic_positions, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls, ci_test_disableenumserialization, ci_test_disabletuplereferenceconversion, ci_test_skiplibraryversioncheck, ci_test_simdutf, ci_test_strict_nul_handling, ci_test_no_thread_local]
|
target: [ci_cmake_flags, ci_test_diagnostics, ci_test_diagnostic_positions, ci_test_noexceptions, ci_test_noimplicitconversions, ci_test_legacycomparison, ci_test_noglobaludls, ci_test_disableenumserialization, ci_test_skiplibraryversioncheck, ci_test_simdutf, ci_test_strict_nul_handling, ci_test_no_thread_local]
|
||||||
steps:
|
steps:
|
||||||
- name: Install build-essential
|
- name: Install build-essential
|
||||||
run: apt-get update ; apt-get install -y build-essential unzip wget git
|
run: apt-get update ; apt-get install -y build-essential unzip wget git libssl-dev
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
@@ -353,8 +346,6 @@ jobs:
|
|||||||
container: intel/oneapi-hpckit:latest
|
container: intel/oneapi-hpckit:latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -367,8 +358,6 @@ jobs:
|
|||||||
container: nvcr.io/nvidia/nvhpc:25.5-devel-cuda12.9-ubuntu22.04
|
container: nvcr.io/nvidia/nvhpc:25.5-devel-cuda12.9-ubuntu22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
@@ -414,21 +403,3 @@ jobs:
|
|||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --target ${{ matrix.target }}
|
run: cmake --build build --target ${{ matrix.target }}
|
||||||
|
|
||||||
# Native Linux ARM64 runner with the latest GCC. The ubuntu-24.04-arm label is
|
|
||||||
# only available for public repositories.
|
|
||||||
ci_test_arm64:
|
|
||||||
runs-on: ubuntu-24.04-arm
|
|
||||||
container: gcc:latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Get latest CMake and ninja
|
|
||||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
|
||||||
- name: Check that the job runs natively on arm64
|
|
||||||
run: uname -m && test "$(uname -m)" = aarch64
|
|
||||||
- name: Run CMake
|
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
|
||||||
- name: Build
|
|
||||||
run: cmake --build build --target ci_test_compiler_default
|
|
||||||
|
|||||||
@@ -87,8 +87,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
uses: lukka/get-cmake@fffaaafeea488556c2c12dad60690008bc1caacb # v4.4.2
|
||||||
- name: Set extra CXX_FLAGS for latest std_version
|
- name: Set extra CXX_FLAGS for latest std_version
|
||||||
@@ -125,8 +123,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Run CMake (Release)
|
- name: Run CMake (Release)
|
||||||
run: cmake -S . -B build -G "Visual Studio 18 2026" -A ARM64 -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
run: cmake -S . -B build -G "Visual Studio 18 2026" -A ARM64 -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX"
|
||||||
if: matrix.build_type == 'Release'
|
if: matrix.build_type == 'Release'
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"_comment": "Used by the ci_infer CMake target (#5715 item 4b). fail-on-issue makes CI fail on Infer findings; disable-issue-type is a type-level baseline for the ~174 pre-existing findings (all PULSE_UNNECESSARY_COPY*/PULSE_RESOURCE_LEAK/PULSE_CONST_REFABLE, mostly in test code) triaged in run https://github.com/nlohmann/json/actions/runs/35829411620 on commit 1054b2097, so CI fails only on a NEW issue type. Remove an entry here once its findings have been fixed or explicitly accepted.",
|
|
||||||
"fail-on-issue": true,
|
|
||||||
"disable-issue-type": [
|
|
||||||
"PULSE_UNNECESSARY_COPY_ASSIGNMENT",
|
|
||||||
"PULSE_UNNECESSARY_COPY",
|
|
||||||
"PULSE_UNNECESSARY_COPY_INTERMEDIATE",
|
|
||||||
"PULSE_UNNECESSARY_COPY_OPTIONAL",
|
|
||||||
"PULSE_RESOURCE_LEAK",
|
|
||||||
"PULSE_CONST_REFABLE"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -23,6 +23,10 @@ Files: tests/thirdparty/fifo_map/*
|
|||||||
Copyright: 2015-2017 Niels Lohmann
|
Copyright: 2015-2017 Niels Lohmann
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|
||||||
|
Files: tests/thirdparty/Fuzzer/*
|
||||||
|
Copyright: 2003-2022 LLVM Project.
|
||||||
|
License: Apache-2.0
|
||||||
|
|
||||||
Files: tests/thirdparty/imapdl/*
|
Files: tests/thirdparty/imapdl/*
|
||||||
Copyright: 2017 Georg Sauthoff <mail@gms.tf>
|
Copyright: 2017 Georg Sauthoff <mail@gms.tf>
|
||||||
License: GPL-3.0-only
|
License: GPL-3.0-only
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ option(JSON_Diagnostic_Positions "Enable diagnostic positions." OFF)
|
|||||||
option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON)
|
option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON)
|
||||||
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
||||||
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
||||||
option(JSON_DisableTupleReferenceConversion "Disable conversion from a one-element tuple of a JSON reference." OFF)
|
|
||||||
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
||||||
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
||||||
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON)
|
||||||
@@ -102,10 +101,6 @@ if (JSON_DisableEnumSerialization)
|
|||||||
message(STATUS "Enum integer serialization is disabled (JSON_DISABLE_ENUM_SERIALIZATION=1)")
|
message(STATUS "Enum integer serialization is disabled (JSON_DISABLE_ENUM_SERIALIZATION=1)")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (JSON_DisableTupleReferenceConversion)
|
|
||||||
message(STATUS "Tuple reference conversion is disabled (JSON_DISABLE_TUPLE_REFERENCE_CONVERSION=1)")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (JSON_LegacyDiscardedValueComparison)
|
if (JSON_LegacyDiscardedValueComparison)
|
||||||
message(STATUS "Legacy discarded value comparison enabled (JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1)")
|
message(STATUS "Legacy discarded value comparison enabled (JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1)")
|
||||||
endif()
|
endif()
|
||||||
@@ -148,7 +143,6 @@ target_compile_definitions(
|
|||||||
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
|
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
|
||||||
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
|
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
|
||||||
$<$<BOOL:${JSON_DisableEnumSerialization}>:JSON_DISABLE_ENUM_SERIALIZATION=1>
|
$<$<BOOL:${JSON_DisableEnumSerialization}>:JSON_DISABLE_ENUM_SERIALIZATION=1>
|
||||||
$<$<BOOL:${JSON_DisableTupleReferenceConversion}>:JSON_DISABLE_TUPLE_REFERENCE_CONVERSION=1>
|
|
||||||
$<$<BOOL:${JSON_Diagnostics}>:JSON_DIAGNOSTICS=1>
|
$<$<BOOL:${JSON_Diagnostics}>:JSON_DIAGNOSTICS=1>
|
||||||
$<$<BOOL:${JSON_Diagnostic_Positions}>:JSON_DIAGNOSTIC_POSITIONS=1>
|
$<$<BOOL:${JSON_Diagnostic_Positions}>:JSON_DIAGNOSTIC_POSITIONS=1>
|
||||||
$<$<BOOL:${JSON_LegacyDiscardedValueComparison}>:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>
|
$<$<BOOL:${JSON_LegacyDiscardedValueComparison}>:JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1>
|
||||||
|
|||||||
@@ -33,6 +33,17 @@ Further documentation:
|
|||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> The folder `.github/workflows` is predetermined by GitHub.
|
> The folder `.github/workflows` is predetermined by GitHub.
|
||||||
|
|
||||||
|
### `.cirrus.yml`
|
||||||
|
|
||||||
|
Configuration file for the pipeline at [Cirrus CI](https://cirrus-ci.com/github/nlohmann/json).
|
||||||
|
|
||||||
|
Further documentation:
|
||||||
|
|
||||||
|
- [Writing tasks](https://cirrus-ci.org/guide/writing-tasks/)
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> The filename `.cirrus.yml` and position (root of the repository) are predetermined by Cirrus CI.
|
||||||
|
|
||||||
### `.github/external_ci/appveyor.yml`
|
### `.github/external_ci/appveyor.yml`
|
||||||
|
|
||||||
Configuration for the pipelines at [AppVeyor](https://ci.appveyor.com/project/nlohmann/json).
|
Configuration for the pipelines at [AppVeyor](https://ci.appveyor.com/project/nlohmann/json).
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: pretty clean ChangeLog.md release update_hedley update_hedley_undef BUILD.bazel natvis macro_builder_check
|
.PHONY: pretty clean ChangeLog.md release update_hedley update_hedley_undef BUILD.bazel
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# configuration
|
# configuration
|
||||||
@@ -24,9 +24,6 @@ AMALGAMATED_FWD_FILE=single_include/nlohmann/json_fwd.hpp
|
|||||||
# json_literals.hpp only includes <nlohmann/json.hpp>, so it is copied verbatim
|
# json_literals.hpp only includes <nlohmann/json.hpp>, so it is copied verbatim
|
||||||
AMALGAMATED_LITERALS_FILE=single_include/nlohmann/json_literals.hpp
|
AMALGAMATED_LITERALS_FILE=single_include/nlohmann/json_literals.hpp
|
||||||
|
|
||||||
# the header with the argument-counting macros generated by tools/macro_builder
|
|
||||||
MACRO_SCOPE_HPP=include/nlohmann/detail/macro_scope.hpp
|
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# documentation of the Makefile's targets
|
# documentation of the Makefile's targets
|
||||||
@@ -39,9 +36,13 @@ all:
|
|||||||
@echo "ChangeLog.md - generate ChangeLog file"
|
@echo "ChangeLog.md - generate ChangeLog file"
|
||||||
@echo "check-amalgamation - check whether sources have been amalgamated and BUILD.bazel is up to date"
|
@echo "check-amalgamation - check whether sources have been amalgamated and BUILD.bazel is up to date"
|
||||||
@echo "clean - remove built files"
|
@echo "clean - remove built files"
|
||||||
@echo "fuzzing - see tests/fuzzing.md for how to build and run the fuzzers"
|
@echo "doctest - compile example files and check their output"
|
||||||
@echo "macro_builder_check - check that macro_scope.hpp matches tools/macro_builder's output"
|
@echo "fuzz_testing - prepare fuzz testing of the JSON parser"
|
||||||
@echo "natvis - regenerate nlohmann_json.natvis from the current ABI tags and version"
|
@echo "fuzz_testing_bon8 - prepare fuzz testing of the BON8 parser"
|
||||||
|
@echo "fuzz_testing_bson - prepare fuzz testing of the BSON parser"
|
||||||
|
@echo "fuzz_testing_cbor - prepare fuzz testing of the CBOR parser"
|
||||||
|
@echo "fuzz_testing_msgpack - prepare fuzz testing of the MessagePack parser"
|
||||||
|
@echo "fuzz_testing_ubjson - prepare fuzz testing of the UBJSON parser"
|
||||||
@echo "pretty - beautify code with Artistic Style"
|
@echo "pretty - beautify code with Artistic Style"
|
||||||
@echo "run_benchmarks - build and run benchmarks"
|
@echo "run_benchmarks - build and run benchmarks"
|
||||||
@echo "update_hedley - download Hedley and regenerate hedley.hpp / hedley_undef.hpp"
|
@echo "update_hedley - download Hedley and regenerate hedley.hpp / hedley_undef.hpp"
|
||||||
@@ -60,6 +61,74 @@ run_benchmarks:
|
|||||||
cd cmake-build-benchmarks ; ./json_benchmarks
|
cd cmake-build-benchmarks ; ./json_benchmarks
|
||||||
|
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
# fuzzing
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
# the overall fuzz testing target
|
||||||
|
fuzz_testing:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_afl_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_afl_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_bon8:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_bon8_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_bon8_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.bon8 | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_bson:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_bson_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_bson_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.bson | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_cbor:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_cbor_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_cbor_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.cbor | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_msgpack:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_msgpack_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_msgpack_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.msgpack | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzz_testing_ubjson:
|
||||||
|
rm -fr fuzz-testing
|
||||||
|
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
|
||||||
|
$(MAKE) parse_ubjson_fuzzer -C tests CXX=afl-clang++
|
||||||
|
mv tests/parse_ubjson_fuzzer fuzz-testing/fuzzer
|
||||||
|
find tests/data -size -5k -name *.ubjson | xargs -I{} cp "{}" fuzz-testing/testcases
|
||||||
|
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
|
||||||
|
|
||||||
|
fuzzing-start:
|
||||||
|
afl-fuzz -S fuzzer1 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer2 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer3 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer4 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer5 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer6 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -S fuzzer7 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
|
||||||
|
afl-fuzz -M fuzzer0 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer
|
||||||
|
|
||||||
|
fuzzing-stop:
|
||||||
|
-killall fuzzer
|
||||||
|
-killall afl-fuzz
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Static analysis
|
# Static analysis
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@@ -87,7 +156,11 @@ install_astyle:
|
|||||||
|
|
||||||
# call the Artistic Style pretty printer on all source files
|
# call the Artistic Style pretty printer on all source files
|
||||||
pretty: install_astyle
|
pretty: install_astyle
|
||||||
$(ASTYLE) --project=tools/astyle/.astylerc $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE) docs/mkdocs/docs/examples/*.cpp docs/mkdocs/docs/examples/*.hpp
|
$(ASTYLE) --project=tools/astyle/.astylerc $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE) docs/mkdocs/docs/examples/*.cpp
|
||||||
|
|
||||||
|
# call the Clang-Format on all source files
|
||||||
|
pretty_format:
|
||||||
|
for FILE in $(SRCS) $(TESTS_SRCS) $(AMALGAMATED_FILE) docs/mkdocs/docs/examples/*.cpp; do echo $$FILE; clang-format -i $$FILE; done
|
||||||
|
|
||||||
# create single header files and pretty print
|
# create single header files and pretty print
|
||||||
amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE)
|
amalgamate: $(AMALGAMATED_FILE) $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_LITERALS_FILE)
|
||||||
@@ -105,26 +178,8 @@ $(AMALGAMATED_FWD_FILE): $(SRCS)
|
|||||||
$(AMALGAMATED_LITERALS_FILE): include/nlohmann/json_literals.hpp
|
$(AMALGAMATED_LITERALS_FILE): include/nlohmann/json_literals.hpp
|
||||||
cp include/nlohmann/json_literals.hpp $(AMALGAMATED_LITERALS_FILE)
|
cp include/nlohmann/json_literals.hpp $(AMALGAMATED_LITERALS_FILE)
|
||||||
|
|
||||||
# regenerate nlohmann_json.natvis from the ABI tags and version in include/nlohmann/detail/abi_macros.hpp
|
|
||||||
natvis:
|
|
||||||
python3 tools/generate_natvis/generate_natvis.py .
|
|
||||||
|
|
||||||
# regenerate the two tools/macro_builder blocks of $(MACRO_SCOPE_HPP) (see its README.md) and diff against the
|
|
||||||
# checked-in header; phony, because it never writes $(MACRO_SCOPE_HPP) itself
|
|
||||||
macro_builder_check:
|
|
||||||
@set -e; \
|
|
||||||
TMPDIR=$$(mktemp -d ./macro_builder_check.XXXXXX); \
|
|
||||||
trap 'rm -rf "$$TMPDIR"' EXIT; \
|
|
||||||
$(CXX) -std=c++11 tools/macro_builder/main.cpp -o "$$TMPDIR/macro_builder"; \
|
|
||||||
"$$TMPDIR/macro_builder" > "$$TMPDIR/paste.hpp"; \
|
|
||||||
"$$TMPDIR/macro_builder" type_body > "$$TMPDIR/type_body.hpp"; \
|
|
||||||
$(ASTYLE) --project=tools/astyle/.astylerc --suffix=none --quiet "$$TMPDIR/paste.hpp" "$$TMPDIR/type_body.hpp"; \
|
|
||||||
sed -n '/^#define NLOHMANN_JSON_EXPAND( x ) x$$/,/^#define NLOHMANN_JSON_DOUBLE_PASTE63(/p' $(MACRO_SCOPE_HPP) > "$$TMPDIR/paste_actual.hpp"; \
|
|
||||||
sed -n '/^#define NLOHMANN_JSON_TYPE_BODY(Prefix, \.\.\.)/,/^ NLOHMANN_JSON_TYPE_BODY_SENTINEL))$$/p' $(MACRO_SCOPE_HPP) > "$$TMPDIR/type_body_actual.hpp"; \
|
|
||||||
diff "$$TMPDIR/paste.hpp" "$$TMPDIR/paste_actual.hpp" || (echo "===================================================================\n $(MACRO_SCOPE_HPP) (NLOHMANN_JSON_EXPAND..NLOHMANN_JSON_DOUBLE_PASTE63) is out of date!\n Regenerate it, see tools/macro_builder/README.md.\n===================================================================" ; exit 1); \
|
|
||||||
diff "$$TMPDIR/type_body.hpp" "$$TMPDIR/type_body_actual.hpp" || (echo "===================================================================\n $(MACRO_SCOPE_HPP) (NLOHMANN_JSON_TYPE_BODY) is out of date!\n Regenerate it, see tools/macro_builder/README.md.\n===================================================================" ; exit 1)
|
|
||||||
|
|
||||||
# check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources
|
# check if file single_include/nlohmann/json.hpp has been amalgamated from the nlohmann sources
|
||||||
|
# Note: this target is called by Travis
|
||||||
check-amalgamation:
|
check-amalgamation:
|
||||||
@mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~
|
@mv $(AMALGAMATED_FILE) $(AMALGAMATED_FILE)~
|
||||||
@mv $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~
|
@mv $(AMALGAMATED_FWD_FILE) $(AMALGAMATED_FWD_FILE)~
|
||||||
@@ -140,11 +195,6 @@ check-amalgamation:
|
|||||||
@$(MAKE) BUILD.bazel
|
@$(MAKE) BUILD.bazel
|
||||||
@diff BUILD.bazel BUILD.bazel~ || (echo "===================================================================\n BUILD.bazel is out of date! Please run 'make BUILD.bazel'.\n===================================================================" ; mv BUILD.bazel~ BUILD.bazel ; false)
|
@diff BUILD.bazel BUILD.bazel~ || (echo "===================================================================\n BUILD.bazel is out of date! Please run 'make BUILD.bazel'.\n===================================================================" ; mv BUILD.bazel~ BUILD.bazel ; false)
|
||||||
@mv BUILD.bazel~ BUILD.bazel
|
@mv BUILD.bazel~ BUILD.bazel
|
||||||
@mv nlohmann_json.natvis nlohmann_json.natvis~
|
|
||||||
@$(MAKE) natvis
|
|
||||||
@diff nlohmann_json.natvis nlohmann_json.natvis~ || (echo "===================================================================\n nlohmann_json.natvis is out of date! Please run 'make natvis'.\n===================================================================" ; mv nlohmann_json.natvis~ nlohmann_json.natvis ; false)
|
|
||||||
@mv nlohmann_json.natvis~ nlohmann_json.natvis
|
|
||||||
@$(MAKE) macro_builder_check
|
|
||||||
|
|
||||||
# generate the Bazel BUILD file; phony, because a removed header would not trigger a rebuild
|
# generate the Bazel BUILD file; phony, because a removed header would not trigger a rebuild
|
||||||
BUILD.bazel:
|
BUILD.bazel:
|
||||||
@@ -196,7 +246,7 @@ release: include.zip json.tar.xz
|
|||||||
cp $(AMALGAMATED_FWD_FILE) release_files
|
cp $(AMALGAMATED_FWD_FILE) release_files
|
||||||
cp $(AMALGAMATED_LITERALS_FILE) release_files
|
cp $(AMALGAMATED_LITERALS_FILE) release_files
|
||||||
mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc $(AMALGAMATED_LITERALS_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
|
mv $(AMALGAMATED_FILE).asc $(AMALGAMATED_FWD_FILE).asc $(AMALGAMATED_LITERALS_FILE).asc json.tar.xz json.tar.xz.asc include.zip include.zip.asc release_files
|
||||||
cd release_files ; shasum -a 256 $$(find . -type f -not -name '*.asc' | sed 's|^\./||' | sort) > hashes.txt
|
cd release_files ; shasum -a 256 json.hpp include.zip json.tar.xz > hashes.txt
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
@@ -206,6 +256,7 @@ release: include.zip json.tar.xz
|
|||||||
# clean up
|
# clean up
|
||||||
clean:
|
clean:
|
||||||
rm -fr fuzz fuzz-testing *.dSYM tests/*.dSYM
|
rm -fr fuzz fuzz-testing *.dSYM tests/*.dSYM
|
||||||
|
rm -fr benchmarks/files/numbers/*.json
|
||||||
rm -fr cmake-build-benchmarks fuzz-testing cmake-build-pvs-studio release_files
|
rm -fr cmake-build-benchmarks fuzz-testing cmake-build-pvs-studio release_files
|
||||||
$(MAKE) clean -Cdocs
|
$(MAKE) clean -Cdocs
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
[](https://coveralls.io/github/nlohmann/json?branch=develop)
|
[](https://coveralls.io/github/nlohmann/json?branch=develop)
|
||||||
[](https://scan.coverity.com/projects/nlohmann-json)
|
[](https://scan.coverity.com/projects/nlohmann-json)
|
||||||
[](https://app.codacy.com/gh/nlohmann/json/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
[](https://app.codacy.com/gh/nlohmann/json/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
||||||
|
[](https://cirrus-ci.com/github/nlohmann/json)
|
||||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:json)
|
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:json)
|
||||||
[](https://wandbox.org/permlink/1mp10JbaANo6FUc7)
|
[](https://wandbox.org/permlink/1mp10JbaANo6FUc7)
|
||||||
[](https://json.nlohmann.me)
|
[](https://json.nlohmann.me)
|
||||||
|
|||||||
+98
-137
@@ -8,24 +8,24 @@ set(N 10)
|
|||||||
include(FindPython3)
|
include(FindPython3)
|
||||||
find_package(Python3 COMPONENTS Interpreter)
|
find_package(Python3 COMPONENTS Interpreter)
|
||||||
|
|
||||||
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-22 clang++-21 clang++-20 clang++-19 clang++-18 clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
find_program(CLANG_TOOL NAMES clang++-HEAD clang++ clang++-20 clang++-19 clang++-18 clang++-17 clang++-16 clang++-15 clang++-14 clang++-13 clang++-12 clang++-11 clang++)
|
||||||
execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
|
execute_process(COMMAND ${CLANG_TOOL} --version OUTPUT_VARIABLE CLANG_TOOL_VERSION ERROR_VARIABLE CLANG_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TOOL_VERSION "${CLANG_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
message(STATUS "🔖 Clang ${CLANG_TOOL_VERSION} (${CLANG_TOOL})")
|
||||||
|
|
||||||
find_program(CLANG_TIDY_TOOL NAMES clang-tidy-22 clang-tidy-21 clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
|
find_program(CLANG_TIDY_TOOL NAMES clang-tidy-20 clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11 clang-tidy)
|
||||||
execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION)
|
execute_process(COMMAND ${CLANG_TIDY_TOOL} --version OUTPUT_VARIABLE CLANG_TIDY_TOOL_VERSION ERROR_VARIABLE CLANG_TIDY_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CLANG_TIDY_TOOL_VERSION "${CLANG_TIDY_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
|
message(STATUS "🔖 Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})")
|
||||||
|
|
||||||
message(STATUS "🔖 CMake ${CMAKE_VERSION} (${CMAKE_COMMAND})")
|
message(STATUS "🔖 CMake ${CMAKE_VERSION} (${CMAKE_COMMAND})")
|
||||||
|
|
||||||
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++ g++-16 g++-15 g++-14 g++-13 g++-12 g++-11 g++-10)
|
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++ g++-15 g++-14 g++-13 g++-12 g++-11 g++-10)
|
||||||
execute_process(COMMAND ${GCC_TOOL} --version OUTPUT_VARIABLE GCC_TOOL_VERSION ERROR_VARIABLE GCC_TOOL_VERSION)
|
execute_process(COMMAND ${GCC_TOOL} --version OUTPUT_VARIABLE GCC_TOOL_VERSION ERROR_VARIABLE GCC_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")
|
message(STATUS "🔖 GCC ${GCC_TOOL_VERSION} (${GCC_TOOL})")
|
||||||
|
|
||||||
find_program(GCOV_TOOL NAMES gcov-HEAD gcov gcov-16 gcov-15 gcov-14 gcov-13 gcov-12 gcov-11 gcov-10)
|
find_program(GCOV_TOOL NAMES gcov-HEAD gcov gcov-15 gcov-14 gcov-13 gcov-12 gcov-11 gcov-10)
|
||||||
execute_process(COMMAND ${GCOV_TOOL} --version OUTPUT_VARIABLE GCOV_TOOL_VERSION ERROR_VARIABLE GCOV_TOOL_VERSION)
|
execute_process(COMMAND ${GCOV_TOOL} --version OUTPUT_VARIABLE GCOV_TOOL_VERSION ERROR_VARIABLE GCOV_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCOV_TOOL_VERSION "${GCOV_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCOV_TOOL_VERSION "${GCOV_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 GCOV ${GCOV_TOOL_VERSION} (${GCOV_TOOL})")
|
message(STATUS "🔖 GCOV ${GCOV_TOOL_VERSION} (${GCOV_TOOL})")
|
||||||
@@ -40,14 +40,6 @@ execute_process(COMMAND ${IWYU_TOOL} --version OUTPUT_VARIABLE IWYU_TOOL_VERSION
|
|||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" IWYU_TOOL_VERSION "${IWYU_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" IWYU_TOOL_VERSION "${IWYU_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 include-what-you-use ${IWYU_TOOL_VERSION} (${IWYU_TOOL})")
|
message(STATUS "🔖 include-what-you-use ${IWYU_TOOL_VERSION} (${IWYU_TOOL})")
|
||||||
|
|
||||||
# CMake's CXX_INCLUDE_WHAT_YOU_USE launcher runs IWYU during the normal compile step (useful to see
|
|
||||||
# diagnostics inline), but CMake's own __run_co_compile wrapper does not propagate the launched
|
|
||||||
# tool's exit code to the build, so IWYU's own "-Xiwyu --error" cannot fail that step (verified: a
|
|
||||||
# deliberately-unused #include in a header still lets `cmake --build` finish with exit code 0).
|
|
||||||
# iwyu_tool.py, which ships with IWYU, reads compile_commands.json and does return a non-zero exit
|
|
||||||
# code for any analyzed file with findings; ci_single_binaries uses it to actually fail on findings.
|
|
||||||
find_program(IWYU_TOOL_PY NAMES iwyu_tool iwyu_tool.py iwyu-tool)
|
|
||||||
|
|
||||||
find_program(INFER_TOOL NAMES infer)
|
find_program(INFER_TOOL NAMES infer)
|
||||||
execute_process(COMMAND ${INFER_TOOL} --version OUTPUT_VARIABLE INFER_TOOL_VERSION ERROR_VARIABLE INFER_TOOL_VERSION)
|
execute_process(COMMAND ${INFER_TOOL} --version OUTPUT_VARIABLE INFER_TOOL_VERSION ERROR_VARIABLE INFER_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" INFER_TOOL_VERSION "${INFER_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" INFER_TOOL_VERSION "${INFER_TOOL_VERSION}")
|
||||||
@@ -63,6 +55,12 @@ execute_process(COMMAND ${NINJA_TOOL} --version OUTPUT_VARIABLE NINJA_TOOL_VERSI
|
|||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" NINJA_TOOL_VERSION "${NINJA_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" NINJA_TOOL_VERSION "${NINJA_TOOL_VERSION}")
|
||||||
message(STATUS "🔖 Ninja ${NINJA_TOOL_VERSION} (${NINJA_TOOL})")
|
message(STATUS "🔖 Ninja ${NINJA_TOOL_VERSION} (${NINJA_TOOL})")
|
||||||
|
|
||||||
|
find_program(OCLINT_TOOL NAMES oclint-json-compilation-database)
|
||||||
|
find_program(OCLINT_VERSION_TOOL NAMES oclint)
|
||||||
|
execute_process(COMMAND ${OCLINT_VERSION_TOOL} --version OUTPUT_VARIABLE OCLINT_TOOL_VERSION ERROR_VARIABLE OCLINT_TOOL_VERSION)
|
||||||
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" OCLINT_TOOL_VERSION "${OCLINT_TOOL_VERSION}")
|
||||||
|
message(STATUS "🔖 OCLint ${OCLINT_TOOL_VERSION} (${OCLINT_TOOL})")
|
||||||
|
|
||||||
find_program(VALGRIND_TOOL NAMES valgrind)
|
find_program(VALGRIND_TOOL NAMES valgrind)
|
||||||
execute_process(COMMAND ${VALGRIND_TOOL} --version OUTPUT_VARIABLE VALGRIND_TOOL_VERSION ERROR_VARIABLE VALGRIND_TOOL_VERSION)
|
execute_process(COMMAND ${VALGRIND_TOOL} --version OUTPUT_VARIABLE VALGRIND_TOOL_VERSION ERROR_VARIABLE VALGRIND_TOOL_VERSION)
|
||||||
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" VALGRIND_TOOL_VERSION "${VALGRIND_TOOL_VERSION}")
|
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" VALGRIND_TOOL_VERSION "${VALGRIND_TOOL_VERSION}")
|
||||||
@@ -130,16 +128,16 @@ foreach(CXX_STANDARD 11 14 17 20 23 26)
|
|||||||
COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
|
COMMENT "Compile and test with Clang for C++${CXX_STANDARD}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# pass -stdlib=libc++ through CXXFLAGS: an explicit -DCMAKE_CXX_FLAGS would make CMake ignore CXXFLAGS
|
|
||||||
add_custom_target(ci_test_clang_libcxx_cxx${CXX_STANDARD}
|
add_custom_target(ci_test_clang_libcxx_cxx${CXX_STANDARD}
|
||||||
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS};-stdlib=libc++" ${CMAKE_COMMAND}
|
COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
-DJSON_BuildTests=ON -DJSON_FastTests=ON
|
||||||
-DJSON_TestStandards=${CXX_STANDARD}
|
-DJSON_TestStandards=${CXX_STANDARD}
|
||||||
|
-DCMAKE_CXX_FLAGS="-stdlib=libc++"
|
||||||
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi"
|
-DCMAKE_EXE_LINKER_FLAGS="-lc++abi"
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD}
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD}
|
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_libcxx_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
||||||
COMMENT "Compile and test with Clang for C++${CXX_STANDARD} (libc++)"
|
COMMENT "Compile and test with Clang for C++${CXX_STANDARD} (libc++)"
|
||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
@@ -278,20 +276,6 @@ add_custom_target(ci_test_disableenumserialization
|
|||||||
COMMENT "Compile and test with enum serialization disabled"
|
COMMENT "Compile and test with enum serialization disabled"
|
||||||
)
|
)
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Disable conversion from a one-element tuple of a JSON reference.
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
add_custom_target(ci_test_disabletuplereferenceconversion
|
|
||||||
COMMAND ${CMAKE_COMMAND}
|
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
|
||||||
-DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_DisableTupleReferenceConversion=ON
|
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_disabletuplereferenceconversion
|
|
||||||
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_disabletuplereferenceconversion
|
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_disabletuplereferenceconversion && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
|
|
||||||
COMMENT "Compile and test with tuple reference conversion disabled"
|
|
||||||
)
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Skip the multiple-inclusion library version check.
|
# Skip the multiple-inclusion library version check.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -378,20 +362,13 @@ add_custom_target(ci_test_clang_sanitizer
|
|||||||
# Check if header is amalgamated and sources are properly indented.
|
# Check if header is amalgamated and sources are properly indented.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Same file set as .github/workflows/check_amalgamation.yml, so a direct push to develop/master/release/*
|
|
||||||
# (which only this CMake target checks, not the pull_request-only workflow) is held to the same standard.
|
|
||||||
file(GLOB_RECURSE INDENT_FILES
|
file(GLOB_RECURSE INDENT_FILES
|
||||||
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.hpp
|
${PROJECT_SOURCE_DIR}/include/nlohmann/*.hpp
|
||||||
|
${PROJECT_SOURCE_DIR}/tests/src/*.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/tests/src/*.hpp
|
||||||
|
${PROJECT_SOURCE_DIR}/tests/benchmarks/src/benchmarks.cpp
|
||||||
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cpp
|
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cpp
|
||||||
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cu
|
|
||||||
${PROJECT_SOURCE_DIR}/include/*.hpp
|
|
||||||
${PROJECT_SOURCE_DIR}/include/*.cpp
|
|
||||||
${PROJECT_SOURCE_DIR}/include/*.cu
|
|
||||||
${PROJECT_SOURCE_DIR}/tests/*.hpp
|
|
||||||
${PROJECT_SOURCE_DIR}/tests/*.cpp
|
|
||||||
${PROJECT_SOURCE_DIR}/tests/*.cu
|
|
||||||
)
|
)
|
||||||
list(FILTER INDENT_FILES EXCLUDE REGEX "/tests/thirdparty/|/tests/abi/include/nlohmann/")
|
|
||||||
|
|
||||||
set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann)
|
set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann)
|
||||||
set(tool_dir ${PROJECT_SOURCE_DIR}/tools/amalgamate)
|
set(tool_dir ${PROJECT_SOURCE_DIR}/tools/amalgamate)
|
||||||
@@ -400,7 +377,6 @@ add_custom_target(ci_test_amalgamation
|
|||||||
COMMAND cp ${include_dir}/json.hpp ${include_dir}/json.hpp~
|
COMMAND cp ${include_dir}/json.hpp ${include_dir}/json.hpp~
|
||||||
COMMAND cp ${include_dir}/json_fwd.hpp ${include_dir}/json_fwd.hpp~
|
COMMAND cp ${include_dir}/json_fwd.hpp ${include_dir}/json_fwd.hpp~
|
||||||
COMMAND cp ${include_dir}/json_literals.hpp ${include_dir}/json_literals.hpp~
|
COMMAND cp ${include_dir}/json_literals.hpp ${include_dir}/json_literals.hpp~
|
||||||
COMMAND cp ${PROJECT_SOURCE_DIR}/BUILD.bazel ${PROJECT_SOURCE_DIR}/BUILD.bazel~
|
|
||||||
|
|
||||||
COMMAND ${Python3_EXECUTABLE} -mvenv venv_astyle
|
COMMAND ${Python3_EXECUTABLE} -mvenv venv_astyle
|
||||||
COMMAND venv_astyle/bin/pip3 --quiet install -r ${CMAKE_SOURCE_DIR}/tools/astyle/requirements.txt
|
COMMAND venv_astyle/bin/pip3 --quiet install -r ${CMAKE_SOURCE_DIR}/tools/astyle/requirements.txt
|
||||||
@@ -410,18 +386,16 @@ add_custom_target(ci_test_amalgamation
|
|||||||
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_fwd.json -s .
|
COMMAND ${Python3_EXECUTABLE} ${tool_dir}/amalgamate.py -c ${tool_dir}/config_json_fwd.json -s .
|
||||||
COMMAND cp ${PROJECT_SOURCE_DIR}/include/nlohmann/json_literals.hpp ${include_dir}/json_literals.hpp
|
COMMAND cp ${PROJECT_SOURCE_DIR}/include/nlohmann/json_literals.hpp ${include_dir}/json_literals.hpp
|
||||||
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=none ${include_dir}/json.hpp ${include_dir}/json_fwd.hpp
|
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=none ${include_dir}/json.hpp ${include_dir}/json_fwd.hpp
|
||||||
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/scripts/gen_bazel_build_file.cmake
|
|
||||||
|
|
||||||
COMMAND diff ${include_dir}/json.hpp~ ${include_dir}/json.hpp
|
COMMAND diff ${include_dir}/json.hpp~ ${include_dir}/json.hpp
|
||||||
COMMAND diff ${include_dir}/json_fwd.hpp~ ${include_dir}/json_fwd.hpp
|
COMMAND diff ${include_dir}/json_fwd.hpp~ ${include_dir}/json_fwd.hpp
|
||||||
COMMAND diff ${include_dir}/json_literals.hpp~ ${include_dir}/json_literals.hpp
|
COMMAND diff ${include_dir}/json_literals.hpp~ ${include_dir}/json_literals.hpp
|
||||||
COMMAND diff ${PROJECT_SOURCE_DIR}/BUILD.bazel~ ${PROJECT_SOURCE_DIR}/BUILD.bazel
|
|
||||||
|
|
||||||
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=orig ${INDENT_FILES}
|
COMMAND venv_astyle/bin/astyle --project=tools/astyle/.astylerc --suffix=orig ${INDENT_FILES}
|
||||||
COMMAND for FILE in `find . -name '*.orig'`\; do false \; done
|
COMMAND for FILE in `find . -name '*.orig'`\; do false \; done
|
||||||
|
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
COMMENT "Check amalgamation, formatting, and BUILD.bazel"
|
COMMENT "Check amalgamation and indentation"
|
||||||
)
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -456,14 +430,14 @@ add_custom_target(ci_test_valgrind
|
|||||||
# Check code with Clang Static Analyzer.
|
# Check code with Clang Static Analyzer.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
set(CLANG_ANALYZER_CHECKS "nullability.NullableDereferenced,nullability.NullablePassedToNonnull,nullability.NullableReturnedFromNonnull,optin.cplusplus.UninitializedObject,optin.cplusplus.VirtualCall,optin.performance.Padding,optin.portability.UnixAPI,security.FloatLoopCounter,security.insecureAPI.DeprecatedOrUnsafeBufferHandling,security.insecureAPI.bcmp,security.insecureAPI.bcopy,security.insecureAPI.bzero,security.insecureAPI.rand,security.insecureAPI.strcpy,valist.CopyToSelf,valist.Uninitialized,valist.Unterminated,core.CallAndMessage,core.DivideZero,core.NonNullParamChecker,core.NullDereference,core.StackAddressEscape,core.UndefinedBinaryOperatorResult,core.VLASize,core.uninitialized.ArraySubscript,core.uninitialized.Assign,core.uninitialized.Branch,core.uninitialized.CapturedBlockVariable,core.uninitialized.UndefReturn,cplusplus.InnerPointer,cplusplus.Move,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,cplusplus.PlacementNew,cplusplus.PureVirtualCall,deadcode.DeadStores,nullability.NullPassedToNonnull,nullability.NullReturnedFromNonnull,security.insecureAPI.UncheckedReturn,security.insecureAPI.decodeValueOfObjCType,security.insecureAPI.getpw,security.insecureAPI.gets,security.insecureAPI.mkstemp,security.insecureAPI.mktemp,security.insecureAPI.vfork,unix.API,unix.Malloc,unix.MallocSizeof,unix.MismatchedDeallocator,unix.Vfork,unix.cstring.BadSizeArg,unix.cstring.NullArg")
|
set(CLANG_ANALYZER_CHECKS "fuchsia.HandleChecker,nullability.NullableDereferenced,nullability.NullablePassedToNonnull,nullability.NullableReturnedFromNonnull,optin.cplusplus.UninitializedObject,optin.cplusplus.VirtualCall,optin.mpi.MPI-Checker,optin.osx.OSObjectCStyleCast,optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,optin.osx.cocoa.localizability.NonLocalizedStringChecker,optin.performance.GCDAntipattern,optin.performance.Padding,optin.portability.UnixAPI,security.FloatLoopCounter,security.insecureAPI.DeprecatedOrUnsafeBufferHandling,security.insecureAPI.bcmp,security.insecureAPI.bcopy,security.insecureAPI.bzero,security.insecureAPI.rand,security.insecureAPI.strcpy,valist.CopyToSelf,valist.Uninitialized,valist.Unterminated,webkit.NoUncountedMemberChecker,webkit.RefCntblBaseVirtualDtor,core.CallAndMessage,core.DivideZero,core.NonNullParamChecker,core.NullDereference,core.StackAddressEscape,core.UndefinedBinaryOperatorResult,core.VLASize,core.uninitialized.ArraySubscript,core.uninitialized.Assign,core.uninitialized.Branch,core.uninitialized.CapturedBlockVariable,core.uninitialized.UndefReturn,cplusplus.InnerPointer,cplusplus.Move,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,cplusplus.PlacementNew,cplusplus.PureVirtualCall,deadcode.DeadStores,nullability.NullPassedToNonnull,nullability.NullReturnedFromNonnull,osx.API,osx.MIG,osx.NumberObjectConversion,osx.OSObjectRetainCount,osx.ObjCProperty,osx.SecKeychainAPI,osx.cocoa.AtSync,osx.cocoa.AutoreleaseWrite,osx.cocoa.ClassRelease,osx.cocoa.Dealloc,osx.cocoa.IncompatibleMethodTypes,osx.cocoa.Loops,osx.cocoa.MissingSuperCall,osx.cocoa.NSAutoreleasePool,osx.cocoa.NSError,osx.cocoa.NilArg,osx.cocoa.NonNilReturnValue,osx.cocoa.ObjCGenerics,osx.cocoa.RetainCount,osx.cocoa.RunLoopAutoreleaseLeak,osx.cocoa.SelfInit,osx.cocoa.SuperDealloc,osx.cocoa.UnusedIvars,osx.cocoa.VariadicMethodTypes,osx.coreFoundation.CFError,osx.coreFoundation.CFNumber,osx.coreFoundation.CFRetainRelease,osx.coreFoundation.containers.OutOfBounds,osx.coreFoundation.containers.PointerSizedValues,security.insecureAPI.UncheckedReturn,security.insecureAPI.decodeValueOfObjCType,security.insecureAPI.getpw,security.insecureAPI.gets,security.insecureAPI.mkstemp,security.insecureAPI.mktemp,security.insecureAPI.vfork,unix.API,unix.Malloc,unix.MallocSizeof,unix.MismatchedDeallocator,unix.Vfork,unix.cstring.BadSizeArg,unix.cstring.NullArg")
|
||||||
|
|
||||||
add_custom_target(ci_clang_analyze
|
add_custom_target(ci_clang_analyze
|
||||||
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||||
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
-DCMAKE_BUILD_TYPE=Debug -GNinja
|
||||||
-DJSON_BuildTests=ON
|
-DJSON_BuildTests=ON
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_analyze
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_analyze
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_analyze && ${SCAN_BUILD_TOOL} -enable-checker ${CLANG_ANALYZER_CHECKS} --use-c++=${CLANG_TOOL} --use-analyzer=${CLANG_TOOL} -analyze-headers --status-bugs -o ${PROJECT_BINARY_DIR}/report ninja
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_analyze && ${SCAN_BUILD_TOOL} -enable-checker ${CLANG_ANALYZER_CHECKS} --use-c++=${CLANG_TOOL} -analyze-headers -o ${PROJECT_BINARY_DIR}/report ninja
|
||||||
COMMENT "Check code with Clang Analyzer"
|
COMMENT "Check code with Clang Analyzer"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -479,7 +453,7 @@ add_custom_target(ci_cppcheck
|
|||||||
COMMAND venv_cppcheck/bin/cppcheck --enable=warning --check-level=exhaustive --inline-suppr --inconclusive --force
|
COMMAND venv_cppcheck/bin/cppcheck --enable=warning --check-level=exhaustive --inline-suppr --inconclusive --force
|
||||||
--std=c++11 ${PROJECT_SOURCE_DIR}/include/nlohmann/json.hpp -I ${CMAKE_SOURCE_DIR}/include
|
--std=c++11 ${PROJECT_SOURCE_DIR}/include/nlohmann/json.hpp -I ${CMAKE_SOURCE_DIR}/include
|
||||||
--error-exitcode=1 --relative-paths=${PROJECT_SOURCE_DIR} -j ${N} --include=default_defines.hpp
|
--error-exitcode=1 --relative-paths=${PROJECT_SOURCE_DIR} -j ${N} --include=default_defines.hpp
|
||||||
--cppcheck-build-dir=cppcheck
|
--cppcheck-build-dir=cppcheck --check-level=exhaustive
|
||||||
-UJSON_CATCH_USER -UJSON_TRY_USER -UJSON_ASSERT -UJSON_INTERNAL_CATCH -UJSON_THROW
|
-UJSON_CATCH_USER -UJSON_TRY_USER -UJSON_ASSERT -UJSON_INTERNAL_CATCH -UJSON_THROW
|
||||||
-DJSON_HAS_CPP_11 -UJSON_HAS_CPP_14 -UJSON_HAS_CPP_17 -UJSON_HAS_CPP_20 -UJSON_HAS_THREE_WAY_COMPARISON
|
-DJSON_HAS_CPP_11 -UJSON_HAS_CPP_14 -UJSON_HAS_CPP_17 -UJSON_HAS_CPP_20 -UJSON_HAS_THREE_WAY_COMPARISON
|
||||||
COMMENT "Check code with Cppcheck"
|
COMMENT "Check code with Cppcheck"
|
||||||
@@ -497,6 +471,34 @@ add_custom_target(ci_cpplint
|
|||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Check code with OCLint.
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
file(COPY ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp DESTINATION ${PROJECT_BINARY_DIR}/src_single)
|
||||||
|
file(RENAME ${PROJECT_BINARY_DIR}/src_single/json.hpp ${PROJECT_BINARY_DIR}/src_single/all.cpp)
|
||||||
|
file(APPEND "${PROJECT_BINARY_DIR}/src_single/all.cpp" "\n\nint main()\n{}\n")
|
||||||
|
|
||||||
|
add_executable(single_all ${PROJECT_BINARY_DIR}/src_single/all.cpp)
|
||||||
|
target_compile_features(single_all PRIVATE cxx_std_11)
|
||||||
|
|
||||||
|
add_custom_target(ci_oclint
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug
|
||||||
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
-DJSON_BuildTests=OFF -DJSON_CI=ON
|
||||||
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_oclint
|
||||||
|
COMMAND ${OCLINT_TOOL} -i ${PROJECT_BINARY_DIR}/build_oclint/src_single/all.cpp -p ${PROJECT_BINARY_DIR}/build_oclint --
|
||||||
|
-report-type html -enable-global-analysis --max-priority-1=0 --max-priority-2=1000 --max-priority-3=2000
|
||||||
|
--disable-rule=MultipleUnaryOperator
|
||||||
|
--disable-rule=DoubleNegative
|
||||||
|
--disable-rule=ShortVariableName
|
||||||
|
--disable-rule=GotoStatement
|
||||||
|
--disable-rule=LongLine
|
||||||
|
-o ${PROJECT_BINARY_DIR}/build_oclint/oclint_report.html
|
||||||
|
COMMENT "Check code with OCLint"
|
||||||
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Check code with Clang-Tidy.
|
# Check code with Clang-Tidy.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -511,16 +513,29 @@ add_custom_target(ci_clang_tidy
|
|||||||
COMMENT "Check code with Clang-Tidy"
|
COMMENT "Check code with Clang-Tidy"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Check code with PVS-Studio Analyzer <https://www.viva64.com/en/pvs-studio/>.
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
add_custom_target(ci_pvs_studio
|
||||||
|
COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND}
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug
|
||||||
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
-DJSON_BuildTests=ON
|
||||||
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_pvs_studio
|
||||||
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PVS_STUDIO_ANALYZER_TOOL} analyze -j 10
|
||||||
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PLOG_CONVERTER_TOOL} -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs
|
||||||
|
COMMENT "Check code with PVS Studio"
|
||||||
|
)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Check code with Infer <https://fbinfer.com> static analyzer.
|
# Check code with Infer <https://fbinfer.com> static analyzer.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# .inferconfig (repository root) pins --fail-on-issue and the currently-triaged issue types that
|
|
||||||
# are disabled until they are addressed separately; see #5715 item 4b.
|
|
||||||
add_custom_target(ci_infer
|
add_custom_target(ci_infer
|
||||||
COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_infer
|
COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_infer
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} run --project-root ${PROJECT_SOURCE_DIR} -- make
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} run -- make
|
||||||
COMMENT "Check code with Infer"
|
COMMENT "Check code with Infer"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -576,13 +591,7 @@ add_custom_target(ci_reproducible_tests
|
|||||||
# be compiled individually.
|
# be compiled individually.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
set(iwyu_options -Xiwyu --error -Xiwyu --max_line_length=300)
|
set(iwyu_path_and_options ${IWYU_TOOL} -Xiwyu --max_line_length=300)
|
||||||
set(iwyu_path_and_options ${IWYU_TOOL} ${iwyu_options})
|
|
||||||
|
|
||||||
# CMake needs to know the exact flags used to compile each src_single/*.cpp below to hand them to
|
|
||||||
# iwyu_tool.py; JSON_CI already implies a from-scratch configure, so enabling this project-wide has
|
|
||||||
# no downside here.
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
|
|
||||||
foreach(SRC_FILE ${SRC_FILES})
|
foreach(SRC_FILE ${SRC_FILES})
|
||||||
# get relative path of the header file
|
# get relative path of the header file
|
||||||
@@ -597,34 +606,14 @@ foreach(SRC_FILE ${SRC_FILES})
|
|||||||
target_include_directories(single_${RELATIVE_SRC_FILE} PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
target_include_directories(single_${RELATIVE_SRC_FILE} PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||||
target_compile_features(single_${RELATIVE_SRC_FILE} PRIVATE cxx_std_11)
|
target_compile_features(single_${RELATIVE_SRC_FILE} PRIVATE cxx_std_11)
|
||||||
set_property(TARGET single_${RELATIVE_SRC_FILE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "${iwyu_path_and_options}")
|
set_property(TARGET single_${RELATIVE_SRC_FILE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "${iwyu_path_and_options}")
|
||||||
# remember binary for ci_single_binaries
|
# remember binary for ci_single_binaries target
|
||||||
list(APPEND single_binaries single_${RELATIVE_SRC_FILE})
|
list(APPEND single_binaries single_${RELATIVE_SRC_FILE})
|
||||||
# json.hpp pulls together the whole library behind heavily templated, SFINAE-based code, and
|
|
||||||
# IWYU's suggestion for its one truly ambiguous symbol (a container-comparison "swap,
|
|
||||||
# operator!=") is not deterministic between runs (observed <set>, <unordered_map>, and <map>
|
|
||||||
# for the exact same source across otherwise-identical local and containerized builds). Keep
|
|
||||||
# reporting its diagnostics (informational, via CXX_INCLUDE_WHAT_YOU_USE above) but exclude it
|
|
||||||
# from the hard gate below so a fresh IWYU/compiler combination does not fail this target on a
|
|
||||||
# nondeterministic suggestion for a header that already re-exports everything on purpose.
|
|
||||||
if(NOT RELATIVE_SRC_FILE STREQUAL "json")
|
|
||||||
list(APPEND single_binaries_tus src_single/${RELATIVE_SRC_FILE}.cpp)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if(IWYU_TOOL_PY)
|
add_custom_target(ci_single_binaries
|
||||||
add_custom_target(ci_single_binaries
|
DEPENDS ${single_binaries}
|
||||||
DEPENDS ${single_binaries}
|
COMMENT "Check if headers are self-contained"
|
||||||
COMMAND ${IWYU_TOOL_PY} -p ${PROJECT_BINARY_DIR} ${single_binaries_tus} -- ${iwyu_options}
|
)
|
||||||
COMMENT "Check if headers are self-contained"
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
# iwyu_tool.py (ships with IWYU, e.g. as /usr/bin/iwyu_tool on Debian/Ubuntu) was not found;
|
|
||||||
# fall back to building the self-containment check without enforcing the IWYU findings.
|
|
||||||
add_custom_target(ci_single_binaries
|
|
||||||
DEPENDS ${single_binaries}
|
|
||||||
COMMENT "Check if headers are self-contained"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Benchmarks
|
# Benchmarks
|
||||||
@@ -646,41 +635,21 @@ add_custom_target(ci_benchmarks
|
|||||||
# we test the project with different CMake versions:
|
# we test the project with different CMake versions:
|
||||||
# - CMake 3.5 (the earliest supported)
|
# - CMake 3.5 (the earliest supported)
|
||||||
# - CMake 3.31.6 (the latest 3.x release)
|
# - CMake 3.31.6 (the latest 3.x release)
|
||||||
# - CMake 4.0.0 (the first 4.x release)
|
# - CMake 4.0.0 (the latest release)
|
||||||
# - the CMake version running this build (usually the latest release)
|
|
||||||
|
|
||||||
function(ci_get_cmake version var)
|
function(ci_get_cmake version var)
|
||||||
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}/bin/cmake)
|
set(${var} ${PROJECT_BINARY_DIR}/cmake-${version}/bin/cmake)
|
||||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$")
|
add_custom_command(
|
||||||
# Kitware publishes a prebuilt Linux x86_64 archive for every release; unpacking it is far
|
OUTPUT ${${var}}
|
||||||
# cheaper than compiling all of CMake (including its own test helpers) from source.
|
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}.tar.gz
|
||||||
add_custom_command(
|
COMMAND tar xfz cmake-${version}.tar.gz
|
||||||
OUTPUT ${${var}}
|
COMMAND rm cmake-${version}.tar.gz
|
||||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-linux-x86_64.tar.gz
|
# -DCMAKE_POLICY_VERSION_MINIMUM=3.5 required to compile older CMake versions with CMake 4.0.0
|
||||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-SHA-256.txt
|
COMMAND cmake -S cmake-${version} -B cmake-${version} -DCMAKE_POLICY_VERSION_MINIMUM=3.5
|
||||||
# verify the archive against Kitware's published SHA-256 sums before unpacking it
|
COMMAND cmake --build cmake-${version} --parallel 10
|
||||||
COMMAND sh -c "grep ' cmake-${version}-linux-x86_64[.]tar[.]gz$' cmake-${version}-SHA-256.txt | sha256sum -c -"
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||||
COMMAND tar xfz cmake-${version}-linux-x86_64.tar.gz
|
COMMENT "Download CMake ${version}"
|
||||||
COMMAND rm cmake-${version}-linux-x86_64.tar.gz cmake-${version}-SHA-256.txt
|
)
|
||||||
COMMAND ${CMAKE_COMMAND} -E rm -rf cmake-${version}
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E rename cmake-${version}-linux-x86_64 cmake-${version}
|
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
||||||
COMMENT "Download prebuilt CMake ${version}"
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
# no prebuilt archive for this platform (e.g. macOS or Linux aarch64): build from source
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${${var}}
|
|
||||||
COMMAND wget -nc https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}.tar.gz
|
|
||||||
COMMAND tar xfz cmake-${version}.tar.gz
|
|
||||||
COMMAND rm cmake-${version}.tar.gz
|
|
||||||
# -DCMAKE_POLICY_VERSION_MINIMUM=3.5 required to compile older CMake versions with CMake 4.0.0
|
|
||||||
COMMAND cmake -S cmake-${version} -B cmake-${version} -DCMAKE_POLICY_VERSION_MINIMUM=3.5
|
|
||||||
COMMAND cmake --build cmake-${version} --parallel 10
|
|
||||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
||||||
COMMENT "Download and build CMake ${version} from source"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
set(${var} ${${var}} PARENT_SCOPE)
|
set(${var} ${${var}} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@@ -690,24 +659,30 @@ ci_get_cmake(4.0.0 CMAKE_4_0_0_BINARY)
|
|||||||
|
|
||||||
# the tests require CMake 3.13 or later, so they are excluded for CMake 3.5.0
|
# the tests require CMake 3.13 or later, so they are excluded for CMake 3.5.0
|
||||||
set(JSON_CMAKE_FLAGS_3_5_0 JSON_Diagnostics JSON_Diagnostic_Positions JSON_GlobalUDLs JSON_ImplicitConversions JSON_DisableEnumSerialization
|
set(JSON_CMAKE_FLAGS_3_5_0 JSON_Diagnostics JSON_Diagnostic_Positions JSON_GlobalUDLs JSON_ImplicitConversions JSON_DisableEnumSerialization
|
||||||
JSON_LegacyDiscardedValueComparison JSON_Install JSON_MultipleHeaders JSON_SystemInclude JSON_Valgrind
|
JSON_LegacyDiscardedValueComparison JSON_Install JSON_MultipleHeaders JSON_SystemInclude JSON_Valgrind)
|
||||||
JSON_StrictNulHandling)
|
set(JSON_CMAKE_FLAGS_3_31_6 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_31_6})
|
||||||
set(JSON_CMAKE_FLAGS_3_31_6 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_5_0})
|
|
||||||
set(JSON_CMAKE_FLAGS_4_0_0 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_5_0})
|
set(JSON_CMAKE_FLAGS_4_0_0 JSON_BuildTests ${JSON_CMAKE_FLAGS_3_5_0})
|
||||||
|
|
||||||
function(ci_add_cmake_flags_targets flag min_version)
|
function(ci_add_cmake_flags_targets flag min_version)
|
||||||
string(TOLOWER "ci_cmake_flag_${flag}" flag_target)
|
string(TOLOWER "ci_cmake_flag_${flag}" flag_target)
|
||||||
string(REPLACE . _ min_version_var ${min_version})
|
string(REPLACE . _ min_version_var ${min_version})
|
||||||
set(cmake_binary ${CMAKE_${min_version_var}_BINARY})
|
set(cmake_binary ${CMAKE_${min_version_var}_BINARY})
|
||||||
|
add_custom_target(${flag_target}_${min_version}_2
|
||||||
|
COMMENT "Check CMake flag ${flag} (CMake ${CMAKE_VERSION})"
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-Werror=dev
|
||||||
|
-D${flag}=ON
|
||||||
|
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${flag_target}
|
||||||
|
)
|
||||||
add_custom_target(${flag_target}_${min_version_var}
|
add_custom_target(${flag_target}_${min_version_var}
|
||||||
COMMENT "Check CMake flag ${flag} (CMake ${min_version})"
|
COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${min_version})"
|
||||||
COMMAND mkdir -pv ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
COMMAND mkdir -pv ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
||||||
COMMAND cd ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
COMMAND cd ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}
|
||||||
&& ${cmake_binary} -Werror=dev ${PROJECT_SOURCE_DIR} -D${flag}=ON
|
&& ${cmake_binary} -Werror=dev ${PROJECT_SOURCE_DIR} -D${flag}=ON
|
||||||
DEPENDS ${cmake_binary}
|
DEPENDS ${cmake_binary}
|
||||||
)
|
)
|
||||||
list(APPEND JSON_CMAKE_FLAG_TARGETS ${flag_target}_${min_version_var})
|
list(APPEND JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGET} ${flag_target}_${min_version_var})
|
||||||
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var})
|
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target} ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var})
|
||||||
set(JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGETS} PARENT_SCOPE)
|
set(JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGETS} PARENT_SCOPE)
|
||||||
set(JSON_CMAKE_FLAG_BUILD_DIRS ${JSON_CMAKE_FLAG_BUILD_DIRS} PARENT_SCOPE)
|
set(JSON_CMAKE_FLAG_BUILD_DIRS ${JSON_CMAKE_FLAG_BUILD_DIRS} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
@@ -724,20 +699,6 @@ foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS_4_0_0})
|
|||||||
ci_add_cmake_flags_targets(${JSON_CMAKE_FLAG} 4.0.0)
|
ci_add_cmake_flags_targets(${JSON_CMAKE_FLAG} 4.0.0)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# check the same flags with the CMake version running this build
|
|
||||||
foreach(JSON_CMAKE_FLAG ${JSON_CMAKE_FLAGS_4_0_0})
|
|
||||||
string(TOLOWER "ci_cmake_flag_${JSON_CMAKE_FLAG}" flag_target)
|
|
||||||
add_custom_target(${flag_target}
|
|
||||||
COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${CMAKE_VERSION})"
|
|
||||||
COMMAND ${CMAKE_COMMAND}
|
|
||||||
-Werror=dev
|
|
||||||
-D${JSON_CMAKE_FLAG}=ON
|
|
||||||
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${flag_target}
|
|
||||||
)
|
|
||||||
list(APPEND JSON_CMAKE_FLAG_TARGETS ${flag_target})
|
|
||||||
list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
add_custom_target(ci_cmake_flags
|
add_custom_target(ci_cmake_flags
|
||||||
DEPENDS ${JSON_CMAKE_FLAG_TARGETS}
|
DEPENDS ${JSON_CMAKE_FLAG_TARGETS}
|
||||||
COMMENT "Check CMake flags"
|
COMMENT "Check CMake flags"
|
||||||
@@ -896,6 +857,6 @@ add_custom_target(ci_test_build_documentation
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
add_custom_target(ci_clean
|
add_custom_target(ci_clean
|
||||||
COMMAND rm -fr ${PROJECT_BINARY_DIR}/build_* ${PROJECT_BINARY_DIR}/cmake-3.5.0 ${PROJECT_BINARY_DIR}/cmake-3.31.6 ${PROJECT_BINARY_DIR}/cmake-4.0.0 ${JSON_CMAKE_FLAG_BUILD_DIRS} ${single_binaries}
|
COMMAND rm -fr ${PROJECT_BINARY_DIR}/build_* cmake-3.5.0-Darwin64 ${JSON_CMAKE_FLAG_BUILD_DIRS} ${single_binaries}
|
||||||
COMMENT "Clean generated directories"
|
COMMENT "Clean generated directories"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# -Wno-c++98-compat The library targets C++11.
|
# -Wno-c++98-compat The library targets C++11.
|
||||||
# -Wno-c++98-compat-pedantic The library targets C++11.
|
# -Wno-c++98-compat-pedantic The library targets C++11.
|
||||||
# -Wno-deprecated-declarations The library contains annotations for deprecated functions.
|
# -Wno-deprecated-declarations The library contains annotations for deprecated functions.
|
||||||
|
# -Wno-extra-semi-stmt The library uses assert which triggers this warning.
|
||||||
# -Wno-padded We do not care about padding warnings.
|
# -Wno-padded We do not care about padding warnings.
|
||||||
# -Wno-covered-switch-default All switches list all cases and a default case.
|
# -Wno-covered-switch-default All switches list all cases and a default case.
|
||||||
# -Wno-c2y-extensions Clang 22.1 diagnoses __COUNTER__ as a C2y extension, also in
|
# -Wno-c2y-extensions Clang 22.1 diagnoses __COUNTER__ as a C2y extension, also in
|
||||||
@@ -19,6 +20,7 @@ set(CLANG_CXXFLAGS
|
|||||||
-Wno-c++98-compat
|
-Wno-c++98-compat
|
||||||
-Wno-c++98-compat-pedantic
|
-Wno-c++98-compat-pedantic
|
||||||
-Wno-deprecated-declarations
|
-Wno-deprecated-declarations
|
||||||
|
-Wno-extra-semi-stmt
|
||||||
-Wno-padded
|
-Wno-padded
|
||||||
-Wno-covered-switch-default
|
-Wno-covered-switch-default
|
||||||
-Wno-c2y-extensions
|
-Wno-c2y-extensions
|
||||||
|
|||||||
+13
-24
@@ -1,4 +1,4 @@
|
|||||||
# Warning flags determined for GCC 16.2.0 with https://github.com/nlohmann/gcc_flags:
|
# Warning flags determined for GCC 15.1.0 with https://github.com/nlohmann/gcc_flags:
|
||||||
# Ignored GCC warnings:
|
# Ignored GCC warnings:
|
||||||
# -Wno-abi-tag We do not care about ABI tags.
|
# -Wno-abi-tag We do not care about ABI tags.
|
||||||
# -Wno-aggregate-return The library uses aggregate returns.
|
# -Wno-aggregate-return The library uses aggregate returns.
|
||||||
@@ -16,8 +16,6 @@ set(GCC_CXXFLAGS
|
|||||||
--extra-warnings
|
--extra-warnings
|
||||||
-W
|
-W
|
||||||
-WNSObject-attribute
|
-WNSObject-attribute
|
||||||
-Wabbreviated-auto-in-template-arg
|
|
||||||
-Wabi
|
|
||||||
-Wno-abi-tag
|
-Wno-abi-tag
|
||||||
-Waddress
|
-Waddress
|
||||||
-Waddress-of-packed-member
|
-Waddress-of-packed-member
|
||||||
@@ -66,7 +64,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wanalyzer-tainted-divisor
|
-Wanalyzer-tainted-divisor
|
||||||
-Wanalyzer-tainted-offset
|
-Wanalyzer-tainted-offset
|
||||||
-Wanalyzer-tainted-size
|
-Wanalyzer-tainted-size
|
||||||
-Wanalyzer-throw-of-unexpected-type
|
|
||||||
-Wanalyzer-too-complex
|
-Wanalyzer-too-complex
|
||||||
-Wanalyzer-undefined-behavior-ptrdiff
|
-Wanalyzer-undefined-behavior-ptrdiff
|
||||||
-Wanalyzer-undefined-behavior-strtok
|
-Wanalyzer-undefined-behavior-strtok
|
||||||
@@ -83,13 +80,10 @@ set(GCC_CXXFLAGS
|
|||||||
-Warith-conversion
|
-Warith-conversion
|
||||||
-Warray-bounds=2
|
-Warray-bounds=2
|
||||||
-Warray-compare
|
-Warray-compare
|
||||||
-Warray-parameter
|
|
||||||
-Warray-parameter=2
|
-Warray-parameter=2
|
||||||
-Wattribute-alias=2
|
-Wattribute-alias=2
|
||||||
-Wattribute-warning
|
-Wattribute-warning
|
||||||
-Wattributes
|
-Wattributes
|
||||||
-Wauto-profile
|
|
||||||
-Wbidi-chars=any
|
|
||||||
-Wbool-compare
|
-Wbool-compare
|
||||||
-Wbool-operation
|
-Wbool-operation
|
||||||
-Wbuiltin-declaration-mismatch
|
-Wbuiltin-declaration-mismatch
|
||||||
@@ -105,7 +99,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wc++20-compat
|
-Wc++20-compat
|
||||||
-Wc++20-extensions
|
-Wc++20-extensions
|
||||||
-Wc++23-extensions
|
-Wc++23-extensions
|
||||||
-Wc++26-compat
|
|
||||||
-Wc++26-extensions
|
-Wc++26-extensions
|
||||||
-Wc++2a-compat
|
-Wc++2a-compat
|
||||||
-Wcalloc-transposed-args
|
-Wcalloc-transposed-args
|
||||||
@@ -149,7 +142,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wdeprecated-enum-enum-conversion
|
-Wdeprecated-enum-enum-conversion
|
||||||
-Wdeprecated-enum-float-conversion
|
-Wdeprecated-enum-float-conversion
|
||||||
-Wdeprecated-literal-operator
|
-Wdeprecated-literal-operator
|
||||||
-Wdeprecated-openmp
|
|
||||||
-Wdeprecated-variadic-comma-omission
|
-Wdeprecated-variadic-comma-omission
|
||||||
-Wdisabled-optimization
|
-Wdisabled-optimization
|
||||||
-Wdiv-by-zero
|
-Wdiv-by-zero
|
||||||
@@ -164,18 +156,21 @@ set(GCC_CXXFLAGS
|
|||||||
-Wenum-conversion
|
-Wenum-conversion
|
||||||
-Wexceptions
|
-Wexceptions
|
||||||
-Wexpansion-to-defined
|
-Wexpansion-to-defined
|
||||||
-Wexperimental-fmv-target
|
|
||||||
-Wexpose-global-module-tu-local
|
|
||||||
-Wexternal-tu-local
|
|
||||||
-Wextra
|
-Wextra
|
||||||
-Wextra-semi
|
-Wextra-semi
|
||||||
-Wflex-array-member-not-at-end
|
-Wflex-array-member-not-at-end
|
||||||
-Wfloat-conversion
|
-Wfloat-conversion
|
||||||
-Wfloat-equal
|
-Wfloat-equal
|
||||||
-Wformat-diag
|
-Wformat -Wformat-contains-nul
|
||||||
-Wformat-overflow=2
|
-Wformat -Wformat-diag
|
||||||
-Wformat-signedness
|
-Wformat -Wformat-extra-args
|
||||||
-Wformat-truncation=2
|
-Wformat -Wformat-nonliteral
|
||||||
|
-Wformat -Wformat-overflow=2
|
||||||
|
-Wformat -Wformat-security
|
||||||
|
-Wformat -Wformat-signedness
|
||||||
|
-Wformat -Wformat-truncation=2
|
||||||
|
-Wformat -Wformat-y2k
|
||||||
|
-Wformat -Wformat-zero-length
|
||||||
-Wformat=2
|
-Wformat=2
|
||||||
-Wframe-address
|
-Wframe-address
|
||||||
-Wfree-nonheap-object
|
-Wfree-nonheap-object
|
||||||
@@ -202,8 +197,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Winvalid-offsetof
|
-Winvalid-offsetof
|
||||||
-Winvalid-pch
|
-Winvalid-pch
|
||||||
-Winvalid-utf8
|
-Winvalid-utf8
|
||||||
-Wkeyword-macro
|
|
||||||
-Wleading-whitespace=spaces
|
|
||||||
-Wliteral-suffix
|
-Wliteral-suffix
|
||||||
-Wlogical-not-parentheses
|
-Wlogical-not-parentheses
|
||||||
-Wlogical-op
|
-Wlogical-op
|
||||||
@@ -234,7 +227,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wnarrowing
|
-Wnarrowing
|
||||||
-Wnoexcept
|
-Wnoexcept
|
||||||
-Wnoexcept-type
|
-Wnoexcept-type
|
||||||
-Wnon-c-typedef-for-linkage
|
|
||||||
-Wnon-template-friend
|
-Wnon-template-friend
|
||||||
-Wnon-virtual-dtor
|
-Wnon-virtual-dtor
|
||||||
-Wnonnull
|
-Wnonnull
|
||||||
@@ -277,8 +269,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wscalar-storage-order
|
-Wscalar-storage-order
|
||||||
-Wself-move
|
-Wself-move
|
||||||
-Wsequence-point
|
-Wsequence-point
|
||||||
-Wsfinae-incomplete
|
|
||||||
-Wsfinae-incomplete=2
|
|
||||||
-Wshadow=compatible-local
|
-Wshadow=compatible-local
|
||||||
-Wshadow=global
|
-Wshadow=global
|
||||||
-Wshadow=local
|
-Wshadow=local
|
||||||
@@ -299,7 +289,6 @@ set(GCC_CXXFLAGS
|
|||||||
-Wstrict-aliasing=3
|
-Wstrict-aliasing=3
|
||||||
-Wstrict-null-sentinel
|
-Wstrict-null-sentinel
|
||||||
-Wstrict-overflow
|
-Wstrict-overflow
|
||||||
-Wstrict-overflow=5
|
|
||||||
-Wstring-compare
|
-Wstring-compare
|
||||||
-Wstringop-overflow
|
-Wstringop-overflow
|
||||||
-Wstringop-overflow=4
|
-Wstringop-overflow=4
|
||||||
@@ -344,8 +333,8 @@ set(GCC_CXXFLAGS
|
|||||||
-Wunreachable-code
|
-Wunreachable-code
|
||||||
-Wunsafe-loop-optimizations
|
-Wunsafe-loop-optimizations
|
||||||
-Wunused
|
-Wunused
|
||||||
-Wunused-but-set-parameter=3
|
-Wunused-but-set-parameter
|
||||||
-Wunused-but-set-variable=3
|
-Wunused-but-set-variable
|
||||||
-Wunused-const-variable=2
|
-Wunused-const-variable=2
|
||||||
-Wunused-function
|
-Wunused-function
|
||||||
-Wunused-label
|
-Wunused-label
|
||||||
|
|||||||
+5
-16
@@ -11,31 +11,20 @@ EXAMPLES = $(wildcard mkdocs/docs/examples/*.cpp)
|
|||||||
|
|
||||||
cxx_standard = $(lastword c++11 $(filter c++%, $(subst ., ,$1)))
|
cxx_standard = $(lastword c++11 $(filter c++%, $(subst ., ,$1)))
|
||||||
|
|
||||||
# common compile flags for the stand-alone example files
|
|
||||||
EXAMPLE_CPPFLAGS = -I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0
|
|
||||||
EXAMPLE_WARNFLAGS = -Werror=deprecated-declarations
|
|
||||||
|
|
||||||
# examples that document deprecated API and are allowed to use it
|
|
||||||
DEPRECATED_EXAMPLES = $(addprefix mkdocs/docs/examples/, \
|
|
||||||
json_pointer__operator__equal_stringtype \
|
|
||||||
json_pointer__operator__notequal_stringtype \
|
|
||||||
json_pointer__operator_string_t)
|
|
||||||
$(DEPRECATED_EXAMPLES:=.output) $(DEPRECATED_EXAMPLES:=.test): EXAMPLE_WARNFLAGS = -Wno-deprecated-declarations
|
|
||||||
|
|
||||||
# create output from a stand-alone example file
|
# create output from a stand-alone example file
|
||||||
%.output: %.cpp
|
%.output: %.cpp
|
||||||
@echo "standard $(call cxx_standard,$(<:.cpp=))"
|
@echo "standard $(call cxx_standard $(<:.cpp=))"
|
||||||
$(MAKE) $(<:.cpp=) \
|
$(MAKE) $(<:.cpp=) \
|
||||||
CPPFLAGS="$(EXAMPLE_CPPFLAGS)" \
|
CPPFLAGS="-I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0" \
|
||||||
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) $(EXAMPLE_WARNFLAGS)"
|
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) -Wno-deprecated-declarations"
|
||||||
./$(<:.cpp=) > $@
|
./$(<:.cpp=) > $@
|
||||||
rm $(<:.cpp=)
|
rm $(<:.cpp=)
|
||||||
|
|
||||||
# compare created output with current output of the example files
|
# compare created output with current output of the example files
|
||||||
%.test: %.cpp
|
%.test: %.cpp
|
||||||
$(MAKE) $(<:.cpp=) \
|
$(MAKE) $(<:.cpp=) \
|
||||||
CPPFLAGS="$(EXAMPLE_CPPFLAGS)" \
|
CPPFLAGS="-I $(SRCDIR) -DJSON_USE_GLOBAL_UDLS=0" \
|
||||||
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) $(EXAMPLE_WARNFLAGS)"
|
CXXFLAGS="-std=$(call cxx_standard,$(<:.cpp=)) -Wno-deprecated-declarations"
|
||||||
./$(<:.cpp=) > $@
|
./$(<:.cpp=) > $@
|
||||||
diff $@ $(<:.cpp=.output)
|
diff $@ $(<:.cpp=.output)
|
||||||
rm $(<:.cpp=) $@
|
rm $(<:.cpp=) $@
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<key>dashIndexFilePath</key>
|
<key>dashIndexFilePath</key>
|
||||||
<string>index.html</string>
|
<string>index.html</string>
|
||||||
<key>DashDocSetFallbackURL</key>
|
<key>DashDocSetFallbackURL</key>
|
||||||
<string>https://json.nlohmann.me/</string>
|
<string>https://nlohmann.github.io/json/</string>
|
||||||
<key>isJavaScriptEnabled</key>
|
<key>isJavaScriptEnabled</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
|
|||||||
+22
-12
@@ -52,25 +52,35 @@ install_docset_zeal: JSON_for_Modern_C++.docset
|
|||||||
mkdir -p $$docset_root; \
|
mkdir -p $$docset_root; \
|
||||||
cp -r JSON_for_Modern_C++.docset $$docset_root/
|
cp -r JSON_for_Modern_C++.docset $$docset_root/
|
||||||
|
|
||||||
# both targets below compare the docset search index with the mkdocs page
|
|
||||||
# set. They share the same normalization (docs/foo/index.md and
|
|
||||||
# docs/foo.md both become foo/index.html, the URL mkdocs itself would
|
|
||||||
# give the page; the top-level index.md is excluded, as it is not part
|
|
||||||
# of the hand-curated docSet.sql) and use comm(1) on two sorted lists
|
|
||||||
# instead of running a sqlite3 query, or an O(n*m) nested shell loop,
|
|
||||||
# once per page.
|
|
||||||
DOCSET_INDEX_PATHS=$(shell sqlite3 docSet.dsidx "SELECT DISTINCT path FROM searchIndex" | sort)
|
|
||||||
DOCSET_PAGE_PATHS=$(shell echo '$(MKDOCS_PAGES)' | tr ' ' '\n' | grep -v '^index\.md$$' | $(SED) -E 's@/index\.md$$@/index.html@; s@\.md$$@/index.html@' | sort)
|
|
||||||
|
|
||||||
# list mkdocs pages missing from the docset index
|
# list mkdocs pages missing from the docset index
|
||||||
.PHONY: list_missing_pages
|
.PHONY: list_missing_pages
|
||||||
list_missing_pages: docSet.dsidx
|
list_missing_pages: docSet.dsidx
|
||||||
@comm -23 <(echo '$(DOCSET_PAGE_PATHS)' | tr ' ' '\n') <(echo '$(DOCSET_INDEX_PATHS)' | tr ' ' '\n')
|
@for page in $(MKDOCS_PAGES); do \
|
||||||
|
case "$$page" in \
|
||||||
|
*/index.md) path=$${page/\/index.md/} ;; \
|
||||||
|
*) path=$${page/.md/} ;; \
|
||||||
|
esac; \
|
||||||
|
if [ "x$$page" != "xindex.md" -a "x$$(sqlite3 docSet.dsidx "SELECT COUNT(*) FROM searchIndex WHERE path='$$path/index.html'")" = "x0" ]; then \
|
||||||
|
echo $$page; \
|
||||||
|
fi \
|
||||||
|
done
|
||||||
|
|
||||||
# list paths in the docset index without a corresponding mkdocs page
|
# list paths in the docset index without a corresponding mkdocs page
|
||||||
.PHONY: list_removed_paths
|
.PHONY: list_removed_paths
|
||||||
list_removed_paths: docSet.dsidx
|
list_removed_paths: docSet.dsidx
|
||||||
@comm -13 <(echo '$(DOCSET_PAGE_PATHS)' | tr ' ' '\n') <(echo '$(DOCSET_INDEX_PATHS)' | tr ' ' '\n')
|
@for path in $$(sqlite3 docSet.dsidx "SELECT path FROM searchIndex"); do \
|
||||||
|
page=$${path/\/index.html/.md}; \
|
||||||
|
page_index=$${path/index.html/index.md}; \
|
||||||
|
page_found=0; \
|
||||||
|
for p in $(MKDOCS_PAGES); do \
|
||||||
|
if [ "x$$p" = "x$$page" -o "x$$p" = "x$$page_index" ]; then \
|
||||||
|
page_found=1; \
|
||||||
|
fi \
|
||||||
|
done; \
|
||||||
|
if [ "x$$page_found" = "x0" ]; then \
|
||||||
|
echo $$path; \
|
||||||
|
fi \
|
||||||
|
done
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ documentation browsers like [Dash](https://kapeli.com/dash), [Velocity](https://
|
|||||||
The docset can be created with
|
The docset can be created with
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make JSON_for_Modern_C++.docset
|
make nlohmann_json.docset
|
||||||
```
|
```
|
||||||
|
|
||||||
The generated folder `JSON_for_Modern_C++.docset` can then be opened in the documentation browser. `make all` builds a
|
The generated folder `nlohmann_json.docset` can then be opened in the documentation browser.
|
||||||
`JSON_for_Modern_C++.tgz` archive instead, and `make install_docset_zeal` installs the docset for Zeal directly.
|
|
||||||
|
|
||||||
A recent version is also part of the [Dash user contributions](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B).
|
A recent version is also part of the [Dash user contributions](https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/JSON_for_Modern_C%2B%2B).
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,6 @@ INSERT INTO searchIndex(name, type, path) VALUES ('JSON_CATCH_USER', 'Macro', 'a
|
|||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTICS', 'Macro', 'api/macros/json_diagnostics/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTICS', 'Macro', 'api/macros/json_diagnostics/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTIC_POSITIONS', 'Macro', 'api/macros/json_diagnostic_positions/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DIAGNOSTIC_POSITIONS', 'Macro', 'api/macros/json_diagnostic_positions/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DISABLE_ENUM_SERIALIZATION', 'Macro', 'api/macros/json_disable_enum_serialization/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DISABLE_ENUM_SERIALIZATION', 'Macro', 'api/macros/json_disable_enum_serialization/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_DISABLE_TUPLE_REFERENCE_CONVERSION', 'Macro', 'api/macros/json_disable_tuple_reference_conversion/index.html');
|
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_11', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_11', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_14', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_14', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||||
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_17', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
INSERT INTO searchIndex(name, type, path) VALUES ('JSON_HAS_CPP_17', 'Macro', 'api/macros/json_has_cpp_11/index.html');
|
||||||
|
|||||||
@@ -224,5 +224,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
|
|
||||||
1. Added in version 1.0.0.
|
1. Added in version 1.0.0.
|
||||||
2. Added in version 1.0.0.
|
2. Added in version 1.0.0.
|
||||||
3. Added in version 3.11.0.
|
3. Added in version 3.11.0. Fixed in version 3.13.0 to consistently accept `std::string_view`-convertible keys, as
|
||||||
|
already supported by [`operator[]`](operator[].md), [`value`](value.md), [`find`](find.md), and other lookup
|
||||||
|
functions.
|
||||||
4. Added in version 2.0.0.
|
4. Added in version 2.0.0.
|
||||||
|
|||||||
@@ -159,8 +159,6 @@ basic_json(basic_json&& other) noexcept;
|
|||||||
- `CompatibleType` is not `basic_json` (to avoid hijacking copy/move constructors),
|
- `CompatibleType` is not `basic_json` (to avoid hijacking copy/move constructors),
|
||||||
- `CompatibleType` is not a different `basic_json` type (i.e. with different template arguments)
|
- `CompatibleType` is not a different `basic_json` type (i.e. with different template arguments)
|
||||||
- `CompatibleType` is not a `basic_json` nested type (e.g., `json_pointer`, `iterator`, etc.)
|
- `CompatibleType` is not a `basic_json` nested type (e.g., `json_pointer`, `iterator`, etc.)
|
||||||
- if [`JSON_DISABLE_TUPLE_REFERENCE_CONVERSION`](../macros/json_disable_tuple_reference_conversion.md) is defined
|
|
||||||
to `1`: `CompatibleType` is not a one-element `std::tuple` holding a reference to `basic_json`
|
|
||||||
- `json_serializer<U>` (with `U = uncvref_t<CompatibleType>`) has a `to_json(basic_json_t&, CompatibleType&&)`
|
- `json_serializer<U>` (with `U = uncvref_t<CompatibleType>`) has a `to_json(basic_json_t&, CompatibleType&&)`
|
||||||
method
|
method
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,9 @@ Logarithmic in the size of the JSON object.
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 3.11.0.
|
1. Added in version 3.11.0.
|
||||||
2. Added in version 3.6.0. Extended template `KeyType` to support comparable types in version 3.11.0.
|
2. Added in version 3.6.0. Extended template `KeyType` to support comparable types in version 3.11.0. Fixed in
|
||||||
|
version 3.13.0 to consistently accept `std::string_view`-convertible keys, as already supported by
|
||||||
|
[`operator[]`](operator[].md), [`at`](at.md), [`value`](value.md), and other lookup functions.
|
||||||
3. Added in version 3.7.0.
|
3. Added in version 3.7.0.
|
||||||
4. Deleted overloads for integral key types added in version 3.13.0 to reject such calls at compile time instead of
|
4. Deleted overloads for integral key types added in version 3.13.0 to reject such calls at compile time instead of
|
||||||
causing undefined behavior at runtime.
|
causing undefined behavior at runtime.
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ Logarithmic in the size of the JSON object.
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 3.11.0.
|
1. Added in version 3.11.0.
|
||||||
2. Added in version 1.0.0. Changed parameter `key` type to `KeyType&&` in version 3.11.0.
|
2. Added in version 1.0.0. Changed parameter `key` type to `KeyType&&` in version 3.11.0. Fixed in version 3.13.0 to
|
||||||
|
consistently accept `std::string_view`-convertible keys, as already supported by [`operator[]`](operator[].md),
|
||||||
|
[`at`](at.md), [`value`](value.md), and other lookup functions.
|
||||||
3. Deleted overload for integral key types added in version 3.13.0 to reject such calls at compile time instead of
|
3. Deleted overload for integral key types added in version 3.13.0 to reject such calls at compile time instead of
|
||||||
causing undefined behavior at runtime.
|
causing undefined behavior at runtime.
|
||||||
|
|||||||
@@ -25,12 +25,10 @@ and `ensure_ascii` parameters.
|
|||||||
result consists of ASCII characters only.
|
result consists of ASCII characters only.
|
||||||
|
|
||||||
`error_handler` (in)
|
`error_handler` (in)
|
||||||
: how to react on decoding errors; there are four possible values (see [`error_handler_t`](error_handler_t.md):
|
: how to react on decoding errors; there are three possible values (see [`error_handler_t`](error_handler_t.md):
|
||||||
`strict` (throws an exception in case a decoding error occurs; default), `replace` (replace invalid UTF-8 sequences
|
`strict` (throws an exception in case a decoding error occurs; default), `replace` (replace invalid UTF-8 sequences
|
||||||
with U+FFFD), `ignore` (ignore invalid UTF-8 sequences during serialization; all valid bytes are copied to the
|
with U+FFFD), and `ignore` (ignore invalid UTF-8 sequences during serialization; all valid bytes are copied to the
|
||||||
output unchanged, and invalid bytes are dropped), and `keep` (write the ill-formed bytes to the output as is,
|
output unchanged, and invalid bytes are dropped)).
|
||||||
without escaping them, even if `ensure_ascii` is `#!cpp true`; the result is then not valid UTF-8, but equals the
|
|
||||||
input bytes exactly, and well-formed characters around the ill-formed bytes are still escaped as usual)).
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
@@ -96,4 +94,3 @@ Binary values are serialized as an object containing two keys:
|
|||||||
- Indentation character `indent_char`, option `ensure_ascii` and exceptions added in version 3.0.0.
|
- Indentation character `indent_char`, option `ensure_ascii` and exceptions added in version 3.0.0.
|
||||||
- Error handlers added in version 3.4.0.
|
- Error handlers added in version 3.4.0.
|
||||||
- Serialization of binary values added in version 3.8.0.
|
- Serialization of binary values added in version 3.8.0.
|
||||||
- Error handler `keep` added in version 3.13.0.
|
|
||||||
|
|||||||
@@ -213,5 +213,7 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
1. Added in version 1.0.0. Added support for binary types in version 3.8.0.
|
1. Added in version 1.0.0. Added support for binary types in version 3.8.0.
|
||||||
2. Added in version 1.0.0. Added support for binary types in version 3.8.0.
|
2. Added in version 1.0.0. Added support for binary types in version 3.8.0.
|
||||||
3. Added in version 1.0.0.
|
3. Added in version 1.0.0.
|
||||||
4. Added in version 3.11.0.
|
4. Added in version 3.11.0. Fixed in version 3.13.0 to consistently accept `std::string_view`-convertible keys, as
|
||||||
|
already supported by [`operator[]`](operator[].md), [`at`](at.md), [`value`](value.md), and other lookup
|
||||||
|
functions.
|
||||||
5. Added in version 1.0.0.
|
5. Added in version 1.0.0.
|
||||||
|
|||||||
@@ -4,30 +4,15 @@
|
|||||||
enum class error_handler_t {
|
enum class error_handler_t {
|
||||||
strict,
|
strict,
|
||||||
replace,
|
replace,
|
||||||
ignore,
|
ignore
|
||||||
keep
|
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
This enumeration is used to choose how to treat ill-formed UTF-8 in a string value or object key:
|
This enumeration is used in the [`dump`](dump.md) function to choose how to treat decoding errors while serializing a
|
||||||
|
`basic_json` value. Three values are differentiated:
|
||||||
- [`dump`](dump.md) uses it while serializing a `basic_json` value to text.
|
|
||||||
- [`to_cbor`](to_cbor.md), [`to_ubjson`](to_ubjson.md), [`to_bjdata`](to_bjdata.md), and [`to_bson`](to_bson.md) use it
|
|
||||||
while serializing a `basic_json` value to that binary format; none of CBOR, UBJSON, BJData, or BSON requires a
|
|
||||||
decoder to reject ill-formed UTF-8, so by default (`strict`) the library checks on write instead. `to_msgpack` and
|
|
||||||
`to_bon8` do not take this parameter: MessagePack's specification explicitly allows a string to contain ill-formed
|
|
||||||
UTF-8, so `to_msgpack` always passes it through, while BON8 always validates, since UTF-8 lead bytes are structural
|
|
||||||
to that format.
|
|
||||||
- [`from_cbor`](from_cbor.md), [`from_msgpack`](from_msgpack.md), [`from_ubjson`](from_ubjson.md),
|
|
||||||
[`from_bjdata`](from_bjdata.md), and [`from_bson`](from_bson.md) use it while parsing that binary format, to decide
|
|
||||||
whether to check a string value or object key for well-formed UTF-8 at all; by default (`keep`) they do not, as no
|
|
||||||
binary reader did before this parameter was added. `from_bon8` does not take this parameter, for the same reason
|
|
||||||
`to_bon8` does not.
|
|
||||||
|
|
||||||
Four values are differentiated:
|
|
||||||
|
|
||||||
strict
|
strict
|
||||||
: throw a `type_error`/`parse_error` exception in case of invalid UTF-8
|
: throw a `type_error` exception in case of invalid UTF-8
|
||||||
|
|
||||||
replace
|
replace
|
||||||
: replace invalid UTF-8 sequences with U+FFFD (� REPLACEMENT CHARACTER)
|
: replace invalid UTF-8 sequences with U+FFFD (� REPLACEMENT CHARACTER)
|
||||||
@@ -35,12 +20,6 @@ replace
|
|||||||
ignore
|
ignore
|
||||||
: ignore invalid UTF-8 sequences; all valid bytes are copied to the output unchanged, and invalid bytes are dropped
|
: ignore invalid UTF-8 sequences; all valid bytes are copied to the output unchanged, and invalid bytes are dropped
|
||||||
|
|
||||||
keep
|
|
||||||
: keep invalid UTF-8 sequences unchanged; only meaningful for the binary formats mentioned above, since [`dump`]
|
|
||||||
(dump.md) itself must produce text, and `keep` there writes the ill-formed bytes to the output as is, so the
|
|
||||||
result is then not valid UTF-8 (but still equals the input bytes exactly, including around any well-formed
|
|
||||||
characters, which are still escaped as usual)
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -61,5 +40,3 @@ keep
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.4.0.
|
- Added in version 3.4.0.
|
||||||
- Added `keep`, and made this enumeration apply to the binary readers and writers in addition to `dump`, in version
|
|
||||||
3.13.0.
|
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ Logarithmic in the size of the JSON object.
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
1. Added in version 3.11.0.
|
1. Added in version 3.11.0.
|
||||||
2. Added in version 1.0.0. Changed to support comparable types in version 3.11.0.
|
2. Added in version 1.0.0. Changed to support comparable types in version 3.11.0. Fixed in version 3.13.0 to
|
||||||
|
consistently accept `std::string_view`-convertible keys, as already supported by [`operator[]`](operator[].md),
|
||||||
|
[`at`](at.md), [`value`](value.md), and other lookup functions.
|
||||||
3. Deleted overloads for integral key types added in version 3.13.0 to reject such calls at compile time instead of
|
3. Deleted overloads for integral key types added in version 3.13.0 to reject such calls at compile time instead of
|
||||||
causing undefined behavior at runtime.
|
causing undefined behavior at runtime.
|
||||||
|
|||||||
@@ -5,14 +5,12 @@
|
|||||||
template<typename InputType>
|
template<typename InputType>
|
||||||
static basic_json from_bjdata(InputType&& i,
|
static basic_json from_bjdata(InputType&& i,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType, typename SentinelType = IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_bjdata(IteratorType first, SentinelType last,
|
static basic_json from_bjdata(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Deserializes a given input to a JSON value using the BJData (Binary JData) serialization format.
|
Deserializes a given input to a JSON value using the BJData (Binary JData) serialization format.
|
||||||
@@ -60,12 +58,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
`allow_exceptions` (in)
|
`allow_exceptions` (in)
|
||||||
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
||||||
|
|
||||||
`error_handler` (in)
|
|
||||||
: how to treat a string value or object key that is not valid UTF-8; see [`error_handler_t`](error_handler_t.md).
|
|
||||||
BJData does not require a decoder to reject ill-formed UTF-8, so checking is opt-in: the default, `keep`, does not
|
|
||||||
check at all, as every binary reader did before this parameter was added; `strict` checks and throws;
|
|
||||||
`replace`/`ignore` sanitize the string the same way [`dump`](dump.md) would
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
||||||
@@ -81,7 +73,7 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
the end of the file was not reached when `strict` was set to true
|
the end of the file was not reached when `strict` was set to true
|
||||||
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
|
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
|
||||||
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
|
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
|
||||||
successfully, or if a string value or object key is not valid UTF-8 and `error_handler` is `strict`
|
successfully
|
||||||
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the size of an optimized container
|
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the size of an optimized container
|
||||||
or n-dimensional array cannot be represented by `std::size_t`
|
or n-dimensional array cannot be represented by `std::size_t`
|
||||||
|
|
||||||
@@ -119,4 +111,3 @@ Linear in the size of the input.
|
|||||||
- Added in version 3.11.0.
|
- Added in version 3.11.0.
|
||||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
|
||||||
|
|||||||
@@ -5,14 +5,12 @@
|
|||||||
template<typename InputType>
|
template<typename InputType>
|
||||||
static basic_json from_bson(InputType&& i,
|
static basic_json from_bson(InputType&& i,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType, typename SentinelType = IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_bson(IteratorType first, SentinelType last,
|
static basic_json from_bson(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Deserializes a given input to a JSON value using the BSON (Binary JSON) serialization format.
|
Deserializes a given input to a JSON value using the BSON (Binary JSON) serialization format.
|
||||||
@@ -60,12 +58,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
`allow_exceptions` (in)
|
`allow_exceptions` (in)
|
||||||
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
||||||
|
|
||||||
`error_handler` (in)
|
|
||||||
: how to treat a string value or object key that is not valid UTF-8; see [`error_handler_t`](error_handler_t.md).
|
|
||||||
BSON does not require a decoder to reject ill-formed UTF-8, so checking is opt-in: the default, `keep`, does not
|
|
||||||
check at all, as every binary reader did before this parameter was added; `strict` checks and throws;
|
|
||||||
`replace`/`ignore` sanitize the string the same way [`dump`](dump.md) would
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
||||||
@@ -83,8 +75,6 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
invalid string or byte array length)
|
invalid string or byte array length)
|
||||||
- Throws [`parse_error.114`](../../home/exceptions.md#jsonexceptionparse_error114) if an unsupported BSON record type is
|
- Throws [`parse_error.114`](../../home/exceptions.md#jsonexceptionparse_error114) if an unsupported BSON record type is
|
||||||
encountered
|
encountered
|
||||||
- Throws [`parse_error.113`](../../home/exceptions.md#jsonexceptionparse_error113) if a string value or object key is
|
|
||||||
not valid UTF-8 and `error_handler` is `strict`
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -121,7 +111,6 @@ Linear in the size of the input.
|
|||||||
- Added in version 3.4.0.
|
- Added in version 3.4.0.
|
||||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,14 @@ template<typename InputType>
|
|||||||
static basic_json from_cbor(InputType&& i,
|
static basic_json from_cbor(InputType&& i,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true,
|
||||||
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error,
|
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType, typename SentinelType = IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_cbor(IteratorType first, SentinelType last,
|
static basic_json from_cbor(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true,
|
||||||
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error,
|
const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Deserializes a given input to a JSON value using the CBOR (Concise Binary Object Representation) serialization format.
|
Deserializes a given input to a JSON value using the CBOR (Concise Binary Object Representation) serialization format.
|
||||||
@@ -67,12 +65,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: how to treat CBOR tags (optional, `error` by default); see [`cbor_tag_handler_t`](cbor_tag_handler_t.md) for more
|
: how to treat CBOR tags (optional, `error` by default); see [`cbor_tag_handler_t`](cbor_tag_handler_t.md) for more
|
||||||
information
|
information
|
||||||
|
|
||||||
`error_handler` (in)
|
|
||||||
: how to treat a string value or object key that is not valid UTF-8; see [`error_handler_t`](error_handler_t.md).
|
|
||||||
CBOR does not require a decoder to reject ill-formed UTF-8, so checking is opt-in: the default, `keep`, does not
|
|
||||||
check at all, as every binary reader did before this parameter was added; `strict` checks and throws;
|
|
||||||
`replace`/`ignore` sanitize the string the same way [`dump`](dump.md) would
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
||||||
@@ -88,9 +80,8 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
the end of the file was not reached when `strict` was set to true
|
the end of the file was not reached when `strict` was set to true
|
||||||
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if unsupported features from CBOR were
|
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if unsupported features from CBOR were
|
||||||
used in the given input or if the input is not valid CBOR
|
used in the given input or if the input is not valid CBOR
|
||||||
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a map key is not a string (keys of
|
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a map key is not a string (keys of other
|
||||||
other types are not supported, as JSON object keys are always strings), or if a string value or object key is not
|
types are not supported, as JSON object keys are always strings) or a string is malformed
|
||||||
valid UTF-8 and `error_handler` is `strict`
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -130,7 +121,6 @@ Linear in the size of the input.
|
|||||||
- Added `tag_handler` parameter in version 3.9.0.
|
- Added `tag_handler` parameter in version 3.9.0.
|
||||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,12 @@
|
|||||||
template<typename InputType>
|
template<typename InputType>
|
||||||
static basic_json from_msgpack(InputType&& i,
|
static basic_json from_msgpack(InputType&& i,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType, typename SentinelType = IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_msgpack(IteratorType first, SentinelType last,
|
static basic_json from_msgpack(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Deserializes a given input to a JSON value using the MessagePack serialization format.
|
Deserializes a given input to a JSON value using the MessagePack serialization format.
|
||||||
@@ -60,12 +58,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
`allow_exceptions` (in)
|
`allow_exceptions` (in)
|
||||||
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
||||||
|
|
||||||
`error_handler` (in)
|
|
||||||
: how to treat a string value or object key that is not valid UTF-8; see [`error_handler_t`](error_handler_t.md).
|
|
||||||
MessagePack's specification explicitly allows ill-formed UTF-8, so checking is opt-in: the default, `keep`, does
|
|
||||||
not check at all, as every binary reader did before this parameter was added; `strict` checks and throws;
|
|
||||||
`replace`/`ignore` sanitize the string the same way [`dump`](dump.md) would
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
||||||
@@ -81,9 +73,8 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
the end of the file was not reached when `strict` was set to true
|
the end of the file was not reached when `strict` was set to true
|
||||||
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if unsupported features from
|
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if unsupported features from
|
||||||
MessagePack were used in the given input or if the input is not valid MessagePack
|
MessagePack were used in the given input or if the input is not valid MessagePack
|
||||||
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a map key is not a string (keys of
|
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a map key is not a string (keys of other
|
||||||
other types are not supported, as JSON object keys are always strings), or if a string value or object key is not
|
types are not supported, as JSON object keys are always strings) or a string is malformed
|
||||||
valid UTF-8 and `error_handler` is `strict`
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -122,7 +113,6 @@ Linear in the size of the input.
|
|||||||
- Added `allow_exceptions` parameter in version 3.2.0.
|
- Added `allow_exceptions` parameter in version 3.2.0.
|
||||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,12 @@
|
|||||||
template<typename InputType>
|
template<typename InputType>
|
||||||
static basic_json from_ubjson(InputType&& i,
|
static basic_json from_ubjson(InputType&& i,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
// (2)
|
// (2)
|
||||||
template<typename IteratorType, typename SentinelType = IteratorType>
|
template<typename IteratorType, typename SentinelType = IteratorType>
|
||||||
static basic_json from_ubjson(IteratorType first, SentinelType last,
|
static basic_json from_ubjson(IteratorType first, SentinelType last,
|
||||||
const bool strict = true,
|
const bool strict = true,
|
||||||
const bool allow_exceptions = true,
|
const bool allow_exceptions = true);
|
||||||
const error_handler_t error_handler = error_handler_t::keep);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Deserializes a given input to a JSON value using the UBJSON (Universal Binary JSON) serialization format.
|
Deserializes a given input to a JSON value using the UBJSON (Universal Binary JSON) serialization format.
|
||||||
@@ -60,12 +58,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
`allow_exceptions` (in)
|
`allow_exceptions` (in)
|
||||||
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
: whether to throw exceptions in case of a parse error (optional, `#!cpp true` by default)
|
||||||
|
|
||||||
`error_handler` (in)
|
|
||||||
: how to treat a string value or object key that is not valid UTF-8; see [`error_handler_t`](error_handler_t.md).
|
|
||||||
UBJSON does not require a decoder to reject ill-formed UTF-8, so checking is opt-in: the default, `keep`, does not
|
|
||||||
check at all, as every binary reader did before this parameter was added; `strict` checks and throws;
|
|
||||||
`replace`/`ignore` sanitize the string the same way [`dump`](dump.md) would
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `#!cpp false`, the return value will be
|
||||||
@@ -81,7 +73,7 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
the end of the file was not reached when `strict` was set to true
|
the end of the file was not reached when `strict` was set to true
|
||||||
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
|
- Throws [parse_error.112](../../home/exceptions.md#jsonexceptionparse_error112) if a parse error occurs
|
||||||
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
|
- Throws [parse_error.113](../../home/exceptions.md#jsonexceptionparse_error113) if a string could not be parsed
|
||||||
successfully, or if a string value or object key is not valid UTF-8 and `error_handler` is `strict`
|
successfully
|
||||||
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the size of an optimized container
|
- Throws [out_of_range.408](../../home/exceptions.md#jsonexceptionout_of_range408) if the size of an optimized container
|
||||||
or n-dimensional array cannot be represented by `std::size_t`
|
or n-dimensional array cannot be represented by `std::size_t`
|
||||||
|
|
||||||
@@ -120,7 +112,6 @@ Linear in the size of the input.
|
|||||||
- Added `allow_exceptions` parameter in version 3.2.0.
|
- Added `allow_exceptions` parameter in version 3.2.0.
|
||||||
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
|
||||||
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
|
||||||
|
|
||||||
!!! warning "Deprecation"
|
!!! warning "Deprecation"
|
||||||
|
|
||||||
|
|||||||
@@ -37,12 +37,6 @@ Thereby, `Target` is the current object; that is, the patch is applied to the cu
|
|||||||
|
|
||||||
Linear in the lengths of `apply_patch`.
|
Linear in the lengths of `apply_patch`.
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
`apply_patch` may be `#!cpp *this` itself or refer to a value contained in `#!cpp *this` (for example, a subobject
|
|
||||||
returned by `#!cpp (*this)[key]`); it is read as it was when `merge_patch()` was called, before any modification of
|
|
||||||
`#!cpp *this`.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -67,5 +61,3 @@ returned by `#!cpp (*this)[key]`); it is read as it was when `merge_patch()` was
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.0.0.
|
- Added in version 3.0.0.
|
||||||
- Fixed use of freed or relocated memory when `apply_patch` is `#!cpp *this` or refers to a value contained in
|
|
||||||
`#!cpp *this`, in version 3.13.0.
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ range will yield over/underflow when used in a constructor. During deserializati
|
|||||||
will automatically be stored as [`number_unsigned_t`](number_unsigned_t.md) or [`number_float_t`](number_float_t.md).
|
will automatically be stored as [`number_unsigned_t`](number_unsigned_t.md) or [`number_float_t`](number_float_t.md).
|
||||||
|
|
||||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
||||||
> Note that when such software is used, numbers that are integers and are in the range [-2<sup>53</sup>+1, 2<sup>53</sup>-1] are
|
> Note that when such software is used, numbers that are integers and are in the range $[-2^{53}+1, 2^{53}-1]$ are
|
||||||
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
||||||
|
|
||||||
As this range is a subrange of the exactly supported range [INT64_MIN, INT64_MAX], this class's integer type is
|
As this range is a subrange of the exactly supported range [INT64_MIN, INT64_MAX], this class's integer type is
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ when used in a constructor. During deserialization, too large or small integer n
|
|||||||
as [`number_integer_t`](number_integer_t.md) or [`number_float_t`](number_float_t.md).
|
as [`number_integer_t`](number_integer_t.md) or [`number_float_t`](number_float_t.md).
|
||||||
|
|
||||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
||||||
> Note that when such software is used, numbers that are integers and are in the range [-2<sup>53</sup>+1, 2<sup>53</sup>-1] are
|
> Note that when such software is used, numbers that are integers and are in the range $[-2^{53}+1, 2^{53}-1]$ are
|
||||||
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
> interoperable in the sense that implementations will agree exactly on their numeric values.
|
||||||
|
|
||||||
As this range is a subrange (when considered in conjunction with the `number_integer_t` type) of the exactly supported
|
As this range is a subrange (when considered in conjunction with the `number_integer_t` type) of the exactly supported
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ classDiagram
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
For an input with <i>n</i> bytes, 1 is the index of the first character and <i>n</i>+1 is the index of the terminating null byte
|
For an input with $n$ bytes, 1 is the index of the first character and $n+1$ is the index of the terminating null byte
|
||||||
or the end of file. This also holds true when reading a byte vector for binary formats.
|
or the end of file. This also holds true when reading a byte vector for binary formats.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|||||||
@@ -5,18 +5,15 @@
|
|||||||
static std::vector<std::uint8_t> to_bjdata(const basic_json& j,
|
static std::vector<std::uint8_t> to_bjdata(const basic_json& j,
|
||||||
const bool use_size = false,
|
const bool use_size = false,
|
||||||
const bool use_type = false,
|
const bool use_type = false,
|
||||||
const bjdata_version_t version = bjdata_version_t::draft2,
|
const bjdata_version_t version = bjdata_version_t::draft2);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
static void to_bjdata(const basic_json& j, detail::output_adapter<std::uint8_t> o,
|
static void to_bjdata(const basic_json& j, detail::output_adapter<std::uint8_t> o,
|
||||||
const bool use_size = false, const bool use_type = false,
|
const bool use_size = false, const bool use_type = false,
|
||||||
const bjdata_version_t version = bjdata_version_t::draft2,
|
const bjdata_version_t version = bjdata_version_t::draft2);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
static void to_bjdata(const basic_json& j, detail::output_adapter<char> o,
|
static void to_bjdata(const basic_json& j, detail::output_adapter<char> o,
|
||||||
const bool use_size = false, const bool use_type = false,
|
const bool use_size = false, const bool use_type = false,
|
||||||
const bjdata_version_t version = bjdata_version_t::draft2,
|
const bjdata_version_t version = bjdata_version_t::draft2);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Serializes a given JSON value `j` to a byte vector using the BJData (Binary JData) serialization format. BJData aims to
|
Serializes a given JSON value `j` to a byte vector using the BJData (Binary JData) serialization format. BJData aims to
|
||||||
@@ -46,12 +43,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: which version of BJData to use (see note on "Binary values" on [BJData](../../features/binary_formats/bjdata.md));
|
: which version of BJData to use (see note on "Binary values" on [BJData](../../features/binary_formats/bjdata.md));
|
||||||
optional, `#!cpp bjdata_version_t::draft2` by default.
|
optional, `#!cpp bjdata_version_t::draft2` by default.
|
||||||
|
|
||||||
`error_handler` (in)
|
|
||||||
: how to treat a string or object key in `j` that is not valid UTF-8; see [`error_handler_t`](error_handler_t.md).
|
|
||||||
The default, `strict`, throws; `keep` writes the ill-formed bytes to the output as is, as every version of
|
|
||||||
`to_bjdata` did before this parameter was added; `replace`/`ignore` sanitize it the same way
|
|
||||||
[`dump`](dump.md) would
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
1. BJData serialization as byte vector
|
1. BJData serialization as byte vector
|
||||||
@@ -65,8 +56,6 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
|
|
||||||
- Throws [`other_error.502`](../../home/exceptions.md#jsonexceptionother_error502) if `use_type` is true and `use_size`
|
- Throws [`other_error.502`](../../home/exceptions.md#jsonexceptionother_error502) if `use_type` is true and `use_size`
|
||||||
is false.
|
is false.
|
||||||
- Throws [type_error.316](../../home/exceptions.md#jsonexceptiontype_error316) if a string or object key in `j` is
|
|
||||||
not valid UTF-8 and `error_handler` is `strict` (the default)
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -101,5 +90,3 @@ Linear in the size of the JSON value `j`.
|
|||||||
|
|
||||||
- Added in version 3.11.0.
|
- Added in version 3.11.0.
|
||||||
- BJData version parameter (for draft3 binary encoding) added in version 3.12.0.
|
- BJData version parameter (for draft3 binary encoding) added in version 3.12.0.
|
||||||
- Throwing `type_error.316` for a string or object key that is not valid UTF-8 added in version 3.13.0.
|
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
|
||||||
@@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// (1)
|
// (1)
|
||||||
static std::vector<std::uint8_t> to_bson(const basic_json& j,
|
static std::vector<std::uint8_t> to_bson(const basic_json& j);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
static void to_bson(const basic_json& j, detail::output_adapter<std::uint8_t> o,
|
static void to_bson(const basic_json& j, detail::output_adapter<std::uint8_t> o);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
static void to_bson(const basic_json& j, detail::output_adapter<char> o);
|
||||||
static void to_bson(const basic_json& j, detail::output_adapter<char> o,
|
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
BSON (Binary JSON) is a binary format in which zero or more ordered key/value pairs are stored as a single entity (a
|
BSON (Binary JSON) is a binary format in which zero or more ordered key/value pairs are stored as a single entity (a
|
||||||
@@ -28,12 +25,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
`o` (in)
|
`o` (in)
|
||||||
: output adapter to write serialization to
|
: output adapter to write serialization to
|
||||||
|
|
||||||
`error_handler` (in)
|
|
||||||
: how to treat a string or object key in `j` that is not valid UTF-8; see [`error_handler_t`](error_handler_t.md).
|
|
||||||
The default, `strict`, throws; `keep` writes the ill-formed bytes to the output as is, as every version of
|
|
||||||
`to_bson` did before this parameter was added; `replace`/`ignore` sanitize it the same way
|
|
||||||
[`dump`](dump.md) would
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
1. BSON serialization as a byte vector
|
1. BSON serialization as a byte vector
|
||||||
@@ -55,8 +46,6 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
- Throws [`out_of_range.415`](../../home/exceptions.md#jsonexceptionout_of_range415) if the subtype of a binary value
|
- Throws [`out_of_range.415`](../../home/exceptions.md#jsonexceptionout_of_range415) if the subtype of a binary value
|
||||||
exceeds 255, the maximum of the BSON binary subtype; example:
|
exceeds 255, the maximum of the BSON binary subtype; example:
|
||||||
`"subtype 70000 is too large for the BSON binary subtype (max 255)"`
|
`"subtype 70000 is too large for the BSON binary subtype (max 255)"`
|
||||||
- Throws [type_error.316](../../home/exceptions.md#jsonexceptiontype_error316) if a string or object key is
|
|
||||||
not valid UTF-8 and `error_handler` is `strict` (the default)
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -93,6 +82,3 @@ pass before anything is written.
|
|||||||
- Added in version 3.4.0.
|
- Added in version 3.4.0.
|
||||||
- Linear in the size of `j`, and no longer limited by the call stack for deeply nested values, since version 3.13.0.
|
- Linear in the size of `j`, and no longer limited by the call stack for deeply nested values, since version 3.13.0.
|
||||||
- `out_of_range.415` is now detected before anything is written, like the other exceptions above, since version 3.13.0.
|
- `out_of_range.415` is now detected before anything is written, like the other exceptions above, since version 3.13.0.
|
||||||
- Throwing `type_error.316` for a string value or object key that is not valid UTF-8, detected before anything is
|
|
||||||
written, added in version 3.13.0.
|
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
|
||||||
|
|||||||
@@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// (1)
|
// (1)
|
||||||
static std::vector<std::uint8_t> to_cbor(const basic_json& j,
|
static std::vector<std::uint8_t> to_cbor(const basic_json& j);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
static void to_cbor(const basic_json& j, detail::output_adapter<std::uint8_t> o,
|
static void to_cbor(const basic_json& j, detail::output_adapter<std::uint8_t> o);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
static void to_cbor(const basic_json& j, detail::output_adapter<char> o);
|
||||||
static void to_cbor(const basic_json& j, detail::output_adapter<char> o,
|
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Serializes a given JSON value `j` to a byte vector using the CBOR (Concise Binary Object Representation) serialization
|
Serializes a given JSON value `j` to a byte vector using the CBOR (Concise Binary Object Representation) serialization
|
||||||
@@ -29,12 +26,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
`o` (in)
|
`o` (in)
|
||||||
: output adapter to write serialization to
|
: output adapter to write serialization to
|
||||||
|
|
||||||
`error_handler` (in)
|
|
||||||
: how to treat a string or object key in `j` that is not valid UTF-8; see [`error_handler_t`](error_handler_t.md).
|
|
||||||
The default, `strict`, throws; `keep` writes the ill-formed bytes to the output as is, as every version of
|
|
||||||
`to_cbor` did before this parameter was added; `replace`/`ignore` sanitize it the same way
|
|
||||||
[`dump`](dump.md) would
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
1. CBOR serialization as a byte vector
|
1. CBOR serialization as a byte vector
|
||||||
@@ -44,11 +35,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
|
|
||||||
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
|
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
|
||||||
|
|
||||||
## Exceptions
|
|
||||||
|
|
||||||
- Throws [type_error.316](../../home/exceptions.md#jsonexceptiontype_error316) if a string or object key in `j` is
|
|
||||||
not valid UTF-8 and `error_handler` is `strict` (the default)
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
Linear in the size of the JSON value `j`.
|
Linear in the size of the JSON value `j`.
|
||||||
@@ -82,5 +68,3 @@ Linear in the size of the JSON value `j`.
|
|||||||
|
|
||||||
- Added in version 2.0.9.
|
- Added in version 2.0.9.
|
||||||
- Compact representation of floating-point numbers added in version 3.8.0.
|
- Compact representation of floating-point numbers added in version 3.8.0.
|
||||||
- Throwing `type_error.316` for a string or object key that is not valid UTF-8 added in version 3.13.0.
|
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
|
||||||
|
|||||||
@@ -4,16 +4,13 @@
|
|||||||
// (1)
|
// (1)
|
||||||
static std::vector<std::uint8_t> to_ubjson(const basic_json& j,
|
static std::vector<std::uint8_t> to_ubjson(const basic_json& j,
|
||||||
const bool use_size = false,
|
const bool use_size = false,
|
||||||
const bool use_type = false,
|
const bool use_type = false);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
|
|
||||||
// (2)
|
// (2)
|
||||||
static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o,
|
static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o,
|
||||||
const bool use_size = false, const bool use_type = false,
|
const bool use_size = false, const bool use_type = false);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
static void to_ubjson(const basic_json& j, detail::output_adapter<char> o,
|
static void to_ubjson(const basic_json& j, detail::output_adapter<char> o,
|
||||||
const bool use_size = false, const bool use_type = false,
|
const bool use_size = false, const bool use_type = false);
|
||||||
const error_handler_t error_handler = error_handler_t::strict);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Serializes a given JSON value `j` to a byte vector using the UBJSON (Universal Binary JSON) serialization format. UBJSON
|
Serializes a given JSON value `j` to a byte vector using the UBJSON (Universal Binary JSON) serialization format. UBJSON
|
||||||
@@ -39,12 +36,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../
|
|||||||
: whether to add type annotations to container types (must be combined with `#!cpp use_size = true`); optional,
|
: whether to add type annotations to container types (must be combined with `#!cpp use_size = true`); optional,
|
||||||
`#!cpp false` by default.
|
`#!cpp false` by default.
|
||||||
|
|
||||||
`error_handler` (in)
|
|
||||||
: how to treat a string or object key in `j` that is not valid UTF-8; see [`error_handler_t`](error_handler_t.md).
|
|
||||||
The default, `strict`, throws; `keep` writes the ill-formed bytes to the output as is, as every version of
|
|
||||||
`to_ubjson` did before this parameter was added; `replace`/`ignore` sanitize it the same way
|
|
||||||
[`dump`](dump.md) would
|
|
||||||
|
|
||||||
## Return value
|
## Return value
|
||||||
|
|
||||||
1. UBJSON serialization as a byte vector
|
1. UBJSON serialization as a byte vector
|
||||||
@@ -58,8 +49,6 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
|
|||||||
|
|
||||||
- Throws [`other_error.502`](../../home/exceptions.md#jsonexceptionother_error502) if `use_type` is true and `use_size`
|
- Throws [`other_error.502`](../../home/exceptions.md#jsonexceptionother_error502) if `use_type` is true and `use_size`
|
||||||
is false.
|
is false.
|
||||||
- Throws [type_error.316](../../home/exceptions.md#jsonexceptiontype_error316) if a string or object key in `j` is
|
|
||||||
not valid UTF-8 and `error_handler` is `strict` (the default)
|
|
||||||
|
|
||||||
## Complexity
|
## Complexity
|
||||||
|
|
||||||
@@ -93,5 +82,3 @@ Linear in the size of the JSON value `j`.
|
|||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 3.1.0.
|
- Added in version 3.1.0.
|
||||||
- Throwing `type_error.316` for a string or object key that is not valid UTF-8 added in version 3.13.0.
|
|
||||||
- Added `error_handler` parameter in version 3.13.0.
|
|
||||||
|
|||||||
@@ -59,12 +59,6 @@ Basic guarantee: if an exception is thrown during the operation, the JSON value
|
|||||||
1. O(N*log(size() + N)), where N is the number of elements to insert.
|
1. O(N*log(size() + N)), where N is the number of elements to insert.
|
||||||
2. O(N*log(size() + N)), where N is the number of elements to insert.
|
2. O(N*log(size() + N)), where N is the number of elements to insert.
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
The argument `j` (or, for overload (2), the range `[first, last)`) may be `#!cpp *this` itself or refer to a value
|
|
||||||
contained in `#!cpp *this` (for example, a subobject returned by `#!cpp (*this)[key]`); it is read as it was when
|
|
||||||
`update()` was called, before any modification of `#!cpp *this`.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
@@ -161,5 +155,3 @@ contained in `#!cpp *this` (for example, a subobject returned by `#!cpp (*this)[
|
|||||||
|
|
||||||
- Added in version 3.0.0.
|
- Added in version 3.0.0.
|
||||||
- Added `merge_objects` parameter in 3.10.5.
|
- Added `merge_objects` parameter in 3.10.5.
|
||||||
- Fixed use of freed or relocated memory when the argument is `#!cpp *this` or refers to a value contained in
|
|
||||||
`#!cpp *this`, in version 3.13.0.
|
|
||||||
|
|||||||
@@ -195,7 +195,9 @@ changes to any JSON value.
|
|||||||
1. Added in version 1.0.0. Changed parameter `default_value` type from `const ValueType&` to `ValueType&&` in version
|
1. Added in version 1.0.0. Changed parameter `default_value` type from `const ValueType&` to `ValueType&&` in version
|
||||||
3.11.0. Deleted overload for integral key types added in version 3.13.0 to reject such calls at compile time
|
3.11.0. Deleted overload for integral key types added in version 3.13.0 to reject such calls at compile time
|
||||||
instead of causing undefined behavior at runtime.
|
instead of causing undefined behavior at runtime.
|
||||||
2. Added in version 3.11.0. Made `ValueType` the first template parameter in version 3.11.2.
|
2. Added in version 3.11.0. Made `ValueType` the first template parameter in version 3.11.2. Fixed in version 3.13.0
|
||||||
|
to consistently accept `std::string_view`-convertible keys, as already supported by
|
||||||
|
[`operator[]`](operator[].md), [`at`](at.md), [`find`](find.md), and other lookup functions.
|
||||||
3. Added in version 2.0.2. Extended to work with arrays in version 3.13.0, including fixing an issue where resolving
|
3. Added in version 2.0.2. Extended to work with arrays in version 3.13.0, including fixing an issue where resolving
|
||||||
`ptr` through an array unexpectedly threw `out_of_range` instead of returning the resolved element (or
|
`ptr` through an array unexpectedly threw `out_of_range` instead of returning the resolved element (or
|
||||||
`default_value`, as documented).
|
`default_value`, as documented).
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ header. See also the [macro overview page](../../features/macros.md).
|
|||||||
|
|
||||||
- [**JSON_BRACE_INIT_COPY_SEMANTICS**](json_brace_init_copy_semantics.md) - opt in to copy/move semantics for single-element brace initialization
|
- [**JSON_BRACE_INIT_COPY_SEMANTICS**](json_brace_init_copy_semantics.md) - opt in to copy/move semantics for single-element brace initialization
|
||||||
- [**JSON_DISABLE_ENUM_SERIALIZATION**](json_disable_enum_serialization.md) - switch off default serialization/deserialization functions for enums
|
- [**JSON_DISABLE_ENUM_SERIALIZATION**](json_disable_enum_serialization.md) - switch off default serialization/deserialization functions for enums
|
||||||
- [**JSON_DISABLE_TUPLE_REFERENCE_CONVERSION**](json_disable_tuple_reference_conversion.md) - switch off conversion from a one-element tuple of a JSON reference
|
|
||||||
- [**JSON_USE_IMPLICIT_CONVERSIONS**](json_use_implicit_conversions.md) - control implicit conversions
|
- [**JSON_USE_IMPLICIT_CONVERSIONS**](json_use_implicit_conversions.md) - control implicit conversions
|
||||||
|
|
||||||
## Comparison behavior
|
## Comparison behavior
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
# JSON_DISABLE_TUPLE_REFERENCE_CONVERSION
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION /* value */
|
|
||||||
```
|
|
||||||
|
|
||||||
When defined to `1`, a `basic_json` value can no longer be constructed from a one-element `std::tuple` whose element is
|
|
||||||
a reference to that `basic_json` type, such as `std::tuple<json&>`, `std::tuple<const json&>`, or `std::tuple<json&&>`.
|
|
||||||
These are the tuples created by `std::forward_as_tuple(j)`.
|
|
||||||
|
|
||||||
## Default definition
|
|
||||||
|
|
||||||
The default value is `0` (disabled — existing behavior is preserved).
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION 0
|
|
||||||
```
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
!!! note "Background"
|
|
||||||
|
|
||||||
By default, `basic_json` can be constructed from any `std::tuple` whose elements can be converted to JSON; the result
|
|
||||||
is an array. This includes `std::tuple<json&>`, which becomes a one-element array.
|
|
||||||
|
|
||||||
`std::tuple` only converts another tuple element by element if its element type cannot be constructed from the whole
|
|
||||||
source tuple. Because `json` *can* be constructed from `std::tuple<json&>`, `std::tuple` instead converts the whole
|
|
||||||
tuple into a single `json` value. This has two surprising effects:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
json j = true;
|
|
||||||
|
|
||||||
// rejected by some standard libraries (e.g., libc++); with others, the
|
|
||||||
// reference binds to a temporary that is destroyed right away
|
|
||||||
std::tuple<const json&> t1(std::forward_as_tuple(j));
|
|
||||||
|
|
||||||
// compiles, but std::get<0>(t2) is [true], not true
|
|
||||||
std::tuple<json> t2(std::forward_as_tuple(j));
|
|
||||||
```
|
|
||||||
|
|
||||||
Enabling this macro removes the conversion, so both tuples are converted element by element: `std::get<0>(t1)`
|
|
||||||
refers to `j`, and `std::get<0>(t2)` is a copy of `j` (see [#2226](https://github.com/nlohmann/json/issues/2226)).
|
|
||||||
|
|
||||||
!!! warning "Opt-in only"
|
|
||||||
|
|
||||||
This macro must be defined **before** including `<nlohmann/json.hpp>`. Defining it after the include has no effect.
|
|
||||||
|
|
||||||
!!! note "Affected conversions"
|
|
||||||
|
|
||||||
Only one-element tuples holding a reference to the **same** `basic_json` type are affected. Constructing a JSON value
|
|
||||||
from them no longer compiles:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
json j = true;
|
|
||||||
json a = std::forward_as_tuple(j); // error with the macro enabled
|
|
||||||
json b = json::array({j}); // use this instead: [true]
|
|
||||||
```
|
|
||||||
|
|
||||||
Tuples holding a JSON value (`std::make_tuple(j)`), tuples with more than one element, and tuples holding references
|
|
||||||
to other types (including other `basic_json` specializations) are converted to arrays as before.
|
|
||||||
|
|
||||||
!!! hint "CMake option"
|
|
||||||
|
|
||||||
This behavior can also be controlled with the CMake option
|
|
||||||
[`JSON_DisableTupleReferenceConversion`](../../integration/cmake.md#json_disabletuplereferenceconversion)
|
|
||||||
(`OFF` by default) which defines `JSON_DISABLE_TUPLE_REFERENCE_CONVERSION` accordingly.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
??? example "Default behavior (macro not defined)"
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
json j = true;
|
|
||||||
|
|
||||||
std::tuple<json> t(std::forward_as_tuple(j));
|
|
||||||
// std::get<0>(t) is [true] -- the whole tuple was converted
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
??? example "Conversion disabled (macro defined to 1)"
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION 1
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
json j = true;
|
|
||||||
|
|
||||||
std::tuple<json> t(std::forward_as_tuple(j));
|
|
||||||
// std::get<0>(t) is true -- a copy of j
|
|
||||||
|
|
||||||
std::tuple<const json&> r(std::forward_as_tuple(j));
|
|
||||||
// std::get<0>(r) refers to j
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [**basic_json(CompatibleType&&)**](../basic_json/basic_json.md) - the affected constructor
|
|
||||||
- [:simple-cmake: JSON_DisableTupleReferenceConversion](../../integration/cmake.md#json_disabletuplereferenceconversion) -
|
|
||||||
CMake option to control the macro
|
|
||||||
|
|
||||||
## Version history
|
|
||||||
|
|
||||||
- Added in version 3.13.0.
|
|
||||||
@@ -90,7 +90,7 @@ Note: Some modern features (like C++20 ranges or filesystem support) may be disa
|
|||||||
| GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 15.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 16.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
| GNU 16.1.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub |
|
||||||
| GNU 16.1.0 | arm64 | Ubuntu 24.04 | GitHub |
|
| GNU 16.1.0 | arm64 | Linux 6.1.100 | Cirrus CI |
|
||||||
| icpc (ICC) 2021.10.0 20230609 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
| icpc (ICC) 2021.10.0 20230609 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||||
| icpx (Intel oneAPI DPC++/C++) 2025.3.2 | x86_64 | Ubuntu 24.04 LTS | GitHub |
|
| icpx (Intel oneAPI DPC++/C++) 2025.3.2 | x86_64 | Ubuntu 24.04 LTS | GitHub |
|
||||||
| nvc++ (NVIDIA HPC SDK) 25.5-0 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
| nvc++ (NVIDIA HPC SDK) 25.5-0 | x86_64 | Ubuntu 22.04 LTS | GitHub |
|
||||||
@@ -132,8 +132,7 @@ Note: Some modern features (like C++20 ranges or filesystem support) may be disa
|
|||||||
[libstdc++](https://gcc.gnu.org/onlinedocs/libstdc++/) to detect subtle differences or incompatibilities.
|
[libstdc++](https://gcc.gnu.org/onlinedocs/libstdc++/) to detect subtle differences or incompatibilities.
|
||||||
- [x] The code checked with [Include What You Use (IWYU)](https://include-what-you-use.org) that all required standard
|
- [x] The code checked with [Include What You Use (IWYU)](https://include-what-you-use.org) that all required standard
|
||||||
headers are included.
|
headers are included.
|
||||||
- [x] On Windows, the library is compiled with `<Windows.h>` being included to detect and avoid common bugs (see
|
- [x] On Windows, the library is compiled with `<Windows.h>` being included to detect and avoid common bugs.
|
||||||
[`unit-windows_h.cpp`](https://github.com/nlohmann/json/blob/develop/tests/src/unit-windows_h.cpp)).
|
|
||||||
- [x] The library is compiled with exceptions disabled to support alternative means of error handling.
|
- [x] The library is compiled with exceptions disabled to support alternative means of error handling.
|
||||||
|
|
||||||
## Stable public API
|
## Stable public API
|
||||||
|
|||||||
@@ -20,6 +20,5 @@ int main()
|
|||||||
<< j_invalid.dump(-1, ' ', false, json::error_handler_t::replace)
|
<< j_invalid.dump(-1, ' ', false, json::error_handler_t::replace)
|
||||||
<< "\nstring with ignored invalid characters: "
|
<< "\nstring with ignored invalid characters: "
|
||||||
<< j_invalid.dump(-1, ' ', false, json::error_handler_t::ignore)
|
<< j_invalid.dump(-1, ' ', false, json::error_handler_t::ignore)
|
||||||
<< "\nstring with the invalid byte kept as is (" << j_invalid.dump(-1, ' ', false, json::error_handler_t::keep).size()
|
<< '\n';
|
||||||
<< " bytes, not valid UTF-8 itself)\n";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9
|
[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9
|
||||||
string with replaced invalid characters: "ä�ü"
|
string with replaced invalid characters: "ä�ü"
|
||||||
string with ignored invalid characters: "äü"
|
string with ignored invalid characters: "äü"
|
||||||
string with the invalid byte kept as is (7 bytes, not valid UTF-8 itself)
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<a target="_blank" href="https://wandbox.org/permlink/hUJYo1HWmfTBLMGn"><b>online</b></a>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<a target="_blank" href="https://wandbox.org/permlink/AWbpa8e1xRV3y4MM"><b>online</b></a>
|
||||||
@@ -61,13 +61,7 @@ The library uses the following mapping from JSON values types to BJData types ac
|
|||||||
|
|
||||||
The following values can **not** be converted to a BJData value:
|
The following values can **not** be converted to a BJData value:
|
||||||
|
|
||||||
- strings with more than 18446744073709551615 bytes, i.e., 2<sup>64</sup>-1 bytes (theoretical)
|
- strings with more than 18446744073709551615 bytes, i.e., $2^{64}-1$ bytes (theoretical)
|
||||||
|
|
||||||
!!! warning "UTF-8 validation of string values and object keys"
|
|
||||||
|
|
||||||
BJData strings must use UTF-8 encoding. `to_bjdata()` validates the bytes of every string value and object key
|
|
||||||
and throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) for ill-formed UTF-8, so a
|
|
||||||
value with such a string cannot be serialized in the first place.
|
|
||||||
|
|
||||||
!!! info "Unused BJData markers"
|
!!! info "Unused BJData markers"
|
||||||
|
|
||||||
@@ -214,20 +208,6 @@ The library maps BJData types to JSON value types as follows:
|
|||||||
|
|
||||||
The mapping is **complete** in the sense that any BJData value can be converted to a JSON value.
|
The mapping is **complete** in the sense that any BJData value can be converted to a JSON value.
|
||||||
|
|
||||||
!!! warning "Ill-formed UTF-8 in string values and object keys"
|
|
||||||
|
|
||||||
BJData strings must use UTF-8 encoding, but checking it on read is opt-in: with the
|
|
||||||
[`error_handler`](../../api/basic_json/from_bjdata.md) parameter left at `keep` (the default), `from_bjdata()`
|
|
||||||
accepts a string value or object key whose bytes are not valid UTF-8 and hands them back unchanged. Passing
|
|
||||||
`error_handler_t::strict` makes `from_bjdata()` check and throw
|
|
||||||
[`parse_error.113`](../../home/exceptions.md#jsonexceptionparse_error113) for ill-formed UTF-8, and
|
|
||||||
`replace`/`ignore` sanitize the string instead of keeping it. However,
|
|
||||||
[`dump()`](../../api/basic_json/dump.md) still requires valid UTF-8 and throws
|
|
||||||
[`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) for a value read with the default
|
|
||||||
`keep` handler, unless an error handler is passed that replaces or ignores the ill-formed bytes. `to_bjdata()`'s
|
|
||||||
own `error_handler` parameter defaults to `strict` (see above), so a value read this way cannot be written back
|
|
||||||
to BJData unless a non-strict handler is passed there too.
|
|
||||||
|
|
||||||
!!! info "Round trips"
|
!!! info "Round trips"
|
||||||
|
|
||||||
A value returned by [`from_bjdata`](../../api/basic_json/from_bjdata.md) can be serialized with
|
A value returned by [`from_bjdata`](../../api/basic_json/from_bjdata.md) can be serialized with
|
||||||
|
|||||||
@@ -109,22 +109,14 @@ The library maps BSON record types to JSON value types as follows:
|
|||||||
If BSON input must be validated for strict specification compliance, validate it separately before passing it to
|
If BSON input must be validated for strict specification compliance, validate it separately before passing it to
|
||||||
`from_bson()`.
|
`from_bson()`.
|
||||||
|
|
||||||
!!! warning "Ill-formed UTF-8 in string values"
|
!!! warning "UTF-8 validation of string values"
|
||||||
|
|
||||||
The BSON specification requires `string` values (type `0x02`) to be valid UTF-8, but this is not required of a
|
The BSON specification requires `string` values (type `0x02`) to be valid UTF-8. This library validates the
|
||||||
decoder, so checking is opt-in: with the [`error_handler`](../../api/basic_json/from_bson.md) parameter left at
|
bytes of every such string at decode time and rejects ill-formed UTF-8 with a
|
||||||
`keep` (the default), `from_bson()` accepts a `string` value whose bytes are not valid UTF-8 and hands them back
|
[`parse_error.113`](../../home/exceptions.md#jsonexceptionparse_error113) exception (or, with `allow_exceptions`
|
||||||
unchanged. Passing `error_handler_t::strict` makes `from_bson()` check and throw
|
set to `false`, a discarded value), rather than only failing later when the resulting value is dumped. Element
|
||||||
[`parse_error.113`](../../home/exceptions.md#jsonexceptionparse_error113) for ill-formed UTF-8, and
|
(key) names and `binary` values (type `0x05`) are unaffected and are never validated, since they are read
|
||||||
`replace`/`ignore` sanitize the string instead of keeping it. However, [`dump()`](../../api/basic_json/dump.md)
|
byte-by-byte as a C string, or are not required to hold text, respectively.
|
||||||
still requires valid UTF-8 and throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316)
|
|
||||||
for a value read with the default `keep` handler, unless an error handler is passed that replaces or ignores
|
|
||||||
the ill-formed bytes. `to_bson()`'s own `error_handler` parameter defaults to `strict` and throws the same
|
|
||||||
exception for a string value or element (key) name that is not valid UTF-8, so an object with such a key or
|
|
||||||
value cannot be produced in the first place unless a non-strict handler is passed there, even though
|
|
||||||
`from_bson()` would accept it from another source with the default `keep` handler. Element (key) names are
|
|
||||||
never validated on read, since they are read byte-by-byte as a C string. `binary` values (type `0x05`) are
|
|
||||||
unaffected, since they are not required to hold text.
|
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
|
||||||
|
|||||||
@@ -189,21 +189,15 @@ The library maps CBOR types to JSON value types as follows:
|
|||||||
([RFC 8392](https://www.rfc-editor.org/rfc/rfc8392.html)), cannot be read with this library and need a
|
([RFC 8392](https://www.rfc-editor.org/rfc/rfc8392.html)), cannot be read with this library and need a
|
||||||
general-purpose CBOR library instead.
|
general-purpose CBOR library instead.
|
||||||
|
|
||||||
!!! warning "Ill-formed UTF-8 in text strings"
|
!!! warning "UTF-8 validation of text strings"
|
||||||
|
|
||||||
[RFC 8949, Section 3.1](https://www.rfc-editor.org/rfc/rfc8949.html#section-3.1) requires CBOR text strings
|
[RFC 8949, Section 3.1](https://www.rfc-editor.org/rfc/rfc8949.html#section-3.1) requires CBOR text strings
|
||||||
(major type 3) to be valid UTF-8, but leaves it up to the decoder whether to enforce this, so checking is
|
(major type 3) to be valid UTF-8. This library validates the bytes of every text string (object keys included) at
|
||||||
opt-in: with the [`error_handler`](../../api/basic_json/from_cbor.md) parameter left at `keep` (the default),
|
decode time and rejects ill-formed UTF-8 with a
|
||||||
`from_cbor()` accepts a text string (object keys included) whose bytes are not valid UTF-8 and hands them back
|
[`parse_error.113`](../../home/exceptions.md#jsonexceptionparse_error113) exception (or, with
|
||||||
unchanged. Passing `error_handler_t::strict` makes `from_cbor()` check and throw
|
`allow_exceptions` set to `false`, a discarded value), rather than only failing later when the resulting value is
|
||||||
[`parse_error.113`](../../home/exceptions.md#jsonexceptionparse_error113) for ill-formed UTF-8, and
|
dumped. Byte strings (major type 2) are unaffected and are never validated, since they are not required to hold
|
||||||
`replace`/`ignore` sanitize the string instead of keeping it. However, [`dump()`](../../api/basic_json/dump.md)
|
text.
|
||||||
still requires valid UTF-8 and throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316)
|
|
||||||
for a value read with the default `keep` handler, unless an error handler is passed that replaces or ignores
|
|
||||||
the ill-formed bytes. `to_cbor()`'s own [`error_handler`](../../api/basic_json/to_cbor.md) parameter defaults
|
|
||||||
to `strict` and throws the same exception for a string value or object key that is not valid UTF-8, so such a
|
|
||||||
value cannot be written back to CBOR unless a non-strict handler is passed there too. Byte strings (major
|
|
||||||
type 2) are unaffected, since they are not required to hold text.
|
|
||||||
|
|
||||||
!!! warning "Tagged items"
|
!!! warning "Tagged items"
|
||||||
|
|
||||||
|
|||||||
@@ -153,21 +153,14 @@ The library maps MessagePack types to JSON value types as follows:
|
|||||||
This applies to the [SAX interface](../parsing/sax_interface.md) as well, as the key is read before it is passed
|
This applies to the [SAX interface](../parsing/sax_interface.md) as well, as the key is read before it is passed
|
||||||
on. Such input needs a general-purpose MessagePack library instead.
|
on. Such input needs a general-purpose MessagePack library instead.
|
||||||
|
|
||||||
!!! warning "Ill-formed UTF-8 in string values"
|
!!! warning "UTF-8 validation of string values"
|
||||||
|
|
||||||
The MessagePack specification explicitly allows a `str` value (`fixstr`, `str 8`, `str 16`, `str 32`) to contain
|
The MessagePack specification requires `str` values (`fixstr`, `str 8`, `str 16`, `str 32`) to be valid UTF-8.
|
||||||
a byte sequence that is not valid UTF-8, and expects a deserializer to hand the original bytes back unchanged.
|
This library validates the bytes of every such string (object keys included) at decode time and rejects
|
||||||
This library follows that by default: with its
|
ill-formed UTF-8 with a [`parse_error.113`](../../home/exceptions.md#jsonexceptionparse_error113) exception (or,
|
||||||
[`error_handler`](../../api/basic_json/from_msgpack.md) parameter left at `keep` (the default),
|
with `allow_exceptions` set to `false`, a discarded value), rather than only failing later when the resulting
|
||||||
`from_msgpack()` reads `str` bytes (object keys included) as-is, without validating them, so such a value
|
value is dumped. `bin`/`ext`/`fixext` values are unaffected and are never validated, since they are not required
|
||||||
round-trips through `from_msgpack(to_msgpack(j))` byte for byte. Passing `error_handler_t::strict` makes
|
to hold text.
|
||||||
`from_msgpack()` check anyway and throw
|
|
||||||
[`parse_error.113`](../../home/exceptions.md#jsonexceptionparse_error113) for ill-formed UTF-8, and
|
|
||||||
`replace`/`ignore` sanitize the string instead of keeping it. `to_msgpack()` itself has no `error_handler`
|
|
||||||
parameter and always writes `str` bytes as-is, since the specification permits it. However,
|
|
||||||
[`dump()`](../../api/basic_json/dump.md) still requires valid UTF-8 and throws
|
|
||||||
[`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) for a value read this way with the
|
|
||||||
default `keep` handler, unless an error handler is passed that replaces or ignores the ill-formed bytes.
|
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
|
||||||
|
|||||||
@@ -47,12 +47,6 @@ The library uses the following mapping from JSON values types to UBJSON types ac
|
|||||||
|
|
||||||
- strings with more than 9223372036854775807 bytes (theoretical)
|
- strings with more than 9223372036854775807 bytes (theoretical)
|
||||||
|
|
||||||
!!! warning "UTF-8 validation of string values and object keys"
|
|
||||||
|
|
||||||
UBJSON's required string encoding is UTF-8. `to_ubjson()` validates the bytes of every string value and object
|
|
||||||
key and throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) for ill-formed UTF-8, so
|
|
||||||
a value with such a string cannot be serialized in the first place.
|
|
||||||
|
|
||||||
!!! info "Unused UBJSON markers"
|
!!! info "Unused UBJSON markers"
|
||||||
|
|
||||||
The following markers are not used in the conversion:
|
The following markers are not used in the conversion:
|
||||||
@@ -126,20 +120,6 @@ The library maps UBJSON types to JSON value types as follows:
|
|||||||
|
|
||||||
The mapping is **complete** in the sense that any UBJSON value can be converted to a JSON value.
|
The mapping is **complete** in the sense that any UBJSON value can be converted to a JSON value.
|
||||||
|
|
||||||
!!! warning "Ill-formed UTF-8 in string values and object keys"
|
|
||||||
|
|
||||||
UBJSON's required string encoding is UTF-8, but checking it on read is opt-in: with the
|
|
||||||
[`error_handler`](../../api/basic_json/from_ubjson.md) parameter left at `keep` (the default), `from_ubjson()`
|
|
||||||
accepts a string value or object key whose bytes are not valid UTF-8 and hands them back unchanged. Passing
|
|
||||||
`error_handler_t::strict` makes `from_ubjson()` check and throw
|
|
||||||
[`parse_error.113`](../../home/exceptions.md#jsonexceptionparse_error113) for ill-formed UTF-8, and
|
|
||||||
`replace`/`ignore` sanitize the string instead of keeping it. However,
|
|
||||||
[`dump()`](../../api/basic_json/dump.md) still requires valid UTF-8 and throws
|
|
||||||
[`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) for a value read with the default
|
|
||||||
`keep` handler, unless an error handler is passed that replaces or ignores the ill-formed bytes. `to_ubjson()`'s
|
|
||||||
own `error_handler` parameter defaults to `strict` (see above), so a value read this way cannot be written back
|
|
||||||
to UBJSON unless a non-strict handler is passed there too.
|
|
||||||
|
|
||||||
??? example
|
??? example
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
|||||||
@@ -83,13 +83,6 @@ When defined, default parse and serialize functions for enums are excluded and h
|
|||||||
|
|
||||||
See [full documentation of `JSON_DISABLE_ENUM_SERIALIZATION`](../api/macros/json_disable_enum_serialization.md).
|
See [full documentation of `JSON_DISABLE_ENUM_SERIALIZATION`](../api/macros/json_disable_enum_serialization.md).
|
||||||
|
|
||||||
## `JSON_DISABLE_TUPLE_REFERENCE_CONVERSION`
|
|
||||||
|
|
||||||
When defined to `1`, a JSON value can no longer be created from a one-element `std::tuple` holding a reference to a JSON
|
|
||||||
value, such as the result of `std::forward_as_tuple(j)`. This lets `std::tuple` convert such tuples element-wise.
|
|
||||||
|
|
||||||
See [full documentation of `JSON_DISABLE_TUPLE_REFERENCE_CONVERSION`](../api/macros/json_disable_tuple_reference_conversion.md).
|
|
||||||
|
|
||||||
## `JSON_NO_AUTOMATIC_UDLS`
|
## `JSON_NO_AUTOMATIC_UDLS`
|
||||||
|
|
||||||
When defined, `<nlohmann/json.hpp>` does not include `<nlohmann/json_literals.hpp>` with the user-defined string literals
|
When defined, `<nlohmann/json.hpp>` does not include `<nlohmann/json_literals.hpp>` with the user-defined string literals
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ When the default type is used, the maximal unsigned integer number that can be s
|
|||||||
|
|
||||||
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
[RFC 8259](https://tools.ietf.org/html/rfc8259) further states:
|
||||||
|
|
||||||
> Note that when such software is used, numbers that are integers and are in the range [-2<sup>53</sup>+1, 2<sup>53</sup>-1] are interoperable in the sense that implementations will agree exactly on their numeric values.
|
> Note that when such software is used, numbers that are integers and are in the range $[-2^{53}+1, 2^{53}-1]$ are interoperable in the sense that implementations will agree exactly on their numeric values.
|
||||||
|
|
||||||
As this range is a subrange of the exactly supported range [`INT64_MIN`, `INT64_MAX`], this class's integer type is interoperable.
|
As this range is a subrange of the exactly supported range [`INT64_MIN`, `INT64_MAX`], this class's integer type is interoperable.
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ On number interoperability, the following remarks are made:
|
|||||||
for numeric magnitude and precision than is widely available.
|
for numeric magnitude and precision than is widely available.
|
||||||
|
|
||||||
Note that when such software is used, numbers that are integers and
|
Note that when such software is used, numbers that are integers and
|
||||||
are in the range [-2<sup>53</sup>+1, 2<sup>53</sup>-1] are interoperable in the
|
are in the range $[-2^{53}+1, 2^{53}-1]$ are interoperable in the
|
||||||
sense that implementations will agree exactly on their numeric
|
sense that implementations will agree exactly on their numeric
|
||||||
values.
|
values.
|
||||||
|
|
||||||
@@ -95,9 +95,9 @@ This is the same behavior as the code `#!c double x = 3.141592653589793238462643
|
|||||||
|
|
||||||
!!! success "Interoperability"
|
!!! success "Interoperability"
|
||||||
|
|
||||||
- The library is interoperable with respect to the specification, because its supported range [-2<sup>63</sup>, 2<sup>64</sup>-1] is
|
- The library is interoperable with respect to the specification, because its supported range $[-2^{63}, 2^{64}-1]$ is
|
||||||
larger than the described range [-2<sup>53</sup>+1, 2<sup>53</sup>-1].
|
larger than the described range $[-2^{53}+1, 2^{53}-1]$.
|
||||||
- All integers outside the range [-2<sup>63</sup>, 2<sup>64</sup>-1], as well as floating-point numbers are stored as `double`.
|
- All integers outside the range $[-2^{63}, 2^{64}-1]$, as well as floating-point numbers are stored as `double`.
|
||||||
This also concurs with the specification above.
|
This also concurs with the specification above.
|
||||||
|
|
||||||
### Zeros
|
### Zeros
|
||||||
|
|||||||
@@ -341,10 +341,7 @@ An unexpected byte was read in a [binary format](../features/binary_formats/inde
|
|||||||
|
|
||||||
A string could not be read from a [binary format](../features/binary_formats/index.md): either a value that is not a
|
A string could not be read from a [binary format](../features/binary_formats/index.md): either a value that is not a
|
||||||
string was read where one was required (for instance as a map key), the string's length specification is invalid, or
|
string was read where one was required (for instance as a map key), the string's length specification is invalid, or
|
||||||
the string's bytes are not valid UTF-8 and the `error_handler` parameter of the corresponding `from_*` function is
|
the string's bytes are not valid UTF-8.
|
||||||
set to `strict`. By default (`error_handler_t::keep`), the bytes of a string are not checked for valid UTF-8 on read;
|
|
||||||
see the ill-formed UTF-8 notes on the individual [binary format](../features/binary_formats/index.md) pages for how
|
|
||||||
such a string is handled depending on `error_handler`.
|
|
||||||
|
|
||||||
CBOR and MessagePack allow map keys of any type, but JSON object keys are always strings. Maps with keys of any other
|
CBOR and MessagePack allow map keys of any type, but JSON object keys are always strings. Maps with keys of any other
|
||||||
type (for instance integers or `null`) are therefore not supported; see the notes on
|
type (for instance integers or `null`) are therefore not supported; see the notes on
|
||||||
|
|||||||
@@ -169,12 +169,6 @@ Enable position diagnostics by defining macro [`JSON_DIAGNOSTIC_POSITIONS`](../a
|
|||||||
Disable default `enum` serialization by defining the macro
|
Disable default `enum` serialization by defining the macro
|
||||||
[`JSON_DISABLE_ENUM_SERIALIZATION`](../api/macros/json_disable_enum_serialization.md). This option is `OFF` by default.
|
[`JSON_DISABLE_ENUM_SERIALIZATION`](../api/macros/json_disable_enum_serialization.md). This option is `OFF` by default.
|
||||||
|
|
||||||
### `JSON_DisableTupleReferenceConversion`
|
|
||||||
|
|
||||||
Disable the conversion from a one-element `std::tuple` holding a reference to a JSON value by defining the macro
|
|
||||||
[`JSON_DISABLE_TUPLE_REFERENCE_CONVERSION`](../api/macros/json_disable_tuple_reference_conversion.md). This option is
|
|
||||||
`OFF` by default.
|
|
||||||
|
|
||||||
### `JSON_FastTests`
|
### `JSON_FastTests`
|
||||||
|
|
||||||
Skip expensive/slow test suites. This option is `OFF` by default. Depends on `JSON_BuildTests`.
|
Skip expensive/slow test suites. This option is `OFF` by default. Depends on `JSON_BuildTests`.
|
||||||
|
|||||||
@@ -678,11 +678,11 @@ to install the [nlohmann-json](https://ports.macports.org/port/nlohmann-json/) p
|
|||||||
1. Create the following files:
|
1. Create the following files:
|
||||||
|
|
||||||
```cpp title="example.cpp"
|
```cpp title="example.cpp"
|
||||||
--8<-- "integration/macports/example.cpp"
|
--8<-- "integration/homebrew/example.cpp"
|
||||||
```
|
```
|
||||||
|
|
||||||
```cmake title="CMakeLists.txt"
|
```cmake title="CMakeLists.txt"
|
||||||
--8<-- "integration/macports/CMakeLists.txt"
|
--8<-- "integration/homebrew/CMakeLists.txt"
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Install the package:
|
2. Install the package:
|
||||||
|
|||||||
@@ -287,7 +287,6 @@ nav:
|
|||||||
- 'JSON_DIAGNOSTICS': api/macros/json_diagnostics.md
|
- 'JSON_DIAGNOSTICS': api/macros/json_diagnostics.md
|
||||||
- 'JSON_DIAGNOSTIC_POSITIONS': api/macros/json_diagnostic_positions.md
|
- 'JSON_DIAGNOSTIC_POSITIONS': api/macros/json_diagnostic_positions.md
|
||||||
- 'JSON_DISABLE_ENUM_SERIALIZATION': api/macros/json_disable_enum_serialization.md
|
- 'JSON_DISABLE_ENUM_SERIALIZATION': api/macros/json_disable_enum_serialization.md
|
||||||
- 'JSON_DISABLE_TUPLE_REFERENCE_CONVERSION': api/macros/json_disable_tuple_reference_conversion.md
|
|
||||||
- 'JSON_HAS_CPP_11, JSON_HAS_CPP_14, JSON_HAS_CPP_17, JSON_HAS_CPP_20': api/macros/json_has_cpp_11.md
|
- 'JSON_HAS_CPP_11, JSON_HAS_CPP_14, JSON_HAS_CPP_17, JSON_HAS_CPP_20': api/macros/json_has_cpp_11.md
|
||||||
- 'JSON_HAS_EXPERIMENTAL_FILESYSTEM, JSON_HAS_FILESYSTEM': api/macros/json_has_filesystem.md
|
- 'JSON_HAS_EXPERIMENTAL_FILESYSTEM, JSON_HAS_FILESYSTEM': api/macros/json_has_filesystem.md
|
||||||
- 'JSON_HAS_RANGES': api/macros/json_has_ranges.md
|
- 'JSON_HAS_RANGES': api/macros/json_has_ranges.md
|
||||||
@@ -351,6 +350,7 @@ markdown_extensions:
|
|||||||
- toc:
|
- toc:
|
||||||
permalink: true
|
permalink: true
|
||||||
- md_in_html
|
- md_in_html
|
||||||
|
- pymdownx.arithmatex
|
||||||
- pymdownx.betterem:
|
- pymdownx.betterem:
|
||||||
smart_enable: all
|
smart_enable: all
|
||||||
- pymdownx.caret
|
- pymdownx.caret
|
||||||
@@ -442,3 +442,6 @@ plugins:
|
|||||||
|
|
||||||
extra_css:
|
extra_css:
|
||||||
- css/custom.css
|
- css/custom.css
|
||||||
|
|
||||||
|
extra_javascript:
|
||||||
|
- https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ def check_structure() -> None:
|
|||||||
report("whitespace/line_length", f"{file}:{lineno+1} ({current_section})", f"line is too long ({len(line)} vs. 160 chars)")
|
report("whitespace/line_length", f"{file}:{lineno+1} ({current_section})", f"line is too long ({len(line)} vs. 160 chars)")
|
||||||
|
|
||||||
# sections in `<!-- NOLINT -->` comments are treated as present
|
# sections in `<!-- NOLINT -->` comments are treated as present
|
||||||
nolint_match = re.match(r"<!--\s*NOLINT\s+(.*?)\s*-->", line)
|
if line.startswith("<!-- NOLINT"):
|
||||||
if nolint_match:
|
current_section = line.strip("<!-- NOLINT")
|
||||||
current_section = nolint_match.group(1)
|
current_section = current_section.strip(" -->")
|
||||||
existing_sections.append(current_section)
|
existing_sections.append(current_section)
|
||||||
|
|
||||||
# check if sections are correct
|
# check if sections are correct
|
||||||
@@ -97,7 +97,7 @@ def check_structure() -> None:
|
|||||||
if len(unexpected):
|
if len(unexpected):
|
||||||
report("style/numbering", f"{file}:{lineno} ({current_section})", f'unexpected overloads: {", ".join([f"({x})" for x in unexpected])}')
|
report("style/numbering", f"{file}:{lineno} ({current_section})", f'unexpected overloads: {", ".join([f"({x})" for x in unexpected])}')
|
||||||
|
|
||||||
current_section = line[3:]
|
current_section = line.strip("## ")
|
||||||
existing_sections.append(current_section)
|
existing_sections.append(current_section)
|
||||||
|
|
||||||
if current_section in expected_sections:
|
if current_section in expected_sections:
|
||||||
@@ -141,7 +141,7 @@ def check_structure() -> None:
|
|||||||
# check that non-example admonitions have titles
|
# check that non-example admonitions have titles
|
||||||
untitled_admonition = re.match(r"^(\?\?\?|!!!) ([^ ]+)$", line)
|
untitled_admonition = re.match(r"^(\?\?\?|!!!) ([^ ]+)$", line)
|
||||||
if untitled_admonition and untitled_admonition.group(2) != "example":
|
if untitled_admonition and untitled_admonition.group(2) != "example":
|
||||||
report("style/admonition_title", f"{file}:{lineno+1} ({current_section})", f'"{untitled_admonition.group(2)}" admonitions should have a title')
|
report("style/admonition_title", f"{file}:{lineno} ({current_section})", f'"{untitled_admonition.group(2)}" admonitions should have a title')
|
||||||
|
|
||||||
previous_line = line
|
previous_line = line
|
||||||
|
|
||||||
|
|||||||
@@ -354,22 +354,22 @@ void())
|
|||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename T, std::size_t... Idx >
|
template < typename BasicJsonType, typename T, std::size_t... Idx >
|
||||||
std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(const BasicJsonType& j,
|
std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
|
||||||
identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/)
|
identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/)
|
||||||
{
|
{
|
||||||
return { { j.at(Idx).template get<T>()... } };
|
return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename T, std::size_t N >
|
template < typename BasicJsonType, typename T, std::size_t N >
|
||||||
auto from_json(const BasicJsonType& j, identity_tag<std::array<T, N>> tag)
|
auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
|
||||||
-> decltype(from_json_inplace_array_impl(j, tag, make_index_sequence<N> {}))
|
-> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
|
||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
||||||
{
|
{
|
||||||
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
|
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
|
||||||
}
|
}
|
||||||
|
|
||||||
return from_json_inplace_array_impl(j, tag, make_index_sequence<N> {});
|
return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
@@ -504,54 +504,54 @@ template<std::size_t PTagValue, typename BasicJsonType, typename... Types>
|
|||||||
using tuple_type = std::tuple < decltype(from_json_tuple_get_impl(std::declval<BasicJsonType>(), detail::identity_tag<Types> {}, detail::priority_tag<PTagValue> {}))... >;
|
using tuple_type = std::tuple < decltype(from_json_tuple_get_impl(std::declval<BasicJsonType>(), detail::identity_tag<Types> {}, detail::priority_tag<PTagValue> {}))... >;
|
||||||
|
|
||||||
template<std::size_t PTagValue, typename... Args, typename BasicJsonType, std::size_t... Idx>
|
template<std::size_t PTagValue, typename... Args, typename BasicJsonType, std::size_t... Idx>
|
||||||
tuple_type<PTagValue, const BasicJsonType&, Args...> from_json_tuple_impl_base(const BasicJsonType& j, index_sequence<Idx...> /*unused*/)
|
tuple_type<PTagValue, BasicJsonType, Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> /*unused*/)
|
||||||
{
|
{
|
||||||
return tuple_type<PTagValue, const BasicJsonType&, Args...>(from_json_tuple_get_impl(j.at(Idx), detail::identity_tag<Args> {}, detail::priority_tag<PTagValue> {})...);
|
return tuple_type<PTagValue, BasicJsonType, Args...>(from_json_tuple_get_impl(std::forward<BasicJsonType>(j).at(Idx), detail::identity_tag<Args> {}, detail::priority_tag<PTagValue> {})...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t PTagValue, typename BasicJsonType>
|
template<std::size_t PTagValue, typename BasicJsonType>
|
||||||
std::tuple<> from_json_tuple_impl_base(const BasicJsonType& /*unused*/, index_sequence<> /*unused*/)
|
std::tuple<> from_json_tuple_impl_base(BasicJsonType& /*unused*/, index_sequence<> /*unused*/)
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, class A1, class A2 >
|
template < typename BasicJsonType, class A1, class A2 >
|
||||||
std::pair<A1, A2> from_json_tuple_impl(const BasicJsonType& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/)
|
std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/)
|
||||||
{
|
{
|
||||||
return {j.at(0).template get<A1>(),
|
return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
|
||||||
j.at(1).template get<A2>()};
|
std::forward<BasicJsonType>(j).at(1).template get<A2>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename A1, typename A2>
|
template<typename BasicJsonType, typename A1, typename A2>
|
||||||
inline void from_json_tuple_impl(const BasicJsonType& j, std::pair<A1, A2>& p, priority_tag<1> /*unused*/)
|
inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> /*unused*/)
|
||||||
{
|
{
|
||||||
p = from_json_tuple_impl(j, identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
|
p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename... Args>
|
template<typename BasicJsonType, typename... Args>
|
||||||
std::tuple<Args...> from_json_tuple_impl(const BasicJsonType& j, identity_tag<std::tuple<Args...>> /*unused*/, priority_tag<2> /*unused*/)
|
std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> /*unused*/, priority_tag<2> /*unused*/)
|
||||||
{
|
{
|
||||||
static_assert(cxpr_and<cxpr_or<cxpr_not<std::is_reference<Args>>, is_compatible_reference_type<const BasicJsonType&, Args>>...>::value,
|
static_assert(cxpr_and<cxpr_or<cxpr_not<std::is_reference<Args>>, is_compatible_reference_type<BasicJsonType, Args>>...>::value,
|
||||||
"Can not return a tuple containing references to types not contained in a Json, try Json::get_to()");
|
"Can not return a tuple containing references to types not contained in a Json, try Json::get_to()");
|
||||||
return from_json_tuple_impl_base<1, Args...>(j, index_sequence_for<Args...> {});
|
return from_json_tuple_impl_base<1, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename... Args>
|
template<typename BasicJsonType, typename... Args>
|
||||||
inline void from_json_tuple_impl(const BasicJsonType& j, std::tuple<Args...>& t, priority_tag<3> /*unused*/)
|
inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> /*unused*/)
|
||||||
{
|
{
|
||||||
t = from_json_tuple_impl_base<2, Args...>(j, index_sequence_for<Args...> {});
|
t = from_json_tuple_impl_base<2, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BasicJsonType, typename TupleRelated>
|
template<typename BasicJsonType, typename TupleRelated>
|
||||||
auto from_json(const BasicJsonType& j, TupleRelated&& t)
|
auto from_json(BasicJsonType&& j, TupleRelated&& t)
|
||||||
-> decltype(from_json_tuple_impl(j, std::forward<TupleRelated>(t), priority_tag<3> {}))
|
-> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
|
||||||
{
|
{
|
||||||
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
|
||||||
{
|
{
|
||||||
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
|
JSON_THROW(type_error::create(302, concat("type must be array, but is ", j.type_name()), &j));
|
||||||
}
|
}
|
||||||
|
|
||||||
return from_json_tuple_impl(j, std::forward<TupleRelated>(t), priority_tag<3> {});
|
return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,
|
template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,
|
||||||
@@ -636,7 +636,7 @@ struct from_json_fn
|
|||||||
/// namespace to hold default `from_json` function
|
/// namespace to hold default `from_json` function
|
||||||
/// to see why this is required:
|
/// to see why this is required:
|
||||||
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
|
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
|
||||||
namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces,misc-anonymous-namespace-in-header)
|
namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers)
|
JSON_INLINE_VARIABLE constexpr const auto& from_json = // NOLINT(misc-definitions-in-headers)
|
||||||
|
|||||||
@@ -471,13 +471,11 @@ inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<
|
|||||||
j = { std::get<Idx>(t)... };
|
j = { std::get<Idx>(t)... };
|
||||||
}
|
}
|
||||||
|
|
||||||
// A one-element braced list does not reliably wrap its element: with
|
#if JSON_BRACE_INIT_COPY_SEMANTICS
|
||||||
// JSON_BRACE_INIT_COPY_SEMANTICS it copies it, which would serialize
|
// JSON_BRACE_INIT_COPY_SEMANTICS makes a one-element braced list copy its
|
||||||
// std::tuple<int>{5} as 5 rather than [5], and some compilers (e.g., Apple clang
|
// element instead of wrapping it, which would serialize std::tuple<int>{5} as 5
|
||||||
// 15 and 16) copy an element that is itself a basic_json even without it, so
|
// rather than [5]. Build what the default deduction builds instead: an object
|
||||||
// std::tuple<json>{true} became true rather than [true]. Build what the default
|
// if the element is a [string, value] pair, a one-element array otherwise.
|
||||||
// deduction builds instead: an object if the element is a [string, value] pair,
|
|
||||||
// a one-element array otherwise.
|
|
||||||
template<typename BasicJsonType, typename Tuple>
|
template<typename BasicJsonType, typename Tuple>
|
||||||
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<0> /*unused*/)
|
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<0> /*unused*/)
|
||||||
{
|
{
|
||||||
@@ -495,6 +493,7 @@ inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<
|
|||||||
j = BasicJsonType::array({std::move(element)});
|
j = BasicJsonType::array({std::move(element)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename BasicJsonType, typename Tuple>
|
template<typename BasicJsonType, typename Tuple>
|
||||||
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& /*unused*/, index_sequence<> /*unused*/)
|
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& /*unused*/, index_sequence<> /*unused*/)
|
||||||
@@ -547,7 +546,7 @@ struct to_json_fn
|
|||||||
/// namespace to hold default `to_json` function
|
/// namespace to hold default `to_json` function
|
||||||
/// to see why this is required:
|
/// to see why this is required:
|
||||||
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
|
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
|
||||||
namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces,misc-anonymous-namespace-in-header)
|
namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
JSON_INLINE_VARIABLE constexpr const auto& to_json = // NOLINT(misc-definitions-in-headers)
|
JSON_INLINE_VARIABLE constexpr const auto& to_json = // NOLINT(misc-definitions-in-headers)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <algorithm> // min
|
|
||||||
#include <array> // array
|
#include <array> // array
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstdint> // uint32_t
|
|
||||||
#include <cstring> // strlen
|
#include <cstring> // strlen
|
||||||
#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next
|
#include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next
|
||||||
|
#include <memory> // shared_ptr, make_shared, addressof
|
||||||
|
#include <numeric> // accumulate
|
||||||
#include <streambuf> // streambuf
|
#include <streambuf> // streambuf
|
||||||
#include <string> // string, char_traits
|
#include <string> // string, char_traits
|
||||||
#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer
|
#include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer
|
||||||
@@ -28,7 +28,6 @@
|
|||||||
#include <nlohmann/detail/iterators/iterator_traits.hpp>
|
#include <nlohmann/detail/iterators/iterator_traits.hpp>
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||||
#include <nlohmann/detail/string_utils.hpp>
|
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail
|
||||||
@@ -83,9 +82,8 @@ class file_input_adapter
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Input adapter for a (caching) istream. Does not skip a UTF Byte Order Mark
|
Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at
|
||||||
itself; that is done by the lexer's skip_bom(). Does not support changing
|
beginning of input. Does not support changing the underlying std::streambuf
|
||||||
the underlying std::streambuf
|
|
||||||
in mid-input. Maintains underlying std::istream and std::streambuf to support
|
in mid-input. Maintains underlying std::istream and std::streambuf to support
|
||||||
subsequent use of standard std::istream operations to process any input
|
subsequent use of standard std::istream operations to process any input
|
||||||
characters following those used in parsing the JSON input. Clears the
|
characters following those used in parsing the JSON input. Clears the
|
||||||
@@ -456,14 +454,32 @@ struct wide_string_input_helper<BaseInputAdapter, 4>
|
|||||||
// get the current character
|
// get the current character
|
||||||
const auto wc = input.get_character();
|
const auto wc = input.get_character();
|
||||||
|
|
||||||
if (wc <= 0x10FFFF)
|
// UTF-32 to UTF-8 encoding
|
||||||
|
if (wc < 0x80)
|
||||||
{
|
{
|
||||||
// UTF-32 to UTF-8 encoding
|
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
|
||||||
utf8_bytes_filled = 0;
|
utf8_bytes_filled = 1;
|
||||||
encode_utf8(static_cast<std::uint32_t>(wc), [&utf8_bytes, &utf8_bytes_filled](std::uint32_t byte)
|
}
|
||||||
{
|
else if (wc <= 0x7FF)
|
||||||
utf8_bytes[utf8_bytes_filled++] = static_cast<std::char_traits<char>::int_type>(byte);
|
{
|
||||||
});
|
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
|
||||||
|
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
|
||||||
|
utf8_bytes_filled = 2;
|
||||||
|
}
|
||||||
|
else if (wc <= 0xFFFF)
|
||||||
|
{
|
||||||
|
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
|
||||||
|
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
|
||||||
|
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
|
||||||
|
utf8_bytes_filled = 3;
|
||||||
|
}
|
||||||
|
else if (wc <= 0x10FFFF)
|
||||||
|
{
|
||||||
|
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | ((static_cast<unsigned int>(wc) >> 18u) & 0x07u));
|
||||||
|
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
|
||||||
|
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
|
||||||
|
utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
|
||||||
|
utf8_bytes_filled = 4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -500,15 +516,24 @@ struct wide_string_input_helper<BaseInputAdapter, 2>
|
|||||||
// get the current character
|
// get the current character
|
||||||
const auto wc = input.get_character();
|
const auto wc = input.get_character();
|
||||||
|
|
||||||
if (0xD800 > wc || wc >= 0xE000)
|
// UTF-16 to UTF-8 encoding
|
||||||
|
if (wc < 0x80)
|
||||||
{
|
{
|
||||||
// a UTF-16 code unit outside the surrogate range is a valid
|
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
|
||||||
// code point (at most U+FFFF) on its own
|
utf8_bytes_filled = 1;
|
||||||
utf8_bytes_filled = 0;
|
}
|
||||||
encode_utf8(static_cast<std::uint32_t>(wc), [&utf8_bytes, &utf8_bytes_filled](std::uint32_t byte)
|
else if (wc <= 0x7FF)
|
||||||
{
|
{
|
||||||
utf8_bytes[utf8_bytes_filled++] = static_cast<std::char_traits<char>::int_type>(byte);
|
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u)));
|
||||||
});
|
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
|
||||||
|
utf8_bytes_filled = 2;
|
||||||
|
}
|
||||||
|
else if (0xD800 > wc || wc >= 0xE000)
|
||||||
|
{
|
||||||
|
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u)));
|
||||||
|
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
|
||||||
|
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
|
||||||
|
utf8_bytes_filled = 3;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -526,11 +551,11 @@ struct wide_string_input_helper<BaseInputAdapter, 2>
|
|||||||
if (0xDC00 <= wc2 && wc2 <= 0xDFFF)
|
if (0xDC00 <= wc2 && wc2 <= 0xDFFF)
|
||||||
{
|
{
|
||||||
const auto charcode = 0x10000u + (((static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
|
const auto charcode = 0x10000u + (((static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
|
||||||
utf8_bytes_filled = 0;
|
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | (charcode >> 18u));
|
||||||
encode_utf8(charcode, [&utf8_bytes, &utf8_bytes_filled](std::uint32_t byte)
|
utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 12u) & 0x3Fu));
|
||||||
{
|
utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 6u) & 0x3Fu));
|
||||||
utf8_bytes[utf8_bytes_filled++] = static_cast<std::char_traits<char>::int_type>(byte);
|
utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (charcode & 0x3Fu));
|
||||||
});
|
utf8_bytes_filled = 4;
|
||||||
valid_pair = true;
|
valid_pair = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -744,9 +769,6 @@ struct container_input_adapter_factory< ContainerType,
|
|||||||
|
|
||||||
static adapter_type create(ContainerType&& container)
|
static adapter_type create(ContainerType&& container)
|
||||||
{
|
{
|
||||||
// container is forwarded twice on purpose: the resulting begin/end
|
|
||||||
// iterator types must match adapter_type, computed the same way
|
|
||||||
// NOLINTNEXTLINE(bugprone-use-after-move)
|
|
||||||
return input_adapter(begin(std::forward<ContainerType>(container)), end(std::forward<ContainerType>(container)));
|
return input_adapter(begin(std::forward<ContainerType>(container)), end(std::forward<ContainerType>(container)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -862,9 +884,9 @@ auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) /
|
|||||||
return input_adapter(array, array + N);
|
return input_adapter(array, array + N);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This class only handles inputs that construct a contiguous_bytes_input_adapter
|
// This class only handles inputs of input_buffer_adapter type.
|
||||||
// (e.g. span_input_adapter). It's required so that expressions like {ptr, len}
|
// It's required so that expressions like {ptr, len} can be implicitly cast
|
||||||
// can be implicitly cast to the correct adapter.
|
// to the correct adapter.
|
||||||
class span_input_adapter
|
class span_input_adapter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#include <algorithm> // find_if, min
|
#include <algorithm> // find_if, min
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <limits> // numeric_limits
|
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
#include <type_traits> // enable_if_t
|
#include <type_traits> // enable_if_t
|
||||||
#include <utility> // move, pair
|
#include <utility> // move, pair
|
||||||
@@ -176,88 +175,6 @@ template<typename ArrayType>
|
|||||||
inline void reserve_array(ArrayType& /*arr*/, std::size_t /*len*/, priority_tag<0> /*unused*/)
|
inline void reserve_array(ArrayType& /*arr*/, std::size_t /*len*/, priority_tag<0> /*unused*/)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
#if JSON_DIAGNOSTIC_POSITIONS
|
|
||||||
/*!
|
|
||||||
@brief set the diagnostic positions of a value the DOM SAX parsers just stored
|
|
||||||
|
|
||||||
Shared by json_sax_dom_parser and json_sax_dom_callback_parser. basic_json
|
|
||||||
befriends this struct, as the position members are private.
|
|
||||||
*/
|
|
||||||
struct diagnostic_positions
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
@param[in,out] v the value that was just parsed
|
|
||||||
@param[in] lexer the lexer that read it, or nullptr to leave @a v alone
|
|
||||||
*/
|
|
||||||
template<typename BasicJsonType, typename LexerType>
|
|
||||||
static void set_from_lexer(BasicJsonType& v, LexerType* lexer)
|
|
||||||
{
|
|
||||||
if (lexer)
|
|
||||||
{
|
|
||||||
// Lexer has read past the current field value, so set the end position to the current position.
|
|
||||||
// The start position will be set below based on the length of the string representation
|
|
||||||
// of the value.
|
|
||||||
v.end_position = lexer->get_position();
|
|
||||||
|
|
||||||
switch (v.type())
|
|
||||||
{
|
|
||||||
case value_t::boolean:
|
|
||||||
{
|
|
||||||
// 4 and 5 are the string length of "true" and "false"
|
|
||||||
v.start_position = v.end_position - (v.m_data.m_value.boolean ? 4 : 5);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case value_t::null:
|
|
||||||
{
|
|
||||||
// 4 is the string length of "null"
|
|
||||||
v.start_position = v.end_position - 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case value_t::string:
|
|
||||||
{
|
|
||||||
// escape sequences make the token longer than the value it
|
|
||||||
// parses to, so the start position cannot be derived from
|
|
||||||
// the value; use the offset the lexer recorded instead
|
|
||||||
v.start_position = lexer->get_token_start_position();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case value_t::discarded:
|
|
||||||
{
|
|
||||||
// an object or array the callback of
|
|
||||||
// json_sax_dom_callback_parser rejected has no position
|
|
||||||
v.end_position = std::string::npos;
|
|
||||||
v.start_position = v.end_position;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case value_t::binary:
|
|
||||||
case value_t::number_integer:
|
|
||||||
case value_t::number_unsigned:
|
|
||||||
case value_t::number_float:
|
|
||||||
{
|
|
||||||
v.start_position = v.end_position - lexer->get_string().size();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case value_t::object:
|
|
||||||
case value_t::array:
|
|
||||||
{
|
|
||||||
// object and array are handled in start_object() and start_array() handlers
|
|
||||||
// skip setting the values here.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: // LCOV_EXCL_LINE
|
|
||||||
// Handle all possible types discretely, default handler should never be reached.
|
|
||||||
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief SAX implementation to create a JSON value from SAX events
|
@brief SAX implementation to create a JSON value from SAX events
|
||||||
|
|
||||||
@@ -459,6 +376,76 @@ class json_sax_dom_parser
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
|
void handle_diagnostic_positions_for_json_value(BasicJsonType& v)
|
||||||
|
{
|
||||||
|
if (m_lexer_ref)
|
||||||
|
{
|
||||||
|
// Lexer has read past the current field value, so set the end position to the current position.
|
||||||
|
// The start position will be set below based on the length of the string representation
|
||||||
|
// of the value.
|
||||||
|
v.end_position = m_lexer_ref->get_position();
|
||||||
|
|
||||||
|
switch (v.type())
|
||||||
|
{
|
||||||
|
case value_t::boolean:
|
||||||
|
{
|
||||||
|
// 4 and 5 are the string length of "true" and "false"
|
||||||
|
v.start_position = v.end_position - (v.m_data.m_value.boolean ? 4 : 5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::null:
|
||||||
|
{
|
||||||
|
// 4 is the string length of "null"
|
||||||
|
v.start_position = v.end_position - 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::string:
|
||||||
|
{
|
||||||
|
// escape sequences make the token longer than the value it
|
||||||
|
// parses to, so the start position cannot be derived from
|
||||||
|
// the value; use the offset the lexer recorded instead
|
||||||
|
v.start_position = m_lexer_ref->get_token_start_position();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// As we handle the start and end positions for values created during parsing,
|
||||||
|
// we do not expect the following value type to be called. Regardless, set the positions
|
||||||
|
// in case this is created manually or through a different constructor. Exclude from lcov
|
||||||
|
// since the exact condition of this switch is esoteric.
|
||||||
|
// LCOV_EXCL_START
|
||||||
|
case value_t::discarded:
|
||||||
|
{
|
||||||
|
v.end_position = std::string::npos;
|
||||||
|
v.start_position = v.end_position;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
|
case value_t::binary:
|
||||||
|
case value_t::number_integer:
|
||||||
|
case value_t::number_unsigned:
|
||||||
|
case value_t::number_float:
|
||||||
|
{
|
||||||
|
v.start_position = v.end_position - m_lexer_ref->get_string().size();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case value_t::object:
|
||||||
|
case value_t::array:
|
||||||
|
{
|
||||||
|
// object and array are handled in start_object() and start_array() handlers
|
||||||
|
// skip setting the values here.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: // LCOV_EXCL_LINE
|
||||||
|
// Handle all possible types discretely, default handler should never be reached.
|
||||||
|
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors) LCOV_EXCL_LINE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@invariant If the ref stack is empty, then the passed value will be the new
|
@invariant If the ref stack is empty, then the passed value will be the new
|
||||||
root.
|
root.
|
||||||
@@ -474,7 +461,7 @@ class json_sax_dom_parser
|
|||||||
root = BasicJsonType(std::forward<Value>(v));
|
root = BasicJsonType(std::forward<Value>(v));
|
||||||
|
|
||||||
#if JSON_DIAGNOSTIC_POSITIONS
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
diagnostic_positions::set_from_lexer(root, m_lexer_ref);
|
handle_diagnostic_positions_for_json_value(root);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return &root;
|
return &root;
|
||||||
@@ -487,7 +474,7 @@ class json_sax_dom_parser
|
|||||||
ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));
|
ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));
|
||||||
|
|
||||||
#if JSON_DIAGNOSTIC_POSITIONS
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
diagnostic_positions::set_from_lexer(ref_stack.back()->m_data.m_value.array->back(), m_lexer_ref);
|
handle_diagnostic_positions_for_json_value(ref_stack.back()->m_data.m_value.array->back());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return &(ref_stack.back()->m_data.m_value.array->back());
|
return &(ref_stack.back()->m_data.m_value.array->back());
|
||||||
@@ -498,7 +485,7 @@ class json_sax_dom_parser
|
|||||||
*object_element = BasicJsonType(std::forward<Value>(v));
|
*object_element = BasicJsonType(std::forward<Value>(v));
|
||||||
|
|
||||||
#if JSON_DIAGNOSTIC_POSITIONS
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
diagnostic_positions::set_from_lexer(*object_element, m_lexer_ref);
|
handle_diagnostic_positions_for_json_value(*object_element);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return object_element;
|
return object_element;
|
||||||
@@ -687,7 +674,7 @@ class json_sax_dom_callback_parser
|
|||||||
|
|
||||||
#if JSON_DIAGNOSTIC_POSITIONS
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
// Set start/end positions for discarded object.
|
// Set start/end positions for discarded object.
|
||||||
diagnostic_positions::set_from_lexer(*ref_stack.back(), m_lexer_ref);
|
handle_diagnostic_positions_for_json_value(*ref_stack.back());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -803,7 +790,7 @@ class json_sax_dom_callback_parser
|
|||||||
|
|
||||||
#if JSON_DIAGNOSTIC_POSITIONS
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
// Set start/end positions for discarded array.
|
// Set start/end positions for discarded array.
|
||||||
diagnostic_positions::set_from_lexer(*ref_stack.back(), m_lexer_ref);
|
handle_diagnostic_positions_for_json_value(*ref_stack.back());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -856,6 +843,72 @@ class json_sax_dom_callback_parser
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
|
void handle_diagnostic_positions_for_json_value(BasicJsonType& v)
|
||||||
|
{
|
||||||
|
if (m_lexer_ref)
|
||||||
|
{
|
||||||
|
// Lexer has read past the current field value, so set the end position to the current position.
|
||||||
|
// The start position will be set below based on the length of the string representation
|
||||||
|
// of the value.
|
||||||
|
v.end_position = m_lexer_ref->get_position();
|
||||||
|
|
||||||
|
switch (v.type())
|
||||||
|
{
|
||||||
|
case value_t::boolean:
|
||||||
|
{
|
||||||
|
// 4 and 5 are the string length of "true" and "false"
|
||||||
|
v.start_position = v.end_position - (v.m_data.m_value.boolean ? 4 : 5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::null:
|
||||||
|
{
|
||||||
|
// 4 is the string length of "null"
|
||||||
|
v.start_position = v.end_position - 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::string:
|
||||||
|
{
|
||||||
|
// escape sequences make the token longer than the value it
|
||||||
|
// parses to, so the start position cannot be derived from
|
||||||
|
// the value; use the offset the lexer recorded instead
|
||||||
|
v.start_position = m_lexer_ref->get_token_start_position();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::discarded:
|
||||||
|
{
|
||||||
|
v.end_position = std::string::npos;
|
||||||
|
v.start_position = v.end_position;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::binary:
|
||||||
|
case value_t::number_integer:
|
||||||
|
case value_t::number_unsigned:
|
||||||
|
case value_t::number_float:
|
||||||
|
{
|
||||||
|
v.start_position = v.end_position - m_lexer_ref->get_string().size();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::object:
|
||||||
|
case value_t::array:
|
||||||
|
{
|
||||||
|
// object and array are handled in start_object() and start_array() handlers
|
||||||
|
// skip setting the values here.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: // LCOV_EXCL_LINE
|
||||||
|
// Handle all possible types discretely, default handler should never be reached.
|
||||||
|
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors) LCOV_EXCL_LINE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/// if there is a pending duplicate-key stash entry for this exact slot,
|
/// if there is a pending duplicate-key stash entry for this exact slot,
|
||||||
/// remove it from the stash; if restore_value is true, the stashed
|
/// remove it from the stash; if restore_value is true, the stashed
|
||||||
/// previous value is moved back into the slot first (use this when the
|
/// previous value is moved back into the slot first (use this when the
|
||||||
@@ -977,7 +1030,7 @@ class json_sax_dom_callback_parser
|
|||||||
auto value = BasicJsonType(std::forward<Value>(v));
|
auto value = BasicJsonType(std::forward<Value>(v));
|
||||||
|
|
||||||
#if JSON_DIAGNOSTIC_POSITIONS
|
#if JSON_DIAGNOSTIC_POSITIONS
|
||||||
diagnostic_positions::set_from_lexer(value, m_lexer_ref);
|
handle_diagnostic_positions_for_json_value(value);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// check callback
|
// check callback
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#include <array> // array
|
#include <array> // array
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstdint> // uint32_t
|
|
||||||
#include <cstdio> // snprintf
|
#include <cstdio> // snprintf
|
||||||
#include <initializer_list> // initializer_list
|
#include <initializer_list> // initializer_list
|
||||||
#include <string> // char_traits, string
|
#include <string> // char_traits, string
|
||||||
@@ -23,7 +22,6 @@
|
|||||||
#include <nlohmann/detail/input/string_scan.hpp>
|
#include <nlohmann/detail/input/string_scan.hpp>
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||||
#include <nlohmann/detail/string_utils.hpp>
|
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail
|
||||||
@@ -222,9 +220,9 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
/////////////////////
|
/////////////////////
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief get codepoint from 4 hex characters following `\\u`
|
@brief get codepoint from 4 hex characters following `\u`
|
||||||
|
|
||||||
For input "\\u c1 c2 c3 c4" the codepoint is:
|
For input "\u c1 c2 c3 c4" the codepoint is:
|
||||||
(c1 * 0x1000) + (c2 * 0x0100) + (c3 * 0x0010) + c4
|
(c1 * 0x1000) + (c2 * 0x0100) + (c3 * 0x0010) + c4
|
||||||
= (c1 << 12) + (c2 << 8) + (c3 << 4) + (c4 << 0)
|
= (c1 << 12) + (c2 << 8) + (c3 << 4) + (c4 << 0)
|
||||||
|
|
||||||
@@ -488,10 +486,32 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
|
JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
|
||||||
|
|
||||||
// translate codepoint into bytes
|
// translate codepoint into bytes
|
||||||
encode_utf8(static_cast<std::uint32_t>(codepoint), [this](std::uint32_t byte)
|
if (codepoint < 0x80)
|
||||||
{
|
{
|
||||||
add(static_cast<char_int_type>(byte));
|
// 1-byte characters: 0xxxxxxx (ASCII)
|
||||||
});
|
add(static_cast<char_int_type>(codepoint));
|
||||||
|
}
|
||||||
|
else if (codepoint <= 0x7FF)
|
||||||
|
{
|
||||||
|
// 2-byte characters: 110xxxxx 10xxxxxx
|
||||||
|
add(static_cast<char_int_type>(0xC0u | (static_cast<unsigned int>(codepoint) >> 6u)));
|
||||||
|
add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
|
||||||
|
}
|
||||||
|
else if (codepoint <= 0xFFFF)
|
||||||
|
{
|
||||||
|
// 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
|
||||||
|
add(static_cast<char_int_type>(0xE0u | (static_cast<unsigned int>(codepoint) >> 12u)));
|
||||||
|
add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
|
||||||
|
add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||||
|
add(static_cast<char_int_type>(0xF0u | (static_cast<unsigned int>(codepoint) >> 18u)));
|
||||||
|
add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
|
||||||
|
add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
|
||||||
|
add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1389,30 +1409,45 @@ scan_number_done:
|
|||||||
*/
|
*/
|
||||||
token_type convert_number(token_type number_type, std::size_t mantissa_end)
|
token_type convert_number(token_type number_type, std::size_t mantissa_end)
|
||||||
{
|
{
|
||||||
// accept() only needs to know whether the input is valid, so it sets
|
// If the caller does not need the converted value (only whether the
|
||||||
// discard_number_values (see json.hpp), and an integer token whose
|
// input is syntactically valid; see json_sax_acceptor/accept()), an
|
||||||
// digit count shows that it fits is reported without calling
|
// unsigned/integer token can be reported without calling
|
||||||
// convert_integer(). A number with up to 18 digits always fits into
|
// strtoull()/strtoll() at all, *provided* we can already tell from
|
||||||
// both std::uint64_t and std::int64_t (18 nines is about 1e18, below
|
// the digit count alone that the conversion cannot overflow 64 bits.
|
||||||
// INT64_MAX, which is about 9.2e18). Longer tokens take the exact path
|
// Such tokens are always finite and are accepted unconditionally by
|
||||||
// below, including the fallback to floating point when the value does
|
// the parser regardless of their actual value (parser::sax_parse_internal()
|
||||||
// not fit.
|
// never checks finiteness for value_unsigned/value_integer), so the
|
||||||
|
// classification below is all that is needed.
|
||||||
//
|
//
|
||||||
// With a narrower number_unsigned_t/number_integer_t (e.g.
|
// A decimal number with up to 18 digits is always representable in
|
||||||
// std::uint32_t), the exact path would reclassify some of these tokens
|
// both std::uint64_t and std::int64_t (18 nines is ~1e18, well below
|
||||||
// as (finite) floats, while this check reports integers. That does not
|
// both UINT64_MAX ~1.8e19 and INT64_MAX ~9.2e18), so strtoull()/strtoll()
|
||||||
// change the result of accept(): it always parses through
|
// could not have set errno to ERANGE for it. Numbers with more digits
|
||||||
// json_sax_acceptor, whose number callbacks discard their argument and
|
// (rare in practice) fall through to the exact code below, unchanged,
|
||||||
// return true, and the parser rejects neither integers nor finite
|
// so their handling -- including reclassification to value_float when
|
||||||
// floats. value_unsigned/value_integer are left unset here, so a caller
|
// the value overflows 64 bits, and rejection when it is not even
|
||||||
// that reads the converted value must not set discard_number_values.
|
// finite as a double -- is bit-for-bit identical to before this
|
||||||
|
// optimization.
|
||||||
//
|
//
|
||||||
// On contiguous input, scan_number_bulk_contiguous() converts integer
|
// Note this reasons about std::uint64_t/std::int64_t, not about
|
||||||
// tokens itself and does not pass them to this function, unless
|
// number_unsigned_t/number_integer_t (BasicJsonType's own, possibly
|
||||||
// JSON_DIAGNOSTIC_POSITIONS is enabled. This check is therefore only
|
// narrower, template parameters -- e.g. std::uint32_t). That is fine
|
||||||
// reached for input without bulk access (e.g. streams), with
|
// *only* because discard_number_values is exclusively set by
|
||||||
// JSON_DIAGNOSTIC_POSITIONS, or when scan_number_bulk_contiguous()
|
// accept() (see json.hpp), and accept() always parses through the
|
||||||
// falls back to scan_number().
|
// library's own json_sax_acceptor -- never a user-supplied SAX
|
||||||
|
// consumer -- whose number_unsigned()/number_integer()/number_float()
|
||||||
|
// callbacks unconditionally discard their argument and return true.
|
||||||
|
// So for every caller that can reach this branch, neither the token
|
||||||
|
// classification below nor the eventual (possibly narrowed, and on
|
||||||
|
// this fast path left stale/unset) value_unsigned/value_integer is
|
||||||
|
// ever consulted -- an unsigned/integer token is accepted outright,
|
||||||
|
// and even a >18-digit token that this fast path deliberately falls
|
||||||
|
// through for is, once reclassified to value_float, still finite
|
||||||
|
// (and thus accepted) for any digit count that fits in number_unsigned_t
|
||||||
|
// or number_integer_t regardless of that type's width. If this
|
||||||
|
// function is ever taught to run with discard_number_values true for
|
||||||
|
// a caller that *does* read the converted value, this reasoning (and
|
||||||
|
// the fast path below) would need to be revisited.
|
||||||
if (discard_number_values)
|
if (discard_number_values)
|
||||||
{
|
{
|
||||||
constexpr std::size_t safe_digit_count = 18;
|
constexpr std::size_t safe_digit_count = 18;
|
||||||
@@ -1841,7 +1876,7 @@ scan_number_done:
|
|||||||
return value_float;
|
return value_float;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return current string value
|
/// return current string value (implicitly resets the token; useful only once)
|
||||||
string_t& get_string()
|
string_t& get_string()
|
||||||
{
|
{
|
||||||
// a number token holds '.' regardless of the locale (#4084)
|
// a number token holds '.' regardless of the locale (#4084)
|
||||||
@@ -2143,11 +2178,11 @@ scan_number_done:
|
|||||||
/// the position of the decimal point in token_buffer
|
/// the position of the decimal point in token_buffer
|
||||||
std::size_t decimal_point_position = std::string::npos;
|
std::size_t decimal_point_position = std::string::npos;
|
||||||
|
|
||||||
/// whether the caller only needs the token types and never looks at the
|
/// whether the caller (e.g. accept()/json_sax_acceptor) only needs the
|
||||||
/// converted numeric values; set only by accept(), which parses through
|
/// token classification and never looks at the converted numeric value;
|
||||||
/// json_sax_acceptor. When set, convert_number() skips converting integer
|
/// when set, scan_number() may skip strtoull()/strtoll() for
|
||||||
/// tokens whose digit count guarantees that they fit into 64 bits (see
|
/// value_unsigned/value_integer tokens whose digit count guarantees they
|
||||||
/// there)
|
/// fit into 64 bits (see scan_number())
|
||||||
const bool discard_number_values = false;
|
const bool discard_number_values = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -54,8 +54,7 @@ using parser_callback_t =
|
|||||||
/*!
|
/*!
|
||||||
@brief syntax analysis
|
@brief syntax analysis
|
||||||
|
|
||||||
This class implements an iterative parser that keeps the open containers on
|
This class implements a recursive descent parser.
|
||||||
an explicit stack and reports what it reads as SAX events.
|
|
||||||
*/
|
*/
|
||||||
template<typename BasicJsonType, typename InputAdapterType>
|
template<typename BasicJsonType, typename InputAdapterType>
|
||||||
class parser
|
class parser
|
||||||
@@ -99,9 +98,28 @@ class parser
|
|||||||
if (callback)
|
if (callback)
|
||||||
{
|
{
|
||||||
json_sax_dom_callback_parser<BasicJsonType, InputAdapterType> sdp(result, callback, allow_exceptions, &m_lexer);
|
json_sax_dom_callback_parser<BasicJsonType, InputAdapterType> sdp(result, callback, allow_exceptions, &m_lexer);
|
||||||
|
sax_parse_internal(&sdp);
|
||||||
|
|
||||||
|
if (strict)
|
||||||
|
{
|
||||||
|
// in strict mode, input must be completely read
|
||||||
|
if (get_token() != token_type::end_of_input)
|
||||||
|
{
|
||||||
|
sdp.parse_error(m_lexer.get_position(),
|
||||||
|
m_lexer.get_token_string(),
|
||||||
|
parse_error::create(101, m_lexer.get_position(),
|
||||||
|
exception_message(token_type::end_of_input, "value"), nullptr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// the caller keeps using the input: position it right after
|
||||||
|
// the value by leaving the character that terminated it
|
||||||
|
m_lexer.release_lookahead();
|
||||||
|
}
|
||||||
|
|
||||||
// in case of an error, return a discarded value
|
// in case of an error, return a discarded value
|
||||||
if (!parse_dom(sdp, strict))
|
if (sdp.is_errored())
|
||||||
{
|
{
|
||||||
result = value_t::discarded;
|
result = value_t::discarded;
|
||||||
return;
|
return;
|
||||||
@@ -117,9 +135,26 @@ class parser
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
json_sax_dom_parser<BasicJsonType, InputAdapterType> sdp(result, allow_exceptions, &m_lexer);
|
json_sax_dom_parser<BasicJsonType, InputAdapterType> sdp(result, allow_exceptions, &m_lexer);
|
||||||
|
sax_parse_internal(&sdp);
|
||||||
|
|
||||||
|
if (strict)
|
||||||
|
{
|
||||||
|
// in strict mode, input must be completely read
|
||||||
|
if (get_token() != token_type::end_of_input)
|
||||||
|
{
|
||||||
|
sdp.parse_error(m_lexer.get_position(),
|
||||||
|
m_lexer.get_token_string(),
|
||||||
|
parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), nullptr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// see above
|
||||||
|
m_lexer.release_lookahead();
|
||||||
|
}
|
||||||
|
|
||||||
// in case of an error, return a discarded value
|
// in case of an error, return a discarded value
|
||||||
if (!parse_dom(sdp, strict))
|
if (sdp.is_errored())
|
||||||
{
|
{
|
||||||
result = value_t::discarded;
|
result = value_t::discarded;
|
||||||
return;
|
return;
|
||||||
@@ -172,46 +207,6 @@ class parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*!
|
|
||||||
@brief run a DOM SAX parser to completion and position the lexer
|
|
||||||
|
|
||||||
Shared by both branches of @ref parse(): builds no SAX parser itself,
|
|
||||||
but drives an already-constructed @a json_sax_dom_parser or
|
|
||||||
@ref json_sax_dom_callback_parser through @ref sax_parse_internal(),
|
|
||||||
then applies the strict-EOF check (reporting parse_error.101 through
|
|
||||||
@a sdp on failure) or, in non-strict mode, releases the lookahead so
|
|
||||||
the caller can keep reading the input right after the parsed value.
|
|
||||||
|
|
||||||
@param[in,out] sdp the DOM SAX parser to run
|
|
||||||
@param[in] strict whether to expect the last token to be EOF
|
|
||||||
@return whether @a sdp did not report an error
|
|
||||||
*/
|
|
||||||
template<typename DomSax>
|
|
||||||
bool parse_dom(DomSax& sdp, const bool strict)
|
|
||||||
{
|
|
||||||
sax_parse_internal(&sdp);
|
|
||||||
|
|
||||||
if (strict)
|
|
||||||
{
|
|
||||||
// in strict mode, input must be completely read
|
|
||||||
if (get_token() != token_type::end_of_input)
|
|
||||||
{
|
|
||||||
sdp.parse_error(m_lexer.get_position(),
|
|
||||||
m_lexer.get_token_string(),
|
|
||||||
parse_error::create(101, m_lexer.get_position(),
|
|
||||||
exception_message(token_type::end_of_input, "value"), nullptr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// the caller keeps using the input: position it right after
|
|
||||||
// the value by leaving the character that terminated it
|
|
||||||
m_lexer.release_lookahead();
|
|
||||||
}
|
|
||||||
|
|
||||||
return !sdp.is_errored();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename SAX>
|
template<typename SAX>
|
||||||
JSON_HEDLEY_NON_NULL(2)
|
JSON_HEDLEY_NON_NULL(2)
|
||||||
bool sax_parse_internal(SAX* sax)
|
bool sax_parse_internal(SAX* sax)
|
||||||
@@ -444,9 +439,8 @@ class parser
|
|||||||
|
|
||||||
// We are done with this array. Before we can parse a
|
// We are done with this array. Before we can parse a
|
||||||
// new value, we need to evaluate the new state first.
|
// new value, we need to evaluate the new state first.
|
||||||
// By setting skip_to_state_evaluation to true, the next
|
// By setting skip_to_state_evaluation to false, we
|
||||||
// iteration skips parsing a value and evaluates the
|
// are effectively jumping to the beginning of this if.
|
||||||
// enclosing state directly.
|
|
||||||
JSON_ASSERT(!states.empty());
|
JSON_ASSERT(!states.empty());
|
||||||
states.pop_back();
|
states.pop_back();
|
||||||
skip_to_state_evaluation = true;
|
skip_to_state_evaluation = true;
|
||||||
@@ -506,9 +500,8 @@ class parser
|
|||||||
|
|
||||||
// We are done with this object. Before we can parse a
|
// We are done with this object. Before we can parse a
|
||||||
// new value, we need to evaluate the new state first.
|
// new value, we need to evaluate the new state first.
|
||||||
// By setting skip_to_state_evaluation to true, the next
|
// By setting skip_to_state_evaluation to false, we
|
||||||
// iteration skips parsing a value and evaluates the
|
// are effectively jumping to the beginning of this if.
|
||||||
// enclosing state directly.
|
|
||||||
JSON_ASSERT(!states.empty());
|
JSON_ASSERT(!states.empty());
|
||||||
states.pop_back();
|
states.pop_back();
|
||||||
skip_to_state_evaluation = true;
|
skip_to_state_evaluation = true;
|
||||||
|
|||||||
@@ -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
|
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.
|
default-constructed, it is *uninitialized* and most methods are undefined.
|
||||||
**The library uses assertions to detect calls on uninitialized iterators.**
|
**The library uses assertions to detect calls on uninitialized iterators.**
|
||||||
This class satisfies the following concept requirements (REQ-JSON-01):
|
@requirement REQ-JSON-01 The class satisfies the following concept requirements:
|
||||||
-
|
-
|
||||||
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):
|
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):
|
||||||
The iterator that can be moved can be moved in both directions (i.e.
|
The iterator that can be moved can be moved in both directions (i.e.
|
||||||
|
|||||||
@@ -213,11 +213,11 @@ namespace std
|
|||||||
JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wmismatched-tags")
|
JSON_HEDLEY_PRAGMA(clang diagnostic ignored "-Wmismatched-tags")
|
||||||
#endif
|
#endif
|
||||||
template<typename IteratorType>
|
template<typename IteratorType>
|
||||||
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp,bugprone-std-namespace-modification)
|
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)
|
||||||
: public std::integral_constant<std::size_t, 2> {};
|
: public std::integral_constant<std::size_t, 2> {};
|
||||||
|
|
||||||
template<std::size_t N, typename IteratorType>
|
template<std::size_t N, typename IteratorType>
|
||||||
class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp,bugprone-std-namespace-modification)
|
class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp)
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using type = decltype(
|
using type = decltype(
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace detail
|
|||||||
iterator (to create @ref reverse_iterator) and @ref const_iterator (to
|
iterator (to create @ref reverse_iterator) and @ref const_iterator (to
|
||||||
create @ref const_reverse_iterator).
|
create @ref const_reverse_iterator).
|
||||||
|
|
||||||
This class satisfies the following concept requirements (REQ-JSON-02):
|
@requirement REQ-JSON-02 The class satisfies the following concept requirements:
|
||||||
-
|
-
|
||||||
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):
|
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):
|
||||||
The iterator that can be moved can be moved in both directions (i.e.
|
The iterator that can be moved can be moved in both directions (i.e.
|
||||||
|
|||||||
@@ -278,11 +278,11 @@ class json_pointer
|
|||||||
JSON_THROW(detail::out_of_range::create(404, detail::concat("unresolved reference token '", s, "'"), nullptr));
|
JSON_THROW(detail::out_of_range::create(404, detail::concat("unresolved reference token '", s, "'"), nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
// the index does not fit into size_type; on 64-bit platforms this is
|
// only triggered on special platforms (like 32bit), see also
|
||||||
// only SIZE_MAX itself (see #2203 and #5395)
|
// https://github.com/nlohmann/json/pull/2203
|
||||||
if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) // NOLINT(runtime/int)
|
if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)())) // NOLINT(runtime/int)
|
||||||
{
|
{
|
||||||
JSON_THROW(detail::out_of_range::create(410, detail::concat("array index ", s, " exceeds size_type"), nullptr));
|
JSON_THROW(detail::out_of_range::create(410, detail::concat("array index ", s, " exceeds size_type"), nullptr)); // LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<size_type>(res);
|
return static_cast<size_type>(res);
|
||||||
@@ -316,7 +316,7 @@ class json_pointer
|
|||||||
/*!
|
/*!
|
||||||
@brief create and return a reference to the pointed to value
|
@brief create and return a reference to the pointed to value
|
||||||
|
|
||||||
Complexity: Linear in the number of reference tokens.
|
@complexity Linear in the number of reference tokens.
|
||||||
|
|
||||||
@throw parse_error.106 if an array index begins with '0'
|
@throw parse_error.106 if an array index begins with '0'
|
||||||
@throw parse_error.109 if array index is not a number
|
@throw parse_error.109 if array index is not a number
|
||||||
@@ -403,7 +403,7 @@ class json_pointer
|
|||||||
|
|
||||||
@return reference to the JSON value pointed to by the JSON pointer
|
@return reference to the JSON value pointed to by the JSON pointer
|
||||||
|
|
||||||
Complexity: Linear in the length of the JSON pointer.
|
@complexity Linear in the length of the JSON pointer.
|
||||||
|
|
||||||
@throw parse_error.106 if an array index begins with '0'
|
@throw parse_error.106 if an array index begins with '0'
|
||||||
@throw parse_error.109 if an array index was not a number
|
@throw parse_error.109 if an array index was not a number
|
||||||
|
|||||||
@@ -195,6 +195,13 @@
|
|||||||
#define JSON_NO_THREAD_LOCAL 1
|
#define JSON_NO_THREAD_LOCAL 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// disable documentation warnings on clang
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
||||||
|
#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
|
||||||
|
#endif
|
||||||
|
|
||||||
// allow disabling exceptions
|
// allow disabling exceptions
|
||||||
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
|
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
|
||||||
#define JSON_THROW(exception) throw exception
|
#define JSON_THROW(exception) throw exception
|
||||||
@@ -253,7 +260,7 @@
|
|||||||
{ \
|
{ \
|
||||||
/* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \
|
/* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \
|
||||||
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
||||||
/* NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) we don't want to depend on <array> */ \
|
/* NOLINTNEXTLINE(modernize-avoid-c-arrays) we don't want to depend on <array> */ \
|
||||||
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
||||||
auto it = std::find_if(std::begin(m), std::end(m), \
|
auto it = std::find_if(std::begin(m), std::end(m), \
|
||||||
[e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
[e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
||||||
@@ -267,7 +274,7 @@
|
|||||||
{ \
|
{ \
|
||||||
/* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \
|
/* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \
|
||||||
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
||||||
/* NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) we don't want to depend on <array> */ \
|
/* NOLINTNEXTLINE(modernize-avoid-c-arrays) we don't want to depend on <array> */ \
|
||||||
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
||||||
auto it = std::find_if(std::begin(m), std::end(m), \
|
auto it = std::find_if(std::begin(m), std::end(m), \
|
||||||
[&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
[&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
||||||
@@ -306,7 +313,7 @@ void templated_json_throw(ExceptionType exception)
|
|||||||
{ \
|
{ \
|
||||||
/* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \
|
/* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \
|
||||||
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
||||||
/* NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) we don't want to depend on <array> */ \
|
/* NOLINTNEXTLINE(modernize-avoid-c-arrays) we don't want to depend on <array> */ \
|
||||||
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
||||||
auto it = std::find_if(std::begin(m), std::end(m), \
|
auto it = std::find_if(std::begin(m), std::end(m), \
|
||||||
[e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
[e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
||||||
@@ -321,7 +328,7 @@ void templated_json_throw(ExceptionType exception)
|
|||||||
{ \
|
{ \
|
||||||
/* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \
|
/* NOLINTNEXTLINE(modernize-type-traits) we use C++11 */ \
|
||||||
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
||||||
/* NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) we don't want to depend on <array> */ \
|
/* NOLINTNEXTLINE(modernize-avoid-c-arrays) we don't want to depend on <array> */ \
|
||||||
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
||||||
auto it = std::find_if(std::begin(m), std::end(m), \
|
auto it = std::find_if(std::begin(m), std::end(m), \
|
||||||
[&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
[&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
||||||
@@ -352,7 +359,6 @@ void templated_json_throw(ExceptionType exception)
|
|||||||
|
|
||||||
// Macros to simplify conversion from/to types
|
// Macros to simplify conversion from/to types
|
||||||
|
|
||||||
// NLOHMANN_JSON_EXPAND to NLOHMANN_JSON_DOUBLE_PASTE63 are generated by tools/macro_builder (see its README.md)
|
|
||||||
#define NLOHMANN_JSON_EXPAND( x ) x
|
#define NLOHMANN_JSON_EXPAND( x ) x
|
||||||
#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME
|
#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME
|
||||||
#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
|
#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
|
||||||
@@ -615,10 +621,6 @@ void templated_json_throw(ExceptionType exception)
|
|||||||
// arguments, so dispatching on Type,BaseType,member... directly would run out
|
// arguments, so dispatching on Type,BaseType,member... directly would run out
|
||||||
// one slot early and cap the derived-type macros at 62 members instead of the
|
// one slot early and cap the derived-type macros at 62 members instead of the
|
||||||
// 63 that NLOHMANN_JSON_PASTE supports.
|
// 63 that NLOHMANN_JSON_PASTE supports.
|
||||||
//
|
|
||||||
// The slot table below (down to the closing NLOHMANN_JSON_TYPE_BODY_SENTINEL))
|
|
||||||
// is generated by tools/macro_builder (see its README.md; run with the
|
|
||||||
// "type_body" argument).
|
|
||||||
#define NLOHMANN_JSON_TYPE_BODY(Prefix, ...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
|
#define NLOHMANN_JSON_TYPE_BODY(Prefix, ...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
|
||||||
Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, \
|
Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, \
|
||||||
Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, \
|
Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, Prefix ## MEMBERS, \
|
||||||
@@ -913,7 +915,3 @@ void templated_json_throw(ExceptionType exception)
|
|||||||
#ifndef JSON_DISABLE_ENUM_SERIALIZATION
|
#ifndef JSON_DISABLE_ENUM_SERIALIZATION
|
||||||
#define JSON_DISABLE_ENUM_SERIALIZATION 0
|
#define JSON_DISABLE_ENUM_SERIALIZATION 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef JSON_DISABLE_TUPLE_REFERENCE_CONVERSION
|
|
||||||
#define JSON_DISABLE_TUPLE_REFERENCE_CONVERSION 0
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// restore clang diagnostic settings
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
#undef JSON_ASSERT
|
#undef JSON_ASSERT
|
||||||
#undef JSON_INTERNAL_CATCH
|
#undef JSON_INTERNAL_CATCH
|
||||||
@@ -20,7 +25,6 @@
|
|||||||
#undef JSON_INLINE_VARIABLE
|
#undef JSON_INLINE_VARIABLE
|
||||||
#undef JSON_NO_UNIQUE_ADDRESS
|
#undef JSON_NO_UNIQUE_ADDRESS
|
||||||
#undef JSON_DISABLE_ENUM_SERIALIZATION
|
#undef JSON_DISABLE_ENUM_SERIALIZATION
|
||||||
#undef JSON_DISABLE_TUPLE_REFERENCE_CONVERSION
|
|
||||||
|
|
||||||
#ifndef JSON_TEST_KEEP_MACROS
|
#ifndef JSON_TEST_KEEP_MACROS
|
||||||
#undef JSON_CATCH
|
#undef JSON_CATCH
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array> // array
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
|
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
|
||||||
#include <utility> // index_sequence, make_index_sequence, index_sequence_for
|
#include <utility> // index_sequence, make_index_sequence, index_sequence_for
|
||||||
@@ -160,5 +161,11 @@ struct static_const
|
|||||||
constexpr T static_const<T>::value;
|
constexpr T static_const<T>::value;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
|
||||||
|
{
|
||||||
|
return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|||||||
@@ -636,18 +636,6 @@ template<typename BasicJsonType, typename CompatibleType>
|
|||||||
struct is_compatible_type
|
struct is_compatible_type
|
||||||
: is_compatible_type_impl<BasicJsonType, CompatibleType> {};
|
: is_compatible_type_impl<BasicJsonType, CompatibleType> {};
|
||||||
|
|
||||||
// a one-element std::tuple holding a reference to BasicJsonType, as created by
|
|
||||||
// std::forward_as_tuple(j); see JSON_DISABLE_TUPLE_REFERENCE_CONVERSION
|
|
||||||
template<typename BasicJsonType, typename T>
|
|
||||||
struct is_basic_json_reference_tuple : std::false_type {};
|
|
||||||
|
|
||||||
template<typename BasicJsonType, typename T>
|
|
||||||
struct is_basic_json_reference_tuple<BasicJsonType, std::tuple<T>>
|
|
||||||
{
|
|
||||||
static constexpr bool value =
|
|
||||||
std::is_reference<T>::value && std::is_same<uncvref_t<T>, BasicJsonType>::value;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleArrayType>
|
template<typename BasicJsonType, typename CompatibleArrayType>
|
||||||
struct is_compatible_binary_type
|
struct is_compatible_binary_type
|
||||||
{
|
{
|
||||||
@@ -760,6 +748,30 @@ using is_usable_as_key_type = typename std::conditional <
|
|||||||
std::true_type,
|
std::true_type,
|
||||||
std::false_type >::type;
|
std::false_type >::type;
|
||||||
|
|
||||||
|
#ifdef JSON_HAS_CPP_17
|
||||||
|
// type trait to check if KeyType can only be used as an object key after
|
||||||
|
// converting it to std::string_view: it is convertible to std::string_view, the
|
||||||
|
// object's comparator cannot compare it with object_t::key_type directly, but
|
||||||
|
// can compare a std::string_view. JSON pointers and JSON iterators are ruled out
|
||||||
|
// first, so that the conversion checks are never instantiated for them (a JSON
|
||||||
|
// pointer's deprecated conversion to string_t would be named otherwise).
|
||||||
|
template < typename BasicJsonType, typename KeyTypeCVRef, typename KeyType = uncvref_t<KeyTypeCVRef>,
|
||||||
|
bool = is_json_pointer<KeyType>::value || is_json_iterator_of<BasicJsonType, KeyType>::value >
|
||||||
|
struct is_string_view_convertible_key_type : std::false_type {};
|
||||||
|
|
||||||
|
template<typename BasicJsonType, typename KeyTypeCVRef, typename KeyType>
|
||||||
|
struct is_string_view_convertible_key_type<BasicJsonType, KeyTypeCVRef, KeyType, false>
|
||||||
|
: std::integral_constant < bool,
|
||||||
|
std::is_convertible<KeyTypeCVRef, std::string_view>::value
|
||||||
|
&& !is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
|
||||||
|
typename BasicJsonType::object_t::key_type, KeyTypeCVRef, true, false>::value
|
||||||
|
&& is_usable_as_key_type<typename BasicJsonType::object_comparator_t,
|
||||||
|
typename BasicJsonType::object_t::key_type, std::string_view, true, false>::value > {};
|
||||||
|
#else
|
||||||
|
template<typename BasicJsonType, typename KeyTypeCVRef>
|
||||||
|
struct is_string_view_convertible_key_type : std::false_type {};
|
||||||
|
#endif
|
||||||
|
|
||||||
// type trait to check if KeyType can be used as an object key
|
// type trait to check if KeyType can be used as an object key
|
||||||
// true if:
|
// true if:
|
||||||
// - KeyType is comparable with BasicJsonType::object_t::key_type
|
// - KeyType is comparable with BasicJsonType::object_t::key_type
|
||||||
@@ -773,9 +785,7 @@ using is_usable_as_basic_json_key_type = typename std::conditional <
|
|||||||
typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
|
typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
|
||||||
RequireTransparentComparator, ExcludeObjectKeyType>::value
|
RequireTransparentComparator, ExcludeObjectKeyType>::value
|
||||||
&& !is_json_iterator_of<BasicJsonType, KeyType>::value)
|
&& !is_json_iterator_of<BasicJsonType, KeyType>::value)
|
||||||
#ifdef JSON_HAS_CPP_17
|
|| is_string_view_convertible_key_type<BasicJsonType, KeyTypeCVRef>::value
|
||||||
|| std::is_convertible<KeyType, std::string_view>::value
|
|
||||||
#endif
|
|
||||||
, std::true_type,
|
, std::true_type,
|
||||||
std::false_type >::type;
|
std::false_type >::type;
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,38 +0,0 @@
|
|||||||
// __ _____ _____ _____
|
|
||||||
// __| | __| | | | 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
|
|
||||||
|
|
||||||
#include <nlohmann/detail/abi_macros.hpp>
|
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
|
|
||||||
/// how to treat decoding errors
|
|
||||||
///
|
|
||||||
/// @ref basic_json::dump uses this to decide what to do with ill-formed
|
|
||||||
/// UTF-8 while escaping a string, and the binary writers (@ref
|
|
||||||
/// basic_json::to_cbor, @ref basic_json::to_ubjson, @ref
|
|
||||||
/// basic_json::to_bjdata, @ref basic_json::to_bson) use it the same way for
|
|
||||||
/// string values and object keys. The binary readers (@ref
|
|
||||||
/// basic_json::from_cbor, @ref basic_json::from_msgpack, @ref
|
|
||||||
/// basic_json::from_ubjson, @ref basic_json::from_bjdata, @ref
|
|
||||||
/// basic_json::from_bson) use it to decide whether to check text strings
|
|
||||||
/// and object keys for well-formed UTF-8 at all, since none of those
|
|
||||||
/// formats requires a decoder to do so.
|
|
||||||
enum class error_handler_t
|
|
||||||
{
|
|
||||||
strict, ///< throw a type_error/parse_error exception in case of invalid UTF-8
|
|
||||||
replace, ///< replace invalid UTF-8 sequences with U+FFFD
|
|
||||||
ignore, ///< ignore invalid UTF-8 sequences
|
|
||||||
keep ///< keep invalid UTF-8 sequences unchanged
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
|
||||||
@@ -8,10 +8,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm> // copy
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
|
#include <iterator> // back_inserter
|
||||||
#include <memory> // shared_ptr, make_shared
|
#include <memory> // shared_ptr, make_shared
|
||||||
#include <string> // basic_string
|
#include <string> // basic_string
|
||||||
#include <type_traits> // conditional, integral_constant, is_same
|
|
||||||
#include <utility> // move
|
#include <utility> // move
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
|
|
||||||
@@ -30,10 +31,6 @@ namespace detail
|
|||||||
template<typename CharType> struct output_adapter_protocol
|
template<typename CharType> struct output_adapter_protocol
|
||||||
{
|
{
|
||||||
virtual void write_character(CharType c) = 0;
|
virtual void write_character(CharType c) = 0;
|
||||||
/// @param[in] s pointer to the characters to write; binary_writer legitimately
|
|
||||||
/// passes a null pointer together with length 0 for an empty
|
|
||||||
/// string or binary value, so implementations must tolerate that
|
|
||||||
/// @param[in] length number of characters at @a s
|
|
||||||
virtual void write_characters(const CharType* s, std::size_t length) = 0;
|
virtual void write_characters(const CharType* s, std::size_t length) = 0;
|
||||||
virtual ~output_adapter_protocol() = default;
|
virtual ~output_adapter_protocol() = default;
|
||||||
|
|
||||||
@@ -100,6 +97,7 @@ class output_vector_adapter : public output_adapter_protocol<CharType>
|
|||||||
sink.write_character(c);
|
sink.write_character(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON_HEDLEY_NON_NULL(2)
|
||||||
void write_characters(const CharType* s, std::size_t length) override
|
void write_characters(const CharType* s, std::size_t length) override
|
||||||
{
|
{
|
||||||
sink.write_characters(s, length);
|
sink.write_characters(s, length);
|
||||||
@@ -119,13 +117,12 @@ class output_stream_adapter : public output_adapter_protocol<CharType>
|
|||||||
: stream(s)
|
: stream(s)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// NOLINTNEXTLINE(portability-template-virtual-member-function)
|
|
||||||
void write_character(CharType c) override
|
void write_character(CharType c) override
|
||||||
{
|
{
|
||||||
stream.put(c);
|
stream.put(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOLINTNEXTLINE(portability-template-virtual-member-function)
|
JSON_HEDLEY_NON_NULL(2)
|
||||||
void write_characters(const CharType* s, std::size_t length) override
|
void write_characters(const CharType* s, std::size_t length) override
|
||||||
{
|
{
|
||||||
stream.write(s, static_cast<std::streamsize>(length));
|
stream.write(s, static_cast<std::streamsize>(length));
|
||||||
@@ -150,6 +147,7 @@ class output_string_adapter : public output_adapter_protocol<CharType>
|
|||||||
str.push_back(c);
|
str.push_back(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON_HEDLEY_NON_NULL(2)
|
||||||
void write_characters(const CharType* s, std::size_t length) override
|
void write_characters(const CharType* s, std::size_t length) override
|
||||||
{
|
{
|
||||||
str.append(s, length);
|
str.append(s, length);
|
||||||
@@ -192,82 +190,7 @@ class output_adapter_sink
|
|||||||
output_adapter_t<CharType> oa;
|
output_adapter_t<CharType> oa;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief whether std::basic_string<CharType> has a non-deprecated std::char_traits
|
template<typename CharType, typename StringType = std::basic_string<CharType>>
|
||||||
/// specialization, and is therefore usable as output_adapter's default StringType
|
|
||||||
///
|
|
||||||
/// std::char_traits is only guaranteed (and, on some standard libraries, only
|
|
||||||
/// implemented without a deprecation warning) for the character types listed
|
|
||||||
/// below; std::char_traits<T> for any other T (e.g. std::uint8_t, as used by the
|
|
||||||
/// binary writers) is a non-standard extension some standard libraries deprecate.
|
|
||||||
/// See https://github.com/nlohmann/json/issues/5725 item 2.
|
|
||||||
template<typename CharType>
|
|
||||||
struct is_output_adapter_string_char_type : std::integral_constant < bool,
|
|
||||||
std::is_same<CharType, char>::value ||
|
|
||||||
std::is_same<CharType, wchar_t>::value ||
|
|
||||||
std::is_same<CharType, char16_t>::value ||
|
|
||||||
std::is_same<CharType, char32_t>::value
|
|
||||||
#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
|
|
||||||
|| std::is_same<CharType, char8_t>::value
|
|
||||||
#endif
|
|
||||||
> {};
|
|
||||||
|
|
||||||
/// @brief placeholder type for output_adapter's StringType and (with JSON_NO_IO
|
|
||||||
/// undefined) its std::basic_ostream constructor parameter, for CharType
|
|
||||||
/// with no non-deprecated std::char_traits specialization
|
|
||||||
///
|
|
||||||
/// Never actually used: the StringType- and std::basic_ostream-based
|
|
||||||
/// output_adapter constructors are neither documented nor tested for such
|
|
||||||
/// CharType (only the std::vector-based constructor is used for them, by the
|
|
||||||
/// binary writers). Naming std::basic_string<CharType> or
|
|
||||||
/// std::basic_ostream<CharType> anywhere such a constructor would otherwise be
|
|
||||||
/// declared - even as an unused default template argument or an unused,
|
|
||||||
/// never-called overload - instantiates std::char_traits<CharType> merely to
|
|
||||||
/// name the type, which is exactly what triggers the deprecation warning this
|
|
||||||
/// placeholder avoids.
|
|
||||||
template<typename CharType>
|
|
||||||
struct output_adapter_no_string_type {};
|
|
||||||
|
|
||||||
// Select output_adapter's default StringType (and, below, its ostream
|
|
||||||
// constructor's parameter type) via partial specialization, not
|
|
||||||
// std::conditional: std::conditional<B, T, F> requires both T and F to be named
|
|
||||||
// as template arguments up front, which would still instantiate (and thus name)
|
|
||||||
// std::basic_string<CharType> / std::basic_ostream<CharType> for every CharType,
|
|
||||||
// defeating the point. A bool non-type parameter with two specializations only
|
|
||||||
// ever names the type that is actually selected.
|
|
||||||
template<typename CharType, bool = is_output_adapter_string_char_type<CharType>::value>
|
|
||||||
struct output_adapter_default_string_type
|
|
||||||
{
|
|
||||||
using type = output_adapter_no_string_type<CharType>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename CharType>
|
|
||||||
struct output_adapter_default_string_type<CharType, true>
|
|
||||||
{
|
|
||||||
using type = std::basic_string<CharType>;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifndef JSON_NO_IO
|
|
||||||
/// distinct from output_adapter_no_string_type, so the placeholder overloads of
|
|
||||||
/// output_adapter's constructor (used when CharType is not a character type)
|
|
||||||
/// stay distinct overloads instead of colliding into a single redeclaration
|
|
||||||
template<typename CharType>
|
|
||||||
struct output_adapter_no_ostream_type {};
|
|
||||||
|
|
||||||
template<typename CharType, bool = is_output_adapter_string_char_type<CharType>::value>
|
|
||||||
struct output_adapter_ostream_type
|
|
||||||
{
|
|
||||||
using type = output_adapter_no_ostream_type<CharType>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename CharType>
|
|
||||||
struct output_adapter_ostream_type<CharType, true>
|
|
||||||
{
|
|
||||||
using type = std::basic_ostream<CharType>;
|
|
||||||
};
|
|
||||||
#endif // JSON_NO_IO
|
|
||||||
|
|
||||||
template < typename CharType, typename StringType =
|
|
||||||
typename output_adapter_default_string_type<CharType>::type >
|
|
||||||
class output_adapter
|
class output_adapter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -276,7 +199,7 @@ class output_adapter
|
|||||||
: oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
|
: oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
|
||||||
|
|
||||||
#ifndef JSON_NO_IO
|
#ifndef JSON_NO_IO
|
||||||
output_adapter(typename output_adapter_ostream_type<CharType>::type& s)
|
output_adapter(std::basic_ostream<CharType>& s)
|
||||||
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
|
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
|
||||||
#endif // JSON_NO_IO
|
#endif // JSON_NO_IO
|
||||||
|
|
||||||
|
|||||||
@@ -3,23 +3,24 @@
|
|||||||
// | | |__ | | | | | | version 3.12.0
|
// | | |__ | | | | | | version 3.12.0
|
||||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||||
//
|
//
|
||||||
|
// SPDX-FileCopyrightText: 2008, 2009 Björn Hoehrmann <bjoern@hoehrmann.de>
|
||||||
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <algorithm> // remove, fill, find, none_of, min
|
#include <algorithm> // reverse, remove, fill, find, none_of, min
|
||||||
#include <array> // array
|
#include <array> // array
|
||||||
#include <clocale> // localeconv, lconv
|
#include <clocale> // localeconv, lconv
|
||||||
#include <cmath> // isfinite
|
#include <cmath> // labs, isfinite, isnan, signbit
|
||||||
#include <cstddef> // size_t, ptrdiff_t
|
#include <cstddef> // size_t, ptrdiff_t
|
||||||
#include <cstdint> // uint8_t
|
#include <cstdint> // uint8_t
|
||||||
#include <cstdio> // snprintf
|
#include <cstdio> // snprintf
|
||||||
#include <cstring> // memcpy, memset
|
#include <cstring> // memcpy, memset
|
||||||
#include <iterator> // next
|
|
||||||
#include <limits> // numeric_limits
|
#include <limits> // numeric_limits
|
||||||
#include <string> // string, char_traits
|
#include <string> // string, char_traits
|
||||||
#include <type_traits> // is_same
|
#include <type_traits> // is_same
|
||||||
|
#include <utility> // move
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
|
|
||||||
#include <nlohmann/detail/conversions/to_chars.hpp>
|
#include <nlohmann/detail/conversions/to_chars.hpp>
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
#include <nlohmann/detail/input/string_scan.hpp>
|
#include <nlohmann/detail/input/string_scan.hpp>
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
#include <nlohmann/detail/meta/cpp_future.hpp>
|
#include <nlohmann/detail/meta/cpp_future.hpp>
|
||||||
#include <nlohmann/detail/output/error_handler.hpp>
|
#include <nlohmann/detail/output/binary_writer.hpp>
|
||||||
#include <nlohmann/detail/output/output_adapters.hpp>
|
#include <nlohmann/detail/output/output_adapters.hpp>
|
||||||
#include <nlohmann/detail/recursion_depth_limit.hpp>
|
#include <nlohmann/detail/recursion_depth_limit.hpp>
|
||||||
#include <nlohmann/detail/string_concat.hpp>
|
#include <nlohmann/detail/string_concat.hpp>
|
||||||
@@ -42,6 +43,14 @@ namespace detail
|
|||||||
// serialization //
|
// serialization //
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
|
/// how to treat decoding errors
|
||||||
|
enum class error_handler_t
|
||||||
|
{
|
||||||
|
strict, ///< throw a type_error exception in case of invalid UTF-8
|
||||||
|
replace, ///< replace invalid UTF-8 sequences with U+FFFD
|
||||||
|
ignore ///< ignore invalid UTF-8 sequences
|
||||||
|
};
|
||||||
|
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
class serializer
|
class serializer
|
||||||
{
|
{
|
||||||
@@ -58,7 +67,7 @@ class serializer
|
|||||||
@param[in] ichar indentation character to use
|
@param[in] ichar indentation character to use
|
||||||
@param[in] pretty_print_ whether the output shall be pretty-printed
|
@param[in] pretty_print_ whether the output shall be pretty-printed
|
||||||
@param[in] ensure_ascii_ If @a ensure_ascii_ is true, all non-ASCII
|
@param[in] ensure_ascii_ If @a ensure_ascii_ is true, all non-ASCII
|
||||||
characters in the output are escaped with `\\uXXXX` sequences, and the
|
characters in the output are escaped with `\uXXXX` sequences, and the
|
||||||
result consists of ASCII characters only.
|
result consists of ASCII characters only.
|
||||||
@param[in] indent_step_ the indent level
|
@param[in] indent_step_ the indent level
|
||||||
@param[in] error_handler_ how to react on decoding errors
|
@param[in] error_handler_ how to react on decoding errors
|
||||||
@@ -74,6 +83,7 @@ class serializer
|
|||||||
const std::size_t indent_step_ = 0,
|
const std::size_t indent_step_ = 0,
|
||||||
error_handler_t error_handler_ = error_handler_t::strict)
|
error_handler_t error_handler_ = error_handler_t::strict)
|
||||||
: o(&s)
|
: o(&s)
|
||||||
|
, locale(std::localeconv())
|
||||||
, indent_char(ichar)
|
, indent_char(ichar)
|
||||||
, pretty_print(pretty_print_)
|
, pretty_print(pretty_print_)
|
||||||
, ensure_ascii(ensure_ascii_)
|
, ensure_ascii(ensure_ascii_)
|
||||||
@@ -96,10 +106,9 @@ class serializer
|
|||||||
additional parameter. Arrays and objects are serialized without recursion,
|
additional parameter. Arrays and objects are serialized without recursion,
|
||||||
however deeply they are nested.
|
however deeply they are nested.
|
||||||
|
|
||||||
- strings and object keys are escaped using @ref dump_escaped
|
- strings and object keys are escaped using `escape_string()`
|
||||||
- integer numbers are converted using a digit-pair lookup table (@ref dump_integer)
|
- integer numbers are converted implicitly via `operator<<`
|
||||||
- floating-point numbers are converted to a string using @ref dump_float, which
|
- floating-point numbers are converted to a string using `"%g"` format
|
||||||
uses `to_chars` for IEEE-754 types and `snprintf` otherwise
|
|
||||||
- binary values are serialized as objects containing the subtype and the
|
- binary values are serialized as objects containing the subtype and the
|
||||||
byte array
|
byte array
|
||||||
|
|
||||||
@@ -274,16 +283,127 @@ class serializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
case value_t::string:
|
case value_t::string:
|
||||||
case value_t::binary:
|
{
|
||||||
case value_t::boolean:
|
put_char('"');
|
||||||
case value_t::number_integer:
|
dump_escaped(*val.m_data.m_value.string);
|
||||||
case value_t::number_unsigned:
|
put_char('"');
|
||||||
case value_t::number_float:
|
|
||||||
case value_t::discarded:
|
|
||||||
case value_t::null:
|
|
||||||
default:
|
|
||||||
dump_scalar(val, current_indent);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::binary:
|
||||||
|
{
|
||||||
|
if (pretty_print)
|
||||||
|
{
|
||||||
|
put_literal("{\n");
|
||||||
|
|
||||||
|
// variable to hold indentation for recursive calls
|
||||||
|
const auto new_indent = next_indent(current_indent, indent_step);
|
||||||
|
|
||||||
|
put_indent(new_indent);
|
||||||
|
|
||||||
|
put_literal("\"bytes\": [");
|
||||||
|
|
||||||
|
if (!val.m_data.m_value.binary->empty())
|
||||||
|
{
|
||||||
|
for (auto i = val.m_data.m_value.binary->cbegin();
|
||||||
|
i != val.m_data.m_value.binary->cend() - 1; ++i)
|
||||||
|
{
|
||||||
|
dump_byte(*i);
|
||||||
|
put_literal(", ");
|
||||||
|
}
|
||||||
|
dump_byte(val.m_data.m_value.binary->back());
|
||||||
|
}
|
||||||
|
|
||||||
|
put_literal("],\n");
|
||||||
|
put_indent(new_indent);
|
||||||
|
|
||||||
|
put_literal("\"subtype\": ");
|
||||||
|
if (val.m_data.m_value.binary->has_subtype())
|
||||||
|
{
|
||||||
|
dump_integer(val.m_data.m_value.binary->subtype());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
put_literal("null");
|
||||||
|
}
|
||||||
|
put_char('\n');
|
||||||
|
put_indent(current_indent);
|
||||||
|
put_char('}');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
put_literal("{\"bytes\":[");
|
||||||
|
|
||||||
|
if (!val.m_data.m_value.binary->empty())
|
||||||
|
{
|
||||||
|
for (auto i = val.m_data.m_value.binary->cbegin();
|
||||||
|
i != val.m_data.m_value.binary->cend() - 1; ++i)
|
||||||
|
{
|
||||||
|
dump_byte(*i);
|
||||||
|
put_char(',');
|
||||||
|
}
|
||||||
|
dump_byte(val.m_data.m_value.binary->back());
|
||||||
|
}
|
||||||
|
|
||||||
|
put_literal("],\"subtype\":");
|
||||||
|
if (val.m_data.m_value.binary->has_subtype())
|
||||||
|
{
|
||||||
|
dump_integer(val.m_data.m_value.binary->subtype());
|
||||||
|
put_char('}');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
put_literal("null}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::boolean:
|
||||||
|
{
|
||||||
|
if (val.m_data.m_value.boolean)
|
||||||
|
{
|
||||||
|
put_literal("true");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
put_literal("false");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::number_integer:
|
||||||
|
{
|
||||||
|
dump_integer(val.m_data.m_value.number_integer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::number_unsigned:
|
||||||
|
{
|
||||||
|
dump_integer(val.m_data.m_value.number_unsigned);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::number_float:
|
||||||
|
{
|
||||||
|
dump_float(val.m_data.m_value.number_float);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::discarded:
|
||||||
|
{
|
||||||
|
put_literal("<discarded>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case value_t::null:
|
||||||
|
{
|
||||||
|
put_literal("null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: // LCOV_EXCL_LINE
|
||||||
|
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,9 +560,9 @@ class serializer
|
|||||||
@brief serialize the value @a val, but not the elements of a container
|
@brief serialize the value @a val, but not the elements of a container
|
||||||
|
|
||||||
An object or array with elements is opened and pushed onto @a stack for
|
An object or array with elements is opened and pushed onto @a stack for
|
||||||
@ref dump_iteratively to walk; everything else - including a binary value,
|
@ref dump_internal to walk; everything else - including a binary value,
|
||||||
which looks like an object but has no elements to descend into - is written
|
which looks like an object but has no elements to descend into - is written
|
||||||
out in full by @ref dump_scalar.
|
out here in full.
|
||||||
*/
|
*/
|
||||||
void dump_value(const BasicJsonType& val,
|
void dump_value(const BasicJsonType& val,
|
||||||
const std::size_t current_indent,
|
const std::size_t current_indent,
|
||||||
@@ -500,35 +620,6 @@ class serializer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case value_t::string:
|
|
||||||
case value_t::binary:
|
|
||||||
case value_t::boolean:
|
|
||||||
case value_t::number_integer:
|
|
||||||
case value_t::number_unsigned:
|
|
||||||
case value_t::number_float:
|
|
||||||
case value_t::discarded:
|
|
||||||
case value_t::null:
|
|
||||||
default:
|
|
||||||
dump_scalar(val, current_indent);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief serialize the value @a val, which is neither an object nor an array
|
|
||||||
|
|
||||||
Shared by @ref dump_internal and @ref dump_value, so that a value is written
|
|
||||||
the same way however deeply it is nested. A binary value is written out here
|
|
||||||
in full: it looks like an object, but has no elements to descend into.
|
|
||||||
|
|
||||||
@param[in] val value to serialize; not an object or array
|
|
||||||
@param[in] current_indent the indentation of @a val, used for a
|
|
||||||
pretty-printed binary value
|
|
||||||
*/
|
|
||||||
void dump_scalar(const BasicJsonType& val, const std::size_t current_indent)
|
|
||||||
{
|
|
||||||
switch (val.m_data.m_type)
|
|
||||||
{
|
|
||||||
case value_t::string:
|
case value_t::string:
|
||||||
{
|
{
|
||||||
put_char('"');
|
put_char('"');
|
||||||
@@ -649,8 +740,6 @@ class serializer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case value_t::object: // LCOV_EXCL_LINE
|
|
||||||
case value_t::array: // LCOV_EXCL_LINE
|
|
||||||
default: // LCOV_EXCL_LINE
|
default: // LCOV_EXCL_LINE
|
||||||
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
@@ -679,11 +768,11 @@ class serializer
|
|||||||
Escape a string by replacing certain special characters by a sequence of an
|
Escape a string by replacing certain special characters by a sequence of an
|
||||||
escape character (backslash) and another character and other control
|
escape character (backslash) and another character and other control
|
||||||
characters by a sequence of "\u" followed by a four-digit hex
|
characters by a sequence of "\u" followed by a four-digit hex
|
||||||
representation. The escaped string is appended to @ref write_buffer.
|
representation. The escaped string is written to output stream @a o.
|
||||||
|
|
||||||
@param[in] s the string to escape
|
@param[in] s the string to escape
|
||||||
|
|
||||||
Complexity: Linear in the length of string @a s.
|
@complexity Linear in the length of string @a s.
|
||||||
*/
|
*/
|
||||||
void dump_escaped(const string_t& s)
|
void dump_escaped(const string_t& s)
|
||||||
{
|
{
|
||||||
@@ -832,16 +921,6 @@ class serializer
|
|||||||
// EnsureAscii parameter is used, non-ASCII characters
|
// EnsureAscii parameter is used, non-ASCII characters
|
||||||
if ((codepoint <= 0x1F) || (EnsureAscii && (codepoint >= 0x7F)))
|
if ((codepoint <= 0x1F) || (EnsureAscii && (codepoint >= 0x7F)))
|
||||||
{
|
{
|
||||||
if (EnsureAscii && error_handler == error_handler_t::keep)
|
|
||||||
{
|
|
||||||
// this character was buffered as raw bytes
|
|
||||||
// below in case it turned out to be part of
|
|
||||||
// an ill-formed sequence (which is kept as
|
|
||||||
// is); now that it decoded to a well-formed
|
|
||||||
// code point, undo that and \u-escape it
|
|
||||||
// like any other character instead
|
|
||||||
bytes = bytes_after_last_accept;
|
|
||||||
}
|
|
||||||
if (codepoint <= 0xFFFF)
|
if (codepoint <= 0xFFFF)
|
||||||
{
|
{
|
||||||
write_u_escape(bytes, static_cast<std::uint16_t>(codepoint));
|
write_u_escape(bytes, static_cast<std::uint16_t>(codepoint));
|
||||||
@@ -883,7 +962,7 @@ class serializer
|
|||||||
{
|
{
|
||||||
case error_handler_t::strict:
|
case error_handler_t::strict:
|
||||||
{
|
{
|
||||||
JSON_THROW(type_error::create(316, concat("invalid UTF-8 byte at index ", std::to_string(i), ": 0x", detail::hex_byte(byte)), nullptr));
|
JSON_THROW(type_error::create(316, concat("invalid UTF-8 byte at index ", std::to_string(i), ": 0x", hex_bytes(byte | 0)), nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
case error_handler_t::ignore:
|
case error_handler_t::ignore:
|
||||||
@@ -916,9 +995,9 @@ class serializer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string_buffer[bytes++] = '\xEF';
|
string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xEF');
|
||||||
string_buffer[bytes++] = '\xBF';
|
string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBF');
|
||||||
string_buffer[bytes++] = '\xBD';
|
string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBD');
|
||||||
}
|
}
|
||||||
|
|
||||||
// write buffer and reset index; there must be 13 bytes
|
// write buffer and reset index; there must be 13 bytes
|
||||||
@@ -940,44 +1019,6 @@ class serializer
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case error_handler_t::keep:
|
|
||||||
{
|
|
||||||
// the bytes of this (now abandoned) ill-formed
|
|
||||||
// sequence seen so far are already buffered below
|
|
||||||
// and are kept unchanged in the output
|
|
||||||
if (undumped_chars > 0)
|
|
||||||
{
|
|
||||||
// the byte that ended the sequence may be OK
|
|
||||||
// for itself (e.g., a quote that must still be
|
|
||||||
// escaped, or the lead byte of a well-formed
|
|
||||||
// code point), so read it again
|
|
||||||
--i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// a byte that cannot start a sequence (e.g.,
|
|
||||||
// 0xFF or a stray continuation byte) is kept
|
|
||||||
// as well
|
|
||||||
string_buffer[bytes++] = s[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// write buffer and reset index; there must be 13 bytes
|
|
||||||
// left, as this is the maximal number of bytes to be
|
|
||||||
// written ("\uxxxx\uxxxx\0") for one code point
|
|
||||||
if (string_buffer.size() - bytes < 13)
|
|
||||||
{
|
|
||||||
put_buffer(string_buffer, bytes);
|
|
||||||
bytes = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes_after_last_accept = bytes;
|
|
||||||
undumped_chars = 0;
|
|
||||||
|
|
||||||
// continue processing the string
|
|
||||||
state = UTF8_ACCEPT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: // LCOV_EXCL_LINE
|
default: // LCOV_EXCL_LINE
|
||||||
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
@@ -986,12 +1027,9 @@ class serializer
|
|||||||
|
|
||||||
default: // decode found yet incomplete multibyte code point
|
default: // decode found yet incomplete multibyte code point
|
||||||
{
|
{
|
||||||
if (!EnsureAscii || error_handler == error_handler_t::keep)
|
if (!EnsureAscii)
|
||||||
{
|
{
|
||||||
// code point will not be escaped (or will be kept as
|
// code point will not be escaped - copy byte to buffer
|
||||||
// is if it turns out to be ill-formed) - copy byte to
|
|
||||||
// buffer; dropped again above if it decodes to a
|
|
||||||
// well-formed code point that needs \u-escaping
|
|
||||||
string_buffer[bytes++] = s[i];
|
string_buffer[bytes++] = s[i];
|
||||||
}
|
}
|
||||||
++undumped_chars;
|
++undumped_chars;
|
||||||
@@ -1016,7 +1054,7 @@ class serializer
|
|||||||
{
|
{
|
||||||
case error_handler_t::strict:
|
case error_handler_t::strict:
|
||||||
{
|
{
|
||||||
JSON_THROW(type_error::create(316, concat("incomplete UTF-8 string; last byte: 0x", detail::hex_byte(static_cast<std::uint8_t>(s[s.size() - 1]))), nullptr));
|
JSON_THROW(type_error::create(316, concat("incomplete UTF-8 string; last byte: 0x", hex_bytes(static_cast<std::uint8_t>(s[s.size() - 1] | 0))), nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
case error_handler_t::ignore:
|
case error_handler_t::ignore:
|
||||||
@@ -1042,14 +1080,6 @@ class serializer
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case error_handler_t::keep:
|
|
||||||
{
|
|
||||||
// write the ill-formed trailing bytes as is; they were
|
|
||||||
// buffered above regardless of EnsureAscii
|
|
||||||
put_buffer(string_buffer, bytes);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: // LCOV_EXCL_LINE
|
default: // LCOV_EXCL_LINE
|
||||||
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
@@ -1246,7 +1276,21 @@ class serializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief write a lowercase "\\uXXXX" escape sequence into @a string_buffer
|
* @brief convert a byte to a uppercase hex representation
|
||||||
|
* @param[in] byte byte to represent
|
||||||
|
* @return representation ("00".."FF")
|
||||||
|
*/
|
||||||
|
static std::string hex_bytes(std::uint8_t byte)
|
||||||
|
{
|
||||||
|
std::string result = "FF";
|
||||||
|
constexpr const char* nibble_to_hex = "0123456789ABCDEF";
|
||||||
|
result[0] = nibble_to_hex[byte / 16];
|
||||||
|
result[1] = nibble_to_hex[byte % 16];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief write a lowercase "\uXXXX" escape sequence into @a string_buffer
|
||||||
*
|
*
|
||||||
* Branch-free replacement for `snprintf(buf, 7, "\\u%04x", codeunit)` in the
|
* Branch-free replacement for `snprintf(buf, 7, "\\u%04x", codeunit)` in the
|
||||||
* string escaping hot path. It writes exactly six characters ('\\', 'u' and
|
* string escaping hot path. It writes exactly six characters ('\\', 'u' and
|
||||||
@@ -1358,7 +1402,7 @@ class serializer
|
|||||||
/*!
|
/*!
|
||||||
@brief dump an integer
|
@brief dump an integer
|
||||||
|
|
||||||
Dump a given integer, appending it to @ref write_buffer. Works internally with
|
Dump a given integer to output stream @a o. Works internally with
|
||||||
@a number_buffer.
|
@a number_buffer.
|
||||||
|
|
||||||
@param[in] x integer number (signed or unsigned) to dump
|
@param[in] x integer number (signed or unsigned) to dump
|
||||||
@@ -1395,7 +1439,7 @@ class serializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use a pointer to fill the buffer
|
// use a pointer to fill the buffer
|
||||||
auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto)
|
auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||||
|
|
||||||
number_unsigned_t abs_value;
|
number_unsigned_t abs_value;
|
||||||
|
|
||||||
@@ -1449,7 +1493,7 @@ class serializer
|
|||||||
/*!
|
/*!
|
||||||
@brief dump a floating-point number
|
@brief dump a floating-point number
|
||||||
|
|
||||||
Dump a given floating-point number, appending it to @ref write_buffer. Works internally
|
Dump a given floating-point number to output stream @a o. Works internally
|
||||||
with @a number_buffer.
|
with @a number_buffer.
|
||||||
|
|
||||||
@param[in] x floating-point number to dump
|
@param[in] x floating-point number to dump
|
||||||
@@ -1510,28 +1554,21 @@ class serializer
|
|||||||
// check if the buffer was large enough
|
// check if the buffer was large enough
|
||||||
JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size());
|
JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size());
|
||||||
|
|
||||||
// look up the locale's thousands separator and decimal point now,
|
|
||||||
// matching what snprintf_float() just used (see lexer::get_decimal_point())
|
|
||||||
const auto* loc = std::localeconv();
|
|
||||||
JSON_ASSERT(loc != nullptr);
|
|
||||||
const char thousands_sep = (loc->thousands_sep == nullptr) ? '\0' : *loc->thousands_sep;
|
|
||||||
const char decimal_point = (loc->decimal_point == nullptr) ? '\0' : *loc->decimal_point;
|
|
||||||
|
|
||||||
// erase thousands separators
|
// erase thousands separators
|
||||||
if (thousands_sep != '\0')
|
if (locale.thousands_sep != '\0')
|
||||||
{
|
{
|
||||||
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081
|
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081
|
||||||
const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
|
const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, locale.thousands_sep);
|
||||||
std::fill(end, number_buffer.end(), '\0');
|
std::fill(end, number_buffer.end(), '\0');
|
||||||
JSON_ASSERT((end - number_buffer.begin()) <= len);
|
JSON_ASSERT((end - number_buffer.begin()) <= len);
|
||||||
len = (end - number_buffer.begin());
|
len = (end - number_buffer.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert decimal point to '.'
|
// convert decimal point to '.'
|
||||||
if (decimal_point != '\0' && decimal_point != '.')
|
if (locale.decimal_point != '\0' && locale.decimal_point != '.')
|
||||||
{
|
{
|
||||||
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::find returns an iterator, see https://github.com/nlohmann/json/issues/3081
|
// NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::find returns an iterator, see https://github.com/nlohmann/json/issues/3081
|
||||||
const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
|
const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), locale.decimal_point);
|
||||||
if (dec_pos != number_buffer.end())
|
if (dec_pos != number_buffer.end())
|
||||||
{
|
{
|
||||||
*dec_pos = '.';
|
*dec_pos = '.';
|
||||||
@@ -1576,17 +1613,34 @@ class serializer
|
|||||||
*/
|
*/
|
||||||
number_unsigned_t remove_sign(number_integer_t x) noexcept
|
number_unsigned_t remove_sign(number_integer_t x) noexcept
|
||||||
{
|
{
|
||||||
JSON_ASSERT(x < 0);
|
JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)()); // NOLINT(misc-redundant-expression)
|
||||||
return static_cast<number_unsigned_t>(-(x + 1)) + 1;
|
return static_cast<number_unsigned_t>(-(x + 1)) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// the locale's thousand separator and decimal point characters
|
||||||
|
struct locale_chars
|
||||||
|
{
|
||||||
|
explicit locale_chars(const std::lconv* loc) noexcept
|
||||||
|
: thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
|
||||||
|
, decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
|
||||||
|
{}
|
||||||
|
|
||||||
|
const char thousands_sep;
|
||||||
|
const char decimal_point;
|
||||||
|
};
|
||||||
|
|
||||||
/// the output of the serializer (non-owning; the adapter lives at the call site)
|
/// the output of the serializer (non-owning; the adapter lives at the call site)
|
||||||
output_adapter_protocol<char>* o = nullptr;
|
output_adapter_protocol<char>* o = nullptr;
|
||||||
|
|
||||||
/// a (hopefully) large enough character buffer
|
/// a (hopefully) large enough character buffer
|
||||||
std::array<char, 64> number_buffer{{}};
|
std::array<char, 64> number_buffer{{}};
|
||||||
|
|
||||||
|
/// computed once from std::localeconv() at construction; @ref
|
||||||
|
/// locale_chars keeps std::localeconv()'s pointer from having to be held
|
||||||
|
/// past the constructor, while still letting these stay const
|
||||||
|
const locale_chars locale;
|
||||||
|
|
||||||
/// string buffer
|
/// string buffer
|
||||||
std::array<char, 512> string_buffer{{}};
|
std::array<char, 512> string_buffer{{}};
|
||||||
|
|
||||||
@@ -1596,7 +1650,7 @@ class serializer
|
|||||||
/// whether to pretty-print the output
|
/// whether to pretty-print the output
|
||||||
const bool pretty_print;
|
const bool pretty_print;
|
||||||
|
|
||||||
/// whether to escape non-ASCII characters with \\uXXXX sequences
|
/// whether to escape non-ASCII characters with \uXXXX sequences
|
||||||
const bool ensure_ascii;
|
const bool ensure_ascii;
|
||||||
|
|
||||||
/// the indent level
|
/// the indent level
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ inline StringType escape(const StringType& s)
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief string unescaping as described in RFC 6901 (Sect. 4)
|
* @brief string unescaping as described in RFC 6901 (Sect. 4)
|
||||||
* @param[in,out] s string to unescape in place
|
* @param[in] s string to unescape
|
||||||
|
* @return unescaped string
|
||||||
*
|
*
|
||||||
* Note the order of escaping "~1" to "/" and "~0" to "~" is important.
|
* Note the order of escaping "~1" to "/" and "~0" to "~" is important.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// | | |__ | | | | | | version 3.12.0
|
// | | |__ | | | | | | version 3.12.0
|
||||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||||
//
|
//
|
||||||
// SPDX-FileCopyrightText: 2008, 2009 Björn Hoehrmann <bjoern@hoehrmann.de>
|
|
||||||
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
@@ -16,7 +15,6 @@
|
|||||||
|
|
||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
#include <nlohmann/detail/output/error_handler.hpp>
|
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
namespace detail
|
namespace detail
|
||||||
@@ -38,71 +36,6 @@ StringType to_string(std::size_t value)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return a byte as two uppercase hexadecimal digits
|
|
||||||
inline std::string hex_byte(const std::uint8_t byte)
|
|
||||||
{
|
|
||||||
std::string result = "00";
|
|
||||||
constexpr const char* nibble_to_hex = "0123456789ABCDEF";
|
|
||||||
result[0] = nibble_to_hex[byte / 16];
|
|
||||||
result[1] = nibble_to_hex[byte % 16];
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////
|
|
||||||
// UTF-8 encoding //
|
|
||||||
///////////////////
|
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief encode a Unicode code point as UTF-8
|
|
||||||
|
|
||||||
Used to turn a decoded code point back into bytes: by the wide-string input
|
|
||||||
adapters in input_adapters.hpp (one code point per UTF-32 unit, per UTF-16
|
|
||||||
unit outside the surrogate range, and per valid UTF-16 surrogate pair), and
|
|
||||||
by the lexer's `\uXXXX`/`\uXXXX\uYYYY` handling in lexer.hpp. Passing a
|
|
||||||
code point above U+10FFFF, or one in the surrogate range U+D800..U+DFFF, is
|
|
||||||
undefined behavior; callers are expected to have rejected those already
|
|
||||||
(the wide-string adapters pass malformed units through unencoded instead of
|
|
||||||
calling this function, and the lexer rejects unpaired surrogates before
|
|
||||||
reaching it).
|
|
||||||
|
|
||||||
@tparam Out a callable invoked with one byte (as std::uint32_t, 0x00..0xFF)
|
|
||||||
at a time, most significant byte first
|
|
||||||
@param[in] cp the code point to encode (at most U+10FFFF)
|
|
||||||
@param[in] out called once for each byte of the UTF-8 encoding of @a cp
|
|
||||||
*/
|
|
||||||
template<typename Out>
|
|
||||||
void encode_utf8(std::uint32_t cp, Out&& out)
|
|
||||||
{
|
|
||||||
JSON_ASSERT(cp <= 0x10FFFF);
|
|
||||||
|
|
||||||
if (cp < 0x80)
|
|
||||||
{
|
|
||||||
// 1-byte characters: 0xxxxxxx (ASCII)
|
|
||||||
out(cp);
|
|
||||||
}
|
|
||||||
else if (cp <= 0x7FF)
|
|
||||||
{
|
|
||||||
// 2-byte characters: 110xxxxx 10xxxxxx
|
|
||||||
out(0xC0u | (cp >> 6u));
|
|
||||||
out(0x80u | (cp & 0x3Fu));
|
|
||||||
}
|
|
||||||
else if (cp <= 0xFFFF)
|
|
||||||
{
|
|
||||||
// 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
|
|
||||||
out(0xE0u | (cp >> 12u));
|
|
||||||
out(0x80u | ((cp >> 6u) & 0x3Fu));
|
|
||||||
out(0x80u | (cp & 0x3Fu));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
|
||||||
out(0xF0u | (cp >> 18u));
|
|
||||||
out(0x80u | ((cp >> 12u) & 0x3Fu));
|
|
||||||
out(0x80u | ((cp >> 6u) & 0x3Fu));
|
|
||||||
out(0x80u | (cp & 0x3Fu));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// UTF-8 decoding //
|
// UTF-8 decoding //
|
||||||
///////////////////
|
///////////////////
|
||||||
@@ -118,24 +51,11 @@ This is a single-byte step of a "shift-based" UTF-8 decoder originally
|
|||||||
written by Björn Hoehrmann. See
|
written by Björn Hoehrmann. See
|
||||||
http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
|
http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
|
||||||
|
|
||||||
The library checks UTF-8 well-formedness (RFC 3629, section 4) in three
|
This decoder is the single source of truth for UTF-8 validation in this
|
||||||
places, which differ in speed, diagnostics, and how they read the input:
|
library: it is used both by the serializer (to escape and, in strict mode,
|
||||||
|
reject ill-formed UTF-8 when dumping a string) and by the binary readers
|
||||||
- decode() below: the serializer, to escape and, in strict mode, reject
|
(to reject ill-formed UTF-8 in CBOR/MessagePack/BSON/UBJSON text strings at
|
||||||
ill-formed UTF-8 when dumping a string. The CBOR, MessagePack, BSON,
|
decode time; see @ref is_valid_utf8 below).
|
||||||
UBJSON and BJData readers do not use it: none of those specs requires a
|
|
||||||
decoder to reject ill-formed UTF-8 in text strings, so the readers keep
|
|
||||||
the bytes as is and leave the check to dump() and the binary writers.
|
|
||||||
- the per-lead-byte switch in lexer::scan_string(): JSON text, with a
|
|
||||||
diagnostic for each kind of error.
|
|
||||||
- validate_one_utf8() and valid_utf8_prefix() in string_scan.hpp: the lexer's
|
|
||||||
bulk string scan, the bulk path of the BON8 reader, and the BON8 writer.
|
|
||||||
They must accept exactly what the lexer's switch accepts.
|
|
||||||
- the byte path of binary_reader::get_bon8_string(): BON8 input without bulk
|
|
||||||
access, and the bytes the bulk path leaves to it.
|
|
||||||
|
|
||||||
All four must accept the same set of sequences, so a change to one needs a
|
|
||||||
matching change to the others.
|
|
||||||
|
|
||||||
@param[in,out] state the current decoder state
|
@param[in,out] state the current decoder state
|
||||||
@param[in,out] codep codepoint (valid only if resulting state is UTF8_ACCEPT)
|
@param[in,out] codep codepoint (valid only if resulting state is UTF8_ACCEPT)
|
||||||
@@ -181,19 +101,19 @@ inline std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief check a string for well-formed UTF-8 (RFC 3629, section 4)
|
@brief check whether a string consists solely of valid UTF-8
|
||||||
|
|
||||||
Used by the binary readers (CBOR, MessagePack, UBJSON, BJData, BSON) when an
|
Used by the CBOR/MessagePack/BSON/UBJSON binary readers to reject text
|
||||||
@ref error_handler_t other than `keep` is requested for a text string value
|
strings that are not valid UTF-8 at decode time (RFC 8949 §3.1 and the
|
||||||
or object key: none of those formats requires a decoder to reject ill-formed
|
MessagePack/BSON specifications all require text strings to be UTF-8), so
|
||||||
UTF-8 on its own, so the check is opt-in there, unlike the JSON lexer and the
|
that malformed input is caught immediately instead of only surfacing later
|
||||||
serializer's @ref decode -based escaping, which always run it.
|
as a type_error.316 when the resulting value is dumped.
|
||||||
|
|
||||||
@param[in] s the string to check
|
@param[in] s the string to check
|
||||||
@param[in] first the index to start checking at
|
@param[in] first index of the first byte to check; the bytes before it are
|
||||||
@return whether `s.substr(first)` is well-formed UTF-8
|
assumed to have been validated already and to end on a
|
||||||
|
code point boundary
|
||||||
@sa @ref decode
|
@return whether @a s (from index @a first on) is valid UTF-8
|
||||||
*/
|
*/
|
||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
inline bool is_valid_utf8(const StringType& s, const std::size_t first = 0) noexcept
|
inline bool is_valid_utf8(const StringType& s, const std::size_t first = 0) noexcept
|
||||||
@@ -213,101 +133,5 @@ inline bool is_valid_utf8(const StringType& s, const std::size_t first = 0) noex
|
|||||||
return state == UTF8_ACCEPT;
|
return state == UTF8_ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief sanitize a string with ill-formed UTF-8 for @ref error_handler_t::replace or @ref error_handler_t::ignore
|
|
||||||
|
|
||||||
Replaces every maximal ill-formed subsequence with U+FFFD (`replace`) or
|
|
||||||
drops it (`ignore`), using exactly the same boundaries @ref
|
|
||||||
serializer::dump_escaped_impl uses while escaping a string: a byte that does
|
|
||||||
not extend the sequence started by the previous byte(s) is reread as the
|
|
||||||
start of a new one, instead of being swallowed along with them.
|
|
||||||
|
|
||||||
@pre @a error_handler is @ref error_handler_t::replace or @ref error_handler_t::ignore
|
|
||||||
@note Well-formed input is copied through unchanged, including bytes (e.g.
|
|
||||||
control characters or quotes) that @ref serializer::dump_escaped_impl
|
|
||||||
would itself escape; this function only concerns itself with
|
|
||||||
well-formedness, not with producing valid JSON text.
|
|
||||||
|
|
||||||
@param[in] s the string to sanitize
|
|
||||||
@param[in] error_handler @ref error_handler_t::replace or @ref error_handler_t::ignore
|
|
||||||
|
|
||||||
@return @a s with every ill-formed subsequence replaced or removed
|
|
||||||
|
|
||||||
@sa @ref decode
|
|
||||||
*/
|
|
||||||
template<typename StringType>
|
|
||||||
inline StringType sanitize_utf8(const StringType& s, const error_handler_t error_handler)
|
|
||||||
{
|
|
||||||
JSON_ASSERT(error_handler == error_handler_t::replace || error_handler == error_handler_t::ignore);
|
|
||||||
|
|
||||||
StringType result;
|
|
||||||
result.reserve(s.size());
|
|
||||||
|
|
||||||
std::uint32_t codepoint = 0;
|
|
||||||
std::uint8_t state = UTF8_ACCEPT;
|
|
||||||
// length of result after the last accepted code point
|
|
||||||
std::size_t result_len_after_last_accept = 0;
|
|
||||||
// whether bytes of an as yet unresolved sequence were already appended
|
|
||||||
bool pending = false;
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < s.size(); ++i)
|
|
||||||
{
|
|
||||||
switch (decode(state, codepoint, static_cast<std::uint8_t>(s[i])))
|
|
||||||
{
|
|
||||||
case UTF8_ACCEPT: // decode found a well-formed code point
|
|
||||||
{
|
|
||||||
result.push_back(s[i]);
|
|
||||||
result_len_after_last_accept = result.size();
|
|
||||||
pending = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case UTF8_REJECT: // decode found an ill-formed byte
|
|
||||||
{
|
|
||||||
// in case we saw this byte for the first time, read it again,
|
|
||||||
// because it may be fine for itself, just not for the
|
|
||||||
// sequence that came before it
|
|
||||||
if (pending)
|
|
||||||
{
|
|
||||||
--i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// drop the bytes of the ill-formed sequence buffered below
|
|
||||||
result.resize(result_len_after_last_accept);
|
|
||||||
|
|
||||||
if (error_handler == error_handler_t::replace)
|
|
||||||
{
|
|
||||||
result.append("\xEF\xBF\xBD");
|
|
||||||
result_len_after_last_accept = result.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
pending = false;
|
|
||||||
state = UTF8_ACCEPT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: // decode found yet incomplete multibyte code point
|
|
||||||
{
|
|
||||||
result.push_back(s[i]);
|
|
||||||
pending = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// the string ended with an incomplete sequence
|
|
||||||
if (state != UTF8_ACCEPT)
|
|
||||||
{
|
|
||||||
result.resize(result_len_after_last_accept);
|
|
||||||
|
|
||||||
if (error_handler == error_handler_t::replace)
|
|
||||||
{
|
|
||||||
result.append("\xEF\xBF\xBD");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|||||||
+391
-873
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
#include <cstdint> // int64_t, uint64_t
|
#include <cstdint> // int64_t, uint64_t
|
||||||
#include <map> // map
|
#include <map> // map
|
||||||
#include <string> // allocator, string
|
#include <memory> // allocator
|
||||||
|
#include <string> // string
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
|
|
||||||
#include <nlohmann/detail/abi_macros.hpp>
|
#include <nlohmann/detail/abi_macros.hpp>
|
||||||
@@ -31,7 +32,7 @@ This serializer ignores the template arguments and uses ADL
|
|||||||
for serialization.
|
for serialization.
|
||||||
*/
|
*/
|
||||||
template<typename T = void, typename SFINAE = void>
|
template<typename T = void, typename SFINAE = void>
|
||||||
struct adl_serializer; // IWYU pragma: keep
|
struct adl_serializer;
|
||||||
|
|
||||||
/// a class to store JSON values
|
/// a class to store JSON values
|
||||||
/// @sa https://json.nlohmann.me/api/basic_json/
|
/// @sa https://json.nlohmann.me/api/basic_json/
|
||||||
@@ -47,12 +48,12 @@ template<template<typename U, typename V, typename... Args> class ObjectType =
|
|||||||
adl_serializer,
|
adl_serializer,
|
||||||
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
|
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
|
||||||
class CustomBaseClass = void>
|
class CustomBaseClass = void>
|
||||||
class basic_json; // IWYU pragma: keep
|
class basic_json;
|
||||||
|
|
||||||
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
|
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
|
||||||
/// @sa https://json.nlohmann.me/api/json_pointer/
|
/// @sa https://json.nlohmann.me/api/json_pointer/
|
||||||
template<typename RefStringType>
|
template<typename RefStringType>
|
||||||
class json_pointer; // IWYU pragma: keep
|
class json_pointer;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief default specialization
|
@brief default specialization
|
||||||
@@ -63,7 +64,7 @@ using json = basic_json<>;
|
|||||||
/// @brief a minimal map-like container that preserves insertion order
|
/// @brief a minimal map-like container that preserves insertion order
|
||||||
/// @sa https://json.nlohmann.me/api/ordered_map/
|
/// @sa https://json.nlohmann.me/api/ordered_map/
|
||||||
template<class Key, class T, class IgnoredLess, class Allocator>
|
template<class Key, class T, class IgnoredLess, class Allocator>
|
||||||
struct ordered_map; // IWYU pragma: keep
|
struct ordered_map;
|
||||||
|
|
||||||
/// @brief specialization that maintains the insertion order of object keys
|
/// @brief specialization that maintains the insertion order of object keys
|
||||||
/// @sa https://json.nlohmann.me/api/ordered_json/
|
/// @sa https://json.nlohmann.me/api/ordered_json/
|
||||||
|
|||||||
@@ -12,14 +12,13 @@
|
|||||||
#include <functional> // equal_to, less
|
#include <functional> // equal_to, less
|
||||||
#include <initializer_list> // initializer_list
|
#include <initializer_list> // initializer_list
|
||||||
#include <iterator> // input_iterator_tag, iterator_traits
|
#include <iterator> // input_iterator_tag, iterator_traits
|
||||||
#include <new> // for operator new (placement new)
|
#include <memory> // allocator
|
||||||
#include <stdexcept> // for out_of_range
|
#include <stdexcept> // for out_of_range
|
||||||
#include <tuple> // forward_as_tuple
|
#include <tuple> // forward_as_tuple
|
||||||
#include <type_traits> // enable_if, integral_constant, is_convertible, is_nothrow_move_constructible
|
#include <type_traits> // enable_if, integral_constant, is_convertible, is_nothrow_move_constructible
|
||||||
#include <utility> // forward, move, pair, piecewise_construct
|
#include <utility> // forward, move, pair, piecewise_construct
|
||||||
#include <vector> // vector, allocator
|
#include <vector> // vector
|
||||||
|
|
||||||
#include <nlohmann/detail/abi_macros.hpp>
|
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||||
|
|
||||||
|
|||||||
+1973
-2549
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
#include <cstdint> // int64_t, uint64_t
|
#include <cstdint> // int64_t, uint64_t
|
||||||
#include <map> // map
|
#include <map> // map
|
||||||
#include <string> // allocator, string
|
#include <memory> // allocator
|
||||||
|
#include <string> // string
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
|
|
||||||
// #include <nlohmann/detail/abi_macros.hpp>
|
// #include <nlohmann/detail/abi_macros.hpp>
|
||||||
@@ -176,7 +177,7 @@ This serializer ignores the template arguments and uses ADL
|
|||||||
for serialization.
|
for serialization.
|
||||||
*/
|
*/
|
||||||
template<typename T = void, typename SFINAE = void>
|
template<typename T = void, typename SFINAE = void>
|
||||||
struct adl_serializer; // IWYU pragma: keep
|
struct adl_serializer;
|
||||||
|
|
||||||
/// a class to store JSON values
|
/// a class to store JSON values
|
||||||
/// @sa https://json.nlohmann.me/api/basic_json/
|
/// @sa https://json.nlohmann.me/api/basic_json/
|
||||||
@@ -192,12 +193,12 @@ template<template<typename U, typename V, typename... Args> class ObjectType =
|
|||||||
adl_serializer,
|
adl_serializer,
|
||||||
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
|
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
|
||||||
class CustomBaseClass = void>
|
class CustomBaseClass = void>
|
||||||
class basic_json; // IWYU pragma: keep
|
class basic_json;
|
||||||
|
|
||||||
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
|
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
|
||||||
/// @sa https://json.nlohmann.me/api/json_pointer/
|
/// @sa https://json.nlohmann.me/api/json_pointer/
|
||||||
template<typename RefStringType>
|
template<typename RefStringType>
|
||||||
class json_pointer; // IWYU pragma: keep
|
class json_pointer;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief default specialization
|
@brief default specialization
|
||||||
@@ -208,7 +209,7 @@ using json = basic_json<>;
|
|||||||
/// @brief a minimal map-like container that preserves insertion order
|
/// @brief a minimal map-like container that preserves insertion order
|
||||||
/// @sa https://json.nlohmann.me/api/ordered_map/
|
/// @sa https://json.nlohmann.me/api/ordered_map/
|
||||||
template<class Key, class T, class IgnoredLess, class Allocator>
|
template<class Key, class T, class IgnoredLess, class Allocator>
|
||||||
struct ordered_map; // IWYU pragma: keep
|
struct ordered_map;
|
||||||
|
|
||||||
/// @brief specialization that maintains the insertion order of object keys
|
/// @brief specialization that maintains the insertion order of object keys
|
||||||
/// @sa https://json.nlohmann.me/api/ordered_json/
|
/// @sa https://json.nlohmann.me/api/ordered_json/
|
||||||
|
|||||||
+4
-11
@@ -10,6 +10,7 @@ set(JSON_32bitTest AUTO CACHE STRING "Enable the 32bit unit test (ON/OFF/AUT
|
|||||||
set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.")
|
set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.")
|
||||||
|
|
||||||
# using an env var, since this will also affect targets executing cmake (such as "ci_test_compiler_default")
|
# using an env var, since this will also affect targets executing cmake (such as "ci_test_compiler_default")
|
||||||
|
set(JSON_FORCED_GLOBAL_COMPILE_OPTIONS $ENV{JSON_FORCED_GLOBAL_COMPILE_OPTIONS})
|
||||||
if (NOT "" STREQUAL "$ENV{JSON_FORCED_GLOBAL_COMPILE_OPTIONS}")
|
if (NOT "" STREQUAL "$ENV{JSON_FORCED_GLOBAL_COMPILE_OPTIONS}")
|
||||||
add_compile_options($ENV{JSON_FORCED_GLOBAL_COMPILE_OPTIONS})
|
add_compile_options($ENV{JSON_FORCED_GLOBAL_COMPILE_OPTIONS})
|
||||||
endif()
|
endif()
|
||||||
@@ -89,20 +90,15 @@ target_compile_options(test_main PUBLIC
|
|||||||
# https://github.com/nlohmann/json/pull/3229
|
# https://github.com/nlohmann/json/pull/3229
|
||||||
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=2196>
|
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=2196>
|
||||||
|
|
||||||
|
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
|
||||||
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
||||||
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=1786>)
|
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=1786>)
|
||||||
target_include_directories(test_main SYSTEM PUBLIC
|
|
||||||
thirdparty/doctest)
|
|
||||||
target_include_directories(test_main PUBLIC
|
target_include_directories(test_main PUBLIC
|
||||||
|
thirdparty/doctest
|
||||||
|
thirdparty/fifo_map
|
||||||
${PROJECT_BINARY_DIR}/include)
|
${PROJECT_BINARY_DIR}/include)
|
||||||
target_link_libraries(test_main PUBLIC ${NLOHMANN_JSON_TARGET_NAME})
|
target_link_libraries(test_main PUBLIC ${NLOHMANN_JSON_TARGET_NAME})
|
||||||
|
|
||||||
# thirdparty/fifo_map is only used by the #972 regression test, so only
|
|
||||||
# test-regression1 needs it on its include path (see json_test_set_test_options
|
|
||||||
# below), rather than every test-* target via test_main.
|
|
||||||
add_library(fifo_map_include INTERFACE)
|
|
||||||
target_include_directories(fifo_map_include INTERFACE thirdparty/fifo_map)
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# define test- and standard-specific build settings
|
# define test- and standard-specific build settings
|
||||||
#############################################################################
|
#############################################################################
|
||||||
@@ -136,9 +132,6 @@ json_test_set_test_options(test-disabled_exceptions
|
|||||||
# raise timeout of expensive Unicode test
|
# raise timeout of expensive Unicode test
|
||||||
json_test_set_test_options(test-unicode4 TEST_PROPERTIES TIMEOUT 3000)
|
json_test_set_test_options(test-unicode4 TEST_PROPERTIES TIMEOUT 3000)
|
||||||
|
|
||||||
# only the #972 regression test needs thirdparty/fifo_map on its include path
|
|
||||||
json_test_set_test_options(test-regression1 LINK_LIBRARIES fifo_map_include)
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# add unit tests
|
# add unit tests
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ target_compile_options(abi_compat_common INTERFACE
|
|||||||
# https://github.com/nlohmann/json/pull/3229
|
# https://github.com/nlohmann/json/pull/3229
|
||||||
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=2196>
|
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=2196>
|
||||||
|
|
||||||
|
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
|
||||||
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
|
||||||
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=1786>)
|
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=1786>)
|
||||||
target_include_directories(abi_compat_common SYSTEM INTERFACE
|
target_include_directories(abi_compat_common SYSTEM INTERFACE
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ std::string namespace_name(std::string ns, T* /*unused*/ = nullptr) // NOLINT(pe
|
|||||||
std::smatch m;
|
std::smatch m;
|
||||||
|
|
||||||
// extract the true namespace name from the function signature
|
// extract the true namespace name from the function signature
|
||||||
CAPTURE(ns)
|
CAPTURE(ns);
|
||||||
CHECK(std::regex_search(ns, m, std::regex("nlohmann(::[a-zA-Z0-9_]+)*::basic_json")));
|
CHECK(std::regex_search(ns, m, std::regex("nlohmann(::[a-zA-Z0-9_]+)*::basic_json")));
|
||||||
|
|
||||||
return m.str();
|
return m.str();
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
add_test(NAME cmake_add_subdirectory_configure
|
add_test(NAME cmake_add_subdirectory_configure
|
||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-G "${CMAKE_GENERATOR}"
|
-G "${CMAKE_GENERATOR}"
|
||||||
-A "${CMAKE_GENERATOR_PLATFORM}"
|
|
||||||
-T "${CMAKE_GENERATOR_TOOLSET}"
|
|
||||||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||||
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
||||||
-Dnlohmann_json_source=${PROJECT_SOURCE_DIR}
|
-Dnlohmann_json_source=${PROJECT_SOURCE_DIR}
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
add_test(NAME cmake_fetch_content_configure
|
if (${CMAKE_VERSION} VERSION_GREATER "3.11.0")
|
||||||
COMMAND ${CMAKE_COMMAND}
|
add_test(NAME cmake_fetch_content_configure
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-G "${CMAKE_GENERATOR}"
|
-G "${CMAKE_GENERATOR}"
|
||||||
-A "${CMAKE_GENERATOR_PLATFORM}"
|
|
||||||
-T "${CMAKE_GENERATOR_TOOLSET}"
|
|
||||||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||||
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
||||||
|
-Dnlohmann_json_source=${PROJECT_SOURCE_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/project
|
${CMAKE_CURRENT_SOURCE_DIR}/project
|
||||||
)
|
)
|
||||||
add_test(NAME cmake_fetch_content_build
|
add_test(NAME cmake_fetch_content_build
|
||||||
COMMAND ${CMAKE_COMMAND} --build .
|
COMMAND ${CMAKE_COMMAND} --build .
|
||||||
)
|
)
|
||||||
set_tests_properties(cmake_fetch_content_configure PROPERTIES
|
set_tests_properties(cmake_fetch_content_configure PROPERTIES
|
||||||
FIXTURES_SETUP cmake_fetch_content
|
FIXTURES_SETUP cmake_fetch_content
|
||||||
LABELS "git_required;not_reproducible"
|
LABELS "git_required;not_reproducible"
|
||||||
)
|
)
|
||||||
set_tests_properties(cmake_fetch_content_build PROPERTIES
|
set_tests_properties(cmake_fetch_content_build PROPERTIES
|
||||||
FIXTURES_REQUIRED cmake_fetch_content
|
FIXTURES_REQUIRED cmake_fetch_content
|
||||||
LABELS "git_required;not_reproducible"
|
LABELS "git_required;not_reproducible"
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -4,14 +4,6 @@ project(DummyImport CXX)
|
|||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
# This test deliberately covers the pre-3.14 FetchContent_Populate pattern
|
|
||||||
# (see FetchContent_MakeAvailable in ../../cmake_fetch_content2/project for
|
|
||||||
# the 3.14+ alternative), which CMake 3.30 deprecated as CMP0169. Silence the
|
|
||||||
# deprecation warning on purpose instead of switching to the new pattern.
|
|
||||||
if(POLICY CMP0169)
|
|
||||||
cmake_policy(SET CMP0169 OLD)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
get_filename_component(GIT_REPOSITORY_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. ABSOLUTE)
|
get_filename_component(GIT_REPOSITORY_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. ABSOLUTE)
|
||||||
FetchContent_Declare(json GIT_REPOSITORY ${GIT_REPOSITORY_DIRECTORY} GIT_TAG HEAD)
|
FetchContent_Declare(json GIT_REPOSITORY ${GIT_REPOSITORY_DIRECTORY} GIT_TAG HEAD)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14")
|
if (${CMAKE_VERSION} VERSION_GREATER "3.14.0")
|
||||||
add_test(NAME cmake_fetch_content2_configure
|
add_test(NAME cmake_fetch_content2_configure
|
||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-G "${CMAKE_GENERATOR}"
|
-G "${CMAKE_GENERATOR}"
|
||||||
-A "${CMAKE_GENERATOR_PLATFORM}"
|
|
||||||
-T "${CMAKE_GENERATOR_TOOLSET}"
|
|
||||||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||||
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
||||||
|
-Dnlohmann_json_source=${PROJECT_SOURCE_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/project
|
${CMAKE_CURRENT_SOURCE_DIR}/project
|
||||||
)
|
)
|
||||||
add_test(NAME cmake_fetch_content2_build
|
add_test(NAME cmake_fetch_content2_build
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ add_test(NAME cmake_import_configure
|
|||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-G "${CMAKE_GENERATOR}"
|
-G "${CMAKE_GENERATOR}"
|
||||||
-A "${CMAKE_GENERATOR_PLATFORM}"
|
-A "${CMAKE_GENERATOR_PLATFORM}"
|
||||||
-T "${CMAKE_GENERATOR_TOOLSET}"
|
|
||||||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||||
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
||||||
-Dnlohmann_json_DIR=${PROJECT_BINARY_DIR}
|
-Dnlohmann_json_DIR=${PROJECT_BINARY_DIR}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ add_test(NAME cmake_import_minver_configure
|
|||||||
COMMAND ${CMAKE_COMMAND}
|
COMMAND ${CMAKE_COMMAND}
|
||||||
-G "${CMAKE_GENERATOR}"
|
-G "${CMAKE_GENERATOR}"
|
||||||
-A "${CMAKE_GENERATOR_PLATFORM}"
|
-A "${CMAKE_GENERATOR_PLATFORM}"
|
||||||
-T "${CMAKE_GENERATOR_TOOLSET}"
|
|
||||||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||||
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
|
||||||
-Dnlohmann_json_DIR=${PROJECT_BINARY_DIR}
|
-Dnlohmann_json_DIR=${PROJECT_BINARY_DIR}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user