Add QTextStream operators for QStringView
Change-Id: I72d597fa21521a04b7f7c0e41bd45ee9dabb6222 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
0aea57dfc8
commit
189e40e11e
@ -2590,6 +2590,21 @@ QTextStream &QTextStream::operator<<(const QString &string)
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
|
||||
Writes \a string to the stream, and returns a reference to the
|
||||
QTextStream.
|
||||
\since 5.12
|
||||
*/
|
||||
QTextStream &QTextStream::operator<<(QStringView string)
|
||||
{
|
||||
Q_D(QTextStream);
|
||||
CHECK_VALID_STREAM(*this);
|
||||
d->putString(string.cbegin(), int(string.size()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
|
||||
|
@ -184,6 +184,7 @@ public:
|
||||
QTextStream &operator<<(float f);
|
||||
QTextStream &operator<<(double f);
|
||||
QTextStream &operator<<(const QString &s);
|
||||
QTextStream &operator<<(QStringView s);
|
||||
QTextStream &operator<<(QLatin1String s);
|
||||
QTextStream &operator<<(const QStringRef &s);
|
||||
QTextStream &operator<<(const QByteArray &array);
|
||||
|
@ -161,6 +161,7 @@ private slots:
|
||||
void string_write_operator_ToDevice();
|
||||
void latin1String_write_operator_ToDevice();
|
||||
void stringref_write_operator_ToDevice();
|
||||
void stringview_write_operator_ToDevice();
|
||||
|
||||
// other
|
||||
void skipWhiteSpace_data();
|
||||
@ -2573,6 +2574,17 @@ void tst_QTextStream::stringref_write_operator_ToDevice()
|
||||
QCOMPARE(buf.buffer().constData(), "No explicit lengthExplicit length");
|
||||
}
|
||||
|
||||
void tst_QTextStream::stringview_write_operator_ToDevice()
|
||||
{
|
||||
QBuffer buf;
|
||||
buf.open(QBuffer::WriteOnly);
|
||||
QTextStream stream(&buf);
|
||||
const QStringView expected = QStringViewLiteral("expectedStringView");
|
||||
stream << expected;
|
||||
stream.flush();
|
||||
QCOMPARE(buf.buffer().constData(), "expectedStringView");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
void tst_QTextStream::useCase1()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user