Tweaked pretty printing in several cases.

This commit is contained in:
Erik Zandvliet 2013-04-23 14:39:52 +02:00
parent b9613149e0
commit f5cbe7343d
2 changed files with 17 additions and 12 deletions

View file

@ -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 "{}";

View file

@ -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();