diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-02-04 13:05:06 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-04-03 15:41:09 +0000 |
commit | d40dcee642c69784f771aae86531ae65b458f1a5 (patch) | |
tree | cc96f153042a48a770e6b34fe200e7e95c877707 /src | |
parent | b8c61c6bb35c49fc8a6aed4925e59ba1694eab19 (diff) |
QStringIterator: port to QStringView
Pretty straightforward, as the implementation already used only
an iterator range internally.
Change-Id: I6e6b809329e2e2548bba6db414a3d107d09637d1
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp | 5 | ||||
-rw-r--r-- | src/corelib/tools/qstringiterator.qdoc | 8 | ||||
-rw-r--r-- | src/corelib/tools/qstringiterator_p.h | 10 |
3 files changed, 11 insertions, 12 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp index 1fcb7b9945..7a2b4812ef 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qstringiterator.cpp @@ -58,7 +58,7 @@ int main() { //! [0] QString string(QStringLiteral("a string")); -QStringIterator i(string); +QStringIterator i(string); // implicitly converted to QStringView //! [0] //! [1] @@ -71,8 +71,7 @@ while (i.hasNext()) { //! [2] -QString string(QStringLiteral("𝄞 is the G clef")); -QStringIterator i(string); +QStringIterator i(u"𝄞 is the G clef"); qDebug() << hex << i.next(); // will print 1d11e (U+1D11E, MUSICAL SYMBOL G CLEF) qDebug() << hex << i.next(); // will print 20 (U+0020, SPACE) qDebug() << hex << i.next(); // will print 69 (U+0069, LATIN SMALL LETTER I) diff --git a/src/corelib/tools/qstringiterator.qdoc b/src/corelib/tools/qstringiterator.qdoc index ff759b6f0e..ae3ad53653 100644 --- a/src/corelib/tools/qstringiterator.qdoc +++ b/src/corelib/tools/qstringiterator.qdoc @@ -55,7 +55,7 @@ that may be present in a QString, and return the individual Unicode code points. You can create a QStringIterator that iterates over a given - QString by passing the string to the QStringIterator's constructor: + QStringView by passing the string to the QStringIterator's constructor: \snippet code/src_corelib_tools_qstringiterator.cpp 0 @@ -120,12 +120,12 @@ */ /*! - \fn QStringIterator::QStringIterator(const QString &string) + \fn QStringIterator::QStringIterator(QStringView string, QStringView::size_type idx) Constructs an iterator over the contents of \a string. The iterator will point - before the first position in the string. + before position \a idx in the string. - The string \a string must remain valid while the iterator is being used. + The string view \a string must remain valid while the iterator is being used. */ /*! diff --git a/src/corelib/tools/qstringiterator_p.h b/src/corelib/tools/qstringiterator_p.h index 7cf59ae42f..749ba0e62d 100644 --- a/src/corelib/tools/qstringiterator_p.h +++ b/src/corelib/tools/qstringiterator_p.h @@ -60,12 +60,12 @@ QT_BEGIN_NAMESPACE class QStringIterator { QString::const_iterator i, pos, e; - + Q_STATIC_ASSERT((std::is_same<QString::const_iterator, const QChar *>::value)); public: - inline explicit QStringIterator(const QString &string) - : i(string.constBegin()), - pos(string.constBegin()), - e(string.constEnd()) + explicit QStringIterator(QStringView string, QStringView::size_type idx = 0) + : i(string.begin()), + pos(i + idx), + e(string.end()) { } |