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

Commit

Permalink
feat: support importing const char* as Value
Browse files Browse the repository at this point in the history
fix #69
  • Loading branch information
hjiang committed Feb 20, 2021
1 parent 0b8e472 commit 3d0e0d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions jsonxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ class Value {
type_ = STRING_;
*( string_value_ = new String() ) = s;
}
void import( const char* s ) {
reset();
type_ = STRING_;
*( string_value_ = new String() ) = s;
}
void import( const Array &a ) {
reset();
type_ = ARRAY_;
Expand Down
16 changes: 16 additions & 0 deletions jsonxx_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,22 @@ int main(int argc, const char **argv) {
}
}

{
const char * test = "abcmango";
Object obj;

obj << "test_1" << Value(test);
obj << "test_2" << test;
obj << "test_3" << String(test);

obj << "test_4" << Value("defbanana");
obj << "test_5" << "defbanana";
obj << "test_6" << String("defbanana");

TEST( obj.get<String>("test_1") == "abcmango" );
TEST( obj.get<String>("test_6") == "defbanana" );
}

cout << "All tests ok." << endl;
return 0;
}

0 comments on commit 3d0e0d5

Please sign in to comment.