Commit 6e1d10ec authored by miloyip's avatar miloyip

Add GenericValue::EraseMember(string types) APIs

parent 1a570c34
......@@ -1213,6 +1213,31 @@ public:
return pos;
}
//! Erase a member in object by its name.
/*! \param name Name of member to be removed.
\return Whether the member existed.
\note Linear time complexity.
*/
bool EraseMember(const Ch* name) {
GenericValue n(StringRef(name));
return EraseMember(n);
}
#if RAPIDJSON_HAS_STDSTRING
bool EraseMember(const std::basic_string<Ch>& name) { return EraseMember(GenericValue(StringRef(name))); }
#endif
template <typename SourceAllocator>
bool EraseMember(const GenericValue<Encoding, SourceAllocator>& name) {
MemberIterator m = FindMember(name);
if (m != MemberEnd()) {
EraseMember(m);
return true;
}
else
return false;
}
//@}
//!@name Array
......
......@@ -1182,6 +1182,24 @@ TEST(Value, Object) {
EXPECT_TRUE(z.IsObject());
}
TEST(Value, EraseMember_String) {
Value::AllocatorType allocator;
Value x(kObjectType);
x.AddMember("A", "Apple", allocator);
x.AddMember("B", "Banana", allocator);
EXPECT_TRUE(x.EraseMember("B"));
EXPECT_FALSE(x.HasMember("B"));
EXPECT_FALSE(x.EraseMember("nonexist"));
GenericValue<UTF8<>, CrtAllocator> othername("A");
EXPECT_TRUE(x.EraseMember(othername));
EXPECT_FALSE(x.HasMember("A"));
EXPECT_TRUE(x.MemberBegin() == x.MemberEnd());
}
TEST(Value, BigNestedArray) {
MemoryPoolAllocator<> allocator;
Value x(kArrayType);
......
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