summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-04-06 22:38:58 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-04-07 11:29:45 +0000
commit6958e189a3743aae63314acfdc706e2c3283a99b (patch)
tree4c3bb34409919e2d767c3bdc1d1c9e8fe5d11191 /src
parentee0951d69b38f766e67262487be95b88501aa4a5 (diff)
QStringRef: add missing {c,}r{begin,end}()
Most containers have them in Qt 5.7, so add them to QStringRef, too. Brush up the docs, use the const_iterator typedef in the API, for consistency with QString's docs. [ChangeLog][QtCore][QStringRef] Added reverse iterators, rbegin(), rend(), crbegin(), crend(). Change-Id: I3d2884a1b2faae02c610ab3871552b65bc6e2521 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qstring.cpp85
-rw-r--r--src/corelib/tools/qstring.h16
2 files changed, 83 insertions, 18 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index c7cd1a7751..5cbad2554c 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -8759,7 +8759,20 @@ QDataStream &operator>>(QDataStream &in, QString &str)
/*!
\typedef QStringRef::const_iterator
- \internal
+ \since 5.4
+
+ This typedef provides an STL-style const iterator for QStringRef.
+
+ \sa QStringRef::const_reverse_iterator
+*/
+
+/*!
+ \typedef QStringRef::const_reverse_iterator
+ \since 5.7
+
+ This typedef provides an STL-style const reverse iterator for QStringRef.
+
+ \sa QStringRef::const_iterator
*/
/*!
@@ -8883,39 +8896,85 @@ ownership of it, no memory is freed when instances are destroyed.
*/
/*!
- \fn const QChar *QStringRef::begin() const
- \since 5.4
+ \fn const QChar *QStringRef::constData() const
Same as unicode().
*/
/*!
- \fn const QChar *QStringRef::cbegin() const
+ \fn QStringRef::const_iterator QStringRef::begin() const
\since 5.4
- Same as unicode().
+ Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in
+ the string.
+
+ \sa cbegin(), end(), rbegin(), rend()
*/
/*!
- \fn const QChar *QStringRef::end() const
+ \fn QStringRef::const_iterator QStringRef::cbegin() const
\since 5.4
- Returns a pointer to one character past the last one in this string.
- (It is the same as \c {unicode() + size()}.)
+ Same as begin().
+
+ \sa begin(), cend(), rbegin(), rend()
*/
/*!
- \fn const QChar *QStringRef::cend() const
+ \fn QStringRef::const_iterator QStringRef::end() const
+ \since 5.4
+
+ Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
+ character after the last character in the list.
+
+ \sa cbegin(), end(), rbegin(), rend()
+*/
+
+/*! \fn QStringRef::const_iterator QStringRef::cend() const
\since 5.4
- Returns a pointer to one character past the last one in this string.
- (It is the same as \c {unicode() + size()}.)
+ Same as end().
+
+ \sa end(), cbegin(), rbegin(), rend()
*/
/*!
- \fn const QChar *QStringRef::constData() const
+ \fn QStringRef::const_reverse_iterator QStringRef::rbegin() const
+ \since 5.7
- Same as unicode().
+ Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
+ character in the string, in reverse order.
+
+ \sa begin(), crbegin(), rend()
+*/
+
+/*!
+ \fn QStringRef::const_reverse_iterator QStringRef::crbegin() const
+ \since 5.7
+
+ Same as rbegin().
+
+ \sa begin(), rbegin(), rend()
+*/
+
+/*!
+ \fn QStringRef::const_reverse_iterator QStringRef::rend() const
+ \since 5.7
+
+ Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
+ the last character in the string, in reverse order.
+
+ \sa end(), crend(), rbegin()
+*/
+
+
+/*!
+ \fn QStringRef::const_reverse_iterator QStringRef::crend() const
+ \since 5.7
+
+ Same as rend().
+
+ \sa end(), rend(), rbegin()
*/
/*!
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 6676efab41..793a859228 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -1360,7 +1360,8 @@ class Q_CORE_EXPORT QStringRef {
public:
typedef QString::size_type size_type;
typedef QString::value_type value_type;
- typedef QString::const_iterator const_iterator;
+ typedef const QChar *const_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef QString::const_pointer const_pointer;
typedef QString::const_reference const_reference;
@@ -1439,10 +1440,15 @@ public:
}
inline const QChar *data() const { return unicode(); }
inline const QChar *constData() const { return unicode(); }
- inline const QChar *begin() const { return unicode(); }
- inline const QChar *cbegin() const { return unicode(); }
- inline const QChar *end() const { return unicode() + size(); }
- inline const QChar *cend() const { return unicode() + size(); }
+
+ inline const_iterator begin() const { return unicode(); }
+ inline const_iterator cbegin() const { return unicode(); }
+ inline const_iterator end() const { return unicode() + size(); }
+ inline const_iterator cend() const { return unicode() + size(); }
+ inline const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
+ inline const_reverse_iterator crbegin() const { return rbegin(); }
+ inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
+ inline const_reverse_iterator crend() const { return rend(); }
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED QByteArray toAscii() const Q_REQUIRED_RESULT