Commit 0e4c3689 authored by miloyip's avatar miloyip

Merge branch 'master' into schema

parents 677af55f 771fa987
...@@ -273,6 +273,21 @@ public: ...@@ -273,6 +273,21 @@ public:
} }
} }
//! Append a token by value, and return a new Pointer
/*!
\param value Value (either Uint or String) to be appended.
\param allocator Allocator for the newly return Pointer.
\return A new Pointer with appended token.
*/
GenericPointer Append(const ValueType& token, Allocator* allocator = 0) const {
if (token.IsString())
return Append(token.GetString(), token.GetStringLength(), allocator);
else {
RAPIDJSON_ASSERT(token.IsUint64());
return Append(static_cast<SizeType>(token.GetUint64()), allocator);
}
}
//!@name Handling Parse Error //!@name Handling Parse Error
//@{ //@{
......
...@@ -529,10 +529,20 @@ TEST(Pointer, Append) { ...@@ -529,10 +529,20 @@ TEST(Pointer, Append) {
Pointer p; Pointer p;
Pointer q = p.Append("foo"); Pointer q = p.Append("foo");
EXPECT_TRUE(Pointer("/foo") == q); EXPECT_TRUE(Pointer("/foo") == q);
q = q.Append(0); q = q.Append(1234);
EXPECT_TRUE(Pointer("/foo/0") == q); EXPECT_TRUE(Pointer("/foo/1234") == q);
q = q.Append(""); q = q.Append("");
EXPECT_TRUE(Pointer("/foo/0/") == q); EXPECT_TRUE(Pointer("/foo/1234/") == q);
}
{
Pointer p;
Pointer q = p.Append(Value("foo").Move());
EXPECT_TRUE(Pointer("/foo") == q);
q = q.Append(Value(1234).Move());
EXPECT_TRUE(Pointer("/foo/1234") == q);
q = q.Append(Value(kStringType).Move());
EXPECT_TRUE(Pointer("/foo/1234/") == q);
} }
#if RAPIDJSON_HAS_STDSTRING #if RAPIDJSON_HAS_STDSTRING
......
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