From 9b3885248b80cbb22826bcc6e339231db11aab1f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 2 May 2022 15:07:33 +0200 Subject: [PATCH] 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 Reviewed-by: Edward Welbourne --- src/corelib/serialization/qtextstream.cpp | 8 ++++++++ src/corelib/serialization/qtextstream.h | 2 ++ .../serialization/qtextstream/tst_qtextstream.cpp | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp index a29be8969a..f916582f41 100644 --- a/src/corelib/serialization/qtextstream.cpp +++ b/src/corelib/serialization/qtextstream.cpp @@ -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 diff --git a/src/corelib/serialization/qtextstream.h b/src/corelib/serialization/qtextstream.h index 05631c0883..054a5d0972 100644 --- a/src/corelib/serialization/qtextstream.h +++ b/src/corelib/serialization/qtextstream.h @@ -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); diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 5a7be18823..7f674cda42 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -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);