From d426b75daa66e0a1c109c59900be2172abe70d19 Mon Sep 17 00:00:00 2001 From: ljfa-ag Date: Mon, 10 Aug 2015 22:41:15 +0200 Subject: Handle lists of lists or compounds differently for printing --- src/text/json_formatter.cpp | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/text/json_formatter.cpp b/src/text/json_formatter.cpp index 7edecf72f7..d1fce85375 100644 --- a/src/text/json_formatter.cpp +++ b/src/text/json_formatter.cpp @@ -66,21 +66,42 @@ namespace //anonymous void visit(const tag_list& l) override { - os << "[\n"; - ++indent_lvl; - for(unsigned int i = 0; i < l.size(); ++i) + //Wrap lines for lists of lists or compounds. + //Lists of other types can usually be on one line without problem. + const bool break_lines = l.size() > 0 && + (l.el_type() == tag_type::List || l.el_type() == tag_type::Compound); + + os << "["; + if(break_lines) { - indent(); - if(l[i]) - l[i].get().accept(*this); - else - write_null(); - if(i != l.size()-1) - os << ","; os << "\n"; + ++indent_lvl; + for(unsigned int i = 0; i < l.size(); ++i) + { + indent(); + if(l[i]) + l[i].get().accept(*this); + else + write_null(); + if(i != l.size()-1) + os << ","; + os << "\n"; + } + --indent_lvl; + indent(); + } + else + { + for(unsigned int i = 0; i < l.size(); ++i) + { + if(l[i]) + l[i].get().accept(*this); + else + write_null(); + if(i != l.size()-1) + os << ", "; + } } - --indent_lvl; - indent(); os << "]"; } -- cgit 0.0.5-2-1-g0f52