diff options
Diffstat (limited to 'src/corelib/text/qstringview.h')
-rw-r--r-- | src/corelib/text/qstringview.h | 170 |
1 files changed, 85 insertions, 85 deletions
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index a4d0a78e5b..86ffb3cc9e 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -229,19 +229,19 @@ public: [[nodiscard]] constexpr static QStringView fromArray(const Char (&string)[Size]) noexcept { return QStringView(string, Size); } - Q_REQUIRED_RESULT inline QString toString() const; // defined in qstring.h + [[nodiscard]] inline QString toString() const; // defined in qstring.h #if defined(Q_OS_DARWIN) || defined(Q_QDOC) // defined in qcore_foundation.mm - Q_REQUIRED_RESULT Q_CORE_EXPORT CFStringRef toCFString() const Q_DECL_CF_RETURNS_RETAINED; - Q_REQUIRED_RESULT Q_CORE_EXPORT NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED; + [[nodiscard]] Q_CORE_EXPORT CFStringRef toCFString() const Q_DECL_CF_RETURNS_RETAINED; + [[nodiscard]] Q_CORE_EXPORT NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED; #endif - Q_REQUIRED_RESULT constexpr qsizetype size() const noexcept { return m_size; } - Q_REQUIRED_RESULT const_pointer data() const noexcept { return reinterpret_cast<const_pointer>(m_data); } - Q_REQUIRED_RESULT const_pointer constData() const noexcept { return data(); } - Q_REQUIRED_RESULT constexpr const storage_type *utf16() const noexcept { return m_data; } + [[nodiscard]] constexpr qsizetype size() const noexcept { return m_size; } + [[nodiscard]] const_pointer data() const noexcept { return reinterpret_cast<const_pointer>(m_data); } + [[nodiscard]] const_pointer constData() const noexcept { return data(); } + [[nodiscard]] constexpr const storage_type *utf16() const noexcept { return m_data; } - Q_REQUIRED_RESULT constexpr QChar operator[](qsizetype n) const + [[nodiscard]] constexpr QChar operator[](qsizetype n) const { return Q_ASSERT(n >= 0), Q_ASSERT(n < size()), QChar(m_data[n]); } // @@ -249,43 +249,43 @@ public: // template <typename...Args> - Q_REQUIRED_RESULT inline QString arg(Args &&...args) const; // defined in qstring.h + [[nodiscard]] inline QString arg(Args &&...args) const; // defined in qstring.h - Q_REQUIRED_RESULT QByteArray toLatin1() const { return QtPrivate::convertToLatin1(*this); } - Q_REQUIRED_RESULT QByteArray toUtf8() const { return QtPrivate::convertToUtf8(*this); } - Q_REQUIRED_RESULT QByteArray toLocal8Bit() const { return QtPrivate::convertToLocal8Bit(*this); } - Q_REQUIRED_RESULT inline QList<uint> toUcs4() const; // defined in qlist.h + [[nodiscard]] QByteArray toLatin1() const { return QtPrivate::convertToLatin1(*this); } + [[nodiscard]] QByteArray toUtf8() const { return QtPrivate::convertToUtf8(*this); } + [[nodiscard]] QByteArray toLocal8Bit() const { return QtPrivate::convertToLocal8Bit(*this); } + [[nodiscard]] inline QList<uint> toUcs4() const; // defined in qlist.h - Q_REQUIRED_RESULT constexpr QChar at(qsizetype n) const { return (*this)[n]; } + [[nodiscard]] constexpr QChar at(qsizetype n) const { return (*this)[n]; } - Q_REQUIRED_RESULT constexpr QStringView mid(qsizetype pos, qsizetype n = -1) const + [[nodiscard]] constexpr QStringView mid(qsizetype pos, qsizetype n = -1) const { using namespace QtPrivate; auto result = QContainerImplHelper::mid(size(), &pos, &n); return result == QContainerImplHelper::Null ? QStringView() : QStringView(m_data + pos, n); } - Q_REQUIRED_RESULT constexpr QStringView left(qsizetype n) const + [[nodiscard]] constexpr QStringView left(qsizetype n) const { if (size_t(n) >= size_t(size())) n = size(); return QStringView(m_data, n); } - Q_REQUIRED_RESULT constexpr QStringView right(qsizetype n) const + [[nodiscard]] constexpr QStringView right(qsizetype n) const { if (size_t(n) >= size_t(size())) n = size(); return QStringView(m_data + m_size - n, n); } - Q_REQUIRED_RESULT constexpr QStringView first(qsizetype n) const + [[nodiscard]] constexpr QStringView first(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QStringView(m_data, n); } - Q_REQUIRED_RESULT constexpr QStringView last(qsizetype n) const + [[nodiscard]] constexpr QStringView last(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QStringView(m_data + size() - n, n); } - Q_REQUIRED_RESULT constexpr QStringView sliced(qsizetype pos) const + [[nodiscard]] constexpr QStringView sliced(qsizetype pos) const { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QStringView(m_data + pos, size() - pos); } - Q_REQUIRED_RESULT constexpr QStringView sliced(qsizetype pos, qsizetype n) const + [[nodiscard]] constexpr QStringView sliced(qsizetype pos, qsizetype n) const { 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); } - Q_REQUIRED_RESULT constexpr QStringView chopped(qsizetype n) const + [[nodiscard]] constexpr QStringView chopped(qsizetype n) const { return Q_ASSERT(n >= 0), Q_ASSERT(n <= size()), QStringView(m_data, m_size - n); } constexpr void truncate(qsizetype n) @@ -293,90 +293,90 @@ public: constexpr void chop(qsizetype n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size -= n; } - Q_REQUIRED_RESULT QStringView trimmed() const noexcept { return QtPrivate::trimmed(*this); } + [[nodiscard]] QStringView trimmed() const noexcept { return QtPrivate::trimmed(*this); } template <typename Needle, typename...Flags> - Q_REQUIRED_RESULT constexpr inline auto tokenize(Needle &&needle, Flags...flags) const + [[nodiscard]] constexpr inline auto tokenize(Needle &&needle, Flags...flags) const noexcept(noexcept(qTokenize(std::declval<const QStringView&>(), std::forward<Needle>(needle), flags...))) -> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...)) { return qTokenize(*this, std::forward<Needle>(needle), flags...); } - Q_REQUIRED_RESULT int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::compareStrings(*this, other, cs); } - Q_REQUIRED_RESULT inline int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - Q_REQUIRED_RESULT constexpr int compare(QChar c) const noexcept + [[nodiscard]] inline int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + [[nodiscard]] constexpr int compare(QChar c) const noexcept { return size() >= 1 ? compare_single_char_helper(*utf16() - c.unicode()) : -1; } - Q_REQUIRED_RESULT int compare(QChar c, Qt::CaseSensitivity cs) const noexcept + [[nodiscard]] int compare(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); } - Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } - Q_REQUIRED_RESULT inline bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - Q_REQUIRED_RESULT bool startsWith(QChar c) const noexcept + [[nodiscard]] inline bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + [[nodiscard]] bool startsWith(QChar c) const noexcept { return !empty() && front() == c; } - Q_REQUIRED_RESULT bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept + [[nodiscard]] bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::startsWith(*this, QStringView(&c, 1), cs); } - Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::endsWith(*this, s, cs); } - Q_REQUIRED_RESULT inline bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - Q_REQUIRED_RESULT bool endsWith(QChar c) const noexcept + [[nodiscard]] inline bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + [[nodiscard]] bool endsWith(QChar c) const noexcept { return !empty() && back() == c; } - Q_REQUIRED_RESULT bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept + [[nodiscard]] bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); } - Q_REQUIRED_RESULT qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::findString(*this, from, QStringView(&c, 1), cs); } - Q_REQUIRED_RESULT qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::findString(*this, from, s, cs); } - Q_REQUIRED_RESULT inline qsizetype indexOf(QLatin1String s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + [[nodiscard]] inline qsizetype indexOf(QLatin1String s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - Q_REQUIRED_RESULT bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return indexOf(QStringView(&c, 1), 0, cs) != qsizetype(-1); } - Q_REQUIRED_RESULT bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return indexOf(s, 0, cs) != qsizetype(-1); } - Q_REQUIRED_RESULT inline bool contains(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + [[nodiscard]] inline bool contains(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - Q_REQUIRED_RESULT qsizetype count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] qsizetype count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::count(*this, c, cs); } - Q_REQUIRED_RESULT qsizetype count(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] qsizetype count(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::count(*this, s, cs); } - Q_REQUIRED_RESULT qsizetype lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs); } - Q_REQUIRED_RESULT qsizetype lastIndexOf(QStringView s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] qsizetype lastIndexOf(QStringView s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::lastIndexOf(*this, from, s, cs); } - Q_REQUIRED_RESULT inline qsizetype lastIndexOf(QLatin1String s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + [[nodiscard]] inline qsizetype lastIndexOf(QLatin1String s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - Q_REQUIRED_RESULT bool isRightToLeft() const noexcept + [[nodiscard]] bool isRightToLeft() const noexcept { return QtPrivate::isRightToLeft(*this); } - Q_REQUIRED_RESULT bool isValidUtf16() const noexcept + [[nodiscard]] bool isValidUtf16() const noexcept { return QtPrivate::isValidUtf16(*this); } - Q_REQUIRED_RESULT inline short toShort(bool *ok = nullptr, int base = 10) const; - Q_REQUIRED_RESULT inline ushort toUShort(bool *ok = nullptr, int base = 10) const; - Q_REQUIRED_RESULT inline int toInt(bool *ok = nullptr, int base = 10) const; - Q_REQUIRED_RESULT inline uint toUInt(bool *ok = nullptr, int base = 10) const; - Q_REQUIRED_RESULT inline long toLong(bool *ok = nullptr, int base = 10) const; - Q_REQUIRED_RESULT inline ulong toULong(bool *ok = nullptr, int base = 10) const; - Q_REQUIRED_RESULT inline qlonglong toLongLong(bool *ok = nullptr, int base = 10) const; - Q_REQUIRED_RESULT inline qulonglong toULongLong(bool *ok = nullptr, int base = 10) const; - Q_REQUIRED_RESULT Q_CORE_EXPORT float toFloat(bool *ok = nullptr) const; - Q_REQUIRED_RESULT Q_CORE_EXPORT double toDouble(bool *ok = nullptr) const; + [[nodiscard]] inline short toShort(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] inline ushort toUShort(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] inline int toInt(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] inline uint toUInt(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] inline long toLong(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] inline ulong toULong(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] inline qlonglong toLongLong(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] inline qulonglong toULongLong(bool *ok = nullptr, int base = 10) const; + [[nodiscard]] Q_CORE_EXPORT float toFloat(bool *ok = nullptr) const; + [[nodiscard]] Q_CORE_EXPORT double toDouble(bool *ok = nullptr) const; - Q_REQUIRED_RESULT inline qsizetype toWCharArray(wchar_t *array) const; // defined in qstring.h + [[nodiscard]] inline qsizetype toWCharArray(wchar_t *array) const; // defined in qstring.h - Q_REQUIRED_RESULT Q_CORE_EXPORT + [[nodiscard]] Q_CORE_EXPORT QList<QStringView> split(QStringView sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - Q_REQUIRED_RESULT Q_CORE_EXPORT + [[nodiscard]] Q_CORE_EXPORT QList<QStringView> split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #if QT_CONFIG(regularexpression) - Q_REQUIRED_RESULT Q_CORE_EXPORT + [[nodiscard]] Q_CORE_EXPORT QList<QStringView> split(const QRegularExpression &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const; #endif @@ -384,28 +384,28 @@ public: // // STL compatibility API: // - Q_REQUIRED_RESULT const_iterator begin() const noexcept { return data(); } - Q_REQUIRED_RESULT const_iterator end() const noexcept { return data() + size(); } - Q_REQUIRED_RESULT const_iterator cbegin() const noexcept { return begin(); } - Q_REQUIRED_RESULT const_iterator cend() const noexcept { return end(); } - Q_REQUIRED_RESULT const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } - Q_REQUIRED_RESULT const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } - Q_REQUIRED_RESULT const_reverse_iterator crbegin() const noexcept { return rbegin(); } - Q_REQUIRED_RESULT const_reverse_iterator crend() const noexcept { return rend(); } - - Q_REQUIRED_RESULT constexpr bool empty() const noexcept { return size() == 0; } - Q_REQUIRED_RESULT constexpr QChar front() const { return Q_ASSERT(!empty()), QChar(m_data[0]); } - Q_REQUIRED_RESULT constexpr QChar back() const { return Q_ASSERT(!empty()), QChar(m_data[m_size - 1]); } + [[nodiscard]] const_iterator begin() const noexcept { return data(); } + [[nodiscard]] const_iterator end() const noexcept { return data() + size(); } + [[nodiscard]] const_iterator cbegin() const noexcept { return begin(); } + [[nodiscard]] const_iterator cend() const noexcept { return end(); } + [[nodiscard]] const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + [[nodiscard]] const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + [[nodiscard]] const_reverse_iterator crbegin() const noexcept { return rbegin(); } + [[nodiscard]] const_reverse_iterator crend() const noexcept { return rend(); } + + [[nodiscard]] constexpr bool empty() const noexcept { return size() == 0; } + [[nodiscard]] constexpr QChar front() const { return Q_ASSERT(!empty()), QChar(m_data[0]); } + [[nodiscard]] constexpr QChar back() const { return Q_ASSERT(!empty()), QChar(m_data[m_size - 1]); } // // Qt compatibility API: // - Q_REQUIRED_RESULT constexpr bool isNull() const noexcept { return !m_data; } - Q_REQUIRED_RESULT constexpr bool isEmpty() const noexcept { return empty(); } - Q_REQUIRED_RESULT constexpr int length() const /* not nothrow! */ + [[nodiscard]] constexpr bool isNull() const noexcept { return !m_data; } + [[nodiscard]] constexpr bool isEmpty() const noexcept { return empty(); } + [[nodiscard]] constexpr int length() const /* not nothrow! */ { return Q_ASSERT(int(size()) == size()), int(size()); } - Q_REQUIRED_RESULT constexpr QChar first() const { return front(); } - Q_REQUIRED_RESULT constexpr QChar last() const { return back(); } + [[nodiscard]] constexpr QChar first() const { return front(); } + [[nodiscard]] constexpr QChar last() const { return back(); } private: qsizetype m_size; const storage_type *m_data; @@ -423,14 +423,14 @@ inline QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept // QChar inline functions: -Q_REQUIRED_RESULT constexpr auto QChar::fromUcs4(char32_t c) noexcept +[[nodiscard]] constexpr auto QChar::fromUcs4(char32_t c) noexcept { struct R { char16_t chars[2]; - Q_REQUIRED_RESULT constexpr operator QStringView() const noexcept { return {begin(), end()}; } - Q_REQUIRED_RESULT constexpr qsizetype size() const noexcept { return chars[1] ? 2 : 1; } - Q_REQUIRED_RESULT constexpr const char16_t *begin() const noexcept { return chars; } - Q_REQUIRED_RESULT constexpr const char16_t *end() const noexcept { return begin() + size(); } + [[nodiscard]] constexpr operator QStringView() const noexcept { return {begin(), end()}; } + [[nodiscard]] constexpr qsizetype size() const noexcept { return chars[1] ? 2 : 1; } + [[nodiscard]] constexpr const char16_t *begin() const noexcept { return chars; } + [[nodiscard]] constexpr const char16_t *end() const noexcept { return begin() + size(); } }; return requiresSurrogates(c) ? R{{QChar::highSurrogate(c), QChar::lowSurrogate(c)}} : |