File tree 3 files changed +30
-1
lines changed
src/corelib/serialization
tests/auto/corelib/serialization/qcborstreamwriter
3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -419,6 +419,18 @@ void QCborStreamWriter::append(QCborNegativeInteger n)
419
419
QCborStreamReader::readByteArray()
420
420
*/
421
421
422
+ /* !
423
+ \fn void QCborStreamWriter::append(QUtf8StringView str)
424
+ \since 6.10
425
+ \overload
426
+
427
+ Appends the UTF-8 string viewed by \a str to the stream, creating a CBOR
428
+ Text String value. QCborStreamWriter will attempt to write the entire string
429
+ in one chunk.
430
+
431
+ \sa appendTextString(), QCborStreamReader::isString(), QCborStreamReader::readString()
432
+ */
433
+
422
434
/* !
423
435
\overload
424
436
@@ -435,7 +447,7 @@ void QCborStreamWriter::append(QCborNegativeInteger n)
435
447
determine whether the contents are US-ASCII or not. If the string is found
436
448
to contain characters outside of US-ASCII, it will allocate memory and
437
449
convert to UTF-8. If this check is unnecessary, use appendTextString()
438
- instead.
450
+ instead or the overload taking a \l QUtf8StringView .
439
451
440
452
\sa QCborStreamReader::isString(), QCborStreamReader::readString()
441
453
*/
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ class Q_CORE_EXPORT QCborStreamWriter
49
49
void append (QByteArrayView ba) { appendByteString (ba.data (), ba.size ()); }
50
50
void append (QLatin1StringView str);
51
51
void append (QStringView str);
52
+ void append (QUtf8StringView str) { appendTextString (str.data (), str.size ()); }
52
53
void append (QCborTag tag);
53
54
void append (QCborKnownTags tag) { append (QCborTag (tag)); }
54
55
void append (QCborSimpleType st);
Original file line number Diff line number Diff line change @@ -189,6 +189,7 @@ void tst_QCborStreamWriter::nonAsciiStrings()
189
189
190
190
// will be wrong if !isLatin1
191
191
QByteArray latin1 = input.toLatin1 ();
192
+ QByteArray utf8 = input.toUtf8 ();
192
193
193
194
if (useDevice) {
194
195
{
@@ -199,6 +200,14 @@ void tst_QCborStreamWriter::nonAsciiStrings()
199
200
QCOMPARE (buffer.data (), output);
200
201
}
201
202
203
+ {
204
+ QBuffer buffer;
205
+ buffer.open (QIODevice::WriteOnly);
206
+ QCborStreamWriter writer (&buffer);
207
+ writer.append (QUtf8StringView (utf8));
208
+ QCOMPARE (buffer.data (), output);
209
+ }
210
+
202
211
if (isLatin1) {
203
212
QBuffer buffer;
204
213
buffer.open (QIODevice::WriteOnly);
@@ -214,6 +223,13 @@ void tst_QCborStreamWriter::nonAsciiStrings()
214
223
QCOMPARE (buffer, output);
215
224
}
216
225
226
+ {
227
+ QByteArray buffer;
228
+ QCborStreamWriter writer (&buffer);
229
+ writer.append (QUtf8StringView (utf8));
230
+ QCOMPARE (buffer, output);
231
+ }
232
+
217
233
if (isLatin1) {
218
234
QByteArray buffer;
219
235
QCborStreamWriter writer (&buffer);
You can’t perform that action at this time.
0 commit comments