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_ << " : ";