From d5007c7a556a94df6ea76a368804dac729aab83a Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 30 Mar 2023 11:17:52 +0200 Subject: lupdate: Handle C++ string literals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fix for QTBUG-73273 already added code to allow prefixed raw string literals. Now, lupdate supports regular prefixed string literals as well. If the parser encounters a prefixed string literal, ignore the prefix and handle the rest as ordinary string literal. Note that expressions like tr(U"foo") won't compile out of the box. We support them nevertheless. The user might provide their own tr macro that handles such string literals. [ChangeLog][lupdate] lupdate now supports prefixed string literals like u"foo". Pick-to: 6.5 Fixes: QTBUG-59802 Change-Id: Ibe8b4b83ee1197a73678b1e8f37dd6ac7db57714 Reviewed-by: Kai Köhne --- .../lupdate/testdata/good/parsecpp2/main.cpp | 19 ++++++++++ .../testdata/good/parsecpp2/project.ts.result | 43 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) (limited to 'tests') diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp index a4188c4d3..7abc1ac0a 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp @@ -147,3 +147,22 @@ struct IntLiteralsWithSeparators { int x = 0x1'AF'FE; int X = 0X2'E5E7; }; + + +// QTBUG-59802: prefixed string literals +class PrefixedStringLiterals : public QObject { + Q_OBJECT + void foo() + { + #if 0 + tr(u8"UTF-8 string literal"); + tr(u8R"(UTF-8 raw string literal)"); + tr(u"UTF-16 string literal"); + tr(uR"(UTF-16 raw string literal)"); + tr(U"UTF-32 string literal"); + tr(UR"(UTF-32 raw string literal)"); + tr(L"wide string literal"); + tr(LR"(wide raw string literal)"); + #endif + } +}; diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp2/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp2/project.ts.result index 0710915de..63885debf 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp2/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp2/project.ts.result @@ -17,6 +17,49 @@ + + PrefixedStringLiterals + + + UTF-8 string literal + + + + + UTF-8 raw string literal + + + + + UTF-16 string literal + + + + + UTF-16 raw string literal + + + + + UTF-32 string literal + + + + + UTF-32 raw string literal + + + + + wide string literal + + + + + wide raw string literal + + + QObject -- cgit v1.2.1