mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-02-01 14:55:55 +01:00
Add an insert overload function (#1110)
This commit is contained in:
parent
9e0d70aa66
commit
a0bd9adfef
@ -445,8 +445,10 @@ public:
|
|||||||
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
|
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
|
||||||
Value& append(const Value& value);
|
Value& append(const Value& value);
|
||||||
Value& append(Value&& value);
|
Value& append(Value&& value);
|
||||||
|
|
||||||
/// \brief Insert value in array at specific index
|
/// \brief Insert value in array at specific index
|
||||||
bool insert(ArrayIndex index, Value newValue);
|
bool insert(ArrayIndex index, const Value& newValue);
|
||||||
|
bool insert(ArrayIndex index, Value&& newValue);
|
||||||
|
|
||||||
/// Access an object value by name, create a null member if it does not exist.
|
/// Access an object value by name, create a null member if it does not exist.
|
||||||
/// \note Because of our implementation, keys are limited to 2^30 -1 chars.
|
/// \note Because of our implementation, keys are limited to 2^30 -1 chars.
|
||||||
|
@ -1126,7 +1126,11 @@ Value& Value::append(Value&& value) {
|
|||||||
return this->value_.map_->emplace(size(), std::move(value)).first->second;
|
return this->value_.map_->emplace(size(), std::move(value)).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::insert(ArrayIndex index, Value newValue) {
|
bool Value::insert(ArrayIndex index, const Value& newValue) {
|
||||||
|
return insert(index, Value(newValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Value::insert(ArrayIndex index, Value&& newValue) {
|
||||||
JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue,
|
JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue,
|
||||||
"in Json::Value::insert: requires arrayValue");
|
"in Json::Value::insert: requires arrayValue");
|
||||||
ArrayIndex length = size();
|
ArrayIndex length = size();
|
||||||
|
@ -417,8 +417,7 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, arrayInsertAtRandomIndex) {
|
|||||||
}
|
}
|
||||||
vec.push_back(&array[4]);
|
vec.push_back(&array[4]);
|
||||||
// insert rvalue at the tail
|
// insert rvalue at the tail
|
||||||
Json::Value index5("index5");
|
JSONTEST_ASSERT(array.insert(5, "index5"));
|
||||||
JSONTEST_ASSERT(array.insert(5, std::move(index5)));
|
|
||||||
JSONTEST_ASSERT_EQUAL(Json::Value("index3"), array[0]);
|
JSONTEST_ASSERT_EQUAL(Json::Value("index3"), array[0]);
|
||||||
JSONTEST_ASSERT_EQUAL(Json::Value("index0"), array[1]);
|
JSONTEST_ASSERT_EQUAL(Json::Value("index0"), array[1]);
|
||||||
JSONTEST_ASSERT_EQUAL(Json::Value("index4"), array[2]);
|
JSONTEST_ASSERT_EQUAL(Json::Value("index4"), array[2]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user