bes
Updated for version 3.20.5
|
Writer with indentation and spacing. More...
#include <prettywriter.h>
Public Types | |
typedef Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > | Base |
typedef Base::Ch | Ch |
Public Member Functions | |
int | GetMaxDecimalPlaces () const |
bool | IsComplete () const |
Checks whether the output is a complete JSON. More... | |
PrettyWriter (OutputStream &os, StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth) | |
Constructor. More... | |
PrettyWriter (StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth) | |
bool | RawValue (const Ch *json, size_t length, Type type) |
Write a raw JSON value. More... | |
void | Reset (OutputStream &os) |
Reset the writer with a new stream. More... | |
PrettyWriter & | SetFormatOptions (PrettyFormatOptions options) |
Set pretty writer formatting options. More... | |
PrettyWriter & | SetIndent (Ch indentChar, unsigned indentCharCount) |
Set custom indentation. More... | |
void | SetMaxDecimalPlaces (int maxDecimalPlaces) |
Sets the maximum number of decimal places for double output. More... | |
Implementation of Handler | |
| |
bool | Null () |
bool | Bool (bool b) |
bool | Int (int i) |
bool | Uint (unsigned u) |
bool | Int64 (int64_t i64) |
bool | Uint64 (uint64_t u64) |
bool | Double (double d) |
bool | RawNumber (const Ch *str, SizeType length, bool copy=false) |
bool | String (const Ch *str, SizeType length, bool copy=false) |
bool | StartObject () |
bool | Key (const Ch *str, SizeType length, bool copy=false) |
bool | EndObject (SizeType memberCount=0) |
bool | StartArray () |
bool | EndArray (SizeType memberCount=0) |
Convenience extensions | |
bool | String (const Ch *str) |
Simpler but slower overload. More... | |
bool | Key (const Ch *str) |
Static Public Attributes | |
static const int | kDefaultMaxDecimalPlaces = 324 |
Protected Member Functions | |
bool | EndValue (bool ret) |
void | Prefix (Type type) |
void | PrettyPrefix (Type type) |
bool | ScanWriteUnescapedString (GenericStringStream< SourceEncoding > &is, size_t length) |
bool | WriteBool (bool b) |
bool | WriteDouble (double d) |
template<> | |
bool | WriteDouble (double d) |
bool | WriteEndArray () |
bool | WriteEndObject () |
void | WriteIndent () |
bool | WriteInt (int i) |
template<> | |
bool | WriteInt (int i) |
bool | WriteInt64 (int64_t i64) |
template<> | |
bool | WriteInt64 (int64_t i64) |
bool | WriteNull () |
bool | WriteRawValue (const Ch *json, size_t length) |
bool | WriteStartArray () |
bool | WriteStartObject () |
bool | WriteString (const Ch *str, SizeType length) |
bool | WriteUint (unsigned u) |
template<> | |
bool | WriteUint (unsigned u) |
bool | WriteUint64 (uint64_t u64) |
template<> | |
bool | WriteUint64 (uint64_t u) |
Protected Attributes | |
PrettyFormatOptions | formatOptions_ |
bool | hasRoot_ |
Ch | indentChar_ |
unsigned | indentCharCount_ |
internal::Stack< StackAllocator > | level_stack_ |
int | maxDecimalPlaces_ |
OutputStream * | os_ |
Static Protected Attributes | |
static const size_t | kDefaultLevelDepth = 32 |
Writer with indentation and spacing.
OutputStream | Type of ouptut os. |
SourceEncoding | Encoding of source string. |
TargetEncoding | Encoding of output stream. |
StackAllocator | Type of allocator for allocating memory of stack. |
|
inlineexplicit |
Constructor.
os | Output stream. |
allocator | User supplied allocator. If it is null, it will create a private one. |
levelDepth | Initial capacity of stack. |
Definition at line 53 of file prettywriter.h.
|
inlineinherited |
|
inline |
Write a raw JSON value.
For user to write a stringified JSON as a value.
json | A well-formed JSON value. It should not contain null character within [0, length - 1] range. |
length | Length of the json. |
type | Type of the root of json. |
Definition at line 187 of file prettywriter.h.
|
inlineinherited |
Reset the writer with a new stream.
This function reset the writer with a new stream and default settings, in order to make a Writer object reusable for output multiple JSONs.
os | New output stream. Writer<OutputStream> writer(os1); writer.StartObject(); // ... writer.EndObject(); writer.Reset(os2); writer.StartObject(); // ... writer.EndObject(); |
|
inline |
Set pretty writer formatting options.
options | Formatting options. |
Definition at line 75 of file prettywriter.h.
|
inline |
Set custom indentation.
indentChar | Character for indentation. Must be whitespace character (' ', '\t', '\n', '\r'). |
indentCharCount | Number of indent characters for each indentation level. |
Definition at line 65 of file prettywriter.h.
|
inlineinherited |
Sets the maximum number of decimal places for double output.
This setting truncates the output with specified number of decimal places.
For example,
The default setting does not truncate any decimal places. You can restore to this setting by calling
|
inline |
Simpler but slower overload.
Definition at line 173 of file prettywriter.h.