convert strings via the stream codec in QTextStream streaming operators

fixes printing of non-ASCII debug messages (no longer printed as question
marks)

upstream commit:
e96a311334

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-08-09 03:39:58 +03:00
parent 730c3ae5a9
commit 7cc69806a1
2 changed files with 19 additions and 8 deletions

3
README
View file

@ -85,7 +85,8 @@ QTBUG-39285, QTBUG-18173, QTBUG-28968, QTBUG-34336, QTBUG-40974, QTBUG-44286,
QTBUG-12564, QTBUG-20028, QTBUG-71967, QTBUG-70956, QTBUG-71446, QTBUG-61307,
QTBUG-27287, QTBUG-25143, QTBUG-22833, QTBUG-57399, QTBUG-59159, QTBUG-15773,
QTBUG-70506, QTBUG-46054, QTBUG-11223, QTBUG-63108, QTBUG-6932, QTBUG-42365,
QTBUG-83817, QTBUG-4341, QTBUG-36933, QTBUG-49113, QTBUG-69920, QTBUG-40015
QTBUG-83817, QTBUG-4341, QTBUG-36933, QTBUG-49113, QTBUG-69920, QTBUG-40015,
QTBUG-54942
Unless you use QMake and QDoc porting to Katie or even supporting it along with
Qt4 in the same codebase is trivial and requires only minor changes because

View file

@ -468,7 +468,7 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes)
// convert to unicode
readBuffer += codec->toUnicode(buffer.constData(), bytesRead, &readConverterState);
#else
readBuffer += QString::fromLatin1(buffer.constData());
readBuffer += QString::fromAscii(buffer.constData());
#endif
// reset the Text flag.
@ -2064,9 +2064,10 @@ QTextStream &QTextStream::operator>>(QString &str)
/*!
\overload
Converts the word to ISO-8859-1, then stores it in \a array.
Converts the word to Unicode via the stream codec, then stores it in
\a array.
\sa QString::toLatin1()
\sa QTextCodec::fromUnicode(), QString::toAscii()
*/
QTextStream &QTextStream::operator>>(QByteArray &array)
{
@ -2084,8 +2085,11 @@ QTextStream &QTextStream::operator>>(QByteArray &array)
return *this;
}
for (int i = 0; i < length; ++i)
array += ptr[i].toLatin1();
#ifndef QT_NO_TEXTCODEC
array = d->codec->fromUnicode(QString(ptr, length));
#else
array = QString(ptr, length).toAscii();
#endif
d->consumeLastToken();
return *this;
@ -2396,7 +2400,7 @@ QTextStream &QTextStream::operator<<(const QByteArray &array)
\overload
Writes the constant string pointed to by \a string to the stream. \a
string is assumed to be in ISO-8859-1 encoding. This operator
string is encoded via the stream codec. This operator
is convenient when working with constant string data. Example:
\snippet doc/src/snippets/code/src_corelib_io_qtextstream.cpp 8
@ -2404,12 +2408,18 @@ QTextStream &QTextStream::operator<<(const QByteArray &array)
Warning: QTextStream assumes that \a string points to a string of
text, terminated by a '\0' character. If there is no terminating
'\0' character, your application may crash.
\sa QTextCodec::toUnicode(), QString::fromAscii()
*/
QTextStream &QTextStream::operator<<(const char *string)
{
Q_D(QTextStream);
CHECK_VALID_STREAM(*this);
d->putString(QLatin1String(string));
#ifndef QT_NO_TEXTCODEC
d->putString(d->codec->toUnicode(string, qstrlen(string)));
#else
d->putString(QString::fromAscii(string));
#endif
return *this;
}