diff options
author | miloyip <miloyip@gmail.com> | 2015-05-02 16:30:40 +0300 |
---|---|---|
committer | miloyip <miloyip@gmail.com> | 2015-05-02 16:30:40 +0300 |
commit | 2ddbd09031b90765e31fc31a7607e3e0248a17d1 (patch) | |
tree | 0a5cc14a678865282b22953c961e900b73705703 /include/rapidjson/pointer.h | |
parent | 2ece55abc7001962870f7ee4effbd1c852ee182e (diff) |
Add '-' support for Create() and Set()
Diffstat (limited to 'include/rapidjson/pointer.h')
-rw-r--r-- | include/rapidjson/pointer.h | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h index c0b7ba1d..bc2795fe 100644 --- a/include/rapidjson/pointer.h +++ b/include/rapidjson/pointer.h @@ -166,27 +166,30 @@ public: ValueType* v = &root; bool exist = true; for (Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { - if (v->GetType() != kObjectType && v->GetType() != kArrayType) { - if (t->index == kPointerInvalidIndex) - v->SetObject(); - else - v->SetArray(); - } - - if (t->index == kPointerInvalidIndex) { - if (!v->IsObject()) - v->SetObject(); // Change to Object - - typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length)); - if (m == v->MemberEnd()) { - v->AddMember(Value(t->name, t->length, allocator).Move(), Value().Move(), allocator); - v = &(--v->MemberEnd())->value; // Assumes AddMember() appends at the end + if (t->index == kPointerInvalidIndex) { // object name + // Handling of '-' for last element of array + if (t->name[0] == '-' && t->length == 1) { + if (!v->IsArray()) + v->SetArray(); // Change to Array + v->PushBack(Value().Move(), allocator); + v = &((*v)[v->Size() - 1]); exist = false; } - else - v = &m->value; + else { + if (!v->IsObject()) + v->SetObject(); // Change to Object + + typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length)); + if (m == v->MemberEnd()) { + v->AddMember(Value(t->name, t->length, allocator).Move(), Value().Move(), allocator); + v = &(--v->MemberEnd())->value; // Assumes AddMember() appends at the end + exist = false; + } + else + v = &m->value; + } } - else { + else { // array index if (!v->IsArray()) v->SetArray(); // Change to Array |