Simplify pretty-print in JsonBuilder.

GitOrigin-RevId: bf1606d732c665555fa744ade9cd498af6a5ccf7
This commit is contained in:
levlam 2019-08-13 18:33:32 +03:00
parent 2f7fc17460
commit c99486e667

View File

@ -198,8 +198,11 @@ class JsonBuilder {
return offset_ >= 0;
}
void print_offset() {
for (int x = 0; x < offset_; x++) {
sb_ << " ";
if (offset_ >= 0) {
sb_ << '\n';
for (int x = 0; x < offset_; x++) {
sb_ << " ";
}
}
}
void dec_offset() {
@ -363,10 +366,7 @@ class JsonArrayScope : public JsonScope {
}
void leave() {
jb_->dec_offset();
if (jb_->is_pretty()) {
*sb_ << "\n";
jb_->print_offset();
}
jb_->print_offset();
*sb_ << "]";
}
template <class T>
@ -385,10 +385,7 @@ class JsonArrayScope : public JsonScope {
} else {
is_first_ = true;
}
if (jb_->is_pretty()) {
*sb_ << "\n";
jb_->print_offset();
}
jb_->print_offset();
return jb_->enter_value();
}
@ -410,10 +407,7 @@ class JsonObjectScope : public JsonScope {
}
void leave() {
jb_->dec_offset();
if (jb_->is_pretty()) {
*sb_ << "\n";
jb_->print_offset();
}
jb_->print_offset();
*sb_ << "}";
}
template <class S, class T>
@ -432,10 +426,7 @@ class JsonObjectScope : public JsonScope {
} else {
is_first_ = true;
}
if (jb_->is_pretty()) {
*sb_ << "\n";
jb_->print_offset();
}
jb_->print_offset();
jb_->enter_value() << key;
if (jb_->is_pretty()) {
*sb_ << " : ";