diff options
Diffstat (limited to 'src/corelib/tools/qstring.h')
-rw-r--r-- | src/corelib/tools/qstring.h | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index b50b2ee4e5..e06927d434 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -144,15 +144,10 @@ typedef QLatin1String QLatin1Literal; typedef QTypedArrayData<ushort> QStringData; -#if defined(Q_COMPILER_UNICODE_STRINGS) - -#define QT_UNICODE_LITERAL_II(str) u"" str -typedef char16_t qunicodechar; - -#elif defined(Q_OS_WIN) \ - || (defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 2) \ - || (!defined(__SIZEOF_WCHAR_T__) && defined(WCHAR_MAX) && (WCHAR_MAX - 0 < 65536)) -// wchar_t is 2 bytes +#if defined(Q_OS_WIN) && !defined(Q_COMPILER_UNICODE_STRINGS) +// fall back to wchar_t if the a Windows compiler does not +// support Unicode string literals, assuming wchar_t is 2 bytes +// on that platform (sanity-checked by static_assert further below) #if defined(Q_CC_MSVC) # define QT_UNICODE_LITERAL_II(str) L##str @@ -162,21 +157,22 @@ typedef char16_t qunicodechar; typedef wchar_t qunicodechar; #else +// all our supported compilers support Unicode string literals, +// even if their Q_COMPILER_UNICODE_STRING has been revoked due +// to lacking stdlib support. But QStringLiteral only needs the +// core language feature, so just use u"" here unconditionally: -#define QT_NO_UNICODE_LITERAL -typedef ushort qunicodechar; +#define QT_UNICODE_LITERAL_II(str) u"" str +typedef char16_t qunicodechar; #endif Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, "qunicodechar must typedef an integral type of size 2"); -#ifndef QT_NO_UNICODE_LITERAL -# define QT_UNICODE_LITERAL(str) QT_UNICODE_LITERAL_II(str) -# if defined(Q_COMPILER_LAMBDA) - -# define QStringLiteral(str) \ - ([]() -> QString { \ +#define QT_UNICODE_LITERAL(str) QT_UNICODE_LITERAL_II(str) +#define QStringLiteral(str) \ + ([]() Q_DECL_NOEXCEPT -> QString { \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QStaticStringData<Size> qstring_literal = { \ Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \ @@ -187,17 +183,6 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, }()) \ /**/ -# endif -#endif // QT_NO_UNICODE_LITERAL - -#ifndef QStringLiteral -// no lambdas, not GCC, or GCC in C++98 mode with 4-byte wchar_t -// fallback, return a temporary QString -// source code is assumed to be encoded in UTF-8 - -# define QStringLiteral(str) QString::fromUtf8("" str "", sizeof(str) - 1) -#endif - #define Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \ { Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, offset } \ /**/ @@ -397,7 +382,7 @@ 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_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) && !defined(Q_CLANG_QDOC) # if defined(Q_CC_GNU) // required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941 # pragma push_macro("Q_REQUIRED_RESULT") @@ -522,7 +507,7 @@ public: const ushort *utf16() const; -#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) +#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) && !defined(Q_CLANG_QDOC) QByteArray toLatin1() const & Q_REQUIRED_RESULT { return toLatin1_helper(*this); } QByteArray toLatin1() && Q_REQUIRED_RESULT @@ -532,9 +517,9 @@ public: QByteArray toUtf8() && Q_REQUIRED_RESULT { return toUtf8_helper(*this); } QByteArray toLocal8Bit() const & Q_REQUIRED_RESULT - { return toLocal8Bit_helper(constData(), size()); } + { return toLocal8Bit_helper(isNull() ? nullptr : constData(), size()); } QByteArray toLocal8Bit() && Q_REQUIRED_RESULT - { return toLocal8Bit_helper(constData(), size()); } + { return toLocal8Bit_helper(isNull() ? nullptr : constData(), size()); } #else QByteArray toLatin1() const Q_REQUIRED_RESULT; QByteArray toUtf8() const Q_REQUIRED_RESULT; @@ -1400,7 +1385,8 @@ public: QStringRef(QStringRef &&other) Q_DECL_NOTHROW : m_string(other.m_string), m_position(other.m_position), m_size(other.m_size) {} QStringRef &operator=(QStringRef &&other) Q_DECL_NOTHROW { return *this = other; } #endif - QStringRef &operator=(const QStringRef &other) Q_DECL_NOTHROW { + QStringRef &operator=(const QStringRef &other) Q_DECL_NOTHROW + { m_string = other.m_string; m_position = other.m_position; m_size = other.m_size; return *this; } @@ -1449,6 +1435,8 @@ public: m_size -= n; } + bool isRightToLeft() const; + bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -1461,7 +1449,8 @@ public: inline QStringRef &operator=(const QString *string); - inline const QChar *unicode() const { + inline const QChar *unicode() const + { if (!m_string) return reinterpret_cast<const QChar *>(QString::Data::sharedNull()->data()); return m_string->unicode() + m_position; @@ -1471,8 +1460,10 @@ public: inline const_iterator begin() const { return unicode(); } inline const_iterator cbegin() const { return unicode(); } + inline const_iterator constBegin() const { return unicode(); } inline const_iterator end() const { return unicode() + size(); } inline const_iterator cend() const { return unicode() + size(); } + inline const_iterator constEnd() const { return unicode() + size(); } inline const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } inline const_reverse_iterator crbegin() const { return rbegin(); } inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } |