QTextStream: add missing op<<(QStringRef)
It simply is missing. We could wait for QStringView to come around, but I need this function in uic _now_, so let's add it. [ChangeLog][QtCore][QTextStream] Can now stream QStringRef without converting to a QString first. Change-Id: Idd178e0ba8a89c025f4533d46de912cbdb3883d5 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>bb10
parent
e9835a3812
commit
dde8d5e3a0
|
|
@ -2519,6 +2519,21 @@ QTextStream &QTextStream::operator<<(QLatin1String string)
|
|||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.6
|
||||
\overload
|
||||
|
||||
Writes \a string to the stream, and returns a reference to the
|
||||
QTextStream.
|
||||
*/
|
||||
QTextStream &QTextStream::operator<<(const QStringRef &string)
|
||||
{
|
||||
Q_D(QTextStream);
|
||||
CHECK_VALID_STREAM(*this);
|
||||
d->putString(string.data(), string.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ public:
|
|||
QTextStream &operator<<(double f);
|
||||
QTextStream &operator<<(const QString &s);
|
||||
QTextStream &operator<<(QLatin1String s);
|
||||
QTextStream &operator<<(const QStringRef &s);
|
||||
QTextStream &operator<<(const QByteArray &array);
|
||||
QTextStream &operator<<(const char *c);
|
||||
QTextStream &operator<<(const void *ptr);
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ private slots:
|
|||
void string_write_operator_ToDevice_data();
|
||||
void string_write_operator_ToDevice();
|
||||
void latin1String_write_operator_ToDevice();
|
||||
void stringref_write_operator_ToDevice();
|
||||
|
||||
// other
|
||||
void skipWhiteSpace_data();
|
||||
|
|
@ -2554,6 +2555,22 @@ void tst_QTextStream::latin1String_write_operator_ToDevice()
|
|||
QCOMPARE(buf.buffer().constData(), "No explicit lengthExplicit length");
|
||||
}
|
||||
|
||||
void tst_QTextStream::stringref_write_operator_ToDevice()
|
||||
{
|
||||
QBuffer buf;
|
||||
buf.open(QBuffer::WriteOnly);
|
||||
QTextStream stream(&buf);
|
||||
stream.setCodec(QTextCodec::codecForName("ISO-8859-1"));
|
||||
stream.setAutoDetectUnicode(true);
|
||||
|
||||
const QString expected = "No explicit lengthExplicit length";
|
||||
|
||||
stream << expected.leftRef(18);
|
||||
stream << expected.midRef(18);
|
||||
stream.flush();
|
||||
QCOMPARE(buf.buffer().constData(), "No explicit lengthExplicit length");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
void tst_QTextStream::useCase1()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue