diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2023-03-30 11:17:52 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2023-04-01 09:34:46 +0200 |
commit | d5007c7a556a94df6ea76a368804dac729aab83a (patch) | |
tree | face9cb632063e1e0a5d7bcf4f2e4ce2ad6cbc40 /src/linguist | |
parent | 811b7c2f7eaac22e64cbb92508b67ccad5eed07c (diff) | |
download | qttools-d5007c7a556a94df6ea76a368804dac729aab83a.tar.gz |
lupdate: Handle C++ string literals
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 <kai.koehne@qt.io>
Diffstat (limited to 'src/linguist')
-rw-r--r-- | src/linguist/lupdate/cpp.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp index 7779bd99e..bf1d358b6 100644 --- a/src/linguist/lupdate/cpp.cpp +++ b/src/linguist/lupdate/cpp.cpp @@ -335,6 +335,14 @@ CppParser::TokenType CppParser::lookAheadToSemicolonOrLeftBrace() } } +static bool isStringLiteralPrefix(const QStringView s) +{ + return s == u"L"_s + || s == u"U"_s + || s == u"u"_s + || s == u"u8"_s; +} + static const QString strQ_OBJECT = u"Q_OBJECT"_s; static const QString strclass = u"class"_s; static const QString strenum = u"enum"_s; @@ -564,6 +572,11 @@ CppParser::TokenType CppParser::getToken() //qDebug() << "IDENT: " << yyWord; + if (yyCh == '"' && isStringLiteralPrefix(yyWord)) { + // Handle prefixed string literals as ordinary string literals. + continue; + } + switch (yyWord.unicode()[0].unicode()) { case 'N': if (yyWord == strNULL) |