From 0b9fb15b1a9bd9b5c8658e38c753343ff7ecd390 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 31 Jan 2017 00:36:54 +0100 Subject: QStringView: add mid(), left(), right() Change-Id: If1d2cf175d51b3c02881e21937b0a2d33b78aadd Reviewed-by: Anton Kudryavtsev Reviewed-by: Ville Voutilainen Reviewed-by: Lars Knoll Reviewed-by: Edward Welbourne --- src/corelib/tools/qstringview.cpp | 46 +++++++++++++++++++++++++++++++++++++++ src/corelib/tools/qstringview.h | 9 ++++++++ 2 files changed, 55 insertions(+) (limited to 'src') diff --git a/src/corelib/tools/qstringview.cpp b/src/corelib/tools/qstringview.cpp index fe00965a5c..ec77e11740 100644 --- a/src/corelib/tools/qstringview.cpp +++ b/src/corelib/tools/qstringview.cpp @@ -548,4 +548,50 @@ QT_BEGIN_NAMESPACE \sa back(), front(), first() */ +/*! + \fn QStringView QStringView::mid(size_type start) const + + Returns the substring starting at position \a start in this object, + and extending to the end of the string. + + \note The behavior is undefined when \a start < 0 or \a start > size(). + + \sa left(), right() +*/ + +/*! + \fn QStringView QStringView::mid(size_type start, size_type length) const + \overload + + Returns the substring of length \a length starting at position + \a start in this object. + + \note The behavior is undefined when \a start < 0, \a length < 0, + or \a start + \a length > size(). + + \sa left(), right() +*/ + +/*! + \fn QStringView QStringView::left(size_type length) const + + Returns the substring of length \a length starting at position + 0 in this object. + + \note The behavior is undefined when \a length < 0 or \a length > size(). + + \sa mid(), right() +*/ + +/*! + \fn QStringView QStringView::right(size_type length) const + + Returns the substring of length \a length starting at position + size() - \a length in this object. + + \note The behavior is undefined when \a length < 0 or \a length > size(). + + \sa mid(), left() +*/ + QT_END_NAMESPACE diff --git a/src/corelib/tools/qstringview.h b/src/corelib/tools/qstringview.h index b1722e4657..1eb267f78e 100644 --- a/src/corelib/tools/qstringview.h +++ b/src/corelib/tools/qstringview.h @@ -183,6 +183,15 @@ public: Q_DECL_CONSTEXPR QChar at(size_type n) const { return (*this)[n]; } + Q_DECL_CONSTEXPR QStringView mid(size_type pos) const + { return Q_ASSERT(pos >= 0), Q_ASSERT(pos <= size()), QStringView(m_data + pos, m_size - pos); } + Q_DECL_CONSTEXPR QStringView mid(size_type pos, size_type n) const + { return Q_ASSERT(pos >= 0), Q_ASSERT(n >= 0), Q_ASSERT(pos + n <= size()), QStringView(m_data + pos, n); } + Q_DECL_CONSTEXPR QStringView left(size_type n) const + { return Q_ASSERT(n >= 0), Q_ASSERT(n <= size()), QStringView(m_data, n); } + Q_DECL_CONSTEXPR QStringView right(size_type n) const + { return Q_ASSERT(n >= 0), Q_ASSERT(n <= size()), QStringView(m_data + m_size - n, n); } + // // STL compatibility API: // -- cgit v1.2.3