summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qstring
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-11-12 09:59:37 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-11-21 14:25:55 +0000
commit1005b7a0dec049f200baa8c14066bd3bb1512d2f (patch)
treef5be4c477b58f8ebaf16ccc80ec4da5d942118e5 /tests/auto/corelib/tools/qstring
parent226ce6020ee4eb0ccec744500c350cf54a39f231 (diff)
Long live qUtf16Printable()
QString::asprintf() has the ability to take a ushort* array as obtained from QString::utf16() and insert that into the output with an %ls conversion. But no-one ever used this, because just passing QString::utf16() to QString::asprintf() creates a warning about wchar_t* expected, but ushort* provided. The new qUtf16Printable() macro adds the necessary casts (via void* to prevent any "type-punned pointer" warnings) to make passing QString::utf16() to QString::asprintf() work silently. This should greatly reduce the need to do a round-trip via utf-8 just to print the contents of a QString. [ChangeLog][QtCore] Added qUtf16Printable(). Change-Id: I7ddd8d2b2a2191c9faa26aca95d49850d94b287c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools/qstring')
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 9cc552390e..9556dfbd51 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -1279,21 +1279,21 @@ void tst_QString::sprintfS()
QCOMPARE(a, QString("foobarwhiz"));
{ // %ls
- QCOMPARE(a.sprintf("%.3ls", QString("Hello").utf16() ), QLatin1String("Hel"));
- QCOMPARE(a.sprintf("%10.3ls", QString("Hello").utf16() ), QLatin1String(" Hel"));
- QCOMPARE(a.sprintf("%.10ls", QString("Hello").utf16() ), QLatin1String("Hello"));
- QCOMPARE(a.sprintf("%10.10ls", QString("Hello").utf16() ), QLatin1String(" Hello"));
- QCOMPARE(a.sprintf("%-10.10ls", QString("Hello").utf16() ), QLatin1String("Hello "));
- QCOMPARE(a.sprintf("%-10.3ls", QString("Hello").utf16() ), QLatin1String("Hel "));
- QCOMPARE(a.sprintf("%-5.5ls", QString("Hello").utf16() ), QLatin1String("Hello"));
+ QCOMPARE(a.sprintf("%.3ls", qUtf16Printable("Hello")), QLatin1String("Hel"));
+ QCOMPARE(a.sprintf("%10.3ls", qUtf16Printable("Hello")), QLatin1String(" Hel"));
+ QCOMPARE(a.sprintf("%.10ls", qUtf16Printable("Hello")), QLatin1String("Hello"));
+ QCOMPARE(a.sprintf("%10.10ls", qUtf16Printable("Hello")), QLatin1String(" Hello"));
+ QCOMPARE(a.sprintf("%-10.10ls", qUtf16Printable("Hello")), QLatin1String("Hello "));
+ QCOMPARE(a.sprintf("%-10.3ls", qUtf16Printable("Hello")), QLatin1String("Hel "));
+ QCOMPARE(a.sprintf("%-5.5ls", qUtf16Printable("Hello")), QLatin1String("Hello"));
// Check utf16 is preserved for %ls
QCOMPARE(a.sprintf("%ls",
- QString::fromUtf8("\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205").utf16()),
+ qUtf16Printable("\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205")),
QLatin1String("\366\344\374\326\304\334\370\346\345\330\306\305"));
int n;
- a.sprintf("%ls%n%s", QString("hello").utf16(), &n, "goodbye");
+ a.sprintf("%ls%n%s", qUtf16Printable("hello"), &n, "goodbye");
QCOMPARE(n, 5);
QCOMPARE(a, QLatin1String("hellogoodbye"));
}