diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-11-17 21:11:23 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2014-12-04 02:26:29 +0100 |
commit | 9ef3ff30e1119ed61791eabe237758665e574060 (patch) | |
tree | d04d66b472ecb922aa2b50960a7141df238d90c4 /src/corelib | |
parent | 9287f17db5b8340b03edb125a3de1ec61c830a50 (diff) |
Add support for char16_t, char32_t and std::nullptr_t in QDebug
This is required before we can add support for those three types in
QVariant.
This commit changes the output format for QChar when it falls outside
the printable ASCII range. In the future, it might be nice to use the
pretty-printing of control characters like QtTest and QJsonDocument.
Change-Id: I4d942da8d11f83de9c1b485ea6ca804fe1622602
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qdebug.cpp | 22 | ||||
-rw-r--r-- | src/corelib/io/qdebug.h | 11 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index c1e0125cb1..9eed1f352a 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -148,6 +148,28 @@ QDebug::~QDebug() } /*! + \internal +*/ +void QDebug::putUcs4(uint ucs4) +{ + maybeQuote('\''); + if (ucs4 < 0x20) { + stream->ts << hex << "\\x" << ucs4 << reset; + } else if (ucs4 < 0x80) { + stream->ts << char(ucs4); + } else { + stream->ts << hex << qSetPadChar(QLatin1Char('0')); + if (ucs4 < 0x10000) + stream->ts << qSetFieldWidth(4) << "\\u"; + else + stream->ts << qSetFieldWidth(8) << "\\U"; + stream->ts << ucs4 << reset; + } + maybeQuote('\''); +} + + +/*! \fn QDebug::swap(QDebug &other) \since 5.0 diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 4edb3057fb..4295800f1a 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -76,6 +76,8 @@ class Q_CORE_EXPORT QDebug // added in 5.4 int flags; } *stream; + + void putUcs4(uint ucs4); public: inline QDebug(QIODevice *device) : stream(new Stream(device)) {} inline QDebug(QString *string) : stream(new Stream(string)) {} @@ -98,11 +100,15 @@ public: inline QDebug &noquote() { stream->setFlag(Stream::NoQuotes); return *this; } inline QDebug &maybeQuote(char c = '"') { if (!(stream->testFlag(Stream::NoQuotes))) stream->ts << c; return *this; } - inline QDebug &operator<<(QChar t) { maybeQuote('\''); stream->ts << t; maybeQuote('\''); return maybeSpace(); } + inline QDebug &operator<<(QChar t) { putUcs4(t.unicode()); return maybeSpace(); } inline QDebug &operator<<(bool t) { stream->ts << (t ? "true" : "false"); return maybeSpace(); } inline QDebug &operator<<(char t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(signed short t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(unsigned short t) { stream->ts << t; return maybeSpace(); } +#ifdef Q_COMPILER_UNICODE_STRINGS + inline QDebug &operator<<(char16_t t) { return *this << QChar(t); } + inline QDebug &operator<<(char32_t t) { putUcs4(t); return maybeSpace(); } +#endif inline QDebug &operator<<(signed int t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(unsigned int t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(signed long t) { stream->ts << t; return maybeSpace(); } @@ -117,6 +123,9 @@ public: 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<<(const void * t) { stream->ts << t; return maybeSpace(); } +#ifdef Q_COMPILER_NULLPTR + inline QDebug &operator<<(std::nullptr_t) { stream->ts << "(nullptr)"; return maybeSpace(); } +#endif inline QDebug &operator<<(QTextStreamFunction f) { stream->ts << f; return *this; |