src/corelib/tools/qbytearray.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
--- a/src/corelib/tools/qbytearray.cpp	Wed Jun 23 19:07:03 2010 +0300
+++ b/src/corelib/tools/qbytearray.cpp	Tue Jul 06 15:10:48 2010 +0300
@@ -154,6 +154,10 @@
     This function assumes that \a dst is at least \a len characters
     long.
 
+    \note When compiling with Visual C++ compiler version 14.00
+    (Visual C++ 2005) or later, internally the function strncpy_s
+    will be used.
+
     \sa qstrcpy()
 */
 
@@ -1061,6 +1065,11 @@
     \internal
 */
 
+/*! \fn bool QByteArray::isSharedWith(const QByteArray &other) const
+
+    \internal
+*/
+
 /*! \fn char QByteArray::at(int i) const
 
     Returns the character at index position \a i in the byte array.
@@ -1799,7 +1808,20 @@
 */
 QByteArray &QByteArray::replace(int pos, int len, const char *after)
 {
-    int alen = qstrlen(after);
+    return replace(pos,len,after,qstrlen(after));
+}
+
+/*! \fn QByteArray &QByteArray::replace(int pos, int len, const char *after, int alen)
+
+    \overload
+
+    Replaces \a len bytes from index position \a pos with \a alen bytes
+    from the string \a after. \a after is allowed to have '\0' characters.
+
+    \since 4.7
+*/
+QByteArray &QByteArray::replace(int pos, int len, const char *after, int alen)
+{
     if (len == alen && (pos + len <= d->size)) {
         detach();
         memcpy(d->data + pos, after, len*sizeof(char));
@@ -2659,7 +2681,7 @@
     Writes byte array \a ba to the stream \a out and returns a reference
     to the stream.
 
-    \sa {Format of the QDataStream operators}
+    \sa {Serializing Qt Data Types}
 */
 
 QDataStream &operator<<(QDataStream &out, const QByteArray &ba)
@@ -2676,7 +2698,7 @@
     Reads a byte array into \a ba from the stream \a in and returns a
     reference to the stream.
 
-    \sa {Format of the QDataStream operators}
+    \sa {Serializing Qt Data Types}
 */
 
 QDataStream &operator>>(QDataStream &in, QByteArray &ba)
@@ -3792,7 +3814,7 @@
     accepting a \c{const char *} expected to be '\\0'-terminated will
     fail.
 
-    \sa data(), constData()
+    \sa setRawData(), data(), constData()
 */
 
 QByteArray QByteArray::fromRawData(const char *data, int size)
@@ -3812,6 +3834,37 @@
 }
 
 /*!
+    \since 4.7
+
+    Resets the QByteArray to use the first \a size bytes of the
+    \a data array. The bytes are \e not copied. The QByteArray will
+    contain the \a data pointer. The caller guarantees that \a data
+    will not be deleted or modified as long as this QByteArray and any
+    copies of it exist that have not been modified.
+
+    This function can be used instead of fromRawData() to re-use
+    existings QByteArray objects to save memory re-allocations.
+
+    \sa fromRawData(), data(), constData()
+*/
+QByteArray &QByteArray::setRawData(const char *data, uint size)
+{
+    if (d->ref != 1 || d->alloc) {
+        *this = fromRawData(data, size);
+    } else {
+        if (data) {
+            d->data = const_cast<char *>(data);
+        } else {
+            d->data = d->array;
+            size = 0;
+        }
+        d->alloc = d->size = size;
+        *d->array = '\0';
+    }
+    return *this;
+}
+
+/*!
     Returns a decoded copy of the Base64 array \a base64. Input is not checked
     for validity; invalid characters in the input are skipped, enabling the
     decoding process to continue with subsequent characters.
@@ -4206,12 +4259,6 @@
 */
 
 /*!
-    \fn QByteArray& QByteArray::setRawData(const char *a, uint n)
-
-    Use fromRawData() instead.
-*/
-
-/*!
     \fn void QByteArray::resetRawData(const char *data, uint n)
 
     Use clear() instead.