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
37140198
Commit
37140198
authored
Aug 17, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ShrinkToFit() to StringBuffer and MemoryBuffer
parent
2e237877
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
0 deletions
+8
-0
memorybuffer.h
include/rapidjson/memorybuffer.h
+1
-0
stringbuffer.h
include/rapidjson/stringbuffer.h
+6
-0
writertest.cpp
test/unittest/writertest.cpp
+1
-0
No files found.
include/rapidjson/memorybuffer.h
View file @
37140198
...
...
@@ -49,6 +49,7 @@ struct GenericMemoryBuffer {
void
Flush
()
{}
void
Clear
()
{
stack_
.
Clear
();
}
void
ShrinkToFit
()
{
stack_
.
ShrinkToFit
();
}
Ch
*
Push
(
size_t
count
)
{
return
stack_
.
template
Push
<
Ch
>
(
count
);
}
void
Pop
(
size_t
count
)
{
stack_
.
template
Pop
<
Ch
>
(
count
);
}
...
...
include/rapidjson/stringbuffer.h
View file @
37140198
...
...
@@ -42,6 +42,12 @@ struct GenericStringBuffer {
void
Flush
()
{}
void
Clear
()
{
stack_
.
Clear
();
}
void
ShrinkToFit
()
{
// Push and pop a null terminator. This is safe.
*
stack_
.
template
Push
<
Ch
>
()
=
'\0'
;
stack_
.
ShrinkToFit
();
stack_
.
template
Pop
<
Ch
>
(
1
);
}
Ch
*
Push
(
size_t
count
)
{
return
stack_
.
template
Push
<
Ch
>
(
count
);
}
void
Pop
(
size_t
count
)
{
stack_
.
template
Pop
<
Ch
>
(
count
);
}
...
...
test/unittest/writertest.cpp
View file @
37140198
...
...
@@ -31,6 +31,7 @@ TEST(Writer, Compact) {
StringStream
s
(
"{
\"
hello
\"
:
\"
world
\"
,
\"
t
\"
: true ,
\"
f
\"
: false,
\"
n
\"
: null,
\"
i
\"
:123,
\"
pi
\"
: 3.1416,
\"
a
\"
:[1, 2, 3] } "
);
StringBuffer
buffer
;
Writer
<
StringBuffer
>
writer
(
buffer
);
buffer
.
ShrinkToFit
();
Reader
reader
;
reader
.
Parse
<
0
>
(
s
,
writer
);
EXPECT_STREQ
(
"{
\"
hello
\"
:
\"
world
\"
,
\"
t
\"
:true,
\"
f
\"
:false,
\"
n
\"
:null,
\"
i
\"
:123,
\"
pi
\"
:3.1416,
\"
a
\"
:[1,2,3]}"
,
buffer
.
GetString
());
...
...
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