Commit a2d09f0a authored by miloyip's avatar miloyip

Refactor GenericPointer::Erase()

parent 6e1d10ec
...@@ -686,34 +686,37 @@ public: ...@@ -686,34 +686,37 @@ public:
ValueType* v = &root; ValueType* v = &root;
const Token* last = tokens_ + (tokenCount_ - 1); 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()) { switch (v->GetType()) {
case kObjectType: case kObjectType:
{ {
typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length)); typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
if (m == v->MemberEnd()) if (m == v->MemberEnd())
return false; return false;
if (t == last) {
v->EraseMember(m);
return true;
}
v = &m->value; v = &m->value;
} }
break; break;
case kArrayType: case kArrayType:
if (t->index == kPointerInvalidIndex || t->index >= v->Size()) if (t->index == kPointerInvalidIndex || t->index >= v->Size())
return false; return false;
if (t == last) {
v->Erase(v->Begin() + t->index);
return true;
}
v = &((*v)[t->index]); v = &((*v)[t->index]);
break; break;
default: default:
return false; 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: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment