From b62bff2ef3a6c846462e5381664651f49944261a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 10 May 2020 16:23:42 +0200 Subject: [PATCH] Use QChar::fromUcs4() more Change-Id: I02be41de92d84145186de9ac5f5ea3541a941964 Reviewed-by: Konstantin Ritt Reviewed-by: Lars Knoll --- src/gui/text/qharfbuzzng.cpp | 5 ++++- src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp | 3 +-- tests/auto/corelib/codecs/utf8/utf8data.cpp | 4 ++-- .../corelib/text/qstringiterator/tst_qstringiterator.cpp | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/gui/text/qharfbuzzng.cpp b/src/gui/text/qharfbuzzng.cpp index 0ee44192b1..a93f648bc9 100644 --- a/src/gui/text/qharfbuzzng.cpp +++ b/src/gui/text/qharfbuzzng.cpp @@ -333,7 +333,10 @@ _hb_qt_unicode_compose(hb_unicode_funcs_t * /*ufuncs*/, void * /*user_data*/) { // ### optimize - QString s = QString::fromUcs4(&a, 1) + QString::fromUcs4(&b, 1); + QString s; + s.reserve(4); + s += QChar::fromUcs4(a); + s += QChar::fromUcs4(b); QString normalized = s.normalized(QString::NormalizationForm_C); QStringIterator it(normalized); diff --git a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp index e3a6aea99f..f46a1d556a 100644 --- a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp +++ b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp @@ -76,8 +76,7 @@ static QString keyString(int sym, QChar::Category category) } else if (category == QChar::Other_PrivateUse) { return keyStringForPrivateUseQnxKey(sym); } else { - uint ucs4_sym = sym; - return QString::fromUcs4(&ucs4_sym, 1); + return QStringView{QChar::fromUcs4(sym)}.toString(); } } diff --git a/tests/auto/corelib/codecs/utf8/utf8data.cpp b/tests/auto/corelib/codecs/utf8/utf8data.cpp index 221e1d5579..ef02761a0e 100644 --- a/tests/auto/corelib/codecs/utf8/utf8data.cpp +++ b/tests/auto/corelib/codecs/utf8/utf8data.cpp @@ -149,9 +149,9 @@ void loadNonCharactersRows() char(0x80 | (uchar(ucs4 >> 6) & 0x3f)), char(0x80 | (uchar(ucs4) & 0x3f)), 0 }; - ushort utf16[] = { QChar::highSurrogate(ucs4), QChar::lowSurrogate(ucs4), 0 }; + const auto utf16 = QChar::fromUcs4(ucs4); - QTest::newRow(qPrintable(QString::number(ucs4, 16))) << QByteArray(utf8) << QString::fromUtf16(utf16); + QTest::newRow(qPrintable(QString::number(ucs4, 16))) << QByteArray(utf8) << QStringView{utf16}.toString(); } } diff --git a/tests/auto/corelib/text/qstringiterator/tst_qstringiterator.cpp b/tests/auto/corelib/text/qstringiterator/tst_qstringiterator.cpp index 7d5504c22c..922063e779 100644 --- a/tests/auto/corelib/text/qstringiterator/tst_qstringiterator.cpp +++ b/tests/auto/corelib/text/qstringiterator/tst_qstringiterator.cpp @@ -203,7 +203,7 @@ void tst_QStringIterator::sweep() if (codePoint == ~0u) rebuiltString += *(i.position() - 1); else - rebuiltString += QString::fromUcs4(&codePoint, 1); + rebuiltString += QChar::fromUcs4(codePoint); ++count; } @@ -244,7 +244,7 @@ void tst_QStringIterator::sweep() QVERIFY(peekedCodePoint == codePoint); QVERIFY(codePoint <= 0x10FFFFu); - rebuiltString += QString::fromUcs4(&codePoint, 1); + rebuiltString += QChar::fromUcs4(codePoint); ++count; }