QTextStream: remove a use of QString::sprintf()

Instead of using QString::sprintf() (and converting the result back to QByteArray),
simply do the conversion from uchar to hex digits ourselves, using QtMiscUtils.

This function is a copy of a similar (but not identical) one
in qprocess_unix.cpp, but it's not clear whether they can or
should be merged (both are only conditionally compiled), so
this patch does not attempt to do so.

Change-Id: I0be87963f78a98e35a54c98c5fb444756c57b672
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
bb10
Marc Mutz 2015-01-23 11:57:36 +01:00
parent 11abc94b04
commit 7ee74f870b
1 changed files with 11 additions and 4 deletions

View File

@ -233,6 +233,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384;
#if defined QTEXTSTREAM_DEBUG
#include <ctype.h>
#include "private/qtools_p.h"
QT_BEGIN_NAMESPACE
@ -250,10 +251,16 @@ static QByteArray qt_prettyDebug(const char *data, int len, int maxSize)
case '\n': out += "\\n"; break;
case '\r': out += "\\r"; break;
case '\t': out += "\\t"; break;
default:
QString tmp;
tmp.sprintf("\\x%x", (unsigned int)(unsigned char)c);
out += tmp.toLatin1();
default: {
const char buf[] = {
'\\',
'x',
QtMiscUtils::toHexLower(uchar(c) / 16),
QtMiscUtils::toHexLower(uchar(c) % 16),
0
};
out += buf;
}
}
}