From f2abfb39d775deffe16fe08a58c9518bd12c43f3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 30 Jul 2020 17:21:37 -0700 Subject: QDebug: add operator<<(const char16_t *) Avoids the conversion from UTF-8 for uses that are not dumping a string. Mass conversion of Qt sources left for future opportunity. Fixes: QTBUG-85811 Change-Id: I4ca4a35b687b46c39030fffd1626ae6c3294cacf Reviewed-by: Edward Welbourne Reviewed-by: Lars Knoll --- src/corelib/io/qdebug.cpp | 35 +++++++++++++++++++++++++---------- src/corelib/io/qdebug.h | 1 + 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index bac362dc80..120c6b13a8 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -597,9 +597,24 @@ QDebug &QDebug::resetFormat() /*! \fn QDebug &QDebug::operator<<(const char *t) - Writes the '\\0'-terminated string, \a t, to the stream and returns a - reference to the stream. The string is never quoted nor transformed to the - output, but note that some QDebug backends might not be 8-bit clean. + Writes the '\\0'-terminated UTF-8 string, \a t, to the stream and returns a + reference to the stream. The string is never quoted or escaped for the + output. Note that QDebug buffers internally as UTF-16 and may need to + transform to 8-bit using the locale's codec in order to use some backends, + which may cause garbled output (mojibake). Restricting to US-ASCII strings + is recommended. +*/ + +/*! + \fn QDebug &QDebug::operator<<(const char16_t *t) + \since 6.0 + + Writes the u'\\0'-terminated UTF-16 string, \a t, to the stream and returns + a reference to the stream. The string is never quoted or escaped for the + output. Note that QDebug buffers internally as UTF-16 and may need to + transform to 8-bit using the locale's codec in order to use some backends, + which may cause garbled output (mojibake). Restricting to US-ASCII strings + is recommended. */ /*! @@ -950,18 +965,18 @@ QDebug qt_QMetaEnum_debugOperator(QDebug &dbg, int value, const QMetaObject *met const int verbosity = dbg.verbosity(); if (verbosity >= QDebug::DefaultVerbosity) { if (const char *scope = me.scope()) - dbg << scope << "::"; + dbg << scope << u"::"; } const char *key = me.valueToKey(value); const bool scoped = me.isScoped() || verbosity & 1; if (scoped || !key) - dbg << me.enumName() << (!key ? "(" : "::"); + dbg << me.enumName() << (!key ? u"(" : u"::"); if (key) dbg << key; else - dbg << value << ")"; + dbg << value << ')'; return dbg; } @@ -1008,18 +1023,18 @@ QDebug qt_QMetaEnum_flagDebugOperator(QDebug &debug, quint64 value, const QMetaO const bool classScope = verbosity >= QDebug::DefaultVerbosity; if (classScope) { - debug << "QFlags<"; + debug << u"QFlags<"; if (const char *scope = me.scope()) - debug << scope << "::"; + debug << scope << u"::"; } const bool enumScope = me.isScoped() || verbosity > QDebug::MinimumVerbosity; if (enumScope) { debug << me.enumName(); if (classScope) - debug << ">"; - debug << "("; + debug << '>'; + debug << '('; } debug << me.valueToKeys(value); diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 46fd762874..77004ef952 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -155,6 +155,7 @@ public: inline QDebug &operator<<(float t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(double t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(const char* t) { stream->ts << QString::fromUtf8(t); return maybeSpace(); } + inline QDebug &operator<<(const char16_t *t) { stream->ts << QStringView(t); return maybeSpace(); } #if QT_STRINGVIEW_LEVEL < 2 inline QDebug &operator<<(const QString & t) { putString(t.constData(), uint(t.length())); return maybeSpace(); } #endif -- cgit v1.2.3