diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-11-03 13:16:05 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-11-04 05:16:48 +0100 |
commit | de2b221ce84c50d90c3e6f5bffcee87fe7ea11cf (patch) | |
tree | a9be57d2b9febc3431874188345804f85070c2f6 /src/corelib/text/qstringview.h | |
parent | bf5011815d917e07ae7cf45e5768f1775f70e90d (diff) |
Add noexcept to slicing and indexing of QStringView
None of those paths should be able to cast.
Change-Id: I947f26c0aae134076499c9f80e910b0257d2bc62
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qstringview.h')
-rw-r--r-- | src/corelib/text/qstringview.h | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 05966ec9df..df05fce252 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -255,41 +255,41 @@ public: [[nodiscard]] QByteArray toLocal8Bit() const { return QtPrivate::convertToLocal8Bit(*this); } [[nodiscard]] inline QList<uint> toUcs4() const; // defined in qlist.h - [[nodiscard]] constexpr QChar at(qsizetype n) const { return (*this)[n]; } + [[nodiscard]] constexpr QChar at(qsizetype n) const noexcept { return (*this)[n]; } - [[nodiscard]] constexpr QStringView mid(qsizetype pos, qsizetype n = -1) const + [[nodiscard]] constexpr QStringView mid(qsizetype pos, qsizetype n = -1) const noexcept { using namespace QtPrivate; auto result = QContainerImplHelper::mid(size(), &pos, &n); return result == QContainerImplHelper::Null ? QStringView() : QStringView(m_data + pos, n); } - [[nodiscard]] constexpr QStringView left(qsizetype n) const + [[nodiscard]] constexpr QStringView left(qsizetype n) const noexcept { if (size_t(n) >= size_t(size())) n = size(); return QStringView(m_data, n); } - [[nodiscard]] constexpr QStringView right(qsizetype n) const + [[nodiscard]] constexpr QStringView right(qsizetype n) const noexcept { if (size_t(n) >= size_t(size())) n = size(); return QStringView(m_data + m_size - n, n); } - [[nodiscard]] constexpr QStringView first(qsizetype n) const + [[nodiscard]] constexpr QStringView first(qsizetype n) const noexcept { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QStringView(m_data, n); } - [[nodiscard]] constexpr QStringView last(qsizetype n) const + [[nodiscard]] constexpr QStringView last(qsizetype n) const noexcept { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QStringView(m_data + size() - n, n); } - [[nodiscard]] constexpr QStringView sliced(qsizetype pos) const + [[nodiscard]] constexpr QStringView sliced(qsizetype pos) const noexcept { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QStringView(m_data + pos, size() - pos); } - [[nodiscard]] constexpr QStringView sliced(qsizetype pos, qsizetype n) const + [[nodiscard]] constexpr QStringView sliced(qsizetype pos, qsizetype n) const noexcept { Q_ASSERT(pos >= 0); Q_ASSERT(n >= 0); Q_ASSERT(size_t(pos) + size_t(n) <= size_t(size())); return QStringView(m_data + pos, n); } - [[nodiscard]] constexpr QStringView chopped(qsizetype n) const + [[nodiscard]] constexpr QStringView chopped(qsizetype n) const noexcept { return Q_ASSERT(n >= 0), Q_ASSERT(n <= size()), QStringView(m_data, m_size - n); } - constexpr void truncate(qsizetype n) + constexpr void truncate(qsizetype n) noexcept { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size = n; } - constexpr void chop(qsizetype n) + constexpr void chop(qsizetype n) noexcept { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size -= n; } [[nodiscard]] QStringView trimmed() const noexcept { return QtPrivate::trimmed(*this); } |