summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qstringview.cpp46
-rw-r--r--src/corelib/tools/qstringview.h9
-rw-r--r--tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp6
3 files changed, 61 insertions, 0 deletions
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:
//
diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
index d5c22be029..dd8cbbfbcd 100644
--- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
+++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -197,6 +197,8 @@ private Q_SLOTS:
void mid_QString() { mid_impl<QString>(); }
void mid_QStringRef_data() { mid_data(); }
void mid_QStringRef() { mid_impl<QStringRef>(); }
+ void mid_QStringView_data() { mid_data(); }
+ void mid_QStringView() { mid_impl<QStringView>(); }
void mid_QLatin1String_data() { mid_data(); }
void mid_QLatin1String() { mid_impl<QLatin1String>(); }
void mid_QByteArray_data() { mid_data(); }
@@ -206,6 +208,8 @@ private Q_SLOTS:
void left_QString() { left_impl<QString>(); }
void left_QStringRef_data() { left_data(); }
void left_QStringRef() { left_impl<QStringRef>(); }
+ void left_QStringView_data() { left_data(); }
+ void left_QStringView() { left_impl<QStringView>(); }
void left_QLatin1String_data() { left_data(); }
void left_QLatin1String() { left_impl<QLatin1String>(); }
void left_QByteArray_data() { left_data(); }
@@ -215,6 +219,8 @@ private Q_SLOTS:
void right_QString() { right_impl<QString>(); }
void right_QStringRef_data() { right_data(); }
void right_QStringRef() { right_impl<QStringRef>(); }
+ void right_QStringView_data() { right_data(); }
+ void right_QStringView() { right_impl<QStringView>(); }
void right_QLatin1String_data() { right_data(); }
void right_QLatin1String() { right_impl<QLatin1String>(); }
void right_QByteArray_data() { right_data(); }