summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qstringview.cpp46
-rw-r--r--src/corelib/tools/qstringview.h9
2 files changed, 55 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:
//