20#include <xrpl/beast/utility/instrumentation.h>
21#include <xrpl/json/json_writer.h>
32 return ch > 0 && ch <= 0x1F;
53 *--current = (value % 10) +
'0';
62 char* current = buffer +
sizeof(buffer);
63 bool isNegative = value < 0;
73 XRPL_ASSERT(current >= buffer,
"Json::valueToString(Int) : buffer check");
81 char* current = buffer +
sizeof(buffer);
83 XRPL_ASSERT(current >= buffer,
"Json::valueToString(UInt) : buffer check");
96#if defined(_MSC_VER) && \
97 defined(__STDC_SECURE_LIB__)
99 sprintf_s(buffer,
sizeof(buffer),
"%.16g", value);
101 snprintf(buffer,
sizeof(buffer),
"%.16g", value);
109 return value ?
"true" :
"false";
116 if (strpbrk(value,
"\"\\\b\f\n\r\t") ==
nullptr &&
123 unsigned maxsize = strlen(value) * 2 + 3;
128 for (
const char* c = value; *c != 0; ++c)
173 <<
static_cast<int>(*c);
203 switch (value.
type())
231 int size = value.
size();
233 for (
int index = 0; index < size; ++index)
249 for (Value::Members::iterator it = members.
begin();
255 if (it != members.
begin())
290 switch (value.
type())
329 Value::Members::iterator it = members.
begin();
334 const Value& childValue = value[name];
339 if (++it == members.
end())
356 unsigned size = value.
size();
364 if (isArrayMultiLine)
373 const Value& childValue = value[index];
396 "Json::StyledWriter::writeArrayValue : child size match");
399 for (
unsigned index = 0; index < size; ++index)
415 int size = value.
size();
419 for (
int index = 0; index < size && !isMultiLine; ++index)
421 const Value& childValue = value[index];
422 isMultiLine = isMultiLine ||
424 childValue.
size() > 0);
431 int lineLength = 4 + (size - 1) * 2;
433 for (
int index = 0; index < size; ++index)
440 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
490 "Json::StyledWriter::unindent : maximum indent size");
498 : document_(nullptr), rightMargin_(74), indentation_(indentation)
516 switch (value.
type())
555 Value::Members::iterator it = members.
begin();
560 const Value& childValue = value[name];
565 if (++it == members.
end())
582 unsigned size = value.
size();
590 if (isArrayMultiLine)
599 const Value& childValue = value[index];
622 "Json::StyledStreamWriter::writeArrayValue : child size match");
625 for (
unsigned index = 0; index < size; ++index)
641 int size = value.
size();
645 for (
int index = 0; index < size && !isMultiLine; ++index)
647 const Value& childValue = value[index];
648 isMultiLine = isMultiLine ||
650 childValue.
size() > 0);
657 int lineLength = 4 + (size - 1) * 2;
659 for (
int index = 0; index < size; ++index)
666 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
717 "Json::StyledStreamWriter::unindent : maximum indent size");
725 writer.
write(sout, root);
void writeValue(const Value &value)
std::string write(const Value &root) override
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string.
void write(std::ostream &out, const Value &root)
Serialize a Value in JSON format.
void writeValue(const Value &value)
void writeWithIndent(std::string const &value)
void writeArrayValue(const Value &value)
bool isMultineArray(const Value &value)
StyledStreamWriter(std::string indentation="\t")
void pushValue(std::string const &value)
std::string indentString_
void writeArrayValue(const Value &value)
std::string indentString_
void pushValue(std::string const &value)
bool isMultineArray(const Value &value)
std::string write(const Value &root) override
Serialize a Value in JSON format.
void writeValue(const Value &value)
void writeWithIndent(std::string const &value)
const char * asCString() const
UInt size() const
Number of values in array or object.
Members getMemberNames() const
Return a list of the member names.
JSON (JavaScript Object Notation).
static bool isControlCharacter(char ch)
static void uintToString(unsigned int value, char *¤t)
std::string valueToString(Int value)
@ stringValue
UTF-8 string value.
@ arrayValue
array value (ordered list)
@ intValue
signed integer value
@ objectValue
object value (collection of name/value pairs).
@ uintValue
unsigned integer value
std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
std::string valueToQuotedString(const char *value)
static bool containsControlCharacter(const char *str)