/*!
\overload append()
+ \since 5.0
+
+ Appends \a len characters from the QChar array \a str to this string.
+*/
+QString &QString::append(const QChar *str, int len)
+{
+ if (str && len > 0) {
+ if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
+ reallocData(uint(d->size + len) + 1u, true);
+ memcpy(d->data() + d->size, str, len * sizeof(QChar));
+ d->size += len;
+ d->data()[d->size] = '\0';
+ }
+ return *this;
+}
+
+/*!
+ \overload append()
Appends the Latin-1 string \a str to this string.
*/
inline QString &insert(int i, const QString &s) { return insert(i, s.constData(), s.length()); }
QString &insert(int i, QLatin1String s);
QString &append(QChar c);
+ QString &append(const QChar *uc, int len);
QString &append(const QString &s);
QString &append(const QStringRef &s);
QString &append(QLatin1String s);
void tst_QString::append()
{
- QString a;
- a = "<>ABCABCABCABC";
- QCOMPARE(a.append(">"),(QString)"<>ABCABCABCABC>");
+ {
+ QString a;
+ a = "<>ABCABCABCABC";
+ QCOMPARE(a.append(">"),QString("<>ABCABCABCABC>"));
+ }
+
+ {
+ QString a;
+ static const QChar unicode[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!' };
+ a.append(unicode, sizeof unicode / sizeof *unicode);
+ QCOMPARE(a, QLatin1String("Hello, World!"));
+ static const QChar nl('\n');
+ a.append(&nl, 1);
+ QCOMPARE(a, QLatin1String("Hello, World!\n"));
+ a.append(unicode, sizeof unicode / sizeof *unicode);
+ QCOMPARE(a, QLatin1String("Hello, World!\nHello, World!"));
+ a.append(unicode, 0); // no-op
+ QCOMPARE(a, QLatin1String("Hello, World!\nHello, World!"));
+ a.append(unicode, -1); // no-op
+ QCOMPARE(a, QLatin1String("Hello, World!\nHello, World!"));
+ a.append(0, 1); // no-op
+ QCOMPARE(a, QLatin1String("Hello, World!\nHello, World!"));
+ }
}
void tst_QString::append_bytearray_data()