summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2021-05-14 11:14:31 +0200
committerAndy Shaw <andy.shaw@qt.io>2021-05-24 19:40:14 +0200
commit0e2776320cc39a95b914787d28a09c615f68b708 (patch)
tree6c396e2bab12a0616afe4d308a3c0a95866fa6ce /src
parent3d5d5cbe71d9f556aac888353efe7c2b9b219b52 (diff)
Fix QStringView::mid() to behave as documented when passed -1 for length
With 84b53a4514c the behaviour was documented to be the same as QString::mid(), however this did not account for when -1 is passed for the length when it should get the rest of the string. So this ensures this behavior is put in place. Fixes: QTBUG-93677 Change-Id: Id41e136d78a13ff369508e37e6c679c76c6ae399 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qstringview.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h
index cbb2071f9d..e7d7ea1636 100644
--- a/src/corelib/text/qstringview.h
+++ b/src/corelib/text/qstringview.h
@@ -244,7 +244,8 @@ public:
}
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QStringView mid(qsizetype pos, qsizetype n) const
{
- return QStringView(m_data + qBound(qsizetype(0), pos, m_size), qBound(qsizetype(0), pos + n, m_size) - qBound(qsizetype(0), pos, m_size));
+ return QStringView(m_data + qBound(qsizetype(0), pos, m_size),
+ n == -1 ? m_size - pos : qBound(qsizetype(0), pos + n, m_size) - qBound(qsizetype(0), pos, m_size));
}
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QStringView left(qsizetype n) const
{