diff options
author | Zeno Albisser <zeno.albisser@nokia.com> | 2010-02-22 13:14:22 (GMT) |
---|---|---|
committer | Zeno Albisser <zeno.albisser@nokia.com> | 2010-02-23 08:17:21 (GMT) |
commit | d1592b1d4f6f0ea0d180e6848af42b3692e7490a (patch) | |
tree | fd20dc2031cc76dd59cf64a20f0390f5d362fc6a /src | |
parent | fcdecd732d2fd6a863e903239f71c8f050c88dd0 (diff) | |
download | Qt-d1592b1d4f6f0ea0d180e6848af42b3692e7490a.zip Qt-d1592b1d4f6f0ea0d180e6848af42b3692e7490a.tar.gz Qt-d1592b1d4f6f0ea0d180e6848af42b3692e7490a.tar.bz2 |
Added function overload for QByteArray &QByteArray::replace()
This overloaded function can be used to replace a specific portion
of a QByteArray with an arbitary amount of characters from a char[].
Reviewed-by: Markus Goetz
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 15 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.h | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index a27e488..3324796 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -1804,7 +1804,20 @@ QByteArray &QByteArray::replace(int pos, int len, const QByteArray &after) */ 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)); diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index ec592f5f..0b77512 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -237,6 +237,7 @@ public: QByteArray &insert(int i, const QByteArray &a); QByteArray &remove(int index, int len); QByteArray &replace(int index, int len, const char *s); + QByteArray &replace(int index, int len, const char *s, int alen); QByteArray &replace(int index, int len, const QByteArray &s); QByteArray &replace(char before, const char *after); QByteArray &replace(char before, const QByteArray &after); |