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) <ogoffart@woboq.com>
This commit is contained in:
Thiago Macieira 2015-01-23 14:25:07 -08:00
parent b584648df1
commit 51b7bd1e4f

View File

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