mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-27 01:07:30 +02:00
Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
f82a227da6 | |||
fcd8159617 | |||
f51ccb5c3f | |||
e0cd5b6405 | |||
6a71f31820 | |||
3428ab1e89 | |||
956e4a7cbb | |||
669bad27d4 | |||
2c3ae1c181 | |||
f570fe8c37 | |||
1b74ad0731 | |||
6717700d3b | |||
b810833145 | |||
9d58e566fd | |||
6632fa8da1 | |||
5790f3c8f7 | |||
4073b52c00 | |||
f5c7a6478e | |||
ebf58320ca | |||
09ddb0f824 | |||
f02a699c26 | |||
67d0931c19 | |||
19d079c33c | |||
40723a4cc7 | |||
8a9a26588c |
@ -13,7 +13,8 @@ RUN add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty main' &
|
||||
add-apt-repository -yn 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-6.0 main' && \
|
||||
add-apt-repository -yn 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main' && \
|
||||
add-apt-repository -yn 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main' && \
|
||||
add-apt-repository -yn 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
|
||||
add-apt-repository -yn 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main' && \
|
||||
add-apt-repository -yn 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'
|
||||
|
||||
RUN apt-get update && apt-get -y install \
|
||||
cmake \
|
||||
@ -30,6 +31,7 @@ RUN apt-get update && apt-get -y install \
|
||||
g++-8 \
|
||||
g++-9 \
|
||||
g++-10 \
|
||||
g++-11 \
|
||||
clang-3.5 \
|
||||
clang-3.6 \
|
||||
clang-3.7 \
|
||||
|
@ -12,7 +12,8 @@
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools",
|
||||
"ms-vscode.cpptools"
|
||||
"ms-vscode.cpptools",
|
||||
"xaver.clang-format"
|
||||
],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
|
28
.github/workflows/ci.yml
vendored
28
.github/workflows/ci.yml
vendored
@ -3,22 +3,24 @@ name: Continuous Integration
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
clang-format:
|
||||
name: Clang-Format
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Install
|
||||
run: sudo apt-get install -y clang-format
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Format
|
||||
run: find src/ extras/ -name '*.[ch]pp' | xargs clang-format -i --verbose --style=file
|
||||
- name: Diff
|
||||
run: git diff --exit-code
|
||||
- name: Symlinks
|
||||
run: find * -type l -printf "::error::%p is a symlink. This is forbidden by the Arduino Library Specification." -exec false {} +
|
||||
- name: Clang-format
|
||||
run: |
|
||||
find src/ extras/ -name '*.[ch]pp' | xargs clang-format -i --verbose --style=file
|
||||
git diff --exit-code
|
||||
|
||||
gcc:
|
||||
name: GCC
|
||||
needs: clang-format
|
||||
needs: lint
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@ -38,6 +40,7 @@ jobs:
|
||||
- gcc: "9"
|
||||
cxxflags: -fsanitize=address -fno-sanitize-recover=all
|
||||
- gcc: "10"
|
||||
- gcc: "11"
|
||||
steps:
|
||||
- name: Install
|
||||
run: |
|
||||
@ -47,6 +50,7 @@ jobs:
|
||||
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe'
|
||||
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main'
|
||||
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe'
|
||||
sudo add-apt-repository -yn 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }}
|
||||
- name: Checkout
|
||||
@ -66,7 +70,7 @@ jobs:
|
||||
|
||||
clang:
|
||||
name: Clang
|
||||
needs: clang-format
|
||||
needs: lint
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@ -239,6 +243,9 @@ jobs:
|
||||
- name: Install adafruit-nrfutil
|
||||
if: ${{ matrix.platform == 'nordicnrf52' }}
|
||||
run: pip install adafruit-nrfutil
|
||||
- name: Include Adafruit_TinyUSB.h # https://github.com/adafruit/Adafruit_nRF52_Arduino/issues/653
|
||||
if: ${{ matrix.platform == 'nordicnrf52' }}
|
||||
run: find examples/ -name '*.ino' -exec sed -i 's/\(#include <ArduinoJson.h>\)/\1\n#include <Adafruit_TinyUSB.h>/' {} +
|
||||
- name: Set up cache for platformio
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
@ -470,6 +477,11 @@ jobs:
|
||||
submodules: true
|
||||
- name: Install ESP-IDF
|
||||
run: ./esp-idf/install.sh
|
||||
- name: Add component
|
||||
# NOTE: we cannot commit the symlink because the Arduino Library Specification forbids it.
|
||||
run: |
|
||||
mkdir -p extras/ci/espidf/components
|
||||
ln -s $PWD extras/ci/espidf/components/ArduinoJson
|
||||
- name: Build example
|
||||
run: |
|
||||
source esp-idf/export.sh
|
||||
|
51
.github/workflows/release.yml
vendored
Normal file
51
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*.*.*
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Create release
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Set variables
|
||||
id: init
|
||||
run: |
|
||||
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
|
||||
echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Write release body
|
||||
id: body
|
||||
run: |
|
||||
FILENAME=RELEASE.md
|
||||
extras/scripts/get-release-body.sh ${{ steps.init.outputs.tag }} CHANGELOG.md | tee $FILENAME
|
||||
echo ::set-output name=filename::$FILENAME
|
||||
- name: Amalgamate ArduinoJson.h
|
||||
id: amalgamate_h
|
||||
run: |
|
||||
FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.h
|
||||
extras/scripts/build-single-header.sh src/ArduinoJson.h "$FILENAME"
|
||||
echo ::set-output name=filename::$FILENAME
|
||||
- name: Amalgamate ArduinoJson.hpp
|
||||
id: amalgamate_hpp
|
||||
run: |
|
||||
FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.hpp
|
||||
extras/scripts/build-single-header.sh src/ArduinoJson.hpp "$FILENAME"
|
||||
echo ::set-output name=filename::$FILENAME
|
||||
- name: Create Arduino package
|
||||
id: arduino
|
||||
run: |
|
||||
FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.zip
|
||||
extras/scripts/build-arduino-package.sh . "$FILENAME"
|
||||
echo ::set-output name=filename::$FILENAME
|
||||
- name: Create release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
bodyFile: ${{ steps.body.outputs.filename }}
|
||||
draft: true
|
||||
name: ArduinoJson ${{ steps.init.outputs.version }}
|
||||
artifacts: ${{ steps.amalgamate_h.outputs.filename }},${{ steps.amalgamate_hpp.outputs.filename }},${{ steps.arduino.outputs.filename }}
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
13
.vscode/settings.json
vendored
13
.vscode/settings.json
vendored
@ -4,5 +4,16 @@
|
||||
"git.inputValidationLength": 80,
|
||||
"git.inputValidationSubjectLength": 72,
|
||||
"files.insertFinalNewline": true,
|
||||
"files.trimFinalNewlines": true
|
||||
"files.trimFinalNewlines": true,
|
||||
"files.associations": {
|
||||
"fstream": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"string": "cpp",
|
||||
"system_error": "cpp",
|
||||
"vector": "cpp",
|
||||
"xlocmon": "cpp",
|
||||
"xlocnum": "cpp",
|
||||
"xloctime": "cpp",
|
||||
"xstring": "cpp"
|
||||
}
|
||||
}
|
||||
|
24
CHANGELOG.md
24
CHANGELOG.md
@ -1,6 +1,30 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v6.18.5 (2021-09-28)
|
||||
-------
|
||||
|
||||
* Set `ARDUINOJSON_EMBEDDED_MODE` to `1` on Nios II (issue #1657)
|
||||
|
||||
v6.18.4 (2021-09-06)
|
||||
-------
|
||||
|
||||
* Fixed error `'dummy' may be used uninitialized` on GCC 11
|
||||
* Fixed error `expected unqualified-id before 'const'` on GCC 11 (issue #1622)
|
||||
* Filter: exact match takes precedence over wildcard (issue #1628)
|
||||
* Fixed deserialization of `\u0000` (issue #1646)
|
||||
|
||||
v6.18.3 (2021-07-27)
|
||||
-------
|
||||
|
||||
* Changed return type of `convertToJson()` and `Converter<T>::toJson()` to `void`
|
||||
* Added `as<std::string_view>()` and `is<std::string_view>()`
|
||||
|
||||
v6.18.2 (2021-07-19)
|
||||
-------
|
||||
|
||||
* Removed a symlink because the Arduino Library Specification forbids it
|
||||
|
||||
v6.18.1 (2021-07-03)
|
||||
-------
|
||||
|
||||
|
@ -11,7 +11,7 @@ if(ESP_PLATFORM)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(ArduinoJson VERSION 6.18.1)
|
||||
project(ArduinoJson VERSION 6.18.5)
|
||||
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
include(CTest)
|
||||
|
13
README.md
13
README.md
@ -2,12 +2,17 @@
|
||||
|
||||
---
|
||||
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.18.1)
|
||||
[](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
|
||||
[](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
|
||||
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
[](https://github.com/bblanchon/ArduinoJson/stargazers)
|
||||
|
||||
|
||||
[](https://discord.gg/DzN6hHHD4h)
|
||||
[](https://github.com/bblanchon/ArduinoJson/stargazers)
|
||||
[](https://github.com/sponsors/bblanchon)
|
||||
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.18.5)
|
||||
|
||||
ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||
|
||||
@ -78,7 +83,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
* Continuously tested on
|
||||
* [Visual Studio 2010, 2012, 2013, 2015, 2017, 2019](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
* [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||
* [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8, 9, 10, 11](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||
* [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||
* [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
* Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/)
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 6.18.1.{build}
|
||||
version: 6.18.5.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
|
@ -1 +0,0 @@
|
||||
../../../..
|
@ -1,21 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
TAG=$(git describe)
|
||||
OUTPUT="ArduinoJson-$TAG.zip"
|
||||
set -eu
|
||||
|
||||
cd $(dirname $0)/../../..
|
||||
INPUT=$1
|
||||
OUTPUT=$2
|
||||
|
||||
cd "$INPUT"
|
||||
|
||||
# remove existing file
|
||||
rm -f $OUTPUT
|
||||
rm -f "$OUTPUT"
|
||||
|
||||
# create zip
|
||||
7z a $OUTPUT \
|
||||
-xr!.vs \
|
||||
ArduinoJson/CHANGELOG.md \
|
||||
ArduinoJson/examples \
|
||||
ArduinoJson/src \
|
||||
ArduinoJson/keywords.txt \
|
||||
ArduinoJson/library.properties \
|
||||
ArduinoJson/LICENSE.md \
|
||||
ArduinoJson/README.md \
|
||||
ArduinoJson/ArduinoJson.h
|
||||
7z a "$OUTPUT" \
|
||||
-xr!.vs \
|
||||
CHANGELOG.md \
|
||||
examples \
|
||||
src \
|
||||
keywords.txt \
|
||||
library.properties \
|
||||
LICENSE.md \
|
||||
README.md \
|
||||
ArduinoJson.h
|
||||
|
14
extras/scripts/get-release-body.sh
Executable file
14
extras/scripts/get-release-body.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
TAG="$1"
|
||||
CHANGELOG="$2"
|
||||
|
||||
cat << END
|
||||
## Changes
|
||||
|
||||
$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' "$CHANGELOG")
|
||||
|
||||
[View version history](https://github.com/bblanchon/ArduinoJson/blob/$TAG/CHANGELOG.md)
|
||||
END
|
18
extras/scripts/get-release-page.sh
Executable file
18
extras/scripts/get-release-page.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
VERSION="$1"
|
||||
CHANGELOG="$2"
|
||||
FRONTMATTER="$3"
|
||||
|
||||
cat << END
|
||||
---
|
||||
branch: v6
|
||||
version: $VERSION
|
||||
date: '$(date +'%Y-%m-%d')'
|
||||
$(cat "$FRONTMATTER")
|
||||
---
|
||||
|
||||
$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' "$CHANGELOG")
|
||||
END
|
@ -59,6 +59,10 @@ commit_new_version
|
||||
add_tag
|
||||
push
|
||||
|
||||
extras/scripts/build-arduino-package.sh
|
||||
extras/scripts/build-single-header.sh
|
||||
extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h"
|
||||
extras/scripts/build-arduino-package.sh . "../ArduinoJson-$TAG.zip"
|
||||
extras/scripts/build-single-header.sh "src/ArduinoJson.h" "../ArduinoJson-$TAG.h"
|
||||
extras/scripts/build-single-header.sh "src/ArduinoJson.hpp" "../ArduinoJson-$TAG.hpp"
|
||||
extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG-wandbox.txt"
|
||||
extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG-wandbox.txt" > "../ArduinoJson-$TAG.md"
|
||||
|
||||
echo "You can now copy ../ArduinoJson-$TAG.md into arduinojson.org/collections/_versions/$VERSION.md"
|
||||
|
@ -21,7 +21,7 @@ compile() {
|
||||
END
|
||||
URL=$(curl -sS -H "Content-type: application/json" -d @parameters.json https://wandbox.org/api/compile.json | jq --raw-output .url)
|
||||
rm parameters.json
|
||||
echo " $1: $URL"
|
||||
echo "$1: $URL"
|
||||
}
|
||||
|
||||
compile "JsonGeneratorExample"
|
||||
|
@ -12,6 +12,7 @@ link_libraries(ArduinoJson catch)
|
||||
include_directories(Helpers)
|
||||
add_subdirectory(Cpp11)
|
||||
add_subdirectory(Cpp17)
|
||||
add_subdirectory(Cpp20)
|
||||
add_subdirectory(FailingBuilds)
|
||||
add_subdirectory(IntegrationTests)
|
||||
add_subdirectory(JsonArray)
|
||||
|
@ -29,6 +29,14 @@ TEST_CASE("nullptr") {
|
||||
REQUIRE(variant.isNull());
|
||||
}
|
||||
|
||||
SECTION("JsonVariant.set(nullptr) with unbound reference") {
|
||||
JsonVariant unboundReference;
|
||||
|
||||
unboundReference.set(nullptr);
|
||||
|
||||
REQUIRE(variant.isNull());
|
||||
}
|
||||
|
||||
SECTION("JsonVariant.is<nullptr_t>()") {
|
||||
variant.set(42);
|
||||
REQUIRE(variant.is<std::nullptr_t>() == false);
|
||||
|
@ -58,6 +58,20 @@ TEST_CASE("string_view") {
|
||||
doc.add(std::string_view("example two", 7));
|
||||
REQUIRE(doc.memoryUsage() == JSON_ARRAY_SIZE(2) + 8);
|
||||
}
|
||||
|
||||
SECTION("as<std::string_view>()") {
|
||||
doc["s"] = "Hello World";
|
||||
doc["i"] = 42;
|
||||
REQUIRE(doc["s"].as<std::string_view>() == std::string_view("Hello World"));
|
||||
REQUIRE(doc["i"].as<std::string_view>() == std::string_view());
|
||||
}
|
||||
|
||||
SECTION("is<std::string_view>()") {
|
||||
doc["s"] = "Hello World";
|
||||
doc["i"] = 42;
|
||||
REQUIRE(doc["s"].is<std::string_view>() == true);
|
||||
REQUIRE(doc["i"].is<std::string_view>() == false);
|
||||
}
|
||||
}
|
||||
|
||||
using ARDUINOJSON_NAMESPACE::adaptString;
|
||||
@ -71,9 +85,5 @@ TEST_CASE("StringViewAdapter") {
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
CHECK_FALSE(adapter.equals(NULL));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
29
extras/tests/Cpp20/CMakeLists.txt
Normal file
29
extras/tests/Cpp20/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2021
|
||||
# MIT License
|
||||
|
||||
if(MSVC_VERSION LESS 1910)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_executable(Cpp20Tests
|
||||
smoke_test.cpp
|
||||
)
|
||||
|
||||
add_test(Cpp20 Cpp20Tests)
|
||||
|
||||
set_tests_properties(Cpp20
|
||||
PROPERTIES
|
||||
LABELS "Catch"
|
||||
)
|
15
extras/tests/Cpp20/smoke_test.cpp
Normal file
15
extras/tests/Cpp20/smoke_test.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("C++20 smoke test") {
|
||||
StaticJsonDocument<128> doc;
|
||||
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
REQUIRE(doc["hello"] == "world");
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc, json);
|
||||
REQUIRE(json == "{\"hello\":\"world\"}");
|
||||
}
|
@ -7,73 +7,83 @@
|
||||
|
||||
TEST_CASE("JsonArray::remove()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray _array = doc.to<JsonArray>();
|
||||
_array.add(1);
|
||||
_array.add(2);
|
||||
_array.add(3);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
array.add(1);
|
||||
array.add(2);
|
||||
array.add(3);
|
||||
|
||||
SECTION("RemoveFirstByIndex") {
|
||||
_array.remove(0);
|
||||
SECTION("remove first by index") {
|
||||
array.remove(0);
|
||||
|
||||
REQUIRE(2 == _array.size());
|
||||
REQUIRE(_array[0] == 2);
|
||||
REQUIRE(_array[1] == 3);
|
||||
REQUIRE(2 == array.size());
|
||||
REQUIRE(array[0] == 2);
|
||||
REQUIRE(array[1] == 3);
|
||||
}
|
||||
|
||||
SECTION("RemoveMiddleByIndex") {
|
||||
_array.remove(1);
|
||||
SECTION("remove middle by index") {
|
||||
array.remove(1);
|
||||
|
||||
REQUIRE(2 == _array.size());
|
||||
REQUIRE(_array[0] == 1);
|
||||
REQUIRE(_array[1] == 3);
|
||||
REQUIRE(2 == array.size());
|
||||
REQUIRE(array[0] == 1);
|
||||
REQUIRE(array[1] == 3);
|
||||
}
|
||||
|
||||
SECTION("RemoveLastByIndex") {
|
||||
_array.remove(2);
|
||||
SECTION("remove last by index") {
|
||||
array.remove(2);
|
||||
|
||||
REQUIRE(2 == _array.size());
|
||||
REQUIRE(_array[0] == 1);
|
||||
REQUIRE(_array[1] == 2);
|
||||
REQUIRE(2 == array.size());
|
||||
REQUIRE(array[0] == 1);
|
||||
REQUIRE(array[1] == 2);
|
||||
}
|
||||
|
||||
SECTION("RemoveFirstByIterator") {
|
||||
JsonArray::iterator it = _array.begin();
|
||||
_array.remove(it);
|
||||
SECTION("remove first by iterator") {
|
||||
JsonArray::iterator it = array.begin();
|
||||
array.remove(it);
|
||||
|
||||
REQUIRE(2 == _array.size());
|
||||
REQUIRE(_array[0] == 2);
|
||||
REQUIRE(_array[1] == 3);
|
||||
REQUIRE(2 == array.size());
|
||||
REQUIRE(array[0] == 2);
|
||||
REQUIRE(array[1] == 3);
|
||||
}
|
||||
|
||||
SECTION("RemoveMiddleByIterator") {
|
||||
JsonArray::iterator it = _array.begin();
|
||||
SECTION("remove middle by iterator") {
|
||||
JsonArray::iterator it = array.begin();
|
||||
++it;
|
||||
_array.remove(it);
|
||||
array.remove(it);
|
||||
|
||||
REQUIRE(2 == _array.size());
|
||||
REQUIRE(_array[0] == 1);
|
||||
REQUIRE(_array[1] == 3);
|
||||
REQUIRE(2 == array.size());
|
||||
REQUIRE(array[0] == 1);
|
||||
REQUIRE(array[1] == 3);
|
||||
}
|
||||
|
||||
SECTION("RemoveLastByIterator") {
|
||||
JsonArray::iterator it = _array.begin();
|
||||
SECTION("remove last bty iterator") {
|
||||
JsonArray::iterator it = array.begin();
|
||||
++it;
|
||||
++it;
|
||||
_array.remove(it);
|
||||
array.remove(it);
|
||||
|
||||
REQUIRE(2 == _array.size());
|
||||
REQUIRE(_array[0] == 1);
|
||||
REQUIRE(_array[1] == 2);
|
||||
REQUIRE(2 == array.size());
|
||||
REQUIRE(array[0] == 1);
|
||||
REQUIRE(array[1] == 2);
|
||||
}
|
||||
|
||||
SECTION("In a loop") {
|
||||
for (JsonArray::iterator it = _array.begin(); it != _array.end(); ++it) {
|
||||
for (JsonArray::iterator it = array.begin(); it != array.end(); ++it) {
|
||||
if (*it == 2)
|
||||
_array.remove(it);
|
||||
array.remove(it);
|
||||
}
|
||||
|
||||
REQUIRE(2 == _array.size());
|
||||
REQUIRE(_array[0] == 1);
|
||||
REQUIRE(_array[1] == 3);
|
||||
REQUIRE(2 == array.size());
|
||||
REQUIRE(array[0] == 1);
|
||||
REQUIRE(array[1] == 3);
|
||||
}
|
||||
|
||||
SECTION("remove by index on unbound reference") {
|
||||
JsonArray unboundArray;
|
||||
unboundArray.remove(20);
|
||||
}
|
||||
|
||||
SECTION("remove by iterator on unbound reference") {
|
||||
JsonArray unboundArray;
|
||||
unboundArray.remove(unboundArray.begin());
|
||||
}
|
||||
}
|
||||
|
@ -232,6 +232,15 @@ TEST_CASE("Filtering") {
|
||||
"{\"example\":{\"outcome\":42}}",
|
||||
2 * JSON_OBJECT_SIZE(1) + 16
|
||||
},
|
||||
{
|
||||
// exclusion filter (issue #1628)
|
||||
"{\"example\":1,\"ignored\":2}",
|
||||
"{\"*\":true,\"ignored\":false}",
|
||||
10,
|
||||
DeserializationError::Ok,
|
||||
"{\"example\":1}",
|
||||
JSON_OBJECT_SIZE(1) + 8
|
||||
},
|
||||
{
|
||||
// only the first element of array counts
|
||||
"[1,2,3]",
|
||||
|
@ -46,6 +46,25 @@ TEST_CASE("Valid JSON strings value") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("\\u0000") {
|
||||
StaticJsonDocument<200> doc;
|
||||
|
||||
DeserializationError err = deserializeJson(doc, "\"wx\\u0000yz\"");
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
|
||||
const char* result = doc.as<const char*>();
|
||||
CHECK(result[0] == 'w');
|
||||
CHECK(result[1] == 'x');
|
||||
CHECK(result[2] == 0);
|
||||
CHECK(result[3] == 'y');
|
||||
CHECK(result[4] == 'z');
|
||||
CHECK(result[5] == 0);
|
||||
|
||||
// ArduinoJson strings doesn't store string length, so the following returns 2
|
||||
// instead of 5 (issue #1646)
|
||||
CHECK(doc.as<std::string>().size() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Truncated JSON string") {
|
||||
const char* testCases[] = {"\"hello", "\'hello", "'\\u", "'\\u00", "'\\u000"};
|
||||
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
|
||||
|
@ -70,8 +70,13 @@ TEST_CASE("JsonObject::remove()") {
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("should work on null object") {
|
||||
JsonObject null;
|
||||
null.remove("key");
|
||||
SECTION("remove by key on unbound reference") {
|
||||
JsonObject unboundObject;
|
||||
unboundObject.remove("key");
|
||||
}
|
||||
|
||||
SECTION("remove by iterator on unbound reference") {
|
||||
JsonObject unboundObject;
|
||||
unboundObject.remove(unboundObject.begin());
|
||||
}
|
||||
}
|
||||
|
@ -10,21 +10,37 @@ TEST_CASE("JsonVariant::add()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
|
||||
SECTION("integer") {
|
||||
SECTION("add integer to new variant") {
|
||||
var.add(42);
|
||||
|
||||
REQUIRE(var.as<std::string>() == "[42]");
|
||||
}
|
||||
|
||||
SECTION("const char*") {
|
||||
SECTION("add const char* to new variant") {
|
||||
var.add("hello");
|
||||
|
||||
REQUIRE(var.as<std::string>() == "[\"hello\"]");
|
||||
}
|
||||
|
||||
SECTION("std::string") {
|
||||
SECTION("add std::string to new variant") {
|
||||
var.add(std::string("hello"));
|
||||
|
||||
REQUIRE(var.as<std::string>() == "[\"hello\"]");
|
||||
}
|
||||
|
||||
SECTION("add integer to integer") {
|
||||
var.set(123);
|
||||
|
||||
var.add(456); // no-op
|
||||
|
||||
REQUIRE(var.as<std::string>() == "123");
|
||||
}
|
||||
|
||||
SECTION("add integer to object") {
|
||||
var["val"] = 123;
|
||||
|
||||
var.add(456); // no-op
|
||||
|
||||
REQUIRE(var.as<std::string>() == "{\"val\":123}");
|
||||
}
|
||||
}
|
||||
|
@ -158,6 +158,18 @@ TEST_CASE("Compare JsonVariant with JsonVariant") {
|
||||
CHECK_FALSE(a > b);
|
||||
}
|
||||
|
||||
SECTION("42 vs 42U") {
|
||||
a.set(42);
|
||||
b.set(42U);
|
||||
|
||||
CHECK(a == b);
|
||||
CHECK(a <= b);
|
||||
CHECK(a >= b);
|
||||
CHECK_FALSE(a != b);
|
||||
CHECK_FALSE(a < b);
|
||||
CHECK_FALSE(a > b);
|
||||
}
|
||||
|
||||
SECTION("42 vs 42.0") {
|
||||
a.set(42);
|
||||
b.set(42.0);
|
||||
@ -230,6 +242,30 @@ TEST_CASE("Compare JsonVariant with JsonVariant") {
|
||||
CHECK_FALSE(a == b);
|
||||
}
|
||||
|
||||
SECTION("42U vs 42U") {
|
||||
a.set(42U);
|
||||
b.set(42U);
|
||||
|
||||
CHECK(a == b);
|
||||
CHECK(a <= b);
|
||||
CHECK(a >= b);
|
||||
CHECK_FALSE(a != b);
|
||||
CHECK_FALSE(a < b);
|
||||
CHECK_FALSE(a > b);
|
||||
}
|
||||
|
||||
SECTION("42U vs 42") {
|
||||
a.set(42U);
|
||||
b.set(42);
|
||||
|
||||
CHECK(a == b);
|
||||
CHECK(a <= b);
|
||||
CHECK(a >= b);
|
||||
CHECK_FALSE(a != b);
|
||||
CHECK_FALSE(a < b);
|
||||
CHECK_FALSE(a > b);
|
||||
}
|
||||
|
||||
SECTION("[1] vs [1]") {
|
||||
a.add(1);
|
||||
b.add(1);
|
||||
|
@ -13,11 +13,10 @@ struct Date {
|
||||
int year;
|
||||
};
|
||||
|
||||
bool convertToJson(const Date& src, JsonVariant dst) {
|
||||
void convertToJson(const Date& src, JsonVariant dst) {
|
||||
dst["day"] = src.day;
|
||||
dst["month"] = src.month;
|
||||
dst["year"] = src.year;
|
||||
return true;
|
||||
}
|
||||
|
||||
void convertFromJson(JsonVariantConst src, Date& dst) {
|
||||
@ -92,10 +91,9 @@ class Complex {
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
template <>
|
||||
struct Converter<Complex> {
|
||||
static bool toJson(const Complex& src, VariantRef dst) {
|
||||
static void toJson(const Complex& src, VariantRef dst) {
|
||||
dst["real"] = src.real();
|
||||
dst["imag"] = src.imag();
|
||||
return true;
|
||||
}
|
||||
|
||||
static Complex fromJson(VariantConstRef src) {
|
||||
|
@ -83,4 +83,13 @@ TEST_CASE("JsonVariant::set(JsonVariant)") {
|
||||
REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(7));
|
||||
REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(7));
|
||||
}
|
||||
|
||||
SECTION("destination is unbound") {
|
||||
JsonVariant unboundVariant;
|
||||
|
||||
unboundVariant.set(var1);
|
||||
|
||||
REQUIRE(unboundVariant.isUndefined());
|
||||
REQUIRE(unboundVariant.isNull());
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,15 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
REQUIRE(1 == var[0].size());
|
||||
REQUIRE(std::string("world") == var[0]["hello"]);
|
||||
}
|
||||
|
||||
SECTION("variant[0] when variant contains an integer") {
|
||||
var.set(123);
|
||||
|
||||
var[0] = 345; // no-op
|
||||
|
||||
REQUIRE(var.is<int>());
|
||||
REQUIRE(var.as<int>() == 123);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("The JsonVariant is a JsonObject") {
|
||||
|
@ -2,146 +2,118 @@
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_ENABLE_PROGMEM 1
|
||||
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
|
||||
|
||||
#include "custom_string.hpp"
|
||||
#include "progmem_emulation.hpp"
|
||||
#include "weird_strcmp.hpp"
|
||||
|
||||
#include <ArduinoJson/Strings/ArduinoStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/FlashStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/SizedRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/StdStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("ConstRamStringAdapter") {
|
||||
TEST_CASE("const char*") {
|
||||
SECTION("null") {
|
||||
ConstRamStringAdapter adapter(NULL);
|
||||
StringAdapter<const char*> adapter(NULL);
|
||||
|
||||
CHECK(adapter.compare("bravo") < 0);
|
||||
CHECK(adapter.compare(NULL) == 0);
|
||||
|
||||
CHECK(adapter.equals(NULL));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
ConstRamStringAdapter adapter("bravo");
|
||||
StringAdapter<const char*> adapter("bravo");
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SizedRamStringAdapter") {
|
||||
TEST_CASE("const char* + size") {
|
||||
SECTION("null") {
|
||||
SizedRamStringAdapter adapter(NULL, 10);
|
||||
StringAdapter<const char*, true> adapter(NULL, 10);
|
||||
|
||||
CHECK(adapter.compare("bravo") < 0);
|
||||
CHECK(adapter.compare(NULL) == 0);
|
||||
|
||||
CHECK(adapter.equals(NULL));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 10);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
SizedRamStringAdapter adapter("bravo", 5);
|
||||
StringAdapter<const char*, true> adapter("bravo", 5);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("FlashStringAdapter") {
|
||||
TEST_CASE("const __FlashStringHelper*") {
|
||||
SECTION("null") {
|
||||
FlashStringAdapter adapter(NULL);
|
||||
StringAdapter<const __FlashStringHelper*> adapter(NULL);
|
||||
|
||||
CHECK(adapter.compare("bravo") < 0);
|
||||
CHECK(adapter.compare(NULL) == 0);
|
||||
|
||||
CHECK(adapter.equals(NULL));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
FlashStringAdapter adapter = adaptString(F("bravo"));
|
||||
StringAdapter<const __FlashStringHelper*> adapter = adaptString(F("bravo"));
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("std::string") {
|
||||
std::string str("bravo");
|
||||
StdStringAdapter<std::string> adapter = adaptString(str);
|
||||
StringAdapter<std::string> adapter(str);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("Arduino String") {
|
||||
::String str("bravo");
|
||||
ArduinoStringAdapter adapter = adaptString(str);
|
||||
StringAdapter< ::String> adapter(str);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("custom_string") {
|
||||
custom_string str("bravo");
|
||||
StdStringAdapter<custom_string> adapter = adaptString(str);
|
||||
StringAdapter<custom_string> adapter(str);
|
||||
|
||||
CHECK(adapter.compare(NULL) > 0);
|
||||
CHECK(adapter.compare("alpha") > 0);
|
||||
CHECK(adapter.compare("bravo") == 0);
|
||||
CHECK(adapter.compare("charlie") < 0);
|
||||
|
||||
CHECK(adapter.equals("bravo"));
|
||||
CHECK_FALSE(adapter.equals("charlie"));
|
||||
|
||||
CHECK(adapter.size() == 5);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,11 @@ static size_t print(StringWriter& writer, const char* s) {
|
||||
return writer.write(reinterpret_cast<const uint8_t*>(s), strlen(s));
|
||||
}
|
||||
|
||||
template <typename StringWriter>
|
||||
static size_t print(StringWriter& writer, char c) {
|
||||
return writer.write(static_cast<uint8_t>(c));
|
||||
}
|
||||
|
||||
template <typename StringWriter, typename String>
|
||||
void common_tests(StringWriter& writer, const String& output) {
|
||||
SECTION("InitialState") {
|
||||
@ -47,6 +52,7 @@ TEST_CASE("StaticStringWriter") {
|
||||
SECTION("OverCapacity") {
|
||||
REQUIRE(20 == print(writer, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
||||
REQUIRE(0 == print(writer, "ABC"));
|
||||
REQUIRE(0 == print(writer, 'D'));
|
||||
REQUIRE("ABCDEFGHIJKLMNOPQRST" == std::string(output, 20));
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/bblanchon/ArduinoJson.git"
|
||||
},
|
||||
"version": "6.18.1",
|
||||
"version": "6.18.5",
|
||||
"authors": {
|
||||
"name": "Benoit Blanchon",
|
||||
"url": "https://blog.benoitblanchon.fr"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ArduinoJson
|
||||
version=6.18.1
|
||||
version=6.18.5
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=A simple and efficient JSON library for embedded C++.
|
||||
|
@ -173,8 +173,8 @@ class ArrayRef : public ArrayRefBase<CollectionData>,
|
||||
|
||||
template <>
|
||||
struct Converter<ArrayConstRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ArrayConstRef fromJson(VariantConstRef src) {
|
||||
@ -189,8 +189,8 @@ struct Converter<ArrayConstRef> {
|
||||
|
||||
template <>
|
||||
struct Converter<ArrayRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ArrayRef fromJson(VariantRef src) {
|
||||
|
@ -178,8 +178,8 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
||||
return _array.getOrAddElement(_index);
|
||||
}
|
||||
|
||||
friend bool convertToJson(const this_type& src, VariantRef dst) {
|
||||
return dst.set(src.getUpstreamElement());
|
||||
friend void convertToJson(const this_type& src, VariantRef dst) {
|
||||
dst.set(src.getUpstreamElement());
|
||||
}
|
||||
|
||||
TArray _array;
|
||||
|
@ -62,9 +62,9 @@ inline bool CollectionData::copyFrom(const CollectionData& src,
|
||||
VariantData* var;
|
||||
if (s->key() != 0) {
|
||||
if (s->ownsKey())
|
||||
var = addMember(RamStringAdapter(s->key()), pool);
|
||||
var = addMember(adaptString(const_cast<char*>(s->key())), pool);
|
||||
else
|
||||
var = addMember(ConstRamStringAdapter(s->key()), pool);
|
||||
var = addMember(adaptString(s->key()), pool);
|
||||
} else {
|
||||
var = addElement(pool);
|
||||
}
|
||||
@ -107,7 +107,7 @@ template <typename TAdaptedString>
|
||||
inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const {
|
||||
VariantSlot* slot = _head;
|
||||
while (slot) {
|
||||
if (key.equals(slot->key()))
|
||||
if (key.compare(slot->key()) == 0)
|
||||
break;
|
||||
slot = slot->next();
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
|| defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \
|
||||
|| defined(__XC) /* MPLAB XC compiler */ \
|
||||
|| defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \
|
||||
|| defined(__NIOS2__) /* Altera Nios II EDS */ \
|
||||
|| defined(__AVR) /* Atmel AVR8/GNU C Compiler */
|
||||
# define ARDUINOJSON_EMBEDDED_MODE 1
|
||||
# else
|
||||
|
@ -32,8 +32,8 @@ class Filter {
|
||||
Filter operator[](const TKey& key) const {
|
||||
if (_variant == true) // "true" means "allow recursively"
|
||||
return *this;
|
||||
else
|
||||
return Filter(_variant[key] | _variant["*"]);
|
||||
VariantConstRef member = _variant[key];
|
||||
return Filter(member.isNull() ? _variant["*"] : member);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -17,7 +17,7 @@ struct Reader {
|
||||
Reader(TSource& source) : _source(&source) {}
|
||||
|
||||
int read() {
|
||||
return _source->read();
|
||||
return _source->read(); // Error here? You passed an unsupported input type
|
||||
}
|
||||
|
||||
size_t readBytes(char* buffer, size_t length) {
|
||||
|
@ -337,8 +337,8 @@ class JsonDocument : public Visitable {
|
||||
JsonDocument& operator=(const JsonDocument&);
|
||||
};
|
||||
|
||||
inline bool convertToJson(const JsonDocument& src, VariantRef dst) {
|
||||
return dst.set(src.as<VariantConstRef>());
|
||||
inline void convertToJson(const JsonDocument& src, VariantRef dst) {
|
||||
dst.set(src.as<VariantConstRef>());
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -13,14 +13,14 @@ template <typename TStringBuilder>
|
||||
inline void encodeCodepoint(uint32_t codepoint32, TStringBuilder& str) {
|
||||
// this function was optimize for code size on AVR
|
||||
|
||||
// a buffer to store the string in reverse
|
||||
char buf[5];
|
||||
char* p = buf;
|
||||
|
||||
*(p++) = 0;
|
||||
if (codepoint32 < 0x80) {
|
||||
*(p++) = char((codepoint32));
|
||||
str.append(char(codepoint32));
|
||||
} else {
|
||||
// a buffer to store the string in reverse
|
||||
char buf[5];
|
||||
char* p = buf;
|
||||
|
||||
*(p++) = 0;
|
||||
*(p++) = char((codepoint32 | 0x80) & 0xBF);
|
||||
uint16_t codepoint16 = uint16_t(codepoint32 >> 6);
|
||||
if (codepoint16 < 0x20) { // 0x800
|
||||
@ -36,10 +36,10 @@ inline void encodeCodepoint(uint32_t codepoint32, TStringBuilder& str) {
|
||||
*(p++) = char(codepoint16 | 0xF0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (*(--p)) {
|
||||
str.append(*p);
|
||||
while (*(--p)) {
|
||||
str.append(*p);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Utf8
|
||||
|
@ -167,7 +167,7 @@ class MemoryPool {
|
||||
template <typename TAdaptedString>
|
||||
const char* findString(const TAdaptedString& str) {
|
||||
for (char* next = _begin; next < _left; ++next) {
|
||||
if (str.equals(next))
|
||||
if (str.compare(next) == 0)
|
||||
return next;
|
||||
|
||||
// jump to next terminator
|
||||
|
@ -187,8 +187,8 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return _object.getOrAddMember(_key);
|
||||
}
|
||||
|
||||
friend bool convertToJson(const this_type &src, VariantRef dst) {
|
||||
return dst.set(src.getUpstreamMember());
|
||||
friend void convertToJson(const this_type &src, VariantRef dst) {
|
||||
dst.set(src.getUpstreamMember());
|
||||
}
|
||||
|
||||
TObject _object;
|
||||
|
@ -239,8 +239,8 @@ class ObjectRef : public ObjectRefBase<CollectionData>,
|
||||
|
||||
template <>
|
||||
struct Converter<ObjectConstRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ObjectConstRef fromJson(VariantConstRef src) {
|
||||
@ -255,8 +255,8 @@ struct Converter<ObjectConstRef> {
|
||||
|
||||
template <>
|
||||
struct Converter<ObjectRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ObjectRef fromJson(VariantRef src) {
|
||||
|
@ -20,5 +20,6 @@
|
||||
#include "type_traits/is_signed.hpp"
|
||||
#include "type_traits/is_unsigned.hpp"
|
||||
#include "type_traits/make_unsigned.hpp"
|
||||
#include "type_traits/make_void.hpp"
|
||||
#include "type_traits/remove_const.hpp"
|
||||
#include "type_traits/remove_reference.hpp"
|
||||
|
14
src/ArduinoJson/Polyfills/type_traits/make_void.hpp
Normal file
14
src/ArduinoJson/Polyfills/type_traits/make_void.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <class = void>
|
||||
struct make_void {
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -7,14 +7,15 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class ArduinoStringAdapter {
|
||||
template <>
|
||||
class StringAdapter< ::String> {
|
||||
public:
|
||||
ArduinoStringAdapter(const ::String& str) : _str(&str) {}
|
||||
StringAdapter(const ::String& str) : _str(&str) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str->c_str(), n);
|
||||
@ -31,10 +32,6 @@ class ArduinoStringAdapter {
|
||||
return safe_strcmp(me, other);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _str->length();
|
||||
}
|
||||
@ -46,13 +43,9 @@ class ArduinoStringAdapter {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString< ::String> : true_type {};
|
||||
|
||||
template <>
|
||||
struct IsString< ::StringSumHelper> : true_type {};
|
||||
|
||||
inline ArduinoStringAdapter adaptString(const ::String& str) {
|
||||
return ArduinoStringAdapter(str);
|
||||
}
|
||||
class StringAdapter< ::StringSumHelper> : public StringAdapter< ::String> {
|
||||
public:
|
||||
StringAdapter(const ::String& s) : StringAdapter< ::String>(s) {}
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -8,23 +8,20 @@
|
||||
#include <string.h> // strcmp
|
||||
|
||||
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class ConstRamStringAdapter {
|
||||
template <>
|
||||
class StringAdapter<const char*> {
|
||||
public:
|
||||
ConstRamStringAdapter(const char* str = 0) : _str(str) {}
|
||||
StringAdapter(const char* str = 0) : _str(str) {}
|
||||
|
||||
int compare(const char* other) const {
|
||||
return safe_strcmp(_str, other);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
}
|
||||
@ -45,14 +42,10 @@ class ConstRamStringAdapter {
|
||||
const char* _str;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<const char*> : true_type {};
|
||||
|
||||
template <int N>
|
||||
struct IsString<const char[N]> : true_type {};
|
||||
|
||||
inline ConstRamStringAdapter adaptString(const char* str) {
|
||||
return ConstRamStringAdapter(str);
|
||||
}
|
||||
class StringAdapter<const char[N]> : public StringAdapter<const char*> {
|
||||
public:
|
||||
StringAdapter(const char* s) : StringAdapter<const char*>(s) {}
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,14 +5,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/pgmspace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class FlashStringAdapter {
|
||||
template <>
|
||||
class StringAdapter<const __FlashStringHelper*> {
|
||||
public:
|
||||
FlashStringAdapter(const __FlashStringHelper* str) : _str(str) {}
|
||||
StringAdapter(const __FlashStringHelper* str) : _str(str) {}
|
||||
|
||||
int compare(const char* other) const {
|
||||
if (!other && !_str)
|
||||
@ -24,10 +25,6 @@ class FlashStringAdapter {
|
||||
return -strcmp_P(other, reinterpret_cast<const char*>(_str));
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
}
|
||||
@ -48,10 +45,4 @@ class FlashStringAdapter {
|
||||
const __FlashStringHelper* _str;
|
||||
};
|
||||
|
||||
inline FlashStringAdapter adaptString(const __FlashStringHelper* str) {
|
||||
return FlashStringAdapter(str);
|
||||
}
|
||||
|
||||
template <>
|
||||
struct IsString<const __FlashStringHelper*> : true_type {};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
27
src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp
Normal file
27
src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/Adapters/RamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/String.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <>
|
||||
class StringAdapter<String> : public StringAdapter<char*> {
|
||||
public:
|
||||
StringAdapter(const String& str)
|
||||
: StringAdapter<char*>(str.c_str()), _isStatic(str.isStatic()) {}
|
||||
|
||||
bool isStatic() const {
|
||||
return _isStatic;
|
||||
}
|
||||
|
||||
typedef storage_policies::decide_at_runtime storage_policy;
|
||||
|
||||
private:
|
||||
bool _isStatic;
|
||||
};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
29
src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp
Normal file
29
src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename TChar>
|
||||
class StringAdapter<TChar*, false,
|
||||
typename enable_if<sizeof(TChar) == 1 &&
|
||||
!is_same<TChar, void>::value>::type>
|
||||
: public StringAdapter<const char*> {
|
||||
public:
|
||||
StringAdapter(const TChar* str)
|
||||
: StringAdapter<const char*>(reinterpret_cast<const char*>(str)) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str, n);
|
||||
}
|
||||
|
||||
typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,14 +5,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class SizedFlashStringAdapter {
|
||||
template <>
|
||||
class StringAdapter<const __FlashStringHelper*, true> {
|
||||
public:
|
||||
SizedFlashStringAdapter(const __FlashStringHelper* str, size_t sz)
|
||||
StringAdapter(const __FlashStringHelper* str, size_t sz)
|
||||
: _str(str), _size(sz) {}
|
||||
|
||||
int compare(const char* other) const {
|
||||
@ -25,10 +26,6 @@ class SizedFlashStringAdapter {
|
||||
return -strncmp_P(other, reinterpret_cast<const char*>(_str), _size);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
}
|
||||
@ -48,8 +45,4 @@ class SizedFlashStringAdapter {
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
inline SizedFlashStringAdapter adaptString(const __FlashStringHelper* str,
|
||||
size_t sz) {
|
||||
return SizedFlashStringAdapter(str, sz);
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,25 +5,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
#include <string.h> // strcmp
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class SizedRamStringAdapter {
|
||||
template <typename TChar>
|
||||
class StringAdapter<TChar*, true> {
|
||||
public:
|
||||
SizedRamStringAdapter(const char* str, size_t n) : _str(str), _size(n) {}
|
||||
StringAdapter(const char* str, size_t n) : _str(str), _size(n) {}
|
||||
|
||||
int compare(const char* other) const {
|
||||
return safe_strncmp(_str, other, _size);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
return compare(expected) == 0;
|
||||
}
|
||||
|
||||
bool isNull() const {
|
||||
return !_str;
|
||||
}
|
||||
@ -43,9 +40,4 @@ class SizedRamStringAdapter {
|
||||
size_t _size;
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
inline SizedRamStringAdapter adaptString(const TChar* str, size_t size) {
|
||||
return SizedRamStringAdapter(reinterpret_cast<const char*>(str), size);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,17 +5,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename TString>
|
||||
class StdStringAdapter {
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
class StringAdapter<std::basic_string<char, TCharTraits, TAllocator> > {
|
||||
public:
|
||||
StdStringAdapter(const TString& str) : _str(&str) {}
|
||||
typedef std::basic_string<char, TCharTraits, TAllocator> string_type;
|
||||
|
||||
StringAdapter(const string_type& str) : _str(&str) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str->c_str(), n);
|
||||
@ -31,12 +33,6 @@ class StdStringAdapter {
|
||||
return _str->compare(other);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
if (!expected)
|
||||
return false;
|
||||
return *_str == expected;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _str->size();
|
||||
}
|
||||
@ -44,18 +40,7 @@ class StdStringAdapter {
|
||||
typedef storage_policies::store_by_copy storage_policy;
|
||||
|
||||
private:
|
||||
const TString* _str;
|
||||
const string_type* _str;
|
||||
};
|
||||
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
struct IsString<std::basic_string<char, TCharTraits, TAllocator> > : true_type {
|
||||
};
|
||||
|
||||
template <typename TCharTraits, typename TAllocator>
|
||||
inline StdStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >
|
||||
adaptString(const std::basic_string<char, TCharTraits, TAllocator>& str) {
|
||||
return StdStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >(
|
||||
str);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -5,16 +5,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Namespace.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class StringViewAdapter {
|
||||
template <>
|
||||
class StringAdapter<std::string_view> {
|
||||
public:
|
||||
StringViewAdapter(std::string_view str) : _str(str) {}
|
||||
StringAdapter(std::string_view str) : _str(str) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str.data(), n);
|
||||
@ -30,12 +31,6 @@ class StringViewAdapter {
|
||||
return _str.compare(other);
|
||||
}
|
||||
|
||||
bool equals(const char* expected) const {
|
||||
if (!expected)
|
||||
return false;
|
||||
return _str == expected;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return _str.size();
|
||||
}
|
||||
@ -46,11 +41,4 @@ class StringViewAdapter {
|
||||
std::string_view _str;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<std::string_view> : true_type {};
|
||||
|
||||
inline StringViewAdapter adaptString(const std::string_view& str) {
|
||||
return StringViewAdapter(str);
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -1,18 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
template <typename>
|
||||
struct IsString : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<const T> : IsString<T> {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<T&> : IsString<T> {};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -1,43 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class RamStringAdapter : public ConstRamStringAdapter {
|
||||
public:
|
||||
RamStringAdapter(const char* str) : ConstRamStringAdapter(str) {}
|
||||
|
||||
void copyTo(char* p, size_t n) const {
|
||||
memcpy(p, _str, n);
|
||||
}
|
||||
|
||||
typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy;
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
inline RamStringAdapter adaptString(const TChar* str) {
|
||||
return RamStringAdapter(reinterpret_cast<const char*>(str));
|
||||
}
|
||||
|
||||
inline RamStringAdapter adaptString(char* str) {
|
||||
return RamStringAdapter(str);
|
||||
}
|
||||
|
||||
template <typename TChar>
|
||||
struct IsString<TChar*> {
|
||||
static const bool value = sizeof(TChar) == 1;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<void*> {
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -4,10 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class String {
|
||||
@ -53,25 +49,4 @@ class String {
|
||||
bool _isStatic;
|
||||
};
|
||||
|
||||
class StringAdapter : public RamStringAdapter {
|
||||
public:
|
||||
StringAdapter(const String& str)
|
||||
: RamStringAdapter(str.c_str()), _isStatic(str.isStatic()) {}
|
||||
|
||||
bool isStatic() const {
|
||||
return _isStatic;
|
||||
}
|
||||
|
||||
typedef storage_policies::decide_at_runtime storage_policy;
|
||||
|
||||
private:
|
||||
bool _isStatic;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct IsString<String> : true_type {};
|
||||
|
||||
inline StringAdapter adaptString(const String& str) {
|
||||
return StringAdapter(str);
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
32
src/ArduinoJson/Strings/StringAdapter.hpp
Normal file
32
src/ArduinoJson/Strings/StringAdapter.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename T, bool bounded = false, typename Enable = void>
|
||||
class StringAdapter;
|
||||
|
||||
template <typename T>
|
||||
inline StringAdapter<T, false> adaptString(const T& str) {
|
||||
return StringAdapter<T, false>(str);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline StringAdapter<T, true> adaptString(const T& str, size_t sz) {
|
||||
return StringAdapter<T, true>(str, sz);
|
||||
}
|
||||
|
||||
template <typename T, typename Enable = void>
|
||||
struct IsString : false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct IsString<
|
||||
T, typename make_void<typename StringAdapter<T>::storage_policy>::type>
|
||||
: true_type {};
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
@ -4,23 +4,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/RamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/SizedRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/Adapters/RamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp>
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STD_STRING
|
||||
# include <ArduinoJson/Strings/StdStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/StdStringAdapter.hpp>
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STRING_VIEW
|
||||
# include <ArduinoJson/Strings/StringViewAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/StringViewAdapter.hpp>
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_ARDUINO_STRING
|
||||
# include <ArduinoJson/Strings/ArduinoStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/ArduinoStringAdapter.hpp>
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_PROGMEM
|
||||
# include <ArduinoJson/Strings/FlashStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/SizedFlashStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/FlashStringAdapter.hpp>
|
||||
# include <ArduinoJson/Strings/Adapters/SizedFlashStringAdapter.hpp>
|
||||
#endif
|
||||
|
@ -12,9 +12,9 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
template <typename T, typename Enable>
|
||||
struct Converter {
|
||||
static bool toJson(const T& src, VariantRef dst) {
|
||||
static void toJson(const T& src, VariantRef dst) {
|
||||
// clang-format off
|
||||
return convertToJson(src, dst); // Error here? See https://arduinojson.org/v6/unsupported-set/
|
||||
convertToJson(src, dst); // Error here? See https://arduinojson.org/v6/unsupported-set/
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ struct Converter {
|
||||
}
|
||||
|
||||
static bool checkJson(VariantConstRef src) {
|
||||
T dummy;
|
||||
T dummy = T();
|
||||
// clang-format off
|
||||
return canConvertFromJson(src, dummy); // Error here? See https://arduinojson.org/v6/unsupported-is/
|
||||
// clang-format on
|
||||
@ -38,13 +38,11 @@ template <typename T>
|
||||
struct Converter<
|
||||
T, typename enable_if<is_integral<T>::value && !is_same<bool, T>::value &&
|
||||
!is_same<char, T>::value>::type> {
|
||||
static bool toJson(T src, VariantRef dst) {
|
||||
static void toJson(T src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T);
|
||||
if (!data)
|
||||
return false;
|
||||
data->setInteger(src);
|
||||
return true;
|
||||
if (data)
|
||||
data->setInteger(src);
|
||||
}
|
||||
|
||||
static T fromJson(VariantConstRef src) {
|
||||
@ -61,8 +59,8 @@ struct Converter<
|
||||
|
||||
template <typename T>
|
||||
struct Converter<T, typename enable_if<is_enum<T>::value>::type> {
|
||||
static bool toJson(T src, VariantRef dst) {
|
||||
return dst.set(static_cast<Integer>(src));
|
||||
static void toJson(T src, VariantRef dst) {
|
||||
dst.set(static_cast<Integer>(src));
|
||||
}
|
||||
|
||||
static T fromJson(VariantConstRef src) {
|
||||
@ -78,12 +76,10 @@ struct Converter<T, typename enable_if<is_enum<T>::value>::type> {
|
||||
|
||||
template <>
|
||||
struct Converter<bool> {
|
||||
static bool toJson(bool src, VariantRef dst) {
|
||||
static void toJson(bool src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
if (!data)
|
||||
return false;
|
||||
data->setBoolean(src);
|
||||
return true;
|
||||
if (data)
|
||||
data->setBoolean(src);
|
||||
}
|
||||
|
||||
static bool fromJson(VariantConstRef src) {
|
||||
@ -99,12 +95,10 @@ struct Converter<bool> {
|
||||
|
||||
template <typename T>
|
||||
struct Converter<T, typename enable_if<is_floating_point<T>::value>::type> {
|
||||
static bool toJson(T src, VariantRef dst) {
|
||||
static void toJson(T src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
if (!data)
|
||||
return false;
|
||||
data->setFloat(static_cast<Float>(src));
|
||||
return true;
|
||||
if (data)
|
||||
data->setFloat(static_cast<Float>(src));
|
||||
}
|
||||
|
||||
static T fromJson(VariantConstRef src) {
|
||||
@ -120,8 +114,8 @@ struct Converter<T, typename enable_if<is_floating_point<T>::value>::type> {
|
||||
|
||||
template <>
|
||||
struct Converter<const char*> {
|
||||
static bool toJson(const char* src, VariantRef dst) {
|
||||
return variantSetString(getData(dst), adaptString(src), getPool(dst));
|
||||
static void toJson(const char* src, VariantRef dst) {
|
||||
variantSetString(getData(dst), adaptString(src), getPool(dst));
|
||||
}
|
||||
|
||||
static const char* fromJson(VariantConstRef src) {
|
||||
@ -163,12 +157,10 @@ canConvertFromJson(VariantConstRef src, const T&) {
|
||||
|
||||
template <>
|
||||
struct Converter<SerializedValue<const char*> > {
|
||||
static bool toJson(SerializedValue<const char*> src, VariantRef dst) {
|
||||
static void toJson(SerializedValue<const char*> src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
if (!data)
|
||||
return false;
|
||||
data->setLinkedRaw(src);
|
||||
return true;
|
||||
if (data)
|
||||
data->setLinkedRaw(src);
|
||||
}
|
||||
};
|
||||
|
||||
@ -178,10 +170,11 @@ struct Converter<SerializedValue<const char*> > {
|
||||
template <typename T>
|
||||
struct Converter<SerializedValue<T>,
|
||||
typename enable_if<!is_same<const char*, T>::value>::type> {
|
||||
static bool toJson(SerializedValue<T> src, VariantRef dst) {
|
||||
static void toJson(SerializedValue<T> src, VariantRef dst) {
|
||||
VariantData* data = getData(dst);
|
||||
MemoryPool* pool = getPool(dst);
|
||||
return data != 0 && data->setOwnedRaw(src, pool);
|
||||
if (data)
|
||||
data->setOwnedRaw(src, pool);
|
||||
}
|
||||
};
|
||||
|
||||
@ -189,9 +182,8 @@ struct Converter<SerializedValue<T>,
|
||||
|
||||
template <>
|
||||
struct Converter<decltype(nullptr)> {
|
||||
static bool toJson(decltype(nullptr), VariantRef dst) {
|
||||
static void toJson(decltype(nullptr), VariantRef dst) {
|
||||
variantSetNull(getData(dst));
|
||||
return true;
|
||||
}
|
||||
static decltype(nullptr) fromJson(VariantConstRef) {
|
||||
return nullptr;
|
||||
@ -247,20 +239,33 @@ class MemoryPoolPrint : public Print {
|
||||
size_t _capacity;
|
||||
};
|
||||
|
||||
inline bool convertToJson(const ::Printable& src, VariantRef dst) {
|
||||
inline void convertToJson(const ::Printable& src, VariantRef dst) {
|
||||
MemoryPool* pool = getPool(dst);
|
||||
VariantData* data = getData(dst);
|
||||
if (!pool || !data)
|
||||
return false;
|
||||
return;
|
||||
MemoryPoolPrint print(pool);
|
||||
src.printTo(print);
|
||||
if (print.overflowed()) {
|
||||
pool->markAsOverflowed();
|
||||
data->setNull();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
data->setStringPointer(print.c_str(), storage_policies::store_by_copy());
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_STRING_VIEW
|
||||
|
||||
inline void convertFromJson(VariantConstRef src, std::string_view& dst) {
|
||||
const char* str = src.as<const char*>();
|
||||
if (str) // the standard doesn't allow passing null to the constructor
|
||||
dst = std::string_view(str);
|
||||
}
|
||||
|
||||
inline bool canConvertFromJson(VariantConstRef src, const std::string_view&) {
|
||||
return src.is<const char*>();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <ArduinoJson/Misc/Visitable.hpp>
|
||||
#include <ArduinoJson/Numbers/arithmeticCompare.hpp>
|
||||
#include <ArduinoJson/Polyfills/type_traits.hpp>
|
||||
#include <ArduinoJson/Strings/IsString.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapter.hpp>
|
||||
#include <ArduinoJson/Variant/Visitor.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
//
|
||||
enum {
|
||||
VALUE_MASK = 0x7F,
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Misc/SerializedValue.hpp>
|
||||
#include <ArduinoJson/Numbers/convertNumber.hpp>
|
||||
#include <ArduinoJson/Strings/RamStringAdapter.hpp>
|
||||
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
||||
#include <ArduinoJson/Variant/VariantContent.hpp>
|
||||
|
||||
// VariantData can't have a constructor (to be a POD), so we have no way to fix
|
||||
@ -103,7 +103,8 @@ class VariantData {
|
||||
case VALUE_IS_OBJECT:
|
||||
return toObject().copyFrom(src._content.asCollection, pool);
|
||||
case VALUE_IS_OWNED_STRING:
|
||||
return setString(RamStringAdapter(src._content.asString), pool);
|
||||
return setString(adaptString(const_cast<char *>(src._content.asString)),
|
||||
pool);
|
||||
case VALUE_IS_OWNED_RAW:
|
||||
return setOwnedRaw(
|
||||
serialized(src._content.asRaw.data, src._content.asRaw.size), pool);
|
||||
|
@ -85,7 +85,8 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(const T &value) const {
|
||||
return Converter<T>::toJson(value, *this);
|
||||
Converter<T>::toJson(value, *this);
|
||||
return _pool && !_pool->overflowed();
|
||||
}
|
||||
|
||||
bool ARDUINOJSON_DEPRECATED(
|
||||
@ -94,7 +95,8 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(T *value) const {
|
||||
return Converter<T *>::toJson(value, *this);
|
||||
Converter<T *>::toJson(value, *this);
|
||||
return _pool && !_pool->overflowed();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -339,8 +341,8 @@ class VariantConstRef : public VariantRefBase<const VariantData>,
|
||||
|
||||
template <>
|
||||
struct Converter<VariantRef> {
|
||||
static bool toJson(VariantRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static VariantRef fromJson(VariantRef src) {
|
||||
@ -362,8 +364,8 @@ struct Converter<VariantRef> {
|
||||
|
||||
template <>
|
||||
struct Converter<VariantConstRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static VariantConstRef fromJson(VariantConstRef src) {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARDUINOJSON_VERSION "6.18.1"
|
||||
#define ARDUINOJSON_VERSION "6.18.5"
|
||||
#define ARDUINOJSON_VERSION_MAJOR 6
|
||||
#define ARDUINOJSON_VERSION_MINOR 18
|
||||
#define ARDUINOJSON_VERSION_REVISION 1
|
||||
#define ARDUINOJSON_VERSION_REVISION 5
|
||||
|
Reference in New Issue
Block a user