diff options
author | Milo Yip <miloyip@gmail.com> | 2014-08-17 14:32:08 +0400 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2014-08-17 14:32:08 +0400 |
commit | 37140198193ab203e716db1b43ce3a697df206dd (patch) | |
tree | 64e4a5edc6c3c704f0f65af0440b82956d5dc06a /include | |
parent | 2e23787753c425569ddca967ba8e1c35ef23eb5a (diff) |
Add ShrinkToFit() to StringBuffer and MemoryBuffer
Diffstat (limited to 'include')
-rw-r--r-- | include/rapidjson/memorybuffer.h | 1 | ||||
-rw-r--r-- | include/rapidjson/stringbuffer.h | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/include/rapidjson/memorybuffer.h b/include/rapidjson/memorybuffer.h index 4e820360..b94d2df9 100644 --- a/include/rapidjson/memorybuffer.h +++ b/include/rapidjson/memorybuffer.h @@ -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); } diff --git a/include/rapidjson/stringbuffer.h b/include/rapidjson/stringbuffer.h index b8d7968c..bccc2472 100644 --- a/include/rapidjson/stringbuffer.h +++ b/include/rapidjson/stringbuffer.h @@ -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); }
|