mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-06-25 01:11:35 +02:00
@ -5,6 +5,7 @@ HEAD
|
||||
----
|
||||
|
||||
* Optimize storage of tiny strings (up to 3 characters)
|
||||
* Fix support for `const char[]` (issue #2166)
|
||||
|
||||
v7.3.1 (2025-02-27)
|
||||
------
|
||||
|
@ -7,6 +7,7 @@ add_executable(MiscTests
|
||||
conflicts.cpp
|
||||
issue1967.cpp
|
||||
issue2129.cpp
|
||||
issue2166.cpp
|
||||
JsonString.cpp
|
||||
NoArduinoHeader.cpp
|
||||
printable.cpp
|
||||
|
@ -128,6 +128,7 @@ TEST_CASE("IsString<T>") {
|
||||
CHECK(IsString<const __FlashStringHelper*>::value == true);
|
||||
CHECK(IsString<const char*>::value == true);
|
||||
CHECK(IsString<const char[8]>::value == true);
|
||||
CHECK(IsString<const char[]>::value == true);
|
||||
CHECK(IsString<::String>::value == true);
|
||||
CHECK(IsString<::StringSumHelper>::value == true);
|
||||
CHECK(IsString<const EmptyStruct*>::value == false);
|
||||
|
22
extras/tests/Misc/issue2166.cpp
Normal file
22
extras/tests/Misc/issue2166.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2025, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
struct CCLASS {
|
||||
static const char mszKey[];
|
||||
};
|
||||
|
||||
TEST_CASE("Issue #2166") {
|
||||
JsonDocument doc;
|
||||
doc[CCLASS::mszKey] = 12;
|
||||
REQUIRE(doc.as<std::string>() == "{\"test3\":12}");
|
||||
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj[CCLASS::mszKey] = 12;
|
||||
REQUIRE(doc.as<std::string>() == "{\"test3\":12}");
|
||||
}
|
||||
|
||||
const char CCLASS::mszKey[] = "test3";
|
@ -76,6 +76,16 @@ struct StringAdapter<TChar*, enable_if_t<IsChar<TChar>::value>> {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TChar>
|
||||
struct StringAdapter<TChar[], enable_if_t<IsChar<TChar>::value>> {
|
||||
using AdaptedString = RamString;
|
||||
|
||||
static AdaptedString adapt(const TChar* p) {
|
||||
auto str = reinterpret_cast<const char*>(p);
|
||||
return AdaptedString(str, str ? ::strlen(str) : 0);
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t N>
|
||||
struct StringAdapter<const char (&)[N]> {
|
||||
using AdaptedString = RamString;
|
||||
|
Reference in New Issue
Block a user