diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-04-24 11:32:17 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-04-28 16:41:36 +0000 |
commit | d21a147e2bad29906696125605328a563cd7ed2f (patch) | |
tree | c047b8e493cc3d6ae8cc638f25a8be1e145e2fb5 /src/corelib/tools/qstringview.h | |
parent | 5f3d6ce5709466d08b11b6f2c8608d131e7c3f43 (diff) |
QStringView: add startsWith(), endsWith()
Change-Id: I72aef9236daedc3013c62d3f1d737159f85572b8
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools/qstringview.h')
-rw-r--r-- | src/corelib/tools/qstringview.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/corelib/tools/qstringview.h b/src/corelib/tools/qstringview.h index 527f1d48e7..62173f9765 100644 --- a/src/corelib/tools/qstringview.h +++ b/src/corelib/tools/qstringview.h @@ -241,6 +241,22 @@ public: Q_DECL_RELAXED_CONSTEXPR void chop(qssize_t n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size -= n; } + Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + { return qStartsWith(*this, s, cs); } + Q_REQUIRED_RESULT inline bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT bool startsWith(QChar c) const Q_DECL_NOTHROW + { return !empty() && front() == c; } + Q_REQUIRED_RESULT bool startsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW + { return qStartsWith(*this, QStringView(&c, 1), cs); } + + Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW + { return qEndsWith(*this, s, cs); } + Q_REQUIRED_RESULT inline bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; + Q_REQUIRED_RESULT bool endsWith(QChar c) const Q_DECL_NOTHROW + { return !empty() && back() == c; } + Q_REQUIRED_RESULT bool endsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW + { return qEndsWith(*this, QStringView(&c, 1), cs); } + // // STL compatibility API: // |