diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-04-06 19:36:47 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-04-07 08:32:32 +0000 |
commit | 399ab058c94978b40876e42b5b677d392f2e33f5 (patch) | |
tree | ae1d0920f45e63d9c65fb91c0a765c981c45cde9 /src/corelib/tools/qbytearray.h | |
parent | 5dc1e08c8c602738f6a827cea0de44683c7bbd0b (diff) |
Add front()/back() to QString, QStringRef, QByteArray and QLatin1String
These STL-compatibility functions are present on our generic
containers, but not on the string classes.
[ChangeLog][QtCore][QString/QStringRef/QByteArray/QLatin1String] Added
front() and back() for STL compatibility.
Change-Id: I536019396b319abd1e2daf9c64ebab4e7a35b334
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools/qbytearray.h')
-rw-r--r-- | src/corelib/tools/qbytearray.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 06a50e5990..c6b7fe4053 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -212,6 +212,10 @@ public: char operator[](uint i) const; QByteRef operator[](int i); QByteRef operator[](uint i); + char front() const Q_REQUIRED_RESULT { return at(0); } + QByteRef front() Q_REQUIRED_RESULT; + char back() const Q_REQUIRED_RESULT { return at(size() - 1); } + QByteRef back() Q_REQUIRED_RESULT; int indexOf(char c, int from = 0) const; int indexOf(const char *c, int from = 0) const; @@ -549,6 +553,8 @@ inline QByteRef QByteArray::operator[](int i) { Q_ASSERT(i >= 0); return QByteRef(*this, i); } inline QByteRef QByteArray::operator[](uint i) { return QByteRef(*this, i); } +inline QByteRef QByteArray::front() { return operator[](0); } +inline QByteRef QByteArray::back() { return operator[](size() - 1); } inline QByteArray::iterator QByteArray::begin() { detach(); return d->data(); } inline QByteArray::const_iterator QByteArray::begin() const |