From f5cbe7343da2c79c6381472c6666c5339df76b46 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Tue, 23 Apr 2013 14:39:52 +0200 Subject: [PATCH] Tweaked pretty printing in several cases. --- lib/json.cpp | 18 +++++++++++------- lib/mp4.cpp | 11 ++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/json.cpp b/lib/json.cpp index e5f2d72e..dc6b3da2 100644 --- a/lib/json.cpp +++ b/lib/json.cpp @@ -581,11 +581,11 @@ std::string JSON::Value::toPrettyString(int indentation){ } case ARRAY: { if (arrVal.size() > 0){ - std::string tmp = "[\n"; + std::string tmp = "[\n" + std::string(indentation + 2, ' '); for (ArrIter it = ArrBegin(); it != ArrEnd(); it++){ - tmp += std::string(indentation + 2, ' ') + it->toPrettyString(indentation + 2); + tmp += it->toPrettyString(indentation + 2); if (it + 1 != ArrEnd()){ - tmp += ",\n"; + tmp += ", "; } } tmp += "\n" + std::string(indentation, ' ') + "]"; @@ -597,17 +597,21 @@ std::string JSON::Value::toPrettyString(int indentation){ } case OBJECT: { if (objVal.size() > 0){ - std::string tmp2 = "{\n"; + bool shortMode = false; + if (size() <= 3 && isMember("len")){ + shortMode = true; + } + std::string tmp2 = "{" + std::string((shortMode ? "" : "\n")); ObjIter it3 = ObjEnd(); --it3; for (ObjIter it2 = ObjBegin(); it2 != ObjEnd(); it2++){ - tmp2 += std::string(indentation + 2, ' ') + "\"" + it2->first + "\":"; + tmp2 += (shortMode ? std::string("") : std::string(indentation + 2, ' ')) + "\"" + it2->first + "\":"; tmp2 += it2->second.toPrettyString(indentation + 2); if (it2 != it3){ - tmp2 += ",\n"; + tmp2 += "," + std::string((shortMode ? " " : "\n")); } } - tmp2 += "\n" + std::string(indentation, ' ') + "}"; + tmp2 += (shortMode ? std::string("") : "\n" + std::string(indentation, ' ')) + "}"; return tmp2; }else{ return "{}"; diff --git a/lib/mp4.cpp b/lib/mp4.cpp index c94dacbb..3b9cfce3 100644 --- a/lib/mp4.cpp +++ b/lib/mp4.cpp @@ -1490,20 +1490,21 @@ namespace MP4 { r << std::string(indent + 1, ' ') << "SampleInformation (" << getSampleInformationCount() << "):" << std::endl; for (int i = 0; i < getSampleInformationCount(); ++i){ - r << std::string(indent + 2, ' ') << "[" << i << "]" << std::endl; + r << std::string(indent + 2, ' ') << "[" << i << "] "; trunSampleInformation samp = getSampleInformation(i); if (flags & trunsampleDuration){ - r << std::string(indent + 2, ' ') << "Duration " << samp.sampleDuration << std::endl; + r << "Duration=" << samp.sampleDuration << " "; } if (flags & trunsampleSize){ - r << std::string(indent + 2, ' ') << "Size " << samp.sampleSize << std::endl; + r << "Size=" << samp.sampleSize << " "; } if (flags & trunsampleFlags){ - r << std::string(indent + 2, ' ') << "Flags " << prettySampleFlags(samp.sampleFlags) << std::endl; + r << "Flags=" << prettySampleFlags(samp.sampleFlags) << " "; } if (flags & trunsampleOffsets){ - r << std::string(indent + 2, ' ') << "Offset " << samp.sampleOffset << std::endl; + r << "Offset=" << samp.sampleOffset << " "; } + r << std::endl; } return r.str();