Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit 3d0e0d5

Browse files
committed
feat: support importing const char* as Value
fix #69
1 parent 0b8e472 commit 3d0e0d5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

jsonxx.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ class Value {
261261
type_ = STRING_;
262262
*( string_value_ = new String() ) = s;
263263
}
264+
void import( const char* s ) {
265+
reset();
266+
type_ = STRING_;
267+
*( string_value_ = new String() ) = s;
268+
}
264269
void import( const Array &a ) {
265270
reset();
266271
type_ = ARRAY_;

jsonxx_test.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,22 @@ int main(int argc, const char **argv) {
623623
}
624624
}
625625

626+
{
627+
const char * test = "abcmango";
628+
Object obj;
629+
630+
obj << "test_1" << Value(test);
631+
obj << "test_2" << test;
632+
obj << "test_3" << String(test);
633+
634+
obj << "test_4" << Value("defbanana");
635+
obj << "test_5" << "defbanana";
636+
obj << "test_6" << String("defbanana");
637+
638+
TEST( obj.get<String>("test_1") == "abcmango" );
639+
TEST( obj.get<String>("test_6") == "defbanana" );
640+
}
641+
626642
cout << "All tests ok." << endl;
627643
return 0;
628644
}

0 commit comments

Comments
 (0)