mirror of https://github.com/qt/qtbase.git
QString: add {const_,reverse_iterator}, {c,}r{begin,end}()
Had to mark {,c,const}{begin,end}() inline, since they are, and mingw complains about inconsistent dllimport attributes. [ChangeLog][QtCore][QString] Added rbegin(), crbegin(), rend(), crend(), and reverse_iterator and const_reverse_iterator typedefs. Task-number: QTBUG-25919 Change-Id: I1d48729c76e510c1e49c0e5dc41691aa662fdf21 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
683d817ada
commit
92d5733c78
|
@ -1200,6 +1200,22 @@ const QString::Null QString::null = { };
|
|||
\sa QString::const_iterator
|
||||
*/
|
||||
|
||||
/*! \typedef QString::const_reverse_iterator
|
||||
\since 5.6
|
||||
|
||||
This typedef provides an STL-style const reverse iterator for QString.
|
||||
|
||||
\sa QString::reverse_iterator, QString::const_iterator
|
||||
*/
|
||||
|
||||
/*! \typedef QString::reverse_iterator
|
||||
\since 5.6
|
||||
|
||||
This typedef provides an STL-style non-const reverse iterator for QString.
|
||||
|
||||
\sa QString::const_reverse_iterator, QString::iterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QString::size_type
|
||||
|
||||
|
@ -1303,6 +1319,52 @@ const QString::Null QString::null = { };
|
|||
\sa constBegin(), end()
|
||||
*/
|
||||
|
||||
/*! \fn QString::reverse_iterator QString::rbegin()
|
||||
\since 5.6
|
||||
|
||||
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
|
||||
character in the string, in reverse order.
|
||||
|
||||
\sa begin(), crbegin(), rend()
|
||||
*/
|
||||
|
||||
/*! \fn QString::const_reverse_iterator QString::rbegin() const
|
||||
\since 5.6
|
||||
\overload
|
||||
*/
|
||||
|
||||
/*! \fn QString::const_reverse_iterator QString::crbegin() const
|
||||
\since 5.6
|
||||
|
||||
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
|
||||
character in the string, in reverse order.
|
||||
|
||||
\sa begin(), rbegin(), rend()
|
||||
*/
|
||||
|
||||
/*! \fn QString::reverse_iterator QString::rend()
|
||||
\since 5.6
|
||||
|
||||
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 QString::const_reverse_iterator QString::rend() const
|
||||
\since 5.6
|
||||
\overload
|
||||
*/
|
||||
|
||||
/*! \fn QString::const_reverse_iterator QString::crend() const
|
||||
\since 5.6
|
||||
|
||||
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one
|
||||
past the last character in the string, in reverse order.
|
||||
|
||||
\sa end(), rend(), rbegin()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QString::QString()
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include <QtCore/qnamespace.h>
|
||||
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
// std::wstring is disabled on android's glibc, as bionic lacks certain features
|
||||
|
@ -715,14 +716,22 @@ public:
|
|||
typedef const QChar *const_iterator;
|
||||
typedef iterator Iterator;
|
||||
typedef const_iterator ConstIterator;
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
const_iterator cbegin() const;
|
||||
const_iterator constBegin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
const_iterator cend() const;
|
||||
const_iterator constEnd() const;
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
inline iterator begin();
|
||||
inline const_iterator begin() const;
|
||||
inline const_iterator cbegin() const;
|
||||
inline const_iterator constBegin() const;
|
||||
inline iterator end();
|
||||
inline const_iterator end() const;
|
||||
inline const_iterator cend() const;
|
||||
inline const_iterator constEnd() const;
|
||||
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
||||
reverse_iterator rend() { return reverse_iterator(begin()); }
|
||||
const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
|
||||
const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
|
||||
const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); }
|
||||
const_reverse_iterator crend() const { return const_reverse_iterator(begin()); }
|
||||
|
||||
// STL compatibility
|
||||
typedef int size_type;
|
||||
|
|
|
@ -534,6 +534,7 @@ private slots:
|
|||
void localeAwareCompare_data();
|
||||
void localeAwareCompare();
|
||||
#endif
|
||||
void reverseIterators();
|
||||
void split_data();
|
||||
void split();
|
||||
void split_regexp_data();
|
||||
|
@ -5399,6 +5400,20 @@ void tst_QString::localeAwareCompare()
|
|||
}
|
||||
#endif //!defined(Q_OS_WIN) || defined(Q_OS_WIN_AND_WINCE)
|
||||
|
||||
void tst_QString::reverseIterators()
|
||||
{
|
||||
QString s = "1234";
|
||||
QString sr = s;
|
||||
std::reverse(sr.begin(), sr.end());
|
||||
const QString &csr = sr;
|
||||
QVERIFY(std::equal(s.begin(), s.end(), sr.rbegin()));
|
||||
QVERIFY(std::equal(s.begin(), s.end(), sr.crbegin()));
|
||||
QVERIFY(std::equal(s.begin(), s.end(), csr.rbegin()));
|
||||
QVERIFY(std::equal(sr.rbegin(), sr.rend(), s.begin()));
|
||||
QVERIFY(std::equal(sr.crbegin(), sr.crend(), s.begin()));
|
||||
QVERIFY(std::equal(csr.rbegin(), csr.rend(), s.begin()));
|
||||
}
|
||||
|
||||
void tst_QString::split_data()
|
||||
{
|
||||
QTest::addColumn<QString>("str");
|
||||
|
|
Loading…
Reference in New Issue