QByteArray: 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][QByteArray] Added rbegin(), crbegin(), rend(), crend(), and reverse_iterator and const_reverse_iterator typedefs. Task-number: QTBUG-25919 Change-Id: Id5aefb52635f029305135afcd99db0b036a7af82 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
92d5733c78
commit
f405352fee
@ -919,6 +919,52 @@ static inline char qToLower(char c)
|
||||
\sa constBegin(), end()
|
||||
*/
|
||||
|
||||
/*! \fn QByteArray::reverse_iterator QByteArray::rbegin()
|
||||
\since 5.6
|
||||
|
||||
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
|
||||
character in the byte-array, in reverse order.
|
||||
|
||||
\sa begin(), crbegin(), rend()
|
||||
*/
|
||||
|
||||
/*! \fn QByteArray::const_reverse_iterator QByteArray::rbegin() const
|
||||
\since 5.6
|
||||
\overload
|
||||
*/
|
||||
|
||||
/*! \fn QByteArray::const_reverse_iterator QByteArray::crbegin() const
|
||||
\since 5.6
|
||||
|
||||
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
|
||||
character in the byte-array, in reverse order.
|
||||
|
||||
\sa begin(), rbegin(), rend()
|
||||
*/
|
||||
|
||||
/*! \fn QByteArray::reverse_iterator QByteArray::rend()
|
||||
\since 5.6
|
||||
|
||||
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
|
||||
the last character in the byte-array, in reverse order.
|
||||
|
||||
\sa end(), crend(), rbegin()
|
||||
*/
|
||||
|
||||
/*! \fn QByteArray::const_reverse_iterator QByteArray::rend() const
|
||||
\since 5.6
|
||||
\overload
|
||||
*/
|
||||
|
||||
/*! \fn QByteArray::const_reverse_iterator QByteArray::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 byte-array, in reverse order.
|
||||
|
||||
\sa end(), rend(), rbegin()
|
||||
*/
|
||||
|
||||
/*! \fn void QByteArray::push_back(const QByteArray &other)
|
||||
|
||||
This function is provided for STL compatibility. It is equivalent
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
|
||||
#ifdef truncate
|
||||
#error qbytearray.h must be included before any header file that defines truncate
|
||||
@ -390,14 +391,22 @@ public:
|
||||
typedef const char *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;
|
||||
|
@ -67,6 +67,7 @@ private slots:
|
||||
void endsWith_data();
|
||||
void endsWith();
|
||||
void endsWith_char();
|
||||
void reverseIterators();
|
||||
void split_data();
|
||||
void split();
|
||||
void base64_data();
|
||||
@ -540,6 +541,20 @@ void tst_QByteArray::endsWith_char()
|
||||
QVERIFY(!QByteArray().endsWith('\0'));
|
||||
}
|
||||
|
||||
void tst_QByteArray::reverseIterators()
|
||||
{
|
||||
QByteArray s = "1234";
|
||||
QByteArray sr = s;
|
||||
std::reverse(sr.begin(), sr.end());
|
||||
const QByteArray &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_QByteArray::split_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("sample");
|
||||
|
Loading…
Reference in New Issue
Block a user