summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdebug.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-11-18 15:20:21 -0800
committerThiago Macieira <thiago.macieira@intel.com>2015-01-11 03:40:43 +0100
commit62b752b3a2c9a69b5eb9a41b98293e83de347958 (patch)
tree5a713d94545e6a52631d3b5878d06d6f81ac2fe3 /src/corelib/io/qdebug.h
parent2c01d402e19b6137cf24794cbc4533a2b8b2d816 (diff)
Do the same for qDebug of QByteArray and QLatin1String
QLatin1String are actually Unicode, so print them with \uXXXX sequences. QByteArray are binary (arbitrary), so print as hex. Since hex escape sequences in C are not limited in length (\x00000F is a valid hex sequence), we need to insert "" if the next character is a valid hex digit. [ChangeLog][QtCore][QDebug] Similarly, printing of QByteArrays whenever "noquote" is not active now prints the arrays in a format consumable in C++, with all non-printable characters printed in hex escape sequences. Change-Id: Ibd0c1a97cbac98610c65c1091bfbcf5581c835db Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/corelib/io/qdebug.h')
-rw-r--r--src/corelib/io/qdebug.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index a2d6598bce..2f487b8a1f 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -77,8 +77,11 @@ class Q_CORE_EXPORT QDebug
int flags;
} *stream;
+ enum Latin1Content { ContainsBinary = 0, ContainsLatin1 };
+
void putUcs4(uint ucs4);
void putString(const QChar *begin, size_t length);
+ void putByteArray(const char *begin, size_t length, Latin1Content content);
public:
inline QDebug(QIODevice *device) : stream(new Stream(device)) {}
inline QDebug(QString *string) : stream(new Stream(string)) {}
@@ -121,8 +124,8 @@ public:
inline QDebug &operator<<(const char* t) { stream->ts << QString::fromUtf8(t); return maybeSpace(); }
inline QDebug &operator<<(const QString & t) { putString(t.constData(), uint(t.length())); return maybeSpace(); }
inline QDebug &operator<<(const QStringRef & t) { putString(t.constData(), uint(t.length())); return maybeSpace(); }
- inline QDebug &operator<<(QLatin1String t) { maybeQuote(); stream->ts << t; maybeQuote(); return maybeSpace(); }
- inline QDebug &operator<<(const QByteArray & t) { maybeQuote(); stream->ts << t; maybeQuote(); return maybeSpace(); }
+ inline QDebug &operator<<(QLatin1String t) { putByteArray(t.latin1(), t.size(), ContainsLatin1); return maybeSpace(); }
+ inline QDebug &operator<<(const QByteArray & t) { putByteArray(t.constData(), t.size(), ContainsBinary); return maybeSpace(); }
inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); }
#ifdef Q_COMPILER_NULLPTR
inline QDebug &operator<<(std::nullptr_t) { stream->ts << "(nullptr)"; return maybeSpace(); }