From 0e2776320cc39a95b914787d28a09c615f68b708 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 14 May 2021 11:14:31 +0200 Subject: 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 --- src/corelib/text/qstringview.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib/text/qstringview.h') 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 { -- cgit v1.2.3