15#ifndef RAPIDJSON_PRETTYWRITER_H_
16#define RAPIDJSON_PRETTYWRITER_H_
22RAPIDJSON_DIAG_OFF(effc++)
27RAPIDJSON_DIAG_OFF(c++98-compat)
47template<
typename OutputStream,
typename SourceEncoding = UTF8<>,
typename TargetEncoding = UTF8<>,
typename StackAllocator = CrtAllocator,
unsigned writeFlags = kWriteDefaultFlags>
48class PrettyWriter :
public Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> {
65#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
76 RAPIDJSON_ASSERT(indentChar ==
' ' || indentChar ==
'\t' || indentChar ==
'\n' || indentChar ==
'\r');
117#if RAPIDJSON_HAS_STDSTRING
118 bool String(
const std::basic_string<Ch>& str) {
131#if RAPIDJSON_HAS_STDSTRING
132 bool Key(
const std::basic_string<Ch>& str) {
143 bool empty =
Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
167 bool empty =
Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
213 if (level->inArray) {
214 if (level->valueCount > 0) {
226 if (level->valueCount > 0) {
227 if (level->valueCount % 2 == 0) {
239 if (level->valueCount % 2 == 0)
242 if (!level->inArray && level->valueCount % 2 == 0)
269#if defined(__clang__)
Writer with indentation and spacing.
void PrettyPrefix(Type type)
PrettyFormatOptions formatOptions_
bool EndArray(SizeType memberCount=0)
bool Key(const Ch *str, SizeType length, bool copy=false)
bool RawNumber(const Ch *str, SizeType length, bool copy=false)
bool RawValue(const Ch *json, size_t length, Type type)
Write a raw JSON value.
PrettyWriter(StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
bool EndObject(SizeType memberCount=0)
unsigned indentCharCount_
bool String(const Ch *str)
Simpler but slower overload.
PrettyWriter(OutputStream &os, StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
Constructor.
PrettyWriter & SetFormatOptions(PrettyFormatOptions options)
Set pretty writer formatting options.
bool Uint64(uint64_t u64)
PrettyWriter & SetIndent(Ch indentChar, unsigned indentCharCount)
Set custom indentation.
bool String(const Ch *str, SizeType length, bool copy=false)
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Base
bool WriteUint(unsigned u)
void Flush()
Flush the output stream.
bool WriteRawValue(const Ch *json, size_t length)
static const size_t kDefaultLevelDepth
internal::Stack< StackAllocator > level_stack_
bool WriteInt64(int64_t i64)
bool WriteString(const Ch *str, SizeType length)
bool WriteUint64(uint64_t u64)
bool WriteDouble(double d)
void PutN(FileWriteStream &stream, char c, size_t n)
Implement specialized version of PutN() with memset() for better performance.
#define RAPIDJSON_ASSERT(x)
Assertion.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
PrettyFormatOptions
Combination of PrettyWriter format flags.
@ kFormatDefault
Default pretty formatting.
@ kFormatSingleLineArray
Format arrays on a single line.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
unsigned __int64 uint64_t
Information for each nested level.