Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
2ddbd090
Commit
2ddbd090
authored
May 02, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add '-' support for Create() and Set()
parent
2ece55ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
18 deletions
+34
-18
pointer.h
include/rapidjson/pointer.h
+21
-18
pointertest.cpp
test/unittest/pointertest.cpp
+13
-0
No files found.
include/rapidjson/pointer.h
View file @
2ddbd090
...
...
@@ -166,27 +166,30 @@ public:
ValueType
*
v
=
&
root
;
bool
exist
=
true
;
for
(
Token
*
t
=
tokens_
;
t
!=
tokens_
+
tokenCount_
;
++
t
)
{
if
(
v
->
GetType
()
!=
kObjectType
&&
v
->
GetType
()
!=
kArrayType
)
{
if
(
t
->
index
==
kPointerInvalidIndex
)
v
->
SetObject
();
else
v
->
SetArray
();
}
if
(
t
->
index
==
kPointerInvalidIndex
)
{
if
(
!
v
->
IsObject
())
v
->
SetObject
();
// Change to Object
typename
ValueType
::
MemberIterator
m
=
v
->
FindMember
(
GenericStringRef
<
Ch
>
(
t
->
name
,
t
->
length
));
if
(
m
==
v
->
MemberEnd
())
{
v
->
AddMember
(
Value
(
t
->
name
,
t
->
length
,
allocator
).
Move
(),
Value
().
Move
(),
allocator
);
v
=
&
(
--
v
->
MemberEnd
())
->
value
;
// Assumes AddMember() appends at the end
if
(
t
->
index
==
kPointerInvalidIndex
)
{
// object name
// Handling of '-' for last element of array
if
(
t
->
name
[
0
]
==
'-'
&&
t
->
length
==
1
)
{
if
(
!
v
->
IsArray
())
v
->
SetArray
();
// Change to Array
v
->
PushBack
(
Value
().
Move
(),
allocator
);
v
=
&
((
*
v
)[
v
->
Size
()
-
1
]);
exist
=
false
;
}
else
v
=
&
m
->
value
;
else
{
if
(
!
v
->
IsObject
())
v
->
SetObject
();
// Change to Object
typename
ValueType
::
MemberIterator
m
=
v
->
FindMember
(
GenericStringRef
<
Ch
>
(
t
->
name
,
t
->
length
));
if
(
m
==
v
->
MemberEnd
())
{
v
->
AddMember
(
Value
(
t
->
name
,
t
->
length
,
allocator
).
Move
(),
Value
().
Move
(),
allocator
);
v
=
&
(
--
v
->
MemberEnd
())
->
value
;
// Assumes AddMember() appends at the end
exist
=
false
;
}
else
v
=
&
m
->
value
;
}
}
else
{
else
{
// array index
if
(
!
v
->
IsArray
())
v
->
SetArray
();
// Change to Array
...
...
test/unittest/pointertest.cpp
View file @
2ddbd090
...
...
@@ -280,6 +280,14 @@ TEST(Pointer, Create) {
Value
*
v
=
&
Pointer
(
"/foo/0"
).
Create
(
d
,
d
.
GetAllocator
());
EXPECT_EQ
(
&
d
[
"foo"
][
0
],
v
);
}
{
Value
*
v
=
&
Pointer
(
"/foo/-"
).
Create
(
d
,
d
.
GetAllocator
());
EXPECT_EQ
(
&
d
[
"foo"
][
1
],
v
);
}
{
Value
*
v
=
&
Pointer
(
"/foo/-/-"
).
Create
(
d
,
d
.
GetAllocator
());
EXPECT_EQ
(
&
d
[
"foo"
][
2
][
0
],
v
);
}
}
TEST
(
Pointer
,
Get
)
{
...
...
@@ -310,6 +318,8 @@ TEST(Pointer, GetWithDefault) {
EXPECT_TRUE
(
Value
(
"bar"
)
==
Pointer
(
"/foo/0"
).
GetWithDefault
(
d
,
v
,
a
));
EXPECT_TRUE
(
Value
(
"baz"
)
==
Pointer
(
"/foo/1"
).
GetWithDefault
(
d
,
v
,
a
));
EXPECT_TRUE
(
Value
(
"qux"
)
==
Pointer
(
"/foo/2"
).
GetWithDefault
(
d
,
v
,
a
));
EXPECT_TRUE
(
Value
(
"last"
)
==
Pointer
(
"/foo/-"
).
GetWithDefault
(
d
,
Value
(
"last"
).
Move
(),
a
));
EXPECT_STREQ
(
"last"
,
d
[
"foo"
][
3
].
GetString
());
}
TEST
(
Pointer
,
Set
)
{
...
...
@@ -321,6 +331,9 @@ TEST(Pointer, Set) {
Pointer
(
"/foo/0"
).
Set
(
d
,
Value
(
123
).
Move
(),
a
);
EXPECT_EQ
(
123
,
d
[
"foo"
][
0
].
GetInt
());
Pointer
(
"/foo/-"
).
Set
(
d
,
Value
(
456
).
Move
(),
a
);
EXPECT_EQ
(
456
,
d
[
"foo"
][
2
].
GetInt
());
Pointer
(
"/foo/null"
).
Set
(
d
,
Value
().
Move
(),
a
);
EXPECT_TRUE
(
GetValueByPointer
(
d
,
"/foo/null"
)
->
IsNull
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment