1#include <xrpl/json/json_writer.h>
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/json/json_forwards.h>
5#include <xrpl/json/json_value.h>
21 return ch > 0 && ch <= 0x1F;
42 *--current = (value % 10) +
'0';
51 char* current = buffer +
sizeof(buffer);
52 bool const isNegative = value < 0;
62 XRPL_ASSERT(current >= buffer,
"json::valueToString(Int) : buffer check");
70 char* current = buffer +
sizeof(buffer);
72 XRPL_ASSERT(current >= buffer,
"json::valueToString(UInt) : buffer check");
85#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
87 sprintf_s(buffer,
sizeof(buffer),
"%.16g", value);
89 snprintf(buffer,
sizeof(buffer),
"%.16g", value);
97 return value ?
"true" :
"false";
110 unsigned const maxsize = (strlen(value) * 2) + 3;
115 for (
char const* c = value; *c != 0; ++c)
159 <<
static_cast<int>(*c);
189 switch (value.type())
217 int const size = value.size();
219 for (
int index = 0; index < size; ++index)
235 for (Value::Members::iterator it = members.
begin(); it != members.
end(); ++it)
239 if (it != members.
begin())
272 switch (value.type())
313 Value::Members::iterator it = members.
begin();
318 Value const& childValue = value[name];
323 if (++it; it == members.
end())
340 unsigned const size = value.size();
350 if (isArrayMultiLine)
359 Value const& childValue = value[index];
384 "json::StyledWriter::writeArrayValue : child size match");
387 for (
unsigned index = 0; index < size; ++index)
403 int const size = value.size();
407 for (
int index = 0; index < size && !isMultiLine; ++index)
409 Value const& childValue = value[index];
410 isMultiLine = isMultiLine ||
418 int lineLength = 4 + ((size - 1) * 2);
420 for (
int index = 0; index < size; ++index)
427 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
481 "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);
void writeValue(Value const &value)
std::string write(Value const &root) override
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string.
void pushValue(std::string const &value)
void writeArrayValue(Value const &value)
void write(std::ostream &out, Value const &root)
Serialize a Value in JSON format.
void writeValue(Value const &value)
bool isMultilineArray(Value const &value)
StyledStreamWriter(std::string indentation="\t")
void writeWithIndent(std::string const &value)
std::string indentString_
void pushValue(std::string const &value)
bool isMultilineArray(Value const &value)
std::string write(Value const &root) override
Serialize a Value in JSON format.
std::string indentString_
void writeValue(Value const &value)
void writeWithIndent(std::string const &value)
void writeArrayValue(Value const &value)
std::vector< std::string > Members
UInt size() const
Number of values in array or object.
JSON (JavaScript Object Notation).
std::string valueToQuotedString(char const *value)
static bool containsControlCharacter(char const *str)
static bool isControlCharacter(char ch)
@ UInt
unsigned integer value
@ Int
signed integer value
@ String
UTF-8 string value.
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
static void uintToString(unsigned int value, char *¤t)
std::ostream & operator<<(std::ostream &, Value const &root)
Output using the StyledStreamWriter.
std::string valueToString(Int value)