forked from bblanchon/ArduinoJson
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
f9fe8557f1 | |||
e007d71b4f | |||
67a512a923 | |||
9cf4f3871d | |||
31253dbe13 | |||
1110d62128 | |||
c6c0649d70 | |||
61ec2c4f95 | |||
0dd6231b3f | |||
20219d74f0 | |||
64cbaa6ff7 | |||
2512993617 | |||
48ee4a178b |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -403,7 +403,7 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Install Particle CLI
|
||||
run: sudo npm install -g particle-cli particle-usb
|
||||
run: sudo npm install -g particle-cli
|
||||
- name: Login to Particle
|
||||
run: particle login -t "${{ secrets.PARTICLE_TOKEN }}"
|
||||
- name: Compile
|
||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -61,7 +61,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install
|
||||
run: npm install -g particle-cli particle-usb
|
||||
run: npm install -g particle-cli
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Login
|
||||
|
@ -1,6 +1,13 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v7.2.1 (2024-11-15)
|
||||
------
|
||||
|
||||
* Forbid `deserializeJson(JsonArray|JsonObject, ...)` (issue #2135)
|
||||
* Fix VLA support in `JsonDocument::set()`
|
||||
* Fix `operator[](variant)` ignoring NUL characters
|
||||
|
||||
v7.2.0 (2024-09-18)
|
||||
------
|
||||
|
||||
|
@ -10,7 +10,7 @@ if(ESP_PLATFORM)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(ArduinoJson VERSION 7.2.0)
|
||||
project(ArduinoJson VERSION 7.2.1)
|
||||
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
include(CTest)
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 7.2.0.{build}
|
||||
version: 7.2.1.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
|
||||
|
@ -5,15 +5,18 @@
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_subdirectory(catch)
|
||||
link_libraries(ArduinoJson)
|
||||
|
||||
link_libraries(ArduinoJson catch)
|
||||
# Failing builds should only link with ArduinoJson, not catch
|
||||
add_subdirectory(FailingBuilds)
|
||||
|
||||
add_subdirectory(catch)
|
||||
link_libraries(catch)
|
||||
|
||||
include_directories(Helpers)
|
||||
add_subdirectory(Cpp17)
|
||||
add_subdirectory(Cpp20)
|
||||
add_subdirectory(Deprecated)
|
||||
add_subdirectory(FailingBuilds)
|
||||
add_subdirectory(IntegrationTests)
|
||||
add_subdirectory(JsonArray)
|
||||
add_subdirectory(JsonArrayConst)
|
||||
|
@ -44,13 +44,25 @@ TEST_CASE("JsonDocument::containsKey()") {
|
||||
REQUIRE(doc.containsKey("hello") == false);
|
||||
}
|
||||
|
||||
SECTION("support JsonVariant") {
|
||||
SECTION("supports JsonVariant") {
|
||||
doc["hello"] = "world";
|
||||
doc["key"] = "hello";
|
||||
|
||||
REQUIRE(doc.containsKey(doc["key"]) == true);
|
||||
REQUIRE(doc.containsKey(doc["foo"]) == false);
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("supports VLAs") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
doc["hello"] = "world";
|
||||
|
||||
REQUIRE(doc.containsKey(vla) == true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy::containsKey()") {
|
||||
@ -70,6 +82,18 @@ TEST_CASE("MemberProxy::containsKey()") {
|
||||
REQUIRE(mp.containsKey("key"_s) == true);
|
||||
REQUIRE(mp.containsKey("key"_s) == true);
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("supports VLAs") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
mp["hello"] = "world";
|
||||
|
||||
REQUIRE(mp.containsKey(vla) == true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObject::containsKey()") {
|
||||
@ -175,6 +199,18 @@ TEST_CASE("JsonVariant::containsKey()") {
|
||||
REQUIRE(var.containsKey(doc["key"]) == true);
|
||||
REQUIRE(var.containsKey(doc["foo"]) == false);
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("supports VLAs") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
var["hello"] = "world";
|
||||
|
||||
REQUIRE(var.containsKey(vla) == true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariantConst::containsKey()") {
|
||||
|
@ -2,7 +2,11 @@
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
macro(build_should_fail target)
|
||||
macro(add_failing_build source_file)
|
||||
get_filename_component(target ${source_file} NAME_WE)
|
||||
|
||||
add_executable(${target} ${source_file})
|
||||
|
||||
set_target_properties(${target}
|
||||
PROPERTIES
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
@ -16,21 +20,13 @@ macro(build_should_fail target)
|
||||
set_tests_properties(${target}
|
||||
PROPERTIES
|
||||
WILL_FAIL TRUE
|
||||
LABELS "WillFail;Catch"
|
||||
LABELS "WillFail"
|
||||
)
|
||||
endmacro()
|
||||
|
||||
add_executable(Issue978 Issue978.cpp)
|
||||
build_should_fail(Issue978)
|
||||
|
||||
add_executable(read_long_long read_long_long.cpp)
|
||||
build_should_fail(read_long_long)
|
||||
|
||||
add_executable(write_long_long write_long_long.cpp)
|
||||
build_should_fail(write_long_long)
|
||||
|
||||
add_executable(variant_as_char variant_as_char.cpp)
|
||||
build_should_fail(variant_as_char)
|
||||
|
||||
add_executable(assign_char assign_char.cpp)
|
||||
build_should_fail(assign_char)
|
||||
add_failing_build(Issue978.cpp)
|
||||
add_failing_build(read_long_long.cpp)
|
||||
add_failing_build(write_long_long.cpp)
|
||||
add_failing_build(variant_as_char.cpp)
|
||||
add_failing_build(assign_char.cpp)
|
||||
add_failing_build(deserialize_object.cpp)
|
||||
|
12
extras/tests/FailingBuilds/deserialize_object.cpp
Normal file
12
extras/tests/FailingBuilds/deserialize_object.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
// See issue #2135
|
||||
|
||||
int main() {
|
||||
JsonObject obj;
|
||||
deserializeJson(obj, "");
|
||||
}
|
@ -16,6 +16,7 @@ add_executable(JsonDocumentTests
|
||||
nesting.cpp
|
||||
overflowed.cpp
|
||||
remove.cpp
|
||||
set.cpp
|
||||
shrinkToFit.cpp
|
||||
size.cpp
|
||||
subscript.cpp
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
typedef ArduinoJson::detail::ElementProxy<JsonDocument&> ElementProxy;
|
||||
using ElementProxy = ArduinoJson::detail::ElementProxy<JsonDocument&>;
|
||||
|
||||
TEST_CASE("ElementProxy::add()") {
|
||||
JsonDocument doc;
|
||||
@ -26,13 +26,25 @@ TEST_CASE("ElementProxy::add()") {
|
||||
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
|
||||
}
|
||||
|
||||
SECTION("set(char[])") {
|
||||
SECTION("add(char[])") {
|
||||
char s[] = "world";
|
||||
ep.add(s);
|
||||
strcpy(s, "!!!!!");
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("set(vla)") {
|
||||
size_t i = 8;
|
||||
char vla[i];
|
||||
strcpy(vla, "world");
|
||||
|
||||
ep.add(vla);
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("ElementProxy::clear()") {
|
||||
@ -166,6 +178,18 @@ TEST_CASE("ElementProxy::set()") {
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[\"world\"]");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("set(VLA)") {
|
||||
size_t i = 8;
|
||||
char vla[i];
|
||||
strcpy(vla, "world");
|
||||
|
||||
ep.set(vla);
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[\"world\"]");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("ElementProxy::size()") {
|
||||
@ -205,6 +229,18 @@ TEST_CASE("ElementProxy::operator[]") {
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[null,[null,null,42]]");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("set VLA") {
|
||||
size_t i = 8;
|
||||
char vla[i];
|
||||
strcpy(vla, "world");
|
||||
|
||||
ep[0] = vla;
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[null,[\"world\"]]");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("ElementProxy cast to JsonVariantConst") {
|
||||
|
@ -14,8 +14,8 @@
|
||||
using ArduinoJson::detail::sizeofArray;
|
||||
using ArduinoJson::detail::sizeofObject;
|
||||
|
||||
typedef ArduinoJson::detail::MemberProxy<JsonDocument&, const char*>
|
||||
MemberProxy;
|
||||
using MemberProxy =
|
||||
ArduinoJson::detail::MemberProxy<JsonDocument&, const char*>;
|
||||
|
||||
TEST_CASE("MemberProxy::add()") {
|
||||
JsonDocument doc;
|
||||
@ -32,6 +32,18 @@ TEST_CASE("MemberProxy::add()") {
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":[\"world\"]}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("add(vla)") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "world");
|
||||
|
||||
mp.add(vla);
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":[\"world\"]}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy::clear()") {
|
||||
@ -195,6 +207,18 @@ TEST_CASE("MemberProxy::set()") {
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("set(vla)") {
|
||||
size_t i = 8;
|
||||
char vla[i];
|
||||
strcpy(vla, "world");
|
||||
|
||||
mp.set(vla);
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy::size()") {
|
||||
|
@ -79,6 +79,24 @@ TEST_CASE("JsonDocument::add(T)") {
|
||||
Allocate(sizeofString("example")),
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("VLA") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "example");
|
||||
|
||||
doc.add(vla);
|
||||
doc.add(vla);
|
||||
|
||||
CHECK(doc[0].as<const char*>() == doc[1].as<const char*>());
|
||||
REQUIRE("example"_s == doc[0]);
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("example")),
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonDocument::add<T>()") {
|
||||
|
79
extras/tests/JsonDocument/set.cpp
Normal file
79
extras/tests/JsonDocument/set.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
|
||||
#define ARDUINOJSON_ENABLE_PROGMEM 1
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("JsonDocument::set()") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
|
||||
SECTION("integer") {
|
||||
doc.set(42);
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "42");
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
|
||||
SECTION("const char*") {
|
||||
doc.set("example");
|
||||
|
||||
REQUIRE(doc.as<const char*>() == "example"_s);
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
|
||||
SECTION("std::string") {
|
||||
doc.set("example"_s);
|
||||
|
||||
REQUIRE(doc.as<const char*>() == "example"_s);
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofString("example")),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("char*") {
|
||||
char value[] = "example";
|
||||
doc.set(value);
|
||||
|
||||
REQUIRE(doc.as<const char*>() == "example"_s);
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofString("example")),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("Arduino String") {
|
||||
doc.set(String("example"));
|
||||
|
||||
REQUIRE(doc.as<const char*>() == "example"_s);
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofString("example")),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("Flash string") {
|
||||
doc.set(F("example"));
|
||||
|
||||
REQUIRE(doc.as<const char*>() == "example"_s);
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofString("example")),
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("VLA") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "example");
|
||||
|
||||
doc.set(vla);
|
||||
|
||||
REQUIRE(doc.as<const char*>() == "example"_s);
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofString("example")),
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
@ -12,28 +12,55 @@ TEST_CASE("JsonDocument::operator[]") {
|
||||
const JsonDocument& cdoc = doc;
|
||||
|
||||
SECTION("object") {
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
doc["abc"_s] = "ABC";
|
||||
doc["abc\0d"_s] = "ABCD";
|
||||
|
||||
SECTION("const char*") {
|
||||
REQUIRE(doc["hello"] == "world");
|
||||
REQUIRE(cdoc["hello"] == "world");
|
||||
REQUIRE(doc["abc"] == "ABC");
|
||||
REQUIRE(cdoc["abc"] == "ABC");
|
||||
}
|
||||
|
||||
SECTION("std::string") {
|
||||
REQUIRE(doc["hello"_s] == "world");
|
||||
REQUIRE(cdoc["hello"_s] == "world");
|
||||
REQUIRE(doc["abc"_s] == "ABC");
|
||||
REQUIRE(cdoc["abc"_s] == "ABC");
|
||||
REQUIRE(doc["abc\0d"_s] == "ABCD");
|
||||
REQUIRE(cdoc["abc\0d"_s] == "ABCD");
|
||||
}
|
||||
|
||||
SECTION("JsonVariant") {
|
||||
doc["key"] = "hello";
|
||||
REQUIRE(doc[doc["key"]] == "world");
|
||||
REQUIRE(cdoc[cdoc["key"]] == "world");
|
||||
doc["key1"] = "abc";
|
||||
doc["key2"] = "abc\0d"_s;
|
||||
doc["key3"] = "foo";
|
||||
|
||||
CHECK(doc[doc["key1"]] == "ABC");
|
||||
CHECK(doc[doc["key2"]] == "ABCD");
|
||||
CHECK(doc[doc["key3"]] == nullptr);
|
||||
CHECK(doc[doc["key4"]] == nullptr);
|
||||
|
||||
CHECK(cdoc[cdoc["key1"]] == "ABC");
|
||||
CHECK(cdoc[cdoc["key2"]] == "ABCD");
|
||||
CHECK(cdoc[cdoc["key3"]] == nullptr);
|
||||
CHECK(cdoc[cdoc["key4"]] == nullptr);
|
||||
}
|
||||
|
||||
SECTION("supports operator|") {
|
||||
REQUIRE((doc["hello"] | "nope") == "world"_s);
|
||||
REQUIRE((doc["world"] | "nope") == "nope"_s);
|
||||
REQUIRE((doc["abc"] | "nope") == "ABC"_s);
|
||||
REQUIRE((doc["def"] | "nope") == "nope"_s);
|
||||
}
|
||||
|
||||
#if defined(HAS_VARIABLE_LENGTH_ARRAY) && \
|
||||
!defined(SUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR)
|
||||
SECTION("supports VLAs") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
doc[vla] = "world";
|
||||
|
||||
REQUIRE(doc[vla] == "world");
|
||||
REQUIRE(cdoc[vla] == "world");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("array") {
|
||||
|
@ -253,9 +253,15 @@ TEST_CASE("JsonObject::operator[]") {
|
||||
|
||||
SECTION("JsonVariant") {
|
||||
obj["hello"] = "world";
|
||||
doc["key"] = "hello";
|
||||
obj["a\0b"_s] = "ABC";
|
||||
|
||||
REQUIRE(obj[obj["key"]] == "world");
|
||||
REQUIRE(obj[obj["foo"]] == nullptr);
|
||||
doc["key1"] = "hello";
|
||||
doc["key2"] = "a\0b"_s;
|
||||
doc["key3"] = "foo";
|
||||
|
||||
REQUIRE(obj[obj["key1"]] == "world");
|
||||
REQUIRE(obj[obj["key2"]] == "ABC");
|
||||
REQUIRE(obj[obj["key3"]] == nullptr);
|
||||
REQUIRE(obj[obj["key4"]] == nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
TEST_CASE("JsonObjectConst::operator[]") {
|
||||
JsonDocument doc;
|
||||
doc["hello"] = "world";
|
||||
doc["a\0b"_s] = "ABC";
|
||||
JsonObjectConst obj = doc.as<JsonObjectConst>();
|
||||
|
||||
SECTION("supports const char*") {
|
||||
@ -19,6 +20,7 @@ TEST_CASE("JsonObjectConst::operator[]") {
|
||||
|
||||
SECTION("supports std::string") {
|
||||
REQUIRE(obj["hello"_s] == "world"); // issue #2019
|
||||
REQUIRE(obj["a\0b"_s] == "ABC");
|
||||
}
|
||||
|
||||
#if defined(HAS_VARIABLE_LENGTH_ARRAY) && \
|
||||
@ -28,13 +30,17 @@ TEST_CASE("JsonObjectConst::operator[]") {
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
REQUIRE("world"_s == obj[vla]);
|
||||
REQUIRE(obj[vla] == "world"_s);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("supports JsonVariant") {
|
||||
doc["key"] = "hello";
|
||||
REQUIRE(obj[obj["key"]] == "world");
|
||||
REQUIRE(obj[obj["foo"]] == nullptr);
|
||||
doc["key1"] = "hello";
|
||||
doc["key2"] = "a\0b"_s;
|
||||
doc["key3"] = "foo";
|
||||
REQUIRE(obj[obj["key1"]] == "world");
|
||||
REQUIRE(obj[obj["key2"]] == "ABC");
|
||||
REQUIRE(obj[obj["key3"]] == nullptr);
|
||||
REQUIRE(obj[obj["key4"]] == nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,18 @@ TEST_CASE("JsonVariant::add(T)") {
|
||||
|
||||
REQUIRE(var.as<std::string>() == "{\"val\":123}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("supports VLAs") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
var.add(vla);
|
||||
|
||||
REQUIRE(var.as<std::string>() == "[\"hello\"]");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant::add<T>()") {
|
||||
|
@ -83,6 +83,23 @@ TEST_CASE("JsonVariant::remove(std::string)") {
|
||||
REQUIRE(var.as<std::string>() == "{\"a\":1}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
TEST_CASE("JsonVariant::remove(VLA)") {
|
||||
JsonDocument doc;
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
|
||||
var["a"] = 1;
|
||||
var["b"] = 2;
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "b");
|
||||
|
||||
var.remove("b"_s);
|
||||
|
||||
REQUIRE(var.as<std::string>() == "{\"a\":1}");
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("JsonVariant::remove(JsonVariant) from object") {
|
||||
JsonDocument doc;
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
|
@ -99,7 +99,7 @@ TEST_CASE("vector<int>") {
|
||||
}
|
||||
|
||||
TEST_CASE("array<int, 2>") {
|
||||
typedef std::array<int, 2> array_type;
|
||||
using array_type = std::array<int, 2>;
|
||||
|
||||
SECTION("toJson") {
|
||||
array_type v;
|
||||
|
@ -116,12 +116,19 @@ TEST_CASE("JsonVariant::operator[]") {
|
||||
}
|
||||
|
||||
SECTION("use JsonVariant as key") {
|
||||
object["a"] = "a";
|
||||
object["b"] = "b";
|
||||
object["c"] = "b";
|
||||
object["a"] = "A";
|
||||
object["ab"] = "AB";
|
||||
object["ab\0c"_s] = "ABC";
|
||||
object["key1"] = "a";
|
||||
object["key2"] = "ab";
|
||||
object["key3"] = "ab\0c"_s;
|
||||
object["key4"] = "foo";
|
||||
|
||||
REQUIRE(var[var["c"]] == "b");
|
||||
REQUIRE(var[var["d"]].isNull());
|
||||
REQUIRE(var[var["key1"]] == "A");
|
||||
REQUIRE(var[var["key2"]] == "AB");
|
||||
REQUIRE(var[var["key3"]] == "ABC");
|
||||
REQUIRE(var[var["key4"]].isNull());
|
||||
REQUIRE(var[var["key5"]].isNull());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,20 +50,22 @@ TEST_CASE("JsonVariantConst::operator[]") {
|
||||
|
||||
SECTION("object") {
|
||||
JsonObject object = doc.to<JsonObject>();
|
||||
object["a"] = "A";
|
||||
object["b"] = "B";
|
||||
object["ab"_s] = "AB";
|
||||
object["abc"_s] = "ABC";
|
||||
object["abc\0d"_s] = "ABCD";
|
||||
|
||||
SECTION("supports const char*") {
|
||||
REQUIRE("A"_s == var["a"]);
|
||||
REQUIRE("B"_s == var["b"]);
|
||||
REQUIRE(var["c"].isNull());
|
||||
REQUIRE(var["ab"] == "AB"_s);
|
||||
REQUIRE(var["abc"] == "ABC"_s);
|
||||
REQUIRE(var["def"].isNull());
|
||||
REQUIRE(var[0].isNull());
|
||||
}
|
||||
|
||||
SECTION("supports std::string") {
|
||||
REQUIRE("A"_s == var["a"_s]);
|
||||
REQUIRE("B"_s == var["b"_s]);
|
||||
REQUIRE(var["c"_s].isNull());
|
||||
REQUIRE(var["ab"_s] == "AB"_s);
|
||||
REQUIRE(var["abc"_s] == "ABC"_s);
|
||||
REQUIRE(var["abc\0d"_s] == "ABCD"_s);
|
||||
REQUIRE(var["def"_s].isNull());
|
||||
}
|
||||
|
||||
#if defined(HAS_VARIABLE_LENGTH_ARRAY) && \
|
||||
@ -71,16 +73,23 @@ TEST_CASE("JsonVariantConst::operator[]") {
|
||||
SECTION("supports VLA") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "a");
|
||||
strcpy(vla, "abc");
|
||||
|
||||
REQUIRE("A"_s == var[vla]);
|
||||
REQUIRE(var[vla] == "ABC"_s);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("supports JsonVariant") {
|
||||
object["c"] = "b";
|
||||
REQUIRE(var[var["c"]] == "B");
|
||||
REQUIRE(var[var["d"]].isNull());
|
||||
object["key1"] = "ab";
|
||||
object["key2"] = "abc";
|
||||
object["key3"] = "abc\0d"_s;
|
||||
object["key4"] = "foo";
|
||||
|
||||
REQUIRE(var[var["key1"]] == "AB"_s);
|
||||
REQUIRE(var[var["key2"]] == "ABC"_s);
|
||||
REQUIRE(var[var["key3"]] == "ABCD"_s);
|
||||
REQUIRE(var[var["key4"]].isNull());
|
||||
REQUIRE(var[var["key5"]].isNull());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ add_executable(MiscTests
|
||||
arithmeticCompare.cpp
|
||||
conflicts.cpp
|
||||
issue1967.cpp
|
||||
issue2129.cpp
|
||||
JsonString.cpp
|
||||
NoArduinoHeader.cpp
|
||||
printable.cpp
|
||||
|
@ -12,77 +12,101 @@
|
||||
#include "custom_string.hpp"
|
||||
#include "weird_strcmp.hpp"
|
||||
|
||||
using ArduinoJson::JsonString;
|
||||
using namespace ArduinoJson::detail;
|
||||
|
||||
TEST_CASE("ZeroTerminatedRamString") {
|
||||
SECTION("null") {
|
||||
ZeroTerminatedRamString s = adaptString(static_cast<const char*>(0));
|
||||
TEST_CASE("adaptString()") {
|
||||
SECTION("null const char*") {
|
||||
auto s = adaptString(static_cast<const char*>(0));
|
||||
|
||||
CHECK(s.isNull() == true);
|
||||
CHECK(s.size() == 0);
|
||||
CHECK(s.isLinked() == true);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
ZeroTerminatedRamString s = adaptString("bravo");
|
||||
SECTION("non-null const char*") {
|
||||
auto s = adaptString("bravo");
|
||||
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
CHECK(s.isLinked() == true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SizedRamString") {
|
||||
SECTION("null") {
|
||||
SizedRamString s = adaptString(static_cast<const char*>(0), 10);
|
||||
SECTION("null const char* + size") {
|
||||
auto s = adaptString(static_cast<const char*>(0), 10);
|
||||
|
||||
CHECK(s.isNull() == true);
|
||||
CHECK(s.isLinked() == false);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
SizedRamString s = adaptString("bravo", 5);
|
||||
SECTION("non-null const char* + size") {
|
||||
auto s = adaptString("bravo", 5);
|
||||
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
CHECK(s.isLinked() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("FlashString") {
|
||||
SECTION("null") {
|
||||
FlashString s = adaptString(static_cast<const __FlashStringHelper*>(0));
|
||||
SECTION("null Flash string") {
|
||||
auto s = adaptString(static_cast<const __FlashStringHelper*>(0));
|
||||
|
||||
CHECK(s.isNull() == true);
|
||||
CHECK(s.size() == 0);
|
||||
CHECK(s.isLinked() == false);
|
||||
}
|
||||
|
||||
SECTION("non-null") {
|
||||
FlashString s = adaptString(F("bravo"));
|
||||
SECTION("non-null Flash string") {
|
||||
auto s = adaptString(F("bravo"));
|
||||
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
CHECK(s.isLinked() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("std::string") {
|
||||
std::string orig("bravo");
|
||||
SizedRamString s = adaptString(orig);
|
||||
SECTION("std::string") {
|
||||
std::string orig("bravo");
|
||||
auto s = adaptString(orig);
|
||||
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
}
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
CHECK(s.isLinked() == false);
|
||||
}
|
||||
|
||||
TEST_CASE("Arduino String") {
|
||||
::String orig("bravo");
|
||||
SizedRamString s = adaptString(orig);
|
||||
SECTION("Arduino String") {
|
||||
::String orig("bravo");
|
||||
auto s = adaptString(orig);
|
||||
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
}
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
CHECK(s.isLinked() == false);
|
||||
}
|
||||
|
||||
TEST_CASE("custom_string") {
|
||||
custom_string orig("bravo");
|
||||
SizedRamString s = adaptString(orig);
|
||||
SECTION("custom_string") {
|
||||
custom_string orig("bravo");
|
||||
auto s = adaptString(orig);
|
||||
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
CHECK(s.isLinked() == false);
|
||||
}
|
||||
|
||||
SECTION("JsonString linked") {
|
||||
JsonString orig("hello", JsonString::Ownership::Linked);
|
||||
auto s = adaptString(orig);
|
||||
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
CHECK(s.isLinked() == true);
|
||||
}
|
||||
|
||||
SECTION("JsonString copied") {
|
||||
JsonString orig("hello", JsonString::Ownership::Copied);
|
||||
auto s = adaptString(orig);
|
||||
|
||||
CHECK(s.isNull() == false);
|
||||
CHECK(s.size() == 5);
|
||||
CHECK(s.isLinked() == false);
|
||||
}
|
||||
}
|
||||
|
||||
struct EmptyStruct {};
|
||||
@ -97,6 +121,7 @@ TEST_CASE("IsString<T>") {
|
||||
CHECK(IsString<::String>::value == true);
|
||||
CHECK(IsString<::StringSumHelper>::value == true);
|
||||
CHECK(IsString<const EmptyStruct*>::value == false);
|
||||
CHECK(IsString<JsonString>::value == true);
|
||||
}
|
||||
|
||||
TEST_CASE("stringCompare") {
|
||||
|
@ -8,4 +8,4 @@
|
||||
|
||||
struct custom_char_traits : std::char_traits<char> {};
|
||||
|
||||
typedef std::basic_string<char, custom_char_traits> custom_string;
|
||||
using custom_string = std::basic_string<char, custom_char_traits>;
|
||||
|
55
extras/tests/Misc/issue2129.cpp
Normal file
55
extras/tests/Misc/issue2129.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
template <typename T>
|
||||
class Nullable {
|
||||
public:
|
||||
Nullable() : value_{} {}
|
||||
Nullable(T value) : value_{value} {}
|
||||
|
||||
operator T() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
operator T&() {
|
||||
return value_;
|
||||
}
|
||||
|
||||
bool is_valid() const {
|
||||
return value_ != invalid_value_;
|
||||
}
|
||||
|
||||
T value() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
private:
|
||||
T value_;
|
||||
static T invalid_value_;
|
||||
};
|
||||
|
||||
template <>
|
||||
float Nullable<float>::invalid_value_ = std::numeric_limits<float>::lowest();
|
||||
|
||||
template <typename T>
|
||||
void convertToJson(const Nullable<T>& src, JsonVariant dst) {
|
||||
if (src.is_valid()) {
|
||||
dst.set(src.value());
|
||||
} else {
|
||||
dst.clear();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Issue #2129") {
|
||||
Nullable<float> nullable_value = Nullable<float>{123.4f};
|
||||
|
||||
JsonDocument doc;
|
||||
|
||||
doc["value"] = nullable_value;
|
||||
|
||||
REQUIRE(doc["value"].as<float>() == Approx(123.4f));
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
version: "7.2.0"
|
||||
version: "7.2.1"
|
||||
description: >-
|
||||
A simple and efficient JSON library for embedded C++.
|
||||
⭐ 6690 stars on GitHub!
|
||||
★ 6739 stars on GitHub!
|
||||
Supports serialization, deserialization, MessagePack, streams, filtering, and more.
|
||||
Fully tested and documented.
|
||||
url: https://arduinojson.org/
|
||||
|
@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "ArduinoJson",
|
||||
"keywords": "json, rest, http, web",
|
||||
"description": "A simple and efficient JSON library for embedded C++. ⭐ 6690 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented.",
|
||||
"description": "A simple and efficient JSON library for embedded C++. ⭐ 6739 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented.",
|
||||
"homepage": "https://arduinojson.org/?utm_source=meta&utm_medium=library.json",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bblanchon/ArduinoJson.git"
|
||||
},
|
||||
"version": "7.2.0",
|
||||
"version": "7.2.1",
|
||||
"authors": {
|
||||
"name": "Benoit Blanchon",
|
||||
"url": "https://blog.benoitblanchon.fr"
|
||||
|
@ -1,9 +1,9 @@
|
||||
name=ArduinoJson
|
||||
version=7.2.0
|
||||
version=7.2.1
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=A simple and efficient JSON library for embedded C++.
|
||||
paragraph=⭐ 6690 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented.
|
||||
paragraph=⭐ 6739 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented.
|
||||
category=Data Processing
|
||||
url=https://arduinojson.org/?utm_source=meta&utm_medium=library.properties
|
||||
architectures=*
|
||||
|
@ -17,7 +17,7 @@ class JsonArray : public detail::VariantOperators<JsonArray> {
|
||||
friend class detail::VariantAttorney;
|
||||
|
||||
public:
|
||||
typedef JsonArrayIterator iterator;
|
||||
using iterator = JsonArrayIterator;
|
||||
|
||||
// Constructs an unbound reference.
|
||||
JsonArray() : data_(0), resources_(0) {}
|
||||
|
@ -19,7 +19,7 @@ class JsonArrayConst : public detail::VariantOperators<JsonArrayConst> {
|
||||
friend class detail::VariantAttorney;
|
||||
|
||||
public:
|
||||
typedef JsonArrayConstIterator iterator;
|
||||
using iterator = JsonArrayConstIterator;
|
||||
|
||||
// Returns an iterator to the first element of the array.
|
||||
// https://arduinojson.org/v7/api/jsonarrayconst/begin/
|
||||
|
@ -24,14 +24,10 @@ struct first_or_void<T, Rest...> {
|
||||
|
||||
// A meta-function that returns true if T is a valid destination type for
|
||||
// deserialize()
|
||||
template <class T, class = void>
|
||||
struct is_deserialize_destination : false_type {};
|
||||
|
||||
template <class T>
|
||||
struct is_deserialize_destination<
|
||||
T, enable_if_t<is_same<decltype(VariantAttorney::getResourceManager(
|
||||
detail::declval<T&>())),
|
||||
ResourceManager*>::value>> : true_type {};
|
||||
using is_deserialize_destination =
|
||||
bool_constant<is_base_of<JsonDocument, remove_cv_t<T>>::value ||
|
||||
IsVariant<T>::value>;
|
||||
|
||||
template <typename TDestination>
|
||||
inline void shrinkJsonDocument(TDestination&) {
|
||||
|
@ -142,6 +142,13 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
return to<JsonVariant>().set(src);
|
||||
}
|
||||
|
||||
// Replaces the root with the specified value.
|
||||
// https://arduinojson.org/v7/api/jsondocument/set/
|
||||
template <typename TChar>
|
||||
bool set(TChar* src) {
|
||||
return to<JsonVariant>().set(src);
|
||||
}
|
||||
|
||||
// Clears the document and converts it to the specified type.
|
||||
// https://arduinojson.org/v7/api/jsondocument/to/
|
||||
template <typename T>
|
||||
@ -232,8 +239,8 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
||||
template <typename TVariant>
|
||||
detail::enable_if_t<detail::IsVariant<TVariant>::value, JsonVariantConst>
|
||||
operator[](const TVariant& key) const {
|
||||
if (key.template is<const char*>())
|
||||
return operator[](key.template as<const char*>());
|
||||
if (key.template is<JsonString>())
|
||||
return operator[](key.template as<JsonString>());
|
||||
if (key.template is<size_t>())
|
||||
return operator[](key.template as<size_t>());
|
||||
return {};
|
||||
|
@ -13,7 +13,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <typename TWriter>
|
||||
class PrettyJsonSerializer : public JsonSerializer<TWriter> {
|
||||
typedef JsonSerializer<TWriter> base;
|
||||
using base = JsonSerializer<TWriter>;
|
||||
|
||||
public:
|
||||
PrettyJsonSerializer(TWriter writer, const ResourceManager* resources)
|
||||
|
@ -105,7 +105,7 @@ class TextFormatter {
|
||||
|
||||
template <typename T>
|
||||
enable_if_t<is_signed<T>::value> writeInteger(T value) {
|
||||
typedef make_unsigned_t<T> unsigned_type;
|
||||
using unsigned_type = make_unsigned_t<T>;
|
||||
unsigned_type unsigned_value;
|
||||
if (value < 0) {
|
||||
writeRaw('-');
|
||||
|
@ -20,7 +20,7 @@ struct FloatParts {
|
||||
|
||||
template <typename TFloat>
|
||||
inline int16_t normalize(TFloat& value) {
|
||||
typedef FloatTraits<TFloat> traits;
|
||||
using traits = FloatTraits<TFloat>;
|
||||
int16_t powersOf10 = 0;
|
||||
|
||||
int8_t index = sizeof(TFloat) == 8 ? 8 : 5;
|
||||
|
@ -21,12 +21,12 @@ struct FloatTraits {};
|
||||
|
||||
template <typename T>
|
||||
struct FloatTraits<T, 8 /*64bits*/> {
|
||||
typedef uint64_t mantissa_type;
|
||||
using mantissa_type = uint64_t;
|
||||
static const short mantissa_bits = 52;
|
||||
static const mantissa_type mantissa_max =
|
||||
(mantissa_type(1) << mantissa_bits) - 1;
|
||||
|
||||
typedef int16_t exponent_type;
|
||||
using exponent_type = int16_t;
|
||||
static const exponent_type exponent_max = 308;
|
||||
|
||||
static pgm_ptr<T> positiveBinaryPowersOfTen() {
|
||||
@ -105,12 +105,12 @@ struct FloatTraits<T, 8 /*64bits*/> {
|
||||
|
||||
template <typename T>
|
||||
struct FloatTraits<T, 4 /*32bits*/> {
|
||||
typedef uint32_t mantissa_type;
|
||||
using mantissa_type = uint32_t;
|
||||
static const short mantissa_bits = 23;
|
||||
static const mantissa_type mantissa_max =
|
||||
(mantissa_type(1) << mantissa_bits) - 1;
|
||||
|
||||
typedef int8_t exponent_type;
|
||||
using exponent_type = int8_t;
|
||||
static const exponent_type exponent_max = 38;
|
||||
|
||||
static pgm_ptr<T> positiveBinaryPowersOfTen() {
|
||||
|
@ -10,9 +10,9 @@
|
||||
ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
|
||||
#if ARDUINOJSON_USE_DOUBLE
|
||||
typedef double JsonFloat;
|
||||
using JsonFloat = double;
|
||||
#else
|
||||
typedef float JsonFloat;
|
||||
using JsonFloat = float;
|
||||
#endif
|
||||
|
||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
|
@ -12,11 +12,11 @@
|
||||
ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||
|
||||
#if ARDUINOJSON_USE_LONG_LONG
|
||||
typedef int64_t JsonInteger;
|
||||
typedef uint64_t JsonUInt;
|
||||
using JsonInteger = int64_t;
|
||||
using JsonUInt = uint64_t;
|
||||
#else
|
||||
typedef long JsonInteger;
|
||||
typedef unsigned long JsonUInt;
|
||||
using JsonInteger = long;
|
||||
using JsonUInt = unsigned long;
|
||||
#endif
|
||||
|
||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||
|
@ -103,9 +103,9 @@ class Number {
|
||||
};
|
||||
|
||||
inline Number parseNumber(const char* s) {
|
||||
typedef FloatTraits<JsonFloat> traits;
|
||||
typedef largest_type<traits::mantissa_type, JsonUInt> mantissa_t;
|
||||
typedef traits::exponent_type exponent_t;
|
||||
using traits = FloatTraits<JsonFloat>;
|
||||
using mantissa_t = largest_type<traits::mantissa_type, JsonUInt>;
|
||||
using exponent_t = traits::exponent_type;
|
||||
|
||||
ARDUINOJSON_ASSERT(s != 0);
|
||||
|
||||
|
@ -17,7 +17,7 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
friend class detail::VariantAttorney;
|
||||
|
||||
public:
|
||||
typedef JsonObjectIterator iterator;
|
||||
using iterator = JsonObjectIterator;
|
||||
|
||||
// Creates an unbound reference.
|
||||
JsonObject() : data_(0), resources_(0) {}
|
||||
@ -121,10 +121,10 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
||||
// https://arduinojson.org/v7/api/jsonobject/subscript/
|
||||
template <typename TVariant>
|
||||
detail::enable_if_t<detail::IsVariant<TVariant>::value,
|
||||
detail::MemberProxy<JsonObject, const char*>>
|
||||
detail::MemberProxy<JsonObject, JsonString>>
|
||||
operator[](const TVariant& key) const {
|
||||
if (key.template is<const char*>())
|
||||
return {*this, key.template as<const char*>()};
|
||||
if (key.template is<JsonString>())
|
||||
return {*this, key.template as<JsonString>()};
|
||||
else
|
||||
return {*this, nullptr};
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
||||
friend class detail::VariantAttorney;
|
||||
|
||||
public:
|
||||
typedef JsonObjectConstIterator iterator;
|
||||
using iterator = JsonObjectConstIterator;
|
||||
|
||||
// Creates an unbound reference.
|
||||
JsonObjectConst() : data_(0), resources_(0) {}
|
||||
@ -121,8 +121,8 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
||||
template <typename TVariant>
|
||||
detail::enable_if_t<detail::IsVariant<TVariant>::value, JsonVariantConst>
|
||||
operator[](const TVariant& key) const {
|
||||
if (key.template is<const char*>())
|
||||
return operator[](key.template as<const char*>());
|
||||
if (key.template is<JsonString>())
|
||||
return operator[](key.template as<JsonString>());
|
||||
else
|
||||
return JsonVariantConst();
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ struct uint_;
|
||||
|
||||
template <>
|
||||
struct uint_<8> {
|
||||
typedef uint8_t type;
|
||||
using type = uint8_t;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct uint_<16> {
|
||||
typedef uint16_t type;
|
||||
using type = uint16_t;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct uint_<32> {
|
||||
typedef uint32_t type;
|
||||
using type = uint32_t;
|
||||
};
|
||||
|
||||
template <int Bits>
|
||||
|
@ -10,12 +10,12 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <bool Condition, class TrueType, class FalseType>
|
||||
struct conditional {
|
||||
typedef TrueType type;
|
||||
using type = TrueType;
|
||||
};
|
||||
|
||||
template <class TrueType, class FalseType>
|
||||
struct conditional<false, TrueType, FalseType> {
|
||||
typedef FalseType type;
|
||||
using type = FalseType;
|
||||
};
|
||||
|
||||
template <bool Condition, class TrueType, class FalseType>
|
||||
|
@ -14,7 +14,7 @@ struct enable_if {};
|
||||
|
||||
template <typename T>
|
||||
struct enable_if<true, T> {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <bool Condition, typename T = void>
|
||||
|
@ -13,7 +13,10 @@ struct integral_constant {
|
||||
static const T value = v;
|
||||
};
|
||||
|
||||
typedef integral_constant<bool, true> true_type;
|
||||
typedef integral_constant<bool, false> false_type;
|
||||
template <bool B>
|
||||
using bool_constant = integral_constant<bool, B>;
|
||||
|
||||
using true_type = bool_constant<true>;
|
||||
using false_type = bool_constant<false>;
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
@ -27,7 +27,7 @@ struct is_convertible {
|
||||
static int probe(To);
|
||||
static char probe(...);
|
||||
|
||||
static From& from_;
|
||||
static const From& from_;
|
||||
|
||||
public:
|
||||
static const bool value = sizeof(probe(from_)) == sizeof(int);
|
||||
|
@ -11,11 +11,11 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
// A meta-function that return the type T without the const modifier
|
||||
template <typename T>
|
||||
struct remove_const {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
template <typename T>
|
||||
struct remove_const<const T> {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -10,19 +10,19 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <typename T>
|
||||
struct remove_cv {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
template <typename T>
|
||||
struct remove_cv<const T> {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
template <typename T>
|
||||
struct remove_cv<volatile T> {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
template <typename T>
|
||||
struct remove_cv<const volatile T> {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -11,11 +11,11 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
// A meta-function that return the type T without the reference modifier.
|
||||
template <typename T>
|
||||
struct remove_reference {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
template <typename T>
|
||||
struct remove_reference<T&> {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -10,7 +10,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <typename T>
|
||||
struct type_identity {
|
||||
typedef T type;
|
||||
using type = T;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
@ -74,7 +74,7 @@ class FlashString {
|
||||
|
||||
template <>
|
||||
struct StringAdapter<const __FlashStringHelper*, void> {
|
||||
typedef FlashString AdaptedString;
|
||||
using AdaptedString = FlashString;
|
||||
|
||||
static AdaptedString adapt(const __FlashStringHelper* s) {
|
||||
return AdaptedString(s, s ? strlen_P(reinterpret_cast<const char*>(s)) : 0);
|
||||
@ -83,7 +83,7 @@ struct StringAdapter<const __FlashStringHelper*, void> {
|
||||
|
||||
template <>
|
||||
struct SizedStringAdapter<const __FlashStringHelper*, void> {
|
||||
typedef FlashString AdaptedString;
|
||||
using AdaptedString = FlashString;
|
||||
|
||||
static AdaptedString adapt(const __FlashStringHelper* s, size_t n) {
|
||||
return AdaptedString(s, n);
|
||||
|
@ -25,7 +25,7 @@ class JsonStringAdapter : public SizedRamString {
|
||||
|
||||
template <>
|
||||
struct StringAdapter<JsonString> {
|
||||
typedef JsonStringAdapter AdaptedString;
|
||||
using AdaptedString = JsonStringAdapter;
|
||||
|
||||
static AdaptedString adapt(const JsonString& s) {
|
||||
return AdaptedString(s);
|
||||
|
@ -41,18 +41,6 @@ class ZeroTerminatedRamString {
|
||||
return str_;
|
||||
}
|
||||
|
||||
friend int stringCompare(ZeroTerminatedRamString a,
|
||||
ZeroTerminatedRamString b) {
|
||||
ARDUINOJSON_ASSERT(!a.isNull());
|
||||
ARDUINOJSON_ASSERT(!b.isNull());
|
||||
return ::strcmp(a.str_, b.str_);
|
||||
}
|
||||
|
||||
friend bool stringEquals(ZeroTerminatedRamString a,
|
||||
ZeroTerminatedRamString b) {
|
||||
return stringCompare(a, b) == 0;
|
||||
}
|
||||
|
||||
bool isLinked() const {
|
||||
return false;
|
||||
}
|
||||
@ -63,7 +51,7 @@ class ZeroTerminatedRamString {
|
||||
|
||||
template <typename TChar>
|
||||
struct StringAdapter<TChar*, enable_if_t<IsChar<TChar>::value>> {
|
||||
typedef ZeroTerminatedRamString AdaptedString;
|
||||
using AdaptedString = ZeroTerminatedRamString;
|
||||
|
||||
static AdaptedString adapt(const TChar* p) {
|
||||
return AdaptedString(reinterpret_cast<const char*>(p));
|
||||
@ -72,7 +60,7 @@ struct StringAdapter<TChar*, enable_if_t<IsChar<TChar>::value>> {
|
||||
|
||||
template <typename TChar, size_t N>
|
||||
struct StringAdapter<TChar[N], enable_if_t<IsChar<TChar>::value>> {
|
||||
typedef ZeroTerminatedRamString AdaptedString;
|
||||
using AdaptedString = ZeroTerminatedRamString;
|
||||
|
||||
static AdaptedString adapt(const TChar* p) {
|
||||
return AdaptedString(reinterpret_cast<const char*>(p));
|
||||
@ -90,7 +78,7 @@ class StaticStringAdapter : public ZeroTerminatedRamString {
|
||||
|
||||
template <>
|
||||
struct StringAdapter<const char*, void> {
|
||||
typedef StaticStringAdapter AdaptedString;
|
||||
using AdaptedString = StaticStringAdapter;
|
||||
|
||||
static AdaptedString adapt(const char* p) {
|
||||
return AdaptedString(p);
|
||||
@ -132,7 +120,7 @@ class SizedRamString {
|
||||
|
||||
template <typename TChar>
|
||||
struct SizedStringAdapter<TChar*, enable_if_t<IsChar<TChar>::value>> {
|
||||
typedef SizedRamString AdaptedString;
|
||||
using AdaptedString = SizedRamString;
|
||||
|
||||
static AdaptedString adapt(const TChar* p, size_t n) {
|
||||
return AdaptedString(reinterpret_cast<const char*>(p), n);
|
||||
|
@ -15,7 +15,7 @@ struct StringAdapter<
|
||||
T,
|
||||
enable_if_t<(string_traits<T>::has_cstr || string_traits<T>::has_data) &&
|
||||
(string_traits<T>::has_length || string_traits<T>::has_size)>> {
|
||||
typedef SizedRamString AdaptedString;
|
||||
using AdaptedString = SizedRamString;
|
||||
|
||||
static AdaptedString adapt(const T& s) {
|
||||
return AdaptedString(get_data(s), get_size(s));
|
||||
|
@ -136,7 +136,7 @@ class JsonVariantConst : public detail::VariantTag,
|
||||
if (key.template is<size_t>())
|
||||
return operator[](key.template as<size_t>());
|
||||
else
|
||||
return operator[](key.template as<const char*>());
|
||||
return operator[](key.template as<JsonString>());
|
||||
}
|
||||
|
||||
// DEPRECATED: use obj[key].is<T>() instead
|
||||
|
@ -11,7 +11,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
class JsonVariantCopier {
|
||||
public:
|
||||
typedef bool result_type;
|
||||
using result_type = bool;
|
||||
|
||||
JsonVariantCopier(JsonVariant dst) : dst_(dst) {}
|
||||
|
||||
|
@ -13,7 +13,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <typename TResult>
|
||||
struct JsonVariantVisitor {
|
||||
typedef TResult result_type;
|
||||
using result_type = TResult;
|
||||
|
||||
template <typename T>
|
||||
TResult visit(const T&) {
|
||||
|
@ -13,7 +13,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
|
||||
|
||||
template <typename TResult>
|
||||
struct VariantDataVisitor {
|
||||
typedef TResult result_type;
|
||||
using result_type = TResult;
|
||||
|
||||
template <typename T>
|
||||
TResult visit(const T&) {
|
||||
|
@ -207,7 +207,7 @@ class VariantRefBase : public VariantTag {
|
||||
if (key.template is<size_t>())
|
||||
return operator[](key.template as<size_t>());
|
||||
else
|
||||
return operator[](key.template as<const char*>());
|
||||
return operator[](key.template as<JsonString>());
|
||||
}
|
||||
|
||||
// DEPRECATED: use add<JsonVariant>() instead
|
||||
|
@ -20,15 +20,15 @@ struct VariantTo {};
|
||||
|
||||
template <>
|
||||
struct VariantTo<JsonArray> {
|
||||
typedef JsonArray type;
|
||||
using type = JsonArray;
|
||||
};
|
||||
template <>
|
||||
struct VariantTo<JsonObject> {
|
||||
typedef JsonObject type;
|
||||
using type = JsonObject;
|
||||
};
|
||||
template <>
|
||||
struct VariantTo<JsonVariant> {
|
||||
typedef JsonVariant type;
|
||||
using type = JsonVariant;
|
||||
};
|
||||
|
||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARDUINOJSON_VERSION "7.2.0"
|
||||
#define ARDUINOJSON_VERSION "7.2.1"
|
||||
#define ARDUINOJSON_VERSION_MAJOR 7
|
||||
#define ARDUINOJSON_VERSION_MINOR 2
|
||||
#define ARDUINOJSON_VERSION_REVISION 0
|
||||
#define ARDUINOJSON_VERSION_MACRO V720
|
||||
#define ARDUINOJSON_VERSION_REVISION 1
|
||||
#define ARDUINOJSON_VERSION_MACRO V721
|
||||
|
Reference in New Issue
Block a user