diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-10-31 17:27:15 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-11-02 17:21:28 +0100 |
commit | 8acec4dbe6f9faac2c48a8be67f73e0d2ec1185b (patch) | |
tree | e38fbf542db6b56993fb8017cef34d123f3ac133 /tests | |
parent | 3834fee3d33fde303c0a1535c1ef0439aa05c6b0 (diff) |
Long live QUtf8::convertFromLatin1()!
With the introduction of QAnyStringView, overloading based on UTF-8
and Latin-1 is becoming more common. Often, the two overloads can
share the processing backend, because we're only interested in the
US-ASCII subset of each.
But if they can't, we need a faster way to convert L1 into UTF-8 than
going via UTF-16. This is where the new private API comes in.
Eventually, we should have the converse operation, too, to complete
the set of direct conversions between the possible three
QAnyStringView encodings L1/U8/U16, but this direction is easier to
code (there are no error cases) and more immediately useful, so
provide L1->U8 alone for now.
Change-Id: I3f7e1a9c89979d0eb604cb9e42dedf3d514fca2c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp index a346615e39..a60478d542 100644 --- a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp +++ b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp @@ -6,9 +6,11 @@ #include <QtCore/private/qglobal_p.h> #include <qstringconverter.h> +#include <private/qstringconverter_p.h> #include <qthreadpool.h> #include <array> +#include <numeric> using namespace Qt::StringLiterals; @@ -130,6 +132,8 @@ private slots: void roundtrip_data(); void roundtrip(); + void convertL1U8(); + #if QT_CONFIG(icu) void roundtripIcu_data(); void roundtripIcu(); @@ -427,6 +431,18 @@ void tst_QStringConverter::roundtrip() QCOMPARE(decoded, uniString); } +void tst_QStringConverter::convertL1U8() +{ + { + std::array<char, 256> latin1; + std::iota(latin1.data(), latin1.data() + latin1.size(), uchar(0)); + std::array<char, 512> utf8; + auto out = QUtf8::convertFromLatin1(utf8.data(), QLatin1StringView{latin1.data(), latin1.size()}); + QCOMPARE(QString::fromLatin1(latin1.data(), latin1.size()), + QString::fromUtf8(utf8.data(), out - utf8.data())); + } +} + #if QT_CONFIG(icu) void tst_QStringConverter::roundtripIcu_data() |