diff options
author | miloyip <miloyip@gmail.com> | 2015-05-21 11:13:02 +0300 |
---|---|---|
committer | miloyip <miloyip@gmail.com> | 2015-05-21 11:13:02 +0300 |
commit | a2d09f0a03cf58f62f90c0af1416a59b0ca5cf50 (patch) | |
tree | ff4e768cd7e95e05d2e87bc80a15778363d5c844 /include/rapidjson/pointer.h | |
parent | 6e1d10ec6b1454737015ca2b018816185092efc4 (diff) |
Refactor GenericPointer::Erase()
Diffstat (limited to 'include/rapidjson/pointer.h')
-rw-r--r-- | include/rapidjson/pointer.h | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h index 13e688e9..5d2aa8d6 100644 --- a/include/rapidjson/pointer.h +++ b/include/rapidjson/pointer.h @@ -686,34 +686,37 @@ public: ValueType* v = &root; const Token* last = tokens_ + (tokenCount_ - 1); - for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) { + for (const Token *t = tokens_; t != last; ++t) { switch (v->GetType()) { case kObjectType: { typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length)); if (m == v->MemberEnd()) return false; - if (t == last) { - v->EraseMember(m); - return true; - } v = &m->value; } break; case kArrayType: if (t->index == kPointerInvalidIndex || t->index >= v->Size()) return false; - if (t == last) { - v->Erase(v->Begin() + t->index); - return true; - } v = &((*v)[t->index]); break; default: return false; } } - return false; + + switch (v->GetType()) { + case kObjectType: + return v->EraseMember(GenericStringRef<Ch>(last->name, last->length)); + case kArrayType: + if (last->index == kPointerInvalidIndex || last->index >= v->Size()) + return false; + v->Erase(v->Begin() + last->index); + return true; + default: + return false; + } } private: |