20#include <xrpl/beast/utility/instrumentation.h>
21#include <xrpl/json/json_forwards.h>
22#include <xrpl/json/json_value.h>
23#include <xrpl/json/json_writer.h>
39 return ch > 0 && ch <= 0x1F;
60 *--current = (value % 10) +
'0';
69 char* current = buffer +
sizeof(buffer);
70 bool isNegative = value < 0;
80 XRPL_ASSERT(current >= buffer,
"Json::valueToString(Int) : buffer check");
88 char* current = buffer +
sizeof(buffer);
90 XRPL_ASSERT(current >= buffer,
"Json::valueToString(UInt) : buffer check");
103#if defined(_MSC_VER) && \
104 defined(__STDC_SECURE_LIB__)
106 sprintf_s(buffer,
sizeof(buffer),
"%.16g", value);
108 snprintf(buffer,
sizeof(buffer),
"%.16g", value);
116 return value ?
"true" :
"false";
123 if (strpbrk(value,
"\"\\\b\f\n\r\t") ==
nullptr &&
130 unsigned maxsize = strlen(value) * 2 + 3;
135 for (
char const* c = value; *c != 0; ++c)
180 <<
static_cast<int>(*c);
210 switch (value.
type())
238 int size = value.
size();
240 for (
int index = 0; index < size; ++index)
256 for (Value::Members::iterator it = members.
begin();
262 if (it != members.
begin())
297 switch (value.
type())
336 Value::Members::iterator it = members.
begin();
341 Value const& childValue = value[name];
346 if (++it == members.
end())
363 unsigned size = value.
size();
371 if (isArrayMultiLine)
380 Value const& childValue = value[index];
403 "Json::StyledWriter::writeArrayValue : child size match");
406 for (
unsigned index = 0; index < size; ++index)
422 int size = value.
size();
426 for (
int index = 0; index < size && !isMultiLine; ++index)
428 Value const& childValue = value[index];
429 isMultiLine = isMultiLine ||
431 childValue.
size() > 0);
438 int lineLength = 4 + (size - 1) * 2;
440 for (
int index = 0; index < size; ++index)
447 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
497 "Json::StyledWriter::unindent : maximum indent size");
505 : document_(nullptr), rightMargin_(74), indentation_(indentation)
523 switch (value.
type())
562 Value::Members::iterator it = members.
begin();
567 Value const& childValue = value[name];
572 if (++it == members.
end())
589 unsigned size = value.
size();
597 if (isArrayMultiLine)
606 Value const& childValue = value[index];
629 "Json::StyledStreamWriter::writeArrayValue : child size match");
632 for (
unsigned index = 0; index < size; ++index)
648 int size = value.
size();
652 for (
int index = 0; index < size && !isMultiLine; ++index)
654 Value const& childValue = value[index];
655 isMultiLine = isMultiLine ||
657 childValue.
size() > 0);
664 int lineLength = 4 + (size - 1) * 2;
666 for (
int index = 0; index < size; ++index)
673 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
724 "Json::StyledStreamWriter::unindent : maximum indent size");
732 writer.
write(sout, root);
std::string write(Value const &root) override
void writeValue(Value const &value)
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string.
void write(std::ostream &out, Value const &root)
Serialize a Value in JSON format.
void writeWithIndent(std::string const &value)
bool isMultineArray(Value const &value)
void writeValue(Value const &value)
void writeArrayValue(Value const &value)
StyledStreamWriter(std::string indentation="\t")
void pushValue(std::string const &value)
std::string indentString_
std::string write(Value const &root) override
Serialize a Value in JSON format.
std::string indentString_
void pushValue(std::string const &value)
void writeValue(Value const &value)
void writeArrayValue(Value const &value)
void writeWithIndent(std::string const &value)
bool isMultineArray(Value const &value)
UInt size() const
Number of values in array or object.
char const * asCString() const
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)
static bool containsControlCharacter(char const *str)
std::string valueToQuotedString(char const *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 &, Value const &root)
Output using the StyledStreamWriter.