QTextStream: complete char16_t support

... by providing also op>> for char16_t.

[ChangeLog][QtCore][QTextStream] Added op>>(char16_t&).

Change-Id: I2f6cc2b2cdacd5190d364f94c1830f6de62d3b7e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Marc Mutz 2022-05-02 15:07:33 +02:00
parent 48a368b78f
commit 9b3885248b
3 changed files with 19 additions and 0 deletions

View File

@ -1995,6 +1995,14 @@ QTextStream &QTextStream::operator>>(char &c)
return *this;
}
/*!
\fn QTextStream &QTextStream::operator>>(char16_t &c)
\overload
\since 6.4
Reads a character from the stream and stores it in \a c.
*/
/*!
Reads an integer from the stream and stores it in \a i, then
returns a reference to the QTextStream. The number is cast to

View File

@ -153,6 +153,8 @@ public:
QTextStream &operator>>(QChar &ch);
QTextStream &operator>>(char &ch);
QTextStream &operator>>(char16_t &ch)
{ QChar c; *this >> c; ch = c.unicode(); return *this; }
QTextStream &operator>>(signed short &i);
QTextStream &operator>>(unsigned short &i);
QTextStream &operator>>(signed int &i);

View File

@ -1929,10 +1929,19 @@ void tst_QTextStream::char16_t_operators_FromDevice_data()
// ------------------------------------------------------------------------------
void tst_QTextStream::char16_t_operators_FromDevice()
{
QFETCH(QByteArray, input);
QFETCH(const QChar, qchar_output);
QFETCH(const QByteArray, write_output);
const char16_t char16_t_output = qchar_output.unicode();
QBuffer buf(&input);
buf.open(QBuffer::ReadOnly);
QTextStream stream(&buf);
stream.setEncoding(QStringConverter::Latin1);
char16_t tmp;
stream >> tmp;
QCOMPARE(tmp, qchar_output);
QBuffer writeBuf;
writeBuf.open(QBuffer::WriteOnly);