From 51b7bd1e4faa5111489c4376a02969ad8197fadf Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 23 Jan 2015 14:25:07 -0800 Subject: Output the JSON binary data with printable characters This makes it easier to debug QJsonDocument binary bugs. Note that the last character is never printed as printable, but by way of construction it's always binary data anyway (the offsets table is at the end after parsing JSON sources). Change-Id: I8a7a116f51864cecb52fffff13bc24ad01ad8a49 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/tools/moc/generator.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/tools/moc') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index bd9a002d5b..46acbc608b 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1530,7 +1530,13 @@ static void writePluginMetaData(FILE *out, const QJsonObject &data) const QByteArray binary = doc.toBinaryData(); const int last = binary.size() - 1; for (int i = 0; i < last; ++i) { - fprintf(out, " 0x%02x,", (uchar)binary.at(i)); + uchar c = (uchar)binary.at(i); + if (c < 0x20 || c >= 0x7f) + fprintf(out, " 0x%02x,", c); + else if (c == '\'' || c == '\\') + fprintf(out, " '\\%c',", c); + else + fprintf(out, " '%c', ", c); if (!((i + 1) % 8)) fputs("\n ", out); } -- cgit v1.2.3