QDebug: fix streaming of QChars
Commit 9ef3ff30
introduced a new function, putUcs4(), to
output QChar, char16_t, char32_t as a, possibly escaped,
character literal, but got the order of stream modifiers
wrong. Instead of applying the field width to the 'ucs'
streaming, it applied it to the prefix '\u'. The same
problem exists for the pad char, leading to the result
'00\ue4'
for a QChar containing
ä (LATIN SMALL LETTER A WITH DIAERESIS)
Fix by reordering the elements streamed so that the
prefixes come last.
Added a test.
Change-Id: I6eaa0586501b9e780aaa3bb5dcec0e5c2f86a219
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
4fb2b74119
commit
5a15545ee2
@ -160,16 +160,15 @@ void QDebug::putUcs4(uint ucs4)
|
||||
{
|
||||
maybeQuote('\'');
|
||||
if (ucs4 < 0x20) {
|
||||
stream->ts << hex << "\\x" << ucs4 << reset;
|
||||
stream->ts << "\\x" << hex << 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";
|
||||
stream->ts << "\\u" << qSetFieldWidth(4);
|
||||
else
|
||||
stream->ts << qSetFieldWidth(8) << "\\U";
|
||||
stream->ts << ucs4 << reset;
|
||||
stream->ts << "\\U" << qSetFieldWidth(8);
|
||||
stream->ts << hex << qSetPadChar(QLatin1Char('0')) << ucs4 << reset;
|
||||
}
|
||||
maybeQuote('\'');
|
||||
}
|
||||
|
@ -363,14 +363,14 @@ void tst_QDebug::qDebugQChar() const
|
||||
MessageHandlerSetter mhs(myMessageHandler);
|
||||
{
|
||||
QDebug d = qDebug();
|
||||
d << QChar('f');
|
||||
d.nospace().noquote() << QChar('o') << QChar('o');
|
||||
d << QChar('f') << QChar(QLatin1Char('\xE4')); // f, ä
|
||||
d.nospace().noquote() << QChar('o') << QChar('o') << QChar(QLatin1Char('\xC4')); // o, o, Ä
|
||||
}
|
||||
#ifndef QT_NO_MESSAGELOGCONTEXT
|
||||
file = __FILE__; line = __LINE__ - 5; function = Q_FUNC_INFO;
|
||||
#endif
|
||||
QCOMPARE(s_msgType, QtDebugMsg);
|
||||
QCOMPARE(s_msg, QString::fromLatin1("'f' oo"));
|
||||
QCOMPARE(s_msg, QString::fromLatin1("'f' '\\u00e4' oo\\u00c4"));
|
||||
QCOMPARE(QString::fromLatin1(s_file), file);
|
||||
QCOMPARE(s_line, line);
|
||||
QCOMPARE(QString::fromLatin1(s_function), function);
|
||||
|
Loading…
Reference in New Issue
Block a user