diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-23 10:09:42 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-25 07:10:45 +0200 |
commit | c2be9180b7430221e9136afb1a8c2a752ac2710f (patch) | |
tree | 5b390c53f4744c7bd4faeaf4d3a12d77ce3c0ba7 /src/corelib/text | |
parent | 31a1b3280cf076fcdb45a658d0140af3737be138 (diff) |
Replace Q_REQUIRED_RESULT with [[nodiscard]]
It was already used many places directly making the code inconsistent.
Change-Id: I3b14bc6c333640fb3ba33c71eba97e78c973e44b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qbytearray.h | 82 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 186 | ||||
-rw-r--r-- | src/corelib/text/qstringalgorithms.h | 106 | ||||
-rw-r--r-- | src/corelib/text/qstringtokenizer.h | 14 | ||||
-rw-r--r-- | src/corelib/text/qstringview.h | 170 |
5 files changed, 279 insertions, 279 deletions
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index c6f74c4691..f98313a1f0 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -199,11 +199,11 @@ public: inline char at(qsizetype i) const; inline char operator[](qsizetype i) const; - Q_REQUIRED_RESULT inline char &operator[](qsizetype i); - Q_REQUIRED_RESULT char front() const { return at(0); } - Q_REQUIRED_RESULT inline char &front(); - Q_REQUIRED_RESULT char back() const { return at(size() - 1); } - Q_REQUIRED_RESULT inline char &back(); + [[nodiscard]] inline char &operator[](qsizetype i); + [[nodiscard]] char front() const { return at(0); } + [[nodiscard]] inline char &front(); + [[nodiscard]] char back() const { return at(size() - 1); } + [[nodiscard]] inline char &back(); qsizetype indexOf(char c, qsizetype from = 0) const; qsizetype indexOf(QByteArrayView bv, qsizetype from = 0) const @@ -221,19 +221,19 @@ public: inline int compare(QByteArrayView a, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - Q_REQUIRED_RESULT QByteArray left(qsizetype len) const; - Q_REQUIRED_RESULT QByteArray right(qsizetype len) const; - Q_REQUIRED_RESULT QByteArray mid(qsizetype index, qsizetype len = -1) const; + [[nodiscard]] QByteArray left(qsizetype len) const; + [[nodiscard]] QByteArray right(qsizetype len) const; + [[nodiscard]] QByteArray mid(qsizetype index, qsizetype len = -1) const; - Q_REQUIRED_RESULT QByteArray first(qsizetype n) const + [[nodiscard]] QByteArray first(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QByteArray(data(), n); } - Q_REQUIRED_RESULT QByteArray last(qsizetype n) const + [[nodiscard]] QByteArray last(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QByteArray(data() + size() - n, n); } - Q_REQUIRED_RESULT QByteArray sliced(qsizetype pos) const + [[nodiscard]] QByteArray sliced(qsizetype pos) const { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QByteArray(data() + pos, size() - pos); } - Q_REQUIRED_RESULT QByteArray sliced(qsizetype pos, qsizetype n) const + [[nodiscard]] QByteArray 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 QByteArray(data() + pos, n); } - Q_REQUIRED_RESULT QByteArray chopped(qsizetype len) const + [[nodiscard]] QByteArray chopped(qsizetype len) const { Q_ASSERT(len >= 0); Q_ASSERT(len <= size()); return first(size() - len); } bool startsWith(QByteArrayView bv) const @@ -251,31 +251,31 @@ public: void chop(qsizetype n); #if !defined(Q_CLANG_QDOC) - Q_REQUIRED_RESULT QByteArray toLower() const & + [[nodiscard]] QByteArray toLower() const & { return toLower_helper(*this); } - Q_REQUIRED_RESULT QByteArray toLower() && + [[nodiscard]] QByteArray toLower() && { return toLower_helper(*this); } - Q_REQUIRED_RESULT QByteArray toUpper() const & + [[nodiscard]] QByteArray toUpper() const & { return toUpper_helper(*this); } - Q_REQUIRED_RESULT QByteArray toUpper() && + [[nodiscard]] QByteArray toUpper() && { return toUpper_helper(*this); } - Q_REQUIRED_RESULT QByteArray trimmed() const & + [[nodiscard]] QByteArray trimmed() const & { return trimmed_helper(*this); } - Q_REQUIRED_RESULT QByteArray trimmed() && + [[nodiscard]] QByteArray trimmed() && { return trimmed_helper(*this); } - Q_REQUIRED_RESULT QByteArray simplified() const & + [[nodiscard]] QByteArray simplified() const & { return simplified_helper(*this); } - Q_REQUIRED_RESULT QByteArray simplified() && + [[nodiscard]] QByteArray simplified() && { return simplified_helper(*this); } #else - Q_REQUIRED_RESULT QByteArray toLower() const; - Q_REQUIRED_RESULT QByteArray toUpper() const; - Q_REQUIRED_RESULT QByteArray trimmed() const; - Q_REQUIRED_RESULT QByteArray simplified() const; + [[nodiscard]] QByteArray toLower() const; + [[nodiscard]] QByteArray toUpper() const; + [[nodiscard]] QByteArray trimmed() const; + [[nodiscard]] QByteArray simplified() const; #endif - Q_REQUIRED_RESULT QByteArray leftJustified(qsizetype width, char fill = ' ', bool truncate = false) const; - Q_REQUIRED_RESULT QByteArray rightJustified(qsizetype width, char fill = ' ', bool truncate = false) const; + [[nodiscard]] QByteArray leftJustified(qsizetype width, char fill = ' ', bool truncate = false) const; + [[nodiscard]] QByteArray rightJustified(qsizetype width, char fill = ' ', bool truncate = false) const; QByteArray &prepend(char c) { return insert(0, QByteArrayView(&c, 1)); } @@ -329,7 +329,7 @@ public: QList<QByteArray> split(char sep) const; - Q_REQUIRED_RESULT QByteArray repeated(qsizetype times) const; + [[nodiscard]] QByteArray repeated(qsizetype times) const; #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) inline QT_ASCII_CAST_WARN bool operator==(const QString &s2) const; @@ -368,24 +368,24 @@ public: QByteArray &setNum(double, char f = 'g', int prec = 6); QByteArray &setRawData(const char *a, qsizetype n); - Q_REQUIRED_RESULT static QByteArray number(int, int base = 10); - Q_REQUIRED_RESULT static QByteArray number(uint, int base = 10); - Q_REQUIRED_RESULT static QByteArray number(long, int base = 10); - Q_REQUIRED_RESULT static QByteArray number(ulong, int base = 10); - Q_REQUIRED_RESULT static QByteArray number(qlonglong, int base = 10); - Q_REQUIRED_RESULT static QByteArray number(qulonglong, int base = 10); - Q_REQUIRED_RESULT static QByteArray number(double, char f = 'g', int prec = 6); - Q_REQUIRED_RESULT static QByteArray fromRawData(const char *data, qsizetype size) + [[nodiscard]] static QByteArray number(int, int base = 10); + [[nodiscard]] static QByteArray number(uint, int base = 10); + [[nodiscard]] static QByteArray number(long, int base = 10); + [[nodiscard]] static QByteArray number(ulong, int base = 10); + [[nodiscard]] static QByteArray number(qlonglong, int base = 10); + [[nodiscard]] static QByteArray number(qulonglong, int base = 10); + [[nodiscard]] static QByteArray number(double, char f = 'g', int prec = 6); + [[nodiscard]] static QByteArray fromRawData(const char *data, qsizetype size) { return QByteArray(DataPointer(nullptr, const_cast<char *>(data), size)); } class FromBase64Result; - Q_REQUIRED_RESULT static FromBase64Result fromBase64Encoding(QByteArray &&base64, Base64Options options = Base64Encoding); - Q_REQUIRED_RESULT static FromBase64Result fromBase64Encoding(const QByteArray &base64, Base64Options options = Base64Encoding); - Q_REQUIRED_RESULT static QByteArray fromBase64(const QByteArray &base64, Base64Options options = Base64Encoding); - Q_REQUIRED_RESULT static QByteArray fromHex(const QByteArray &hexEncoded); - Q_REQUIRED_RESULT static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%'); + [[nodiscard]] static FromBase64Result fromBase64Encoding(QByteArray &&base64, Base64Options options = Base64Encoding); + [[nodiscard]] static FromBase64Result fromBase64Encoding(const QByteArray &base64, Base64Options options = Base64Encoding); + [[nodiscard]] static QByteArray fromBase64(const QByteArray &base64, Base64Options options = Base64Encoding); + [[nodiscard]] static QByteArray fromHex(const QByteArray &hexEncoded); + [[nodiscard]] static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%'); #if defined(Q_OS_DARWIN) || defined(Q_QDOC) static QByteArray fromCFData(CFDataRef data); diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 789d06f9a2..f4e58e38b2 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -100,40 +100,40 @@ public: constexpr bool isEmpty() const noexcept { return !size(); } template <typename...Args> - Q_REQUIRED_RESULT inline QString arg(Args &&...args) const; + [[nodiscard]] inline QString arg(Args &&...args) const; [[nodiscard]] constexpr QLatin1Char at(qsizetype i) const { return Q_ASSERT(i >= 0), Q_ASSERT(i < size()), QLatin1Char(m_data[i]); } [[nodiscard]] constexpr QLatin1Char operator[](qsizetype i) const { return at(i); } - Q_REQUIRED_RESULT constexpr QLatin1Char front() const { return at(0); } - Q_REQUIRED_RESULT constexpr QLatin1Char back() const { return at(size() - 1); } + [[nodiscard]] constexpr QLatin1Char front() const { return at(0); } + [[nodiscard]] constexpr QLatin1Char back() const { return at(size() - 1); } - 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 int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::compareStrings(*this, other, cs); } - Q_REQUIRED_RESULT constexpr int compare(QChar c) const noexcept + [[nodiscard]] constexpr int compare(QChar c) const noexcept { return isEmpty() || front() == c ? size() - 1 : uchar(m_data[0]) - c.unicode() ; } - 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 bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::startsWith(*this, s, cs); } - Q_REQUIRED_RESULT constexpr bool startsWith(QChar c) const noexcept + [[nodiscard]] constexpr bool startsWith(QChar c) const noexcept { return !isEmpty() && front() == c; } - Q_REQUIRED_RESULT inline bool startsWith(QChar c, Qt::CaseSensitivity cs) const noexcept + [[nodiscard]] inline 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 bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::endsWith(*this, s, cs); } - Q_REQUIRED_RESULT constexpr bool endsWith(QChar c) const noexcept + [[nodiscard]] constexpr bool endsWith(QChar c) const noexcept { return !isEmpty() && back() == c; } - Q_REQUIRED_RESULT inline bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept + [[nodiscard]] inline bool endsWith(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); } [[nodiscard]] qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept @@ -143,11 +143,11 @@ public: [[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 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) != -1; } - Q_REQUIRED_RESULT bool contains(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] bool contains(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return indexOf(s, 0, cs) != -1; } - Q_REQUIRED_RESULT inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return indexOf(QStringView(&c, 1), 0, cs) != -1; } [[nodiscard]] qsizetype lastIndexOf(QStringView s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept @@ -213,10 +213,10 @@ public: constexpr void truncate(qsizetype n) { verify(n); m_size = n; } - Q_REQUIRED_RESULT QLatin1String trimmed() const noexcept { return QtPrivate::trimmed(*this); } + [[nodiscard]] QLatin1String trimmed() const noexcept { return QtPrivate::trimmed(*this); } template <typename Needle, typename...Flags> - Q_REQUIRED_RESULT inline constexpr auto tokenize(Needle &&needle, Flags...flags) const + [[nodiscard]] inline constexpr auto tokenize(Needle &&needle, Flags...flags) const noexcept(noexcept(qTokenize(std::declval<const QLatin1String &>(), std::forward<Needle>(needle), flags...))) -> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...)) { return qTokenize(*this, std::forward<Needle>(needle), flags...); } @@ -367,42 +367,42 @@ public: inline const QChar at(qsizetype i) const; const QChar operator[](qsizetype i) const; - Q_REQUIRED_RESULT QChar &operator[](qsizetype i); + [[nodiscard]] QChar &operator[](qsizetype i); - Q_REQUIRED_RESULT inline QChar front() const { return at(0); } - Q_REQUIRED_RESULT inline QChar &front(); - Q_REQUIRED_RESULT inline QChar back() const { return at(size() - 1); } - Q_REQUIRED_RESULT inline QChar &back(); + [[nodiscard]] inline QChar front() const { return at(0); } + [[nodiscard]] inline QChar &front(); + [[nodiscard]] inline QChar back() const { return at(size() - 1); } + [[nodiscard]] inline QChar &back(); - Q_REQUIRED_RESULT QString arg(qlonglong a, int fieldwidth=0, int base=10, + [[nodiscard]] QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(qulonglong a, int fieldwidth=0, int base=10, + [[nodiscard]] QString arg(qulonglong a, int fieldwidth=0, int base=10, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(long a, int fieldwidth=0, int base=10, + [[nodiscard]] QString arg(long a, int fieldwidth=0, int base=10, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(ulong a, int fieldwidth=0, int base=10, + [[nodiscard]] QString arg(ulong a, int fieldwidth=0, int base=10, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(int a, int fieldWidth = 0, int base = 10, + [[nodiscard]] QString arg(int a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(uint a, int fieldWidth = 0, int base = 10, + [[nodiscard]] QString arg(uint a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(short a, int fieldWidth = 0, int base = 10, + [[nodiscard]] QString arg(short a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(ushort a, int fieldWidth = 0, int base = 10, + [[nodiscard]] QString arg(ushort a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(double a, int fieldWidth = 0, char fmt = 'g', int prec = -1, + [[nodiscard]] QString arg(double a, int fieldWidth = 0, char fmt = 'g', int prec = -1, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(char a, int fieldWidth = 0, + [[nodiscard]] QString arg(char a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(QChar a, int fieldWidth = 0, + [[nodiscard]] QString arg(QChar a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const; #if QT_STRINGVIEW_LEVEL < 2 - Q_REQUIRED_RESULT QString arg(const QString &a, int fieldWidth = 0, + [[nodiscard]] QString arg(const QString &a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const; #endif - Q_REQUIRED_RESULT QString arg(QStringView a, int fieldWidth = 0, + [[nodiscard]] QString arg(QStringView a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const; - Q_REQUIRED_RESULT QString arg(QLatin1String a, int fieldWidth = 0, + [[nodiscard]] QString arg(QLatin1String a, int fieldWidth = 0, QChar fillChar = QLatin1Char(' ')) const; private: template <typename T> @@ -416,7 +416,7 @@ private: : is_convertible_to_view_or_qstring_helper<typename std::decay<T>::type> {}; public: template <typename...Args> - Q_REQUIRED_RESULT + [[nodiscard]] #ifdef Q_CLANG_QDOC QString #else @@ -439,7 +439,7 @@ public: #if QT_STRINGVIEW_LEVEL < 2 qsizetype indexOf(const QString &s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif - 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); } qsizetype lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; qsizetype lastIndexOf(QLatin1String s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -447,7 +447,7 @@ public: qsizetype lastIndexOf(const QString &s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif - 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); } inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -483,26 +483,26 @@ public: #if QT_CONFIG(regularexpression) QString section(const QRegularExpression &re, qsizetype start, qsizetype end = -1, SectionFlags flags = SectionDefault) const; #endif - Q_REQUIRED_RESULT QString left(qsizetype n) const; - Q_REQUIRED_RESULT QString right(qsizetype n) const; - Q_REQUIRED_RESULT QString mid(qsizetype position, qsizetype n = -1) const; + [[nodiscard]] QString left(qsizetype n) const; + [[nodiscard]] QString right(qsizetype n) const; + [[nodiscard]] QString mid(qsizetype position, qsizetype n = -1) const; - Q_REQUIRED_RESULT QString first(qsizetype n) const + [[nodiscard]] QString first(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QString(data(), n); } - Q_REQUIRED_RESULT QString last(qsizetype n) const + [[nodiscard]] QString last(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QString(data() + size() - n, n); } - Q_REQUIRED_RESULT QString sliced(qsizetype pos) const + [[nodiscard]] QString sliced(qsizetype pos) const { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QString(data() + pos, size() - pos); } - Q_REQUIRED_RESULT QString sliced(qsizetype pos, qsizetype n) const + [[nodiscard]] QString 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 QString(data() + pos, n); } - Q_REQUIRED_RESULT QString chopped(qsizetype n) const + [[nodiscard]] QString chopped(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return first(size() - n); } #if QT_STRINGVIEW_LEVEL < 2 bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif - 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); } bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -510,7 +510,7 @@ public: #if QT_STRINGVIEW_LEVEL < 2 bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif - 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); } bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -518,38 +518,38 @@ public: bool isUpper() const; bool isLower() const; - Q_REQUIRED_RESULT QString leftJustified(qsizetype width, QChar fill = QLatin1Char(' '), bool trunc = false) const; - Q_REQUIRED_RESULT QString rightJustified(qsizetype width, QChar fill = QLatin1Char(' '), bool trunc = false) const; + [[nodiscard]] QString leftJustified(qsizetype width, QChar fill = QLatin1Char(' '), bool trunc = false) const; + [[nodiscard]] QString rightJustified(qsizetype width, QChar fill = QLatin1Char(' '), bool trunc = false) const; #if !defined(Q_CLANG_QDOC) - Q_REQUIRED_RESULT QString toLower() const & + [[nodiscard]] QString toLower() const & { return toLower_helper(*this); } - Q_REQUIRED_RESULT QString toLower() && + [[nodiscard]] QString toLower() && { return toLower_helper(*this); } - Q_REQUIRED_RESULT QString toUpper() const & + [[nodiscard]] QString toUpper() const & { return toUpper_helper(*this); } - Q_REQUIRED_RESULT QString toUpper() && + [[nodiscard]] QString toUpper() && { return toUpper_helper(*this); } - Q_REQUIRED_RESULT QString toCaseFolded() const & + [[nodiscard]] QString toCaseFolded() const & { return toCaseFolded_helper(*this); } - Q_REQUIRED_RESULT QString toCaseFolded() && + [[nodiscard]] QString toCaseFolded() && { return toCaseFolded_helper(*this); } - Q_REQUIRED_RESULT QString trimmed() const & + [[nodiscard]] QString trimmed() const & { return trimmed_helper(*this); } - Q_REQUIRED_RESULT QString trimmed() && + [[nodiscard]] QString trimmed() && { return trimmed_helper(*this); } - Q_REQUIRED_RESULT QString simplified() const & + [[nodiscard]] QString simplified() const & { return simplified_helper(*this); } - Q_REQUIRED_RESULT QString simplified() && + [[nodiscard]] QString simplified() && { return simplified_helper(*this); } #else - Q_REQUIRED_RESULT QString toLower() const; - Q_REQUIRED_RESULT QString toUpper() const; - Q_REQUIRED_RESULT QString toCaseFolded() const; - Q_REQUIRED_RESULT QString trimmed() const; - Q_REQUIRED_RESULT QString simplified() const; + [[nodiscard]] QString toLower() const; + [[nodiscard]] QString toUpper() const; + [[nodiscard]] QString toCaseFolded() const; + [[nodiscard]] QString trimmed() const; + [[nodiscard]] QString simplified() const; #endif - Q_REQUIRED_RESULT QString toHtmlEscaped() const; + [[nodiscard]] QString toHtmlEscaped() const; QString &insert(qsizetype i, QChar c); QString &insert(qsizetype i, const QChar *uc, qsizetype len); @@ -606,32 +606,32 @@ public: #endif public: - Q_REQUIRED_RESULT + [[nodiscard]] QStringList split(const QString &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - Q_REQUIRED_RESULT + [[nodiscard]] QStringList split(QChar sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #ifndef QT_NO_REGULAREXPRESSION - Q_REQUIRED_RESULT + [[nodiscard]] QStringList split(const QRegularExpression &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const; #endif template <typename Needle, typename...Flags> - Q_REQUIRED_RESULT inline auto tokenize(Needle &&needle, Flags...flags) const & + [[nodiscard]] inline auto tokenize(Needle &&needle, Flags...flags) const & noexcept(noexcept(qTokenize(std::declval<const QString &>(), std::forward<Needle>(needle), flags...))) -> decltype(qTokenize(*this, std::forward<Needle>(needle), flags...)) { return qTokenize(qToStringViewIgnoringNull(*this), std::forward<Needle>(needle), flags...); } template <typename Needle, typename...Flags> - Q_REQUIRED_RESULT inline auto tokenize(Needle &&needle, Flags...flags) const && + [[nodiscard]] inline auto tokenize(Needle &&needle, Flags...flags) const && noexcept(noexcept(qTokenize(std::declval<const QString>(), std::forward<Needle>(needle), flags...))) -> decltype(qTokenize(std::move(*this), std::forward<Needle>(needle), flags...)) { return qTokenize(std::move(*this), std::forward<Needle>(needle), flags...); } template <typename Needle, typename...Flags> - Q_REQUIRED_RESULT inline auto tokenize(Needle &&needle, Flags...flags) && + [[nodiscard]] inline auto tokenize(Needle &&needle, Flags...flags) && noexcept(noexcept(qTokenize(std::declval<QString>(), std::forward<Needle>(needle), flags...))) -> decltype(qTokenize(std::move(*this), std::forward<Needle>(needle), flags...)) { return qTokenize(std::move(*this), std::forward<Needle>(needle), flags...); } @@ -643,31 +643,31 @@ public: NormalizationForm_KD, NormalizationForm_KC }; - Q_REQUIRED_RESULT QString normalized(NormalizationForm mode, QChar::UnicodeVersion version = QChar::Unicode_Unassigned) const; + [[nodiscard]] QString normalized(NormalizationForm mode, QChar::UnicodeVersion version = QChar::Unicode_Unassigned) const; - Q_REQUIRED_RESULT QString repeated(qsizetype times) const; + [[nodiscard]] QString repeated(qsizetype times) const; const ushort *utf16() const; #if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) && !defined(Q_CLANG_QDOC) - Q_REQUIRED_RESULT QByteArray toLatin1() const & + [[nodiscard]] QByteArray toLatin1() const & { return toLatin1_helper(*this); } - Q_REQUIRED_RESULT QByteArray toLatin1() && + [[nodiscard]] QByteArray toLatin1() && { return toLatin1_helper_inplace(*this); } - Q_REQUIRED_RESULT QByteArray toUtf8() const & + [[nodiscard]] QByteArray toUtf8() const & { return toUtf8_helper(*this); } - Q_REQUIRED_RESULT QByteArray toUtf8() && + [[nodiscard]] QByteArray toUtf8() && { return toUtf8_helper(*this); } - Q_REQUIRED_RESULT QByteArray toLocal8Bit() const & + [[nodiscard]] QByteArray toLocal8Bit() const & { return toLocal8Bit_helper(isNull() ? nullptr : constData(), size()); } - Q_REQUIRED_RESULT QByteArray toLocal8Bit() && + [[nodiscard]] QByteArray toLocal8Bit() && { return toLocal8Bit_helper(isNull() ? nullptr : constData(), size()); } #else - Q_REQUIRED_RESULT QByteArray toLatin1() const; - Q_REQUIRED_RESULT QByteArray toUtf8() const; - Q_REQUIRED_RESULT QByteArray toLocal8Bit() const; + [[nodiscard]] QByteArray toLatin1() const; + [[nodiscard]] QByteArray toUtf8() const; + [[nodiscard]] QByteArray toLocal8Bit() const; #endif - Q_REQUIRED_RESULT QList<uint> toUcs4() const; + [[nodiscard]] QList<uint> toUcs4() const; // note - this are all inline so we can benefit from strlen() compile time optimizations static inline QString fromLatin1(const char *str, qsizetype size = -1) @@ -707,7 +707,7 @@ public: #endif inline qsizetype toWCharArray(wchar_t *array) const; - Q_REQUIRED_RESULT static inline QString fromWCharArray(const wchar_t *string, qsizetype size = -1); + [[nodiscard]] static inline QString fromWCharArray(const wchar_t *string, qsizetype size = -1); QString &setRawData(const QChar *unicode, qsizetype size); QString &setUnicode(const QChar *unicode, qsizetype size); @@ -916,7 +916,7 @@ public: bool isSimpleText() const; bool isRightToLeft() const; - Q_REQUIRED_RESULT bool isValidUtf16() const noexcept + [[nodiscard]] bool isValidUtf16() const noexcept { return QStringView(*this).isValidUtf16(); } QString(qsizetype size, Qt::Initialization); @@ -1512,11 +1512,11 @@ struct QLatin1StringArg : ArgBase { constexpr explicit QLatin1StringArg(QLatin1String v) noexcept : ArgBase{L1}, string{v} {} }; -Q_REQUIRED_RESULT Q_CORE_EXPORT QString argToQString(QStringView pattern, size_t n, const ArgBase **args); -Q_REQUIRED_RESULT Q_CORE_EXPORT QString argToQString(QLatin1String pattern, size_t n, const ArgBase **args); +[[nodiscard]] Q_CORE_EXPORT QString argToQString(QStringView pattern, size_t n, const ArgBase **args); +[[nodiscard]] Q_CORE_EXPORT QString argToQString(QLatin1String pattern, size_t n, const ArgBase **args); template <typename StringView, typename...Args> -Q_REQUIRED_RESULT Q_ALWAYS_INLINE QString argToQStringDispatch(StringView pattern, const Args &...args) +[[nodiscard]] Q_ALWAYS_INLINE QString argToQStringDispatch(StringView pattern, const Args &...args) { const ArgBase *argBases[] = {&args..., /* avoid zero-sized array */ nullptr}; return QtPrivate::argToQString(pattern, sizeof...(Args), argBases); diff --git a/src/corelib/text/qstringalgorithms.h b/src/corelib/text/qstringalgorithms.h index 08cf9b4c0a..5e2eb1912a 100644 --- a/src/corelib/text/qstringalgorithms.h +++ b/src/corelib/text/qstringalgorithms.h @@ -73,59 +73,59 @@ class QChar; namespace QtPrivate { -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const char16_t *str) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION const char16_t *qustrchr(QStringView str, char16_t ch) noexcept; - -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QBasicUtf8StringView<false> rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QBasicUtf8StringView<false> rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QBasicUtf8StringView<false> lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QBasicUtf8StringView<false> lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QBasicUtf8StringView<false> lhs, QBasicUtf8StringView<false> rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; - -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; - -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; - -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QStringView haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QLatin1String haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QLatin1String haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; - -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QStringView haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QLatin1String haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QLatin1String haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; - -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QStringView trimmed(QStringView s) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QLatin1String trimmed(QLatin1String s) noexcept; - -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QStringView haystack, QChar needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; - -Q_REQUIRED_RESULT Q_CORE_EXPORT QString convertToQString(QAnyStringView s); - -Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToLatin1(QStringView str); -Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToUtf8(QStringView str); -Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToLocal8Bit(QStringView str); -Q_REQUIRED_RESULT Q_CORE_EXPORT QList<uint> convertToUcs4(QStringView str); - -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isRightToLeft(QStringView string) noexcept; - -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isAscii(QLatin1String s) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isAscii(QStringView s) noexcept; -Q_REQUIRED_RESULT constexpr inline bool isLatin1(QLatin1String s) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isLatin1(QStringView s) noexcept; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf16(QStringView s) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const char16_t *str) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION const char16_t *qustrchr(QStringView str, char16_t ch) noexcept; + +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QBasicUtf8StringView<false> rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QBasicUtf8StringView<false> rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QBasicUtf8StringView<false> lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QBasicUtf8StringView<false> lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QBasicUtf8StringView<false> lhs, QBasicUtf8StringView<false> rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; + +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; + +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; + +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QStringView haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QLatin1String haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype findString(QLatin1String haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; + +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QStringView haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QStringView haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QLatin1String haystack, qsizetype from, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QLatin1String haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; + +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QStringView trimmed(QStringView s) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QLatin1String trimmed(QLatin1String s) noexcept; + +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QStringView haystack, QChar needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; + +[[nodiscard]] Q_CORE_EXPORT QString convertToQString(QAnyStringView s); + +[[nodiscard]] Q_CORE_EXPORT QByteArray convertToLatin1(QStringView str); +[[nodiscard]] Q_CORE_EXPORT QByteArray convertToUtf8(QStringView str); +[[nodiscard]] Q_CORE_EXPORT QByteArray convertToLocal8Bit(QStringView str); +[[nodiscard]] Q_CORE_EXPORT QList<uint> convertToUcs4(QStringView str); + +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isRightToLeft(QStringView string) noexcept; + +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isAscii(QLatin1String s) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isAscii(QStringView s) noexcept; +[[nodiscard]] constexpr inline bool isLatin1(QLatin1String s) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isLatin1(QStringView s) noexcept; +[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf16(QStringView s) noexcept; } // namespace QtPRivate diff --git a/src/corelib/text/qstringtokenizer.h b/src/corelib/text/qstringtokenizer.h index e0aefe2522..47ee51bfa6 100644 --- a/src/corelib/text/qstringtokenizer.h +++ b/src/corelib/text/qstringtokenizer.h @@ -109,8 +109,8 @@ public: iterator() noexcept = default; // violates std::forward_iterator (returns a reference into the iterator) - Q_REQUIRED_RESULT constexpr const Haystack* operator->() const { return Q_ASSERT(current.ok), ¤t.value; } - Q_REQUIRED_RESULT constexpr const Haystack& operator*() const { return *operator->(); } + [[nodiscard]] constexpr const Haystack* operator->() const { return Q_ASSERT(current.ok), ¤t.value; } + [[nodiscard]] constexpr const Haystack& operator*() const { return *operator->(); } iterator& operator++() { advance(); return *this; } iterator operator++(int) { auto tmp = *this; advance(); return tmp; } @@ -145,12 +145,12 @@ public: using reference = typename iterator::reference; using const_reference = reference; - Q_REQUIRED_RESULT iterator begin() const noexcept { return iterator{*this}; } - Q_REQUIRED_RESULT iterator cbegin() const noexcept { return begin(); } + [[nodiscard]] iterator begin() const noexcept { return iterator{*this}; } + [[nodiscard]] iterator cbegin() const noexcept { return begin(); } template <bool = std::is_same<iterator, sentinel>::value> // ODR protection - Q_REQUIRED_RESULT constexpr sentinel end() const noexcept { return {}; } + [[nodiscard]] constexpr sentinel end() const noexcept { return {}; } template <bool = std::is_same<iterator, sentinel>::value> // ODR protection - Q_REQUIRED_RESULT constexpr sentinel cend() const noexcept { return {}; } + [[nodiscard]] constexpr sentinel cend() const noexcept { return {}; } private: Haystack m_haystack; @@ -395,7 +395,7 @@ QStringTokenizer(Haystack&&, Needle&&, Qt::CaseSensitivity, Qt::SplitBehavior) #undef Q_TOK_RESULT template <typename Haystack, typename Needle, typename...Flags> -Q_REQUIRED_RESULT constexpr auto +[[nodiscard]] constexpr auto qTokenize(Haystack &&h, Needle &&n, Flags...flags) noexcept(QtPrivate::Tok::is_nothrow_constructible_from<Haystack, Needle>::value) -> decltype(QtPrivate::Tok::TokenizerResult<Haystack, Needle>{std::forward<Haystack>(h), 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)}} : |