summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/text/qbytearray.cpp18
-rw-r--r--src/corelib/text/qbytearray.h4
-rw-r--r--tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp12
3 files changed, 34 insertions, 0 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index f4ade684a0..14789c8a2c 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -1955,6 +1955,24 @@ QByteArray &QByteArray::insert(qsizetype i, QByteArrayView data)
}
/*!
+ \fn QByteArray &QByteArray::insert(qsizetype i, const QByteArray &data)
+ Inserts \a data at index position \a i and returns a
+ reference to this byte array.
+
+ \sa append(), prepend(), replace(), remove()
+*/
+
+/*!
+ \fn QByteArray &QByteArray::insert(qsizetype i, const char *s)
+ Inserts \a s at index position \a i and returns a
+ reference to this byte array.
+
+ The function is equivalent to \c{insert(i, QByteArrayView(s))}
+
+ \sa append(), prepend(), replace(), remove()
+*/
+
+/*!
\fn QByteArray &QByteArray::insert(qsizetype i, const char *data, qsizetype len)
\overload
\since 4.6
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h
index 95b607e9dc..9f646aaa62 100644
--- a/src/corelib/text/qbytearray.h
+++ b/src/corelib/text/qbytearray.h
@@ -298,6 +298,10 @@ public:
{ return insert(size(), a); }
QByteArray &insert(qsizetype i, QByteArrayView data);
+ inline QByteArray &insert(qsizetype i, const char *s)
+ { return insert(i, QByteArrayView(s)); }
+ inline QByteArray &insert(qsizetype i, const QByteArray &data)
+ { return insert(i, QByteArrayView(data)); }
QByteArray &insert(qsizetype i, qsizetype count, char c);
QByteArray &insert(qsizetype i, char c)
{ return insert(i, QByteArrayView(&c, 1)); }
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
index cf70a7bbaa..7f9bff844f 100644
--- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
@@ -946,6 +946,18 @@ void tst_QByteArray::insert()
ba = "ab";
QCOMPARE(ba.insert(1, "\0X\0", 3), QByteArray::fromRawData("a\0X\0b", 5));
QCOMPARE(ba.size(), 5);
+
+ ba = "Hello World";
+ QCOMPARE(ba.insert(5, QByteArrayView(",")), QByteArray("Hello, World"));
+ QCOMPARE(ba.size(), 12);
+
+ ba = "one";
+ QCOMPARE(ba.insert(1, ba), QByteArray("oonene"));
+ QCOMPARE(ba.size(), 6);
+
+ ba = "one";
+ QCOMPARE(ba.insert(1, QByteArrayView(ba)), QByteArray("oonene"));
+ QCOMPARE(ba.size(), 6);
}
void tst_QByteArray::insertExtended_data()