summaryrefslogtreecommitdiff
path: root/src/text/json_formatter.cpp
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-08-10 22:41:15 +0200
committerljfa-ag <ljfa-ag@web.de>2015-08-10 22:41:15 +0200
commitd426b75daa66e0a1c109c59900be2172abe70d19 (patch)
tree4bdef588a271ff8a6223a2c05644901127fa7130 /src/text/json_formatter.cpp
parent6a04146baee5662f4debe03f0a401ea434a330f0 (diff)
downloadProject-Tick-d426b75daa66e0a1c109c59900be2172abe70d19.tar.gz
Project-Tick-d426b75daa66e0a1c109c59900be2172abe70d19.zip
Handle lists of lists or compounds differently for printing
Diffstat (limited to 'src/text/json_formatter.cpp')
-rw-r--r--src/text/json_formatter.cpp45
1 files changed, 33 insertions, 12 deletions
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 << "]";
}