diff options
Diffstat (limited to 'src/corelib/tools/qstring.h')
-rw-r--r-- | src/corelib/tools/qstring.h | 88 |
1 files changed, 70 insertions, 18 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index a12946e23c..4d51521b12 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -34,6 +34,10 @@ #ifndef QSTRING_H #define QSTRING_H +#if defined(QT_NO_CAST_FROM_ASCII) && defined(QT_RESTRICTED_CAST_FROM_ASCII) +#error QT_NO_CAST_FROM_ASCII and QT_RESTRICTED_CAST_FROM_ASCII must not be defined at the same time +#endif + #include <QtCore/qchar.h> #include <QtCore/qbytearray.h> #include <QtCore/qrefcount.h> @@ -93,7 +97,7 @@ public: inline bool operator>=(const QString &s) const; inline bool operator<=(const QString &s) const; -#ifndef QT_NO_CAST_FROM_ASCII +#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) inline QT_ASCII_CAST_WARN bool operator==(const char *s) const; inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const; inline QT_ASCII_CAST_WARN bool operator<(const char *s) const; @@ -107,7 +111,7 @@ public: inline QT_ASCII_CAST_WARN bool operator>(const QByteArray &s) const; inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &s) const; inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &s) const; -#endif // QT_NO_CAST_FROM_ASCII +#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) private: int m_size; @@ -327,7 +331,9 @@ public: #ifndef QT_NO_REGULAREXPRESSION int indexOf(const QRegularExpression &re, int from = 0) const; + int indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const; // ### Qt 6: merge overloads int lastIndexOf(const QRegularExpression &re, int from = -1) const; + int lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const; // ### Qt 6: merge overloads bool contains(const QRegularExpression &re) const; bool contains(const QRegularExpression &re, QRegularExpressionMatch *match) const; // ### Qt 6: merge overloads int count(const QRegularExpression &re) const; @@ -369,12 +375,44 @@ public: QString leftJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT; QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT; +#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) +# if defined(Q_CC_GNU) + // required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941 +# pragma push_macro("Q_REQUIRED_RESULT") +# undef Q_REQUIRED_RESULT +# define Q_REQUIRED_RESULT +# define Q_REQUIRED_RESULT_pushed +# endif + QString toLower() const & Q_REQUIRED_RESULT + { return toLower_helper(*this); } + QString toLower() && Q_REQUIRED_RESULT + { return toLower_helper(*this); } + QString toUpper() const & Q_REQUIRED_RESULT + { return toUpper_helper(*this); } + QString toUpper() && Q_REQUIRED_RESULT + { return toUpper_helper(*this); } + QString toCaseFolded() const & Q_REQUIRED_RESULT + { return toCaseFolded_helper(*this); } + QString toCaseFolded() && Q_REQUIRED_RESULT + { return toCaseFolded_helper(*this); } + QString trimmed() const & Q_REQUIRED_RESULT + { return trimmed_helper(*this); } + QString trimmed() && Q_REQUIRED_RESULT + { return trimmed_helper(*this); } + QString simplified() const & Q_REQUIRED_RESULT + { return simplified_helper(*this); } + QString simplified() && Q_REQUIRED_RESULT + { return simplified_helper(*this); } +# ifdef Q_REQUIRED_RESULT_pushed +# pragma pop_macro("Q_REQUIRED_RESULT") +# endif +#else 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 Q_REQUIRED_RESULT; +#endif QString toHtmlEscaped() const Q_REQUIRED_RESULT; QString &insert(int i, QChar c); @@ -596,7 +634,16 @@ public: inline bool operator>=(QLatin1String s) const { return !operator<(s); } // ASCII compatibility -#ifndef QT_NO_CAST_FROM_ASCII +#if defined(QT_RESTRICTED_CAST_FROM_ASCII) + template <int N> + inline QString(const char (&ch)[N]) + : d(fromAscii_helper(ch, N - 1)) + {} + template <int N> + inline QString &operator=(const char (&ch)[N]) + { return (*this = fromLatin1(ch, N - 1)); } +#endif +#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) inline QT_ASCII_CAST_WARN QString(const char *ch) : d(fromAscii_helper(ch, ch ? int(strlen(ch)) : -1)) {} @@ -734,6 +781,16 @@ private: Qt::CaseSensitivity cs = Qt::CaseSensitive); static int localeAwareCompare_helper(const QChar *data1, int length1, const QChar *data2, int length2); + static QString toLower_helper(const QString &str); + static QString toLower_helper(QString &str); + static QString toUpper_helper(const QString &str); + static QString toUpper_helper(QString &str); + static QString toCaseFolded_helper(const QString &str); + static QString toCaseFolded_helper(QString &str); + static QString trimmed_helper(const QString &str); + static QString trimmed_helper(QString &str); + static QString simplified_helper(const QString &str); + static QString simplified_helper(QString &str); static Data *fromLatin1_helper(const char *str, int size = -1); static Data *fromAscii_helper(const char *str, int size = -1); static QString fromUtf8_helper(const char *str, int size); @@ -867,11 +924,8 @@ inline QString QString::arg(const QString &a1, const QString &a2, const QString inline QString QString::section(QChar asep, int astart, int aend, SectionFlags aflags) const { return section(QString(asep), astart, aend, aflags); } -#ifdef Q_CC_MSVC -// "conditional expression is constant" -#pragma warning(push) -#pragma warning(disable : 4127) -#endif +QT_WARNING_PUSH +QT_WARNING_DISABLE_MSVC(4127) // "conditional expression is constant" inline int QString::toWCharArray(wchar_t *array) const { @@ -882,9 +936,7 @@ inline int QString::toWCharArray(wchar_t *array) const return toUcs4_helper(d->data(), size(), reinterpret_cast<uint *>(array)); } -#ifdef Q_CC_MSVC -#pragma warning(pop) -#endif +QT_WARNING_POP inline QString QString::fromWCharArray(const wchar_t *string, int size) { @@ -1083,7 +1135,7 @@ inline bool QLatin1String::operator>=(const QString &s) const inline bool QLatin1String::operator<=(const QString &s) const { return s >= *this; } -#ifndef QT_NO_CAST_FROM_ASCII +#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) inline bool QString::operator==(const char *s) const { return QString::compare_helper(constData(), size(), s, -1) == 0; } inline bool QString::operator!=(const char *s) const @@ -1174,7 +1226,7 @@ inline bool QByteArray::operator<=(const QString &s) const { return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) <= 0; } inline bool QByteArray::operator>=(const QString &s) const { return QString::compare_helper(s.constData(), s.size(), constData(), qstrnlen(constData(), size())) >= 0; } -#endif // QT_NO_CAST_FROM_ASCII +#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) #ifndef QT_NO_CAST_TO_ASCII inline QByteArray &QByteArray::append(const QString &s) @@ -1202,7 +1254,7 @@ inline const QString operator+(const QString &s1, QChar s2) { QString t(s1); t += s2; return t; } inline const QString operator+(QChar s1, const QString &s2) { QString t(s1); t += s2; return t; } -# ifndef QT_NO_CAST_FROM_ASCII +# if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) inline QT_ASCII_CAST_WARN const QString operator+(const QString &s1, const char *s2) { QString t(s1); t += QString::fromUtf8(s2); return t; } inline QT_ASCII_CAST_WARN const QString operator+(const char *s1, const QString &s2) @@ -1355,7 +1407,7 @@ public: inline const QChar at(int i) const { Q_ASSERT(uint(i) < uint(size())); return m_string->at(i + m_position); } -#ifndef QT_NO_CAST_FROM_ASCII +#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) // ASCII compatibility inline QT_ASCII_CAST_WARN bool operator==(const char *s) const; inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const; @@ -1429,7 +1481,7 @@ inline bool operator<=(const QStringRef &s1, const QStringRef &s2) inline bool operator>=(const QStringRef &s1, const QStringRef &s2) { return !(s1 < s2); } -#ifndef QT_NO_CAST_FROM_ASCII +#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) inline QT_ASCII_CAST_WARN bool QStringRef::operator==(const char *s) const { return QString::compare_helper(constData(), size(), s, -1) == 0; } inline QT_ASCII_CAST_WARN bool QStringRef::operator!=(const char *s) const @@ -1455,7 +1507,7 @@ inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QStringRef &s2) { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; } inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2) { return QString::compare_helper(s2.constData(), s2.size(), s1, -1) >= 0; } -#endif // QT_NO_CAST_FROM_ASCII +#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); } |