Skip to content

Commit 11defb7

Browse files
committed
Wrap all WriteXxx() calls within EndValue(), to ensure a flush after root-level scalar value
This attempts to fix issue Tencent#1336.
1 parent 6a905f9 commit 11defb7

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

include/rapidjson/prettywriter.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,26 @@ class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding,
9292
*/
9393
//@{
9494

95-
bool Null() { PrettyPrefix(kNullType); return Base::WriteNull(); }
96-
bool Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); return Base::WriteBool(b); }
97-
bool Int(int i) { PrettyPrefix(kNumberType); return Base::WriteInt(i); }
98-
bool Uint(unsigned u) { PrettyPrefix(kNumberType); return Base::WriteUint(u); }
99-
bool Int64(int64_t i64) { PrettyPrefix(kNumberType); return Base::WriteInt64(i64); }
100-
bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType); return Base::WriteUint64(u64); }
101-
bool Double(double d) { PrettyPrefix(kNumberType); return Base::WriteDouble(d); }
95+
bool Null() { PrettyPrefix(kNullType); return Base::EndValue(Base::WriteNull()); }
96+
bool Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); return Base::EndValue(Base::WriteBool(b)); }
97+
bool Int(int i) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt(i)); }
98+
bool Uint(unsigned u) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint(u)); }
99+
bool Int64(int64_t i64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt64(i64)); }
100+
bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint64(u64)); }
101+
bool Double(double d) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteDouble(d)); }
102102

103103
bool RawNumber(const Ch* str, SizeType length, bool copy = false) {
104104
RAPIDJSON_ASSERT(str != 0);
105105
(void)copy;
106106
PrettyPrefix(kNumberType);
107-
return Base::WriteString(str, length);
107+
return Base::EndValue(Base::WriteString(str, length));
108108
}
109109

110110
bool String(const Ch* str, SizeType length, bool copy = false) {
111111
RAPIDJSON_ASSERT(str != 0);
112112
(void)copy;
113113
PrettyPrefix(kStringType);
114-
return Base::WriteString(str, length);
114+
return Base::EndValue(Base::WriteString(str, length));
115115
}
116116

117117
#if RAPIDJSON_HAS_STDSTRING
@@ -146,7 +146,7 @@ class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding,
146146
Base::os_->Put('\n');
147147
WriteIndent();
148148
}
149-
bool ret = Base::WriteEndObject();
149+
bool ret = Base::EndValue(Base::WriteEndObject());
150150
(void)ret;
151151
RAPIDJSON_ASSERT(ret == true);
152152
if (Base::level_stack_.Empty()) // end of json text
@@ -170,7 +170,7 @@ class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding,
170170
Base::os_->Put('\n');
171171
WriteIndent();
172172
}
173-
bool ret = Base::WriteEndArray();
173+
bool ret = Base::EndValue(Base::WriteEndArray());
174174
(void)ret;
175175
RAPIDJSON_ASSERT(ret == true);
176176
if (Base::level_stack_.Empty()) // end of json text
@@ -201,7 +201,7 @@ class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding,
201201
bool RawValue(const Ch* json, size_t length, Type type) {
202202
RAPIDJSON_ASSERT(json != 0);
203203
PrettyPrefix(type);
204-
return Base::WriteRawValue(json, length);
204+
return Base::EndValue(Base::WriteRawValue(json, length));
205205
}
206206

207207
protected:

0 commit comments

Comments
 (0)