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) && 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 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 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())
312 Value::Members::iterator it = members.
begin();
317 Value const& childValue = value[name];
322 if (++it == members.
end())
339 unsigned size = value.
size();
347 if (isArrayMultiLine)
356 Value const& childValue = value[index];
377 XRPL_ASSERT(
childValues_.
size() == size,
"Json::StyledWriter::writeArrayValue : child size match");
380 for (
unsigned index = 0; index < size; ++index)
396 int size = value.
size();
400 for (
int index = 0; index < size && !isMultiLine; ++index)
402 Value const& childValue = value[index];
403 isMultiLine = isMultiLine || ((childValue.
isArray() || childValue.
isObject()) && childValue.
size() > 0);
410 int lineLength = 4 + (size - 1) * 2;
412 for (
int index = 0; index < size; ++index)
419 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
475 : document_(nullptr), rightMargin_(74), indentation_(indentation)
493 switch (value.
type())
532 Value::Members::iterator it = members.
begin();
537 Value const& childValue = value[name];
542 if (++it == members.
end())
559 unsigned size = value.
size();
567 if (isArrayMultiLine)
576 Value const& childValue = value[index];
597 XRPL_ASSERT(
childValues_.
size() == size,
"Json::StyledStreamWriter::writeArrayValue : child size match");
600 for (
unsigned index = 0; index < size; ++index)
616 int size = value.
size();
620 for (
int index = 0; index < size && !isMultiLine; ++index)
622 Value const& childValue = value[index];
623 isMultiLine = isMultiLine || ((childValue.
isArray() || childValue.
isObject()) && childValue.
size() > 0);
630 int lineLength = 4 + (size - 1) * 2;
632 for (
int index = 0; index < size; ++index)
639 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
697 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.