RAPIDJSON_DIAG_OFF(effc++)
25 #if defined(__clang__) 27RAPIDJSON_DIAG_OFF(c++98-compat)
47 template<
typenameOutputStream,
typenameSourceEncoding = UTF8<>,
typenameTargetEncoding = UTF8<>,
typenameStackAllocator = CrtAllocator,
unsignedwriteFlags = kWriteDefaultFlags>
48 class PrettyWriter:
public Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> {
58 explicit PrettyWriter(OutputStream& os, StackAllocator* allocator = 0,
size_tlevelDepth = Base::kDefaultLevelDepth) :
59 Base(os, allocator, levelDepth), indentChar_(
' '), indentCharCount_(4), formatOptions_(
kFormatDefault), eol_(
true) {}
62 explicit PrettyWriter(StackAllocator* allocator = 0,
size_tlevelDepth = Base::kDefaultLevelDepth) :
63 Base(allocator, levelDepth), indentChar_(
' '), indentCharCount_(4), eol_(
true) {}
65 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 67Base(std::forward<
PrettyWriter>(rhs)), indentChar_(rhs.indentChar_), indentCharCount_(rhs.indentCharCount_), formatOptions_(rhs.formatOptions_), eol_(
true) {}
76 RAPIDJSON_ASSERT(indentChar ==
' '|| indentChar ==
'\t'|| indentChar ==
'\n'|| indentChar ==
'\r');
77indentChar_ = indentChar;
78indentCharCount_ = indentCharCount;
92formatOptions_ = options;
113 returnBase::WriteString(
str, length);
120 returnBase::WriteString(
str, length);
123 #if RAPIDJSON_HAS_STDSTRING 124 boolString(
conststd::basic_string<Ch>&
str) {
131 new(Base::level_stack_.template Push<typename Base::Level>())
typename Base::Level(
false);
132 returnBase::WriteStartObject();
137 #if RAPIDJSON_HAS_STDSTRING 138 boolKey(
conststd::basic_string<Ch>&
str) {
146 RAPIDJSON_ASSERT(!Base::level_stack_.
templateTop<typename Base::Level>()->inArray);
147 bool empty= Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
153 boolret = Base::WriteEndObject();
156 if(Base::level_stack_.
Empty())
163 new(Base::level_stack_.template Push<typename Base::Level>())
typename Base::Level(
true);
164 returnBase::WriteStartArray();
170 RAPIDJSON_ASSERT(Base::level_stack_.
templateTop<typename Base::Level>()->inArray);
171 bool empty= Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
177 boolret = Base::WriteEndArray();
180 if(Base::level_stack_.
Empty())
207PrettyPrefix(
type);
208 returnBase::WriteRawValue(json, length);
214 if(Base::level_stack_.GetSize() != 0) {
215 typename Base::Level* level = Base::level_stack_.template Top<typename Base::Level>();
219Base::os_->Put(
',');
221Base::os_->Put(
' ');
232Base::os_->Put(
',');
236Base::os_->Put(
':');
237Base::os_->Put(
' ');
252Base::hasRoot_ =
true;
257 size_t count= (Base::level_stack_.GetSize() /
sizeof(
typename Base::Level)) * indentCharCount_;
258 PutN(*Base::os_,
static_cast<typename OutputStream::Ch
>(indentChar_),
count);
265Base::os_->Put(
'\n');
282 #if defined(__clang__)Writer with indentation and spacing.
PrettyWriter & SetWriteEol(bool eol)
bool RawNumber(const Ch *str, SizeType length, bool copy=false)
PrettyWriter & SetIndent(Ch indentChar, unsigned indentCharCount)
Set custom indentation.
PrettyFormatOptions formatOptions_
PrettyWriter(StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
bool RawValue(const Ch *json, size_t length, Type type)
Write a raw JSON value.
bool String(const Ch *str)
Simpler but slower overload.
bool Uint64(uint64_t u64)
PrettyWriter(const PrettyWriter &)
Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator > Base
PrettyWriter(OutputStream &os, StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth)
Constructor.
bool EndArray(SizeType memberCount=0)
PrettyWriter & operator=(const PrettyWriter &)
unsigned indentCharCount_
bool EndObject(SizeType memberCount=0)
PrettyWriter & SetFormatOptions(PrettyFormatOptions options)
Set pretty writer formatting options.
bool Key(const Ch *str, SizeType length, bool copy=false)
bool String(const Ch *str, SizeType length, bool copy=false)
void PrettyPrefix(Type type)
bool Empty(const CNcbiOstrstream &src)
static const char * str(char *buf, int n)
#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)
constexpr bool empty(list< Ts... >) noexcept
PrettyFormatOptions
Combination of PrettyWriter format flags.
@ kFormatSingleLineArray
Format arrays on a single line.
@ kFormatDefault
Default pretty formatting.
void PutN(FileWriteStream &stream, char c, size_t n)
Implement specialized version of PutN() with memset() for better performance.
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Information for each nested level.
bool inArray
true if in array, otherwise in object
size_t valueCount
number of values in this level
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4