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 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) && \
85 defined(__STDC_SECURE_LIB__)
87 sprintf_s(buffer,
sizeof(buffer),
"%.16g", value);
89 snprintf(buffer,
sizeof(buffer),
"%.16g", value);
97 return value ?
"true" :
"false";
104 if (strpbrk(value,
"\"\\\b\f\n\r\t") ==
nullptr &&
111 unsigned maxsize = strlen(value) * 2 + 3;
116 for (
char const* c = value; *c != 0; ++c)
161 <<
static_cast<int>(*c);
191 switch (value.
type())
219 int size = value.
size();
221 for (
int index = 0; index < size; ++index)
237 for (Value::Members::iterator it = members.
begin();
243 if (it != members.
begin())
278 switch (value.
type())
317 Value::Members::iterator it = members.
begin();
322 Value const& childValue = value[name];
327 if (++it == members.
end())
344 unsigned size = value.
size();
352 if (isArrayMultiLine)
361 Value const& childValue = value[index];
384 "Json::StyledWriter::writeArrayValue : child size match");
387 for (
unsigned index = 0; index < size; ++index)
403 int size = value.
size();
407 for (
int index = 0; index < size && !isMultiLine; ++index)
409 Value const& childValue = value[index];
410 isMultiLine = isMultiLine ||
412 childValue.
size() > 0);
419 int lineLength = 4 + (size - 1) * 2;
421 for (
int index = 0; index < size; ++index)
428 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
478 "Json::StyledWriter::unindent : maximum indent size");
486 : document_(nullptr), rightMargin_(74), indentation_(indentation)
504 switch (value.
type())
543 Value::Members::iterator it = members.
begin();
548 Value const& childValue = value[name];
553 if (++it == members.
end())
570 unsigned size = value.
size();
578 if (isArrayMultiLine)
587 Value const& childValue = value[index];
610 "Json::StyledStreamWriter::writeArrayValue : child size match");
613 for (
unsigned index = 0; index < size; ++index)
629 int size = value.
size();
633 for (
int index = 0; index < size && !isMultiLine; ++index)
635 Value const& childValue = value[index];
636 isMultiLine = isMultiLine ||
638 childValue.
size() > 0);
645 int lineLength = 4 + (size - 1) * 2;
647 for (
int index = 0; index < size; ++index)
654 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
705 "Json::StyledStreamWriter::unindent : maximum indent size");
713 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.