File tree Expand file tree Collapse file tree 7 files changed +10
-7
lines changed
Expand file tree Collapse file tree 7 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 77* Fix support for NUL characters in ` deserializeJson() `
88* Make ` ElementProxy ` and ` MemberProxy ` non-copyable
99* Change string copy policy: only string literal are stored by pointer
10+ * ` JsonString ` is now stored by copy, unless specified otherwise
1011
1112> ### BREAKING CHANGES
1213>
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ TEST_CASE("JsonString") {
9696 JsonString s (" hello world" , 5 );
9797
9898 CHECK (s.size () == 5 );
99- CHECK (s.isLinked () == true );
99+ CHECK (s.isLinked () == false );
100100 CHECK (s == " hello" );
101101 CHECK (s != " hello world" );
102102 }
Original file line number Diff line number Diff line change @@ -139,7 +139,8 @@ TEST_CASE("serialize MsgPack value") {
139139
140140 SECTION (" str 32" ) {
141141 std::string shortest (65536 , ' ?' );
142- checkVariant (JsonString (shortest.c_str (), true ), // force store by pointer
142+ checkVariant (JsonString (shortest.c_str (),
143+ JsonString::Linked), // force store by pointer
143144 " \xDB\x00\x01\x00\x00 " _s + shortest);
144145 }
145146
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ class MsgPackSerializer : public VariantDataVisitor<size_t> {
9696 }
9797
9898 size_t visit (JsonString value) {
99- ARDUINOJSON_ASSERT (value != NULL );
99+ ARDUINOJSON_ASSERT (!value. isNull () );
100100
101101 auto n = value.size ();
102102
Original file line number Diff line number Diff line change @@ -22,10 +22,10 @@ class JsonString {
2222
2323 JsonString () : str_(nullptr , 0 , true ) {}
2424
25- JsonString (const char * data, Ownership ownership = Linked )
25+ JsonString (const char * data, Ownership ownership = Copied )
2626 : str_(data, data ? ::strlen(data) : 0 , ownership == Linked) {}
2727
28- JsonString (const char * data, size_t sz, Ownership ownership = Linked )
28+ JsonString (const char * data, size_t sz, Ownership ownership = Copied )
2929 : str_(data, sz, ownership == Linked) {}
3030
3131 // Returns a pointer to the characters.
Original file line number Diff line number Diff line change @@ -178,7 +178,7 @@ struct Converter<JsonString> : private detail::VariantAttorney {
178178
179179 static JsonString fromJson (JsonVariantConst src) {
180180 auto data = getData (src);
181- return data ? data->asString () : 0 ;
181+ return data ? data->asString () : JsonString () ;
182182 }
183183
184184 static bool checkJson (JsonVariantConst src) {
Original file line number Diff line number Diff line change @@ -64,7 +64,8 @@ class VariantData {
6464 return visit.visit (content_.asObject );
6565
6666 case VariantType::LinkedString:
67- return visit.visit (JsonString (content_.asLinkedString ));
67+ return visit.visit (
68+ JsonString (content_.asLinkedString , JsonString::Linked));
6869
6970 case VariantType::OwnedString:
7071 return visit.visit (JsonString (content_.asOwnedString ->data ,
You can’t perform that action at this time.
0 commit comments