Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,8 @@ class JSON_API Value {
/// Include delimiters and embedded newlines.
String getComment(CommentPlacement placement) const;

String toStyledString() const;
String toStyledString(const StreamWriterBuilder& builder = StreamWriterBuilder()) const;
String toStyledString(int precision, PrecisionType precisionType = PrecisionType::decimalPlaces) const;

const_iterator begin() const;
const_iterator end() const;
Expand Down
12 changes: 8 additions & 4 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,16 +1559,20 @@ ptrdiff_t Value::getOffsetStart() const { return start_; }

ptrdiff_t Value::getOffsetLimit() const { return limit_; }

String Value::toStyledString() const {
StreamWriterBuilder builder;

String Value::toStyledString(const StreamWriterBuilder& builder) const {
String out = this->hasComment(commentBefore) ? "\n" : "";
out += Json::writeString(builder, *this);
out += '\n';

return out;
}

String Value::toStyledString(int precision, PrecisionType precisionType) const {
StreamWriterBuilder builder;
precisionType == PrecisionType::significantDigits?builder.settings_["precisionType"] = "significant":builder.settings_["precisionType"] = "decimal";
builder.settings_["precision"] = std::min(precision, 17);
return toStyledString(builder);
}

Value::const_iterator Value::begin() const {
switch (type()) {
case arrayValue:
Expand Down