Commit b8d2f7e6 authored by Milo Yip's avatar Milo Yip

Merge regex into schema

parents 3ffac19f a8feeb4c
...@@ -1213,6 +1213,31 @@ public: ...@@ -1213,6 +1213,31 @@ public:
return pos; 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 //!@name Array
......
This diff is collapsed.
...@@ -689,34 +689,37 @@ public: ...@@ -689,34 +689,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:
......
...@@ -967,13 +967,13 @@ private: ...@@ -967,13 +967,13 @@ private:
else { else {
if (use64bit) { if (use64bit) {
if (minus) if (minus)
cont = handler.Int64(-(int64_t)i64); cont = handler.Int64(static_cast<int64_t>(~i64 + 1));
else else
cont = handler.Uint64(i64); cont = handler.Uint64(i64);
} }
else { else {
if (minus) if (minus)
cont = handler.Int(-(int)i); cont = handler.Int(static_cast<int32_t>(~i + 1));
else else
cont = handler.Uint(i); cont = handler.Uint(i);
} }
......
...@@ -298,11 +298,28 @@ TEST_F(RapidJson, internal_Pow10) { ...@@ -298,11 +298,28 @@ TEST_F(RapidJson, internal_Pow10) {
EXPECT_GT(sum, 0.0); EXPECT_GT(sum, 0.0);
} }
TEST_F(RapidJson, SIMD_SUFFIX(Whitespace)) { TEST_F(RapidJson, SkipWhitespace_Basic) {
for (size_t i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
Document doc; rapidjson::StringStream s(whitespace_);
ASSERT_TRUE(doc.Parse(whitespace_).IsArray()); while (s.Peek() == ' ' || s.Peek() == '\n' || s.Peek() == '\r' || s.Peek() == '\t')
} s.Take();
ASSERT_EQ('[', s.Peek());
}
}
TEST_F(RapidJson, SIMD_SUFFIX(SkipWhitespace)) {
for (size_t i = 0; i < kTrialCount; i++) {
rapidjson::StringStream s(whitespace_);
rapidjson::SkipWhitespace(s);
ASSERT_EQ('[', s.Peek());
}
}
TEST_F(RapidJson, SkipWhitespace_strspn) {
for (size_t i = 0; i < kTrialCount; i++) {
const char* s = whitespace_ + std::strspn(whitespace_, " \t\r\n");
ASSERT_EQ('[', *s);
}
} }
TEST_F(RapidJson, UTF8_Validate) { TEST_F(RapidJson, UTF8_Validate) {
......
...@@ -11,6 +11,7 @@ set(UNITTEST_SOURCES ...@@ -11,6 +11,7 @@ set(UNITTEST_SOURCES
pointertest.cpp pointertest.cpp
prettywritertest.cpp prettywritertest.cpp
readertest.cpp readertest.cpp
regextest.cpp
schematest.cpp schematest.cpp
simdtest.cpp simdtest.cpp
strfunctest.cpp strfunctest.cpp
......
...@@ -879,7 +879,13 @@ TEST(Pointer, Erase) { ...@@ -879,7 +879,13 @@ TEST(Pointer, Erase) {
d.Parse(kJson); d.Parse(kJson);
EXPECT_FALSE(Pointer("").Erase(d)); EXPECT_FALSE(Pointer("").Erase(d));
EXPECT_FALSE(Pointer("/nonexist").Erase(d));
EXPECT_FALSE(Pointer("/nonexist/nonexist").Erase(d));
EXPECT_FALSE(Pointer("/foo/nonexist").Erase(d)); EXPECT_FALSE(Pointer("/foo/nonexist").Erase(d));
EXPECT_FALSE(Pointer("/foo/nonexist/nonexist").Erase(d));
EXPECT_FALSE(Pointer("/foo/0/nonexist").Erase(d));
EXPECT_FALSE(Pointer("/foo/0/nonexist/nonexist").Erase(d));
EXPECT_FALSE(Pointer("/foo/2/nonexist").Erase(d));
EXPECT_TRUE(Pointer("/foo/0").Erase(d)); EXPECT_TRUE(Pointer("/foo/0").Erase(d));
EXPECT_EQ(1u, d["foo"].Size()); EXPECT_EQ(1u, d["foo"].Size());
EXPECT_STREQ("baz", d["foo"][0].GetString()); EXPECT_STREQ("baz", d["foo"][0].GetString());
...@@ -887,6 +893,24 @@ TEST(Pointer, Erase) { ...@@ -887,6 +893,24 @@ TEST(Pointer, Erase) {
EXPECT_TRUE(d["foo"].Empty()); EXPECT_TRUE(d["foo"].Empty());
EXPECT_TRUE(Pointer("/foo").Erase(d)); EXPECT_TRUE(Pointer("/foo").Erase(d));
EXPECT_TRUE(Pointer("/foo").Get(d) == 0); EXPECT_TRUE(Pointer("/foo").Get(d) == 0);
Pointer("/a/0/b/0").Create(d);
EXPECT_TRUE(Pointer("/a/0/b/0").Get(d) != 0);
EXPECT_TRUE(Pointer("/a/0/b/0").Erase(d));
EXPECT_TRUE(Pointer("/a/0/b/0").Get(d) == 0);
EXPECT_TRUE(Pointer("/a/0/b").Get(d) != 0);
EXPECT_TRUE(Pointer("/a/0/b").Erase(d));
EXPECT_TRUE(Pointer("/a/0/b").Get(d) == 0);
EXPECT_TRUE(Pointer("/a/0").Get(d) != 0);
EXPECT_TRUE(Pointer("/a/0").Erase(d));
EXPECT_TRUE(Pointer("/a/0").Get(d) == 0);
EXPECT_TRUE(Pointer("/a").Get(d) != 0);
EXPECT_TRUE(Pointer("/a").Erase(d));
EXPECT_TRUE(Pointer("/a").Get(d) == 0);
} }
TEST(Pointer, CreateValueByPointer) { TEST(Pointer, CreateValueByPointer) {
......
This diff is collapsed.
...@@ -1182,6 +1182,24 @@ TEST(Value, Object) { ...@@ -1182,6 +1182,24 @@ TEST(Value, Object) {
EXPECT_TRUE(z.IsObject()); 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) { TEST(Value, BigNestedArray) {
MemoryPoolAllocator<> allocator; MemoryPoolAllocator<> allocator;
Value x(kArrayType); 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