File tree Expand file tree Collapse file tree 5 files changed +35
-0
lines changed
src/ArduinoJson/Strings/Adapters Expand file tree Collapse file tree 5 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 55----
66
77* Optimize storage of tiny strings (up to 3 characters)
8+ * Fix support for ` const char[] ` (issue #2166 )
89
910v7.3.1 (2025-02-27)
1011------
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ add_executable(MiscTests
77 conflicts.cpp
88 issue1967.cpp
99 issue2129.cpp
10+ issue2166.cpp
1011 JsonString.cpp
1112 NoArduinoHeader.cpp
1213 printable.cpp
Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ TEST_CASE("IsString<T>") {
128128 CHECK (IsString<const __FlashStringHelper*>::value == true );
129129 CHECK (IsString<const char *>::value == true );
130130 CHECK (IsString<const char [8 ]>::value == true );
131+ CHECK (IsString<const char []>::value == true );
131132 CHECK (IsString<::String>::value == true );
132133 CHECK (IsString<::StringSumHelper>::value == true );
133134 CHECK (IsString<const EmptyStruct*>::value == false );
Original file line number Diff line number Diff line change 1+ // ArduinoJson - https://arduinojson.org
2+ // Copyright © 2014-2025, Benoit BLANCHON
3+ // MIT License
4+
5+ #include < ArduinoJson.h>
6+ #include < catch.hpp>
7+
8+ struct CCLASS {
9+ static const char mszKey[];
10+ };
11+
12+ TEST_CASE (" Issue #2166" ) {
13+ JsonDocument doc;
14+ doc[CCLASS::mszKey] = 12 ;
15+ REQUIRE (doc.as <std::string>() == " {\" test3\" :12}" );
16+
17+ JsonObject obj = doc.to <JsonObject>();
18+ obj[CCLASS::mszKey] = 12 ;
19+ REQUIRE (doc.as <std::string>() == " {\" test3\" :12}" );
20+ }
21+
22+ const char CCLASS::mszKey[] = " test3" ;
Original file line number Diff line number Diff line change @@ -76,6 +76,16 @@ struct StringAdapter<TChar*, enable_if_t<IsChar<TChar>::value>> {
7676 }
7777};
7878
79+ template <typename TChar>
80+ struct StringAdapter <TChar[], enable_if_t <IsChar<TChar>::value>> {
81+ using AdaptedString = RamString;
82+
83+ static AdaptedString adapt (const TChar* p) {
84+ auto str = reinterpret_cast <const char *>(p);
85+ return AdaptedString (str, str ? ::strlen (str) : 0 );
86+ }
87+ };
88+
7989template <size_t N>
8090struct StringAdapter <const char (&)[N]> {
8191 using AdaptedString = RamString;
You can’t perform that action at this time.
0 commit comments