From c99486e667e9e23c4d3a87d2730b60951a825261 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 13 Aug 2019 18:33:32 +0300 Subject: [PATCH] Simplify pretty-print in JsonBuilder. GitOrigin-RevId: bf1606d732c665555fa744ade9cd498af6a5ccf7 --- tdutils/td/utils/JsonBuilder.h | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/tdutils/td/utils/JsonBuilder.h b/tdutils/td/utils/JsonBuilder.h index 3526787f..42aeb962 100644 --- a/tdutils/td/utils/JsonBuilder.h +++ b/tdutils/td/utils/JsonBuilder.h @@ -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 @@ -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 @@ -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_ << " : ";