diff options
author | Anton Kudryavtsev <a.kudryavtsev@netris.ru> | 2016-07-06 17:58:13 +0300 |
---|---|---|
committer | Anton Kudryavtsev <a.kudryavtsev@netris.ru> | 2016-07-07 15:12:27 +0000 |
commit | e91c41239166beb4b68a3f5523351e8dc3796857 (patch) | |
tree | 70112c72fd2adccf775c53ebb862ecfba12d586c /src | |
parent | a13398d0f060bbfa482cfe411061ece6e07d2b7e (diff) |
QStringRef: add chop()
chop() was missing in the API.
Change-Id: I15af86c8f218cf159b8ce19bbeb2ffa6201f98cf
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 14 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 6 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 55390189b6..32f12bd092 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -5009,7 +5009,7 @@ void QString::truncate(int pos) If you want to remove characters from the \e beginning of the string, use remove() instead. - \sa truncate(), resize(), remove() + \sa truncate(), resize(), remove(), QStringRef::chop() */ void QString::chop(int n) { @@ -9660,6 +9660,18 @@ QStringRef QString::midRef(int position, int n) const */ /*! + \fn void QStringRef::chop(int n) + \since 5.8 + + Removes \a n characters from the end of the string. + + If \a n is greater than or equal to size(), the result is an + empty string; if \a n is negative, it is equivalent to passing zero. + + \sa QString::chop(), truncate() +*/ + +/*! \since 4.8 Returns the index position of the first occurrence of the string \a diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 0c0f3355a9..ec959b50a0 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -1438,6 +1438,12 @@ public: QStringRef mid(int pos, int n = -1) const Q_REQUIRED_RESULT; void truncate(int pos) Q_DECL_NOTHROW { m_size = qBound(0, pos, m_size); } + void chop(int n) Q_DECL_NOTHROW { + if (n >= m_size) + m_size = 0; + else if (n > 0) + m_size -= n; + } bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; |