Skip to content

Commit

Permalink
Fix QStringView::mid() to behave as documented when passed -1 for length
Browse files Browse the repository at this point in the history
With 84b53a4 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 <[email protected]>
  • Loading branch information
AndyShawQt committed May 24, 2021
1 parent 3d5d5cb commit 0e27763
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/corelib/text/qstringview.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ class QStringView
}
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
{
Expand Down

0 comments on commit 0e27763

Please sign in to comment.