mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-09-24 04:32:32 -04:00
feat(JSON): Add precision control parameters to toStyledString
Add support for controlling the precision of JSON string output through parameters, including two modes: decimal places and significant figures.
This commit is contained in:
parent
ca98c98457
commit
88000109da
@ -650,7 +650,8 @@ public:
|
||||
/// 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;
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user