1#include <xrpl/beast/utility/instrumentation.h>
2#include <xrpl/json/json_forwards.h>
3#include <xrpl/json/json_value.h>
4#include <xrpl/json/json_writer.h>
20 return ch > 0 && ch <= 0x1F;
41 *--current = (value % 10) +
'0';
50 char* current = buffer +
sizeof(buffer);
51 bool const isNegative = value < 0;
61 XRPL_ASSERT(current >= buffer,
"Json::valueToString(Int) : buffer check");
69 char* current = buffer +
sizeof(buffer);
71 XRPL_ASSERT(current >= buffer,
"Json::valueToString(UInt) : buffer check");
84#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
86 sprintf_s(buffer,
sizeof(buffer),
"%.16g", value);
88 snprintf(buffer,
sizeof(buffer),
"%.16g", value);
96 return value ?
"true" :
"false";
109 unsigned const maxsize = (strlen(value) * 2) + 3;
114 for (
char const* c = value; *c != 0; ++c)
158 <<
static_cast<int>(*c);
188 switch (value.
type())
216 int const size = value.
size();
218 for (
int index = 0; index < size; ++index)
234 for (Value::Members::iterator it = members.
begin(); it != members.
end(); ++it)
238 if (it != members.
begin())
273 switch (value.
type())
314 Value::Members::iterator it = members.
begin();
319 Value const& childValue = value[name];
324 if (++it; it == members.
end())
341 unsigned const size = value.
size();
351 if (isArrayMultiLine)
360 Value const& childValue = value[index];
385 "Json::StyledWriter::writeArrayValue : child size match");
388 for (
unsigned index = 0; index < size; ++index)
404 int const size = value.
size();
408 for (
int index = 0; index < size && !isMultiLine; ++index)
410 Value const& childValue = value[index];
411 isMultiLine = isMultiLine ||
419 int lineLength = 4 + ((size - 1) * 2);
421 for (
int index = 0; index < size; ++index)
428 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
482 "Json::StyledWriter::unindent : maximum indent size");
507 switch (value.
type())
548 Value::Members::iterator it = members.
begin();
553 Value const& childValue = value[name];
558 if (++it == members.
end())
575 unsigned const size = value.
size();
585 if (isArrayMultiLine)
594 Value const& childValue = value[index];
619 "Json::StyledStreamWriter::writeArrayValue : child size match");
622 for (
unsigned index = 0; index < size; ++index)
638 int const size = value.
size();
642 for (
int index = 0; index < size && !isMultiLine; ++index)
644 Value const& childValue = value[index];
645 isMultiLine = isMultiLine ||
653 int lineLength = 4 + ((size - 1) * 2);
655 for (
int index = 0; index < size; ++index)
662 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
717 "Json::StyledStreamWriter::unindent : maximum indent size");
725 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)
void writeValue(Value const &value)
bool isMultilineArray(Value const &value)
void writeArrayValue(Value const &value)
StyledStreamWriter(std::string indentation="\t")
void pushValue(std::string const &value)
std::string indentString_
bool isMultilineArray(Value const &value)
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)
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.