From c9c598d4d76b703f84ace9d2d06b099e8bcf2b07 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 13 Aug 2020 13:17:07 +0200 Subject: Mark places where we missed conversion to unicode character types We should use char32_t for the toUcs4() methods of QString and QStringView and use char16_t for QString::utf16(), thereby matching QStringView. These naturally imply knock-on changes in various places. Unfortunately, we didn't make those changes in Qt 6, so they'll have to wait for Qt 7. Change-Id: I18451d4b31b76658092e19d3fcbc8bc0fe5ce307 Reviewed-by: Lars Knoll --- src/corelib/text/qstring.h | 8 ++++---- src/corelib/text/qstringalgorithms.h | 2 +- src/corelib/text/qstringview.h | 2 +- src/corelib/tools/qlist.h | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 20a9b46e4c..86f6d829d4 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -708,7 +708,7 @@ public: [[nodiscard]] QString repeated(qsizetype times) const; - const ushort *utf16() const; + const ushort *utf16() const; // ### Qt 7 char16_t #if !defined(Q_CLANG_QDOC) [[nodiscard]] QByteArray toLatin1() const & @@ -728,7 +728,7 @@ public: [[nodiscard]] QByteArray toUtf8() const; [[nodiscard]] QByteArray toLocal8Bit() const; #endif - [[nodiscard]] QList toUcs4() const; + [[nodiscard]] QList toUcs4() const; // ### Qt 7 char32_t // note - this are all inline so we can benefit from strlen() compile time optimizations static QString fromLatin1(QByteArrayView ba); @@ -775,7 +775,7 @@ public: QString &setRawData(const QChar *unicode, qsizetype size); QString &setUnicode(const QChar *unicode, qsizetype size); - inline QString &setUtf16(const ushort *utf16, qsizetype size); + inline QString &setUtf16(const ushort *utf16, qsizetype size); // ### Qt 7 char16_t #if QT_STRINGVIEW_LEVEL < 2 int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; @@ -1089,7 +1089,7 @@ private: static QByteArray toLatin1_helper_inplace(QString &); static QByteArray toUtf8_helper(const QString &); static QByteArray toLocal8Bit_helper(const QChar *data, qsizetype size); - static qsizetype toUcs4_helper(const ushort *uc, qsizetype length, uint *out); + static qsizetype toUcs4_helper(const ushort *uc, qsizetype length, uint *out); // ### Qt 7 char16_t static qlonglong toIntegral_helper(QStringView string, bool *ok, int base); static qulonglong toIntegral_helper(QStringView string, bool *ok, uint base); void replace_helper(size_t *indices, qsizetype nIndices, qsizetype blen, const QChar *after, qsizetype alen); diff --git a/src/corelib/text/qstringalgorithms.h b/src/corelib/text/qstringalgorithms.h index 870ae42af8..5805e4c439 100644 --- a/src/corelib/text/qstringalgorithms.h +++ b/src/corelib/text/qstringalgorithms.h @@ -144,7 +144,7 @@ namespace QtPrivate { [[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 convertToUcs4(QStringView str); +[[nodiscard]] Q_CORE_EXPORT QList convertToUcs4(QStringView str); // ### Qt 7 char32_t [[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isRightToLeft(QStringView string) noexcept; diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index fef2ffde7b..c0082b70b5 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -254,7 +254,7 @@ public: [[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 toUcs4() const; // defined in qlist.h + [[nodiscard]] inline QList toUcs4() const; // defined in qlist.h ### Qt 7 char32_t [[nodiscard]] constexpr QChar at(qsizetype n) const noexcept { return (*this)[n]; } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 1649310a1d..662fede6f7 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -933,6 +933,7 @@ qsizetype erase_if(QList &list, Predicate pred) return QtPrivate::sequential_erase_if(list, pred); } +// ### Qt 7 char32_t QList QStringView::toUcs4() const { return QtPrivate::convertToUcs4(*this); } QT_END_NAMESPACE -- cgit v1.2.3