summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbytearray.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-04-05 08:53:15 +0200
committerMarc Mutz <marc.mutz@kdab.com>2017-04-18 09:43:18 +0000
commitd176808eef61d27a6536f268125dab4088a248d3 (patch)
tree91b8155c55e092bbf9a8976fa77d5be2adbcb6b3 /src/corelib/tools/qbytearray.cpp
parent6d3c4833c26cced876ed57e9f158fbade5b2679c (diff)
QByteArray, QString, QStringRef: Add chopped()
We have two functions to get a substring without doing some calculations involving size(): - mid(p): mid(p, size() - p) - right(n) : mid(size() - n, n) (left does not involve size(), so isn't in that set). What was missing was a name for - f(n): mid(0, size() - n) As an action, it's called chop(), so call the transformation version chopped(). I made chopped(n), n < 0 or n > size(), undefined, because QString(Ref) ::left() is broken[1], while the QByteArray implementation is not. This is the only way to get consistent behavior among the three classes. I's also the correct thing to do. [1] instead of returning the empty string for negative indexes, it returns the whole string. [ChangeLog][QtCore][QString/QStringRef/QByteArray] Added chopped(n), a const version of chop(n). Change-Id: I6c2c5b16e0060fa924ced5860f21f2d0f23bd023 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Diffstat (limited to 'src/corelib/tools/qbytearray.cpp')
-rw-r--r--src/corelib/tools/qbytearray.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index c728a05f55..5f42ff0146 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -2972,7 +2972,7 @@ bool QByteArray::endsWith(char ch) const
Example:
\snippet code/src_corelib_tools_qbytearray.cpp 27
- \sa right(), mid(), startsWith(), truncate()
+ \sa startsWith(), right(), mid(), chopped(), chop(), truncate()
*/
QByteArray QByteArray::left(int len) const
@@ -2994,7 +2994,7 @@ QByteArray QByteArray::left(int len) const
Example:
\snippet code/src_corelib_tools_qbytearray.cpp 28
- \sa endsWith(), left(), mid()
+ \sa endsWith(), left(), mid(), chopped(), chop(), truncate()
*/
QByteArray QByteArray::right(int len) const
@@ -3017,7 +3017,7 @@ QByteArray QByteArray::right(int len) const
Example:
\snippet code/src_corelib_tools_qbytearray.cpp 29
- \sa left(), right()
+ \sa left(), right(), chopped(), chop(), truncate()
*/
QByteArray QByteArray::mid(int pos, int len) const
@@ -3041,6 +3041,18 @@ QByteArray QByteArray::mid(int pos, int len) const
}
/*!
+ \fn QByteArray::chopped(int len) const
+ \since 5.10
+
+ Returns a byte array that contains the leftmost size() - \a len bytes of
+ this byte array.
+
+ \note The behavior is undefined if \a len is negative or greater than size().
+
+ \sa endsWith(), left(), right(), mid(), chop(), truncate().
+*/
+
+/*!
\fn QByteArray QByteArray::toLower() const
Returns a lowercase copy of the byte array. The bytearray is