QCborStreamWriter: add append(QUtf8StringView)
And test appendTextString() through it, which was apparently not directly tested until now (only through appending Latin1 and UTF-16 strings). [ChangeLog][QtCore][QCborStreamWriter] Added a QUtf8StringView overload of append(). Change-Id: I4d306ab1561a4fd6e9a8fffd65f352bdb78b96b9 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
c17a934197
commit
59a081dc7e
@ -419,6 +419,18 @@ void QCborStreamWriter::append(QCborNegativeInteger n)
|
|||||||
QCborStreamReader::readByteArray()
|
QCborStreamReader::readByteArray()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void QCborStreamWriter::append(QUtf8StringView str)
|
||||||
|
\since 6.10
|
||||||
|
\overload
|
||||||
|
|
||||||
|
Appends the UTF-8 string viewed by \a str to the stream, creating a CBOR
|
||||||
|
Text String value. QCborStreamWriter will attempt to write the entire string
|
||||||
|
in one chunk.
|
||||||
|
|
||||||
|
\sa appendTextString(), QCborStreamReader::isString(), QCborStreamReader::readString()
|
||||||
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\overload
|
\overload
|
||||||
|
|
||||||
@ -435,7 +447,7 @@ void QCborStreamWriter::append(QCborNegativeInteger n)
|
|||||||
determine whether the contents are US-ASCII or not. If the string is found
|
determine whether the contents are US-ASCII or not. If the string is found
|
||||||
to contain characters outside of US-ASCII, it will allocate memory and
|
to contain characters outside of US-ASCII, it will allocate memory and
|
||||||
convert to UTF-8. If this check is unnecessary, use appendTextString()
|
convert to UTF-8. If this check is unnecessary, use appendTextString()
|
||||||
instead.
|
instead or the overload taking a \l QUtf8StringView.
|
||||||
|
|
||||||
\sa QCborStreamReader::isString(), QCborStreamReader::readString()
|
\sa QCborStreamReader::isString(), QCborStreamReader::readString()
|
||||||
*/
|
*/
|
||||||
|
@ -49,6 +49,7 @@ public:
|
|||||||
void append(QByteArrayView ba) { appendByteString(ba.data(), ba.size()); }
|
void append(QByteArrayView ba) { appendByteString(ba.data(), ba.size()); }
|
||||||
void append(QLatin1StringView str);
|
void append(QLatin1StringView str);
|
||||||
void append(QStringView str);
|
void append(QStringView str);
|
||||||
|
void append(QUtf8StringView str) { appendTextString(str.data(), str.size()); }
|
||||||
void append(QCborTag tag);
|
void append(QCborTag tag);
|
||||||
void append(QCborKnownTags tag) { append(QCborTag(tag)); }
|
void append(QCborKnownTags tag) { append(QCborTag(tag)); }
|
||||||
void append(QCborSimpleType st);
|
void append(QCborSimpleType st);
|
||||||
|
@ -189,6 +189,7 @@ void tst_QCborStreamWriter::nonAsciiStrings()
|
|||||||
|
|
||||||
// will be wrong if !isLatin1
|
// will be wrong if !isLatin1
|
||||||
QByteArray latin1 = input.toLatin1();
|
QByteArray latin1 = input.toLatin1();
|
||||||
|
QByteArray utf8 = input.toUtf8();
|
||||||
|
|
||||||
if (useDevice) {
|
if (useDevice) {
|
||||||
{
|
{
|
||||||
@ -199,6 +200,14 @@ void tst_QCborStreamWriter::nonAsciiStrings()
|
|||||||
QCOMPARE(buffer.data(), output);
|
QCOMPARE(buffer.data(), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QBuffer buffer;
|
||||||
|
buffer.open(QIODevice::WriteOnly);
|
||||||
|
QCborStreamWriter writer(&buffer);
|
||||||
|
writer.append(QUtf8StringView(utf8));
|
||||||
|
QCOMPARE(buffer.data(), output);
|
||||||
|
}
|
||||||
|
|
||||||
if (isLatin1) {
|
if (isLatin1) {
|
||||||
QBuffer buffer;
|
QBuffer buffer;
|
||||||
buffer.open(QIODevice::WriteOnly);
|
buffer.open(QIODevice::WriteOnly);
|
||||||
@ -214,6 +223,13 @@ void tst_QCborStreamWriter::nonAsciiStrings()
|
|||||||
QCOMPARE(buffer, output);
|
QCOMPARE(buffer, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QByteArray buffer;
|
||||||
|
QCborStreamWriter writer(&buffer);
|
||||||
|
writer.append(QUtf8StringView(utf8));
|
||||||
|
QCOMPARE(buffer, output);
|
||||||
|
}
|
||||||
|
|
||||||
if (isLatin1) {
|
if (isLatin1) {
|
||||||
QByteArray buffer;
|
QByteArray buffer;
|
||||||
QCborStreamWriter writer(&buffer);
|
QCborStreamWriter writer(&buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user