From 4ff398548170451bafdce09bd5d082498e89aabe Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 22 Jul 2014 15:01:37 +0200 Subject: [PATCH] Fixed comma placement issues with DTSC::Scan::toPrettyString --- lib/dtscmeta.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/dtscmeta.cpp b/lib/dtscmeta.cpp index 76e069b5..72c431d4 100644 --- a/lib/dtscmeta.cpp +++ b/lib/dtscmeta.cpp @@ -592,6 +592,7 @@ namespace DTSC { ret << "{" << std::endl; indent += 2; char * i = p + 1; + bool first = true; //object, scan contents while (i[0] + i[1] != 0 && i < p + len) { //while not encountering 0x0000 (we assume 0x0000EE) if (i + 2 >= p + len) { @@ -599,9 +600,13 @@ namespace DTSC { ret << std::string((size_t)indent, ' ') << "} //walked out of object here"; return ret.str(); } + if (!first){ + ret << "," << std::endl; + } + first = false; unsigned int strlen = i[0] * 256 + i[1]; i += 2; - ret << std::string((size_t)indent, ' ') << "\"" << std::string(i, strlen) << "\": " << Scan(i + strlen, len - (i - p)).toPrettyString(indent) << "," << std::endl; + ret << std::string((size_t)indent, ' ') << "\"" << std::string(i, strlen) << "\": " << Scan(i + strlen, len - (i - p)).toPrettyString(indent); i = skipDTSC(i + strlen, p + len); if (!i) { indent -= 2; @@ -610,7 +615,7 @@ namespace DTSC { } } indent -= 2; - ret << std::string((size_t)indent, ' ') << "}"; + ret << std::endl << std::string((size_t)indent, ' ') << "}"; return ret.str(); } case DTSC_ARR: { @@ -619,14 +624,19 @@ namespace DTSC { indent += 2; Scan tmpScan; unsigned int i = 0; + bool first = true; do { tmpScan = getIndice(i++); if (tmpScan.getType()) { - ret << std::string((size_t)indent, ' ') << tmpScan.toPrettyString(indent) << "," << std::endl; + if (!first){ + ret << "," << std::endl; + } + first = false; + ret << std::string((size_t)indent, ' ') << tmpScan.toPrettyString(indent); } } while (tmpScan.getType()); indent -= 2; - ret << std::string((size_t)indent, ' ') << "]"; + ret << std::endl << std::string((size_t)indent, ' ') << "]"; return ret.str(); } default: