QLatin1String: add iterators
[ChangeLog][QtCore][QLatin1String] Added iterators, {c,}{r,}{begin,end}(). Change-Id: I0222a3ff44f2aa827c737e2fa3cfbb8aad69b5a7 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
b181da9885
commit
69415638ae
@ -8313,6 +8313,76 @@ QString &QString::setRawData(const QChar *unicode, int size)
|
||||
\sa QString, QLatin1Char, {QStringLiteral()}{QStringLiteral}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QLatin1String::value_type
|
||||
\since 5.10
|
||||
|
||||
Alias for \c{const char}. Provided for compatibility with the STL.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QLatin1String::difference_type
|
||||
\since 5.10
|
||||
|
||||
Alias for \c{int}. Provided for compatibility with the STL.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QLatin1String::size_type
|
||||
\since 5.10
|
||||
|
||||
Alias for \c{int}. Provided for compatibility with the STL.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QLatin1String::reference
|
||||
\since 5.10
|
||||
|
||||
Alias for \c{value_type &}. Provided for compatibility with the STL.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QLatin1String::iterator
|
||||
\since 5.10
|
||||
|
||||
This typedef provides an STL-style const iterator for QLatin1String.
|
||||
|
||||
QLatin1String does not support mutable iterators, so this is the same
|
||||
as const_iterator.
|
||||
|
||||
\sa const_iterator, reverse_iterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QLatin1String::const_iterator
|
||||
\since 5.10
|
||||
|
||||
This typedef provides an STL-style const iterator for QLatin1String.
|
||||
|
||||
\sa iterator, const_reverse_iterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QLatin1String::reverse_iterator
|
||||
\since 5.10
|
||||
|
||||
This typedef provides an STL-style const reverse iterator for QLatin1String.
|
||||
|
||||
QLatin1String does not support mutable reverse iterators, so this is the
|
||||
same as const_reverse_iterator.
|
||||
|
||||
\sa const_reverse_iterator, iterator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef QLatin1String::const_reverse_iterator
|
||||
\since 5.10
|
||||
|
||||
This typedef provides an STL-style const reverse iterator for QLatin1String.
|
||||
|
||||
\sa reverse_iterator, const_iterator
|
||||
*/
|
||||
|
||||
/*! \fn QLatin1String::QLatin1String()
|
||||
\since 5.6
|
||||
|
||||
@ -8407,6 +8477,97 @@ QString &QString::setRawData(const QChar *unicode, int size)
|
||||
\sa at()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QLatin1String::const_iterator QLatin1String::begin() const
|
||||
\since 5.10
|
||||
|
||||
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in
|
||||
the string.
|
||||
|
||||
This function is provided for STL compatibility.
|
||||
|
||||
\sa end(), cbegin(), rbegin(), data()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QLatin1String::const_iterator QLatin1String::cbegin() const
|
||||
\since 5.10
|
||||
|
||||
Same as begin().
|
||||
|
||||
This function is provided for STL compatibility.
|
||||
|
||||
\sa cend(), begin(), crbegin(), data()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QLatin1String::const_iterator QLatin1String::end() const
|
||||
\since 5.10
|
||||
|
||||
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
|
||||
character after the last character in the list.
|
||||
|
||||
This function is provided for STL compatibility.
|
||||
|
||||
\sa begin(), cend(), rend()
|
||||
*/
|
||||
|
||||
/*! \fn QLatin1String::const_iterator QLatin1String::cend() const
|
||||
\since 5.10
|
||||
|
||||
Same as end().
|
||||
|
||||
This function is provided for STL compatibility.
|
||||
|
||||
\sa cbegin(), end(), crend()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QLatin1String::const_reverse_iterator QLatin1String::rbegin() const
|
||||
\since 5.10
|
||||
|
||||
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
|
||||
character in the string, in reverse order.
|
||||
|
||||
This function is provided for STL compatibility.
|
||||
|
||||
\sa rend(), crbegin(), begin()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QLatin1String::const_reverse_iterator QLatin1String::crbegin() const
|
||||
\since 5.10
|
||||
|
||||
Same as rbegin().
|
||||
|
||||
This function is provided for STL compatibility.
|
||||
|
||||
\sa crend(), rbegin(), cbegin()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QLatin1String::const_reverse_iterator QLatin1String::rend() const
|
||||
\since 5.10
|
||||
|
||||
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
|
||||
the last character in the string, in reverse order.
|
||||
|
||||
This function is provided for STL compatibility.
|
||||
|
||||
\sa rbegin(), crend(), end()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QLatin1String::const_reverse_iterator QLatin1String::crend() const
|
||||
\since 5.10
|
||||
|
||||
Same as rend().
|
||||
|
||||
This function is provided for STL compatibility.
|
||||
|
||||
\sa crbegin(), rend(), cend()
|
||||
*/
|
||||
|
||||
/*! \fn QLatin1String QLatin1String::mid(int start) const
|
||||
\since 5.8
|
||||
|
||||
|
@ -103,6 +103,27 @@ public:
|
||||
Q_DECL_CONSTEXPR QLatin1Char at(int i) const { return QLatin1Char(m_data[i]); }
|
||||
Q_DECL_CONSTEXPR QLatin1Char operator[](int i) const { return at(i); }
|
||||
|
||||
using value_type = const char;
|
||||
using reference = value_type&;
|
||||
using const_reference = reference;
|
||||
using iterator = value_type*;
|
||||
using const_iterator = iterator;
|
||||
using difference_type = int; // violates Container concept requirements
|
||||
using size_type = int; // violates Container concept requirements
|
||||
|
||||
Q_DECL_CONSTEXPR const_iterator begin() const Q_DECL_NOTHROW { return data(); }
|
||||
Q_DECL_CONSTEXPR const_iterator cbegin() const Q_DECL_NOTHROW { return data(); }
|
||||
Q_DECL_CONSTEXPR const_iterator end() const Q_DECL_NOTHROW { return data() + size(); }
|
||||
Q_DECL_CONSTEXPR const_iterator cend() const Q_DECL_NOTHROW { return data() + size(); }
|
||||
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = reverse_iterator;
|
||||
|
||||
const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); }
|
||||
const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); }
|
||||
const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); }
|
||||
const_reverse_iterator crend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); }
|
||||
|
||||
Q_DECL_CONSTEXPR QLatin1String mid(int pos) const
|
||||
{ return QLatin1String(m_data + pos, m_size - pos); }
|
||||
Q_DECL_CONSTEXPR QLatin1String mid(int pos, int n) const
|
||||
|
@ -48,6 +48,7 @@ private Q_SLOTS:
|
||||
void midLeftRight();
|
||||
void nullString();
|
||||
void emptyString();
|
||||
void iterators();
|
||||
void relationalOperators_data();
|
||||
void relationalOperators();
|
||||
};
|
||||
@ -155,6 +156,22 @@ void tst_QLatin1String::emptyString()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QLatin1String::iterators()
|
||||
{
|
||||
QLatin1String hello("hello");
|
||||
QLatin1String olleh("olleh");
|
||||
|
||||
QVERIFY(std::equal(hello.begin(), hello.end(),
|
||||
olleh.rbegin()));
|
||||
QVERIFY(std::equal(hello.rbegin(), hello.rend(),
|
||||
QT_MAKE_CHECKED_ARRAY_ITERATOR(olleh.begin(), olleh.size())));
|
||||
|
||||
QVERIFY(std::equal(hello.cbegin(), hello.cend(),
|
||||
olleh.rbegin()));
|
||||
QVERIFY(std::equal(hello.crbegin(), hello.crend(),
|
||||
QT_MAKE_CHECKED_ARRAY_ITERATOR(olleh.begin(), olleh.size())));
|
||||
}
|
||||
|
||||
void tst_QLatin1String::relationalOperators_data()
|
||||
{
|
||||
QTest::addColumn<QLatin1StringContainer>("lhs");
|
||||
|
Loading…
Reference in New Issue
Block a user