diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2024-02-05 15:40:06 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2024-02-07 14:21:56 +0000 |
commit | 91e72756fb4d4d72a7f3f6af80d72da5a662cf64 (patch) | |
tree | bf30a910af6527386dc1f1f51fa91b0927948eb6 /src/plugins/cppeditor/cppquickfixes.cpp | |
parent | 5ae401b92335a1f81e11e6e1246298602e2b383b (diff) |
CppEditor: Support wrapping strings in QByteArrayLiteral()
Fixes: QTCREATORBUG-12995
Change-Id: I9c0136b93fcfde0d2326bbd2bd6dbd5e75ae97a8
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cppquickfixes.cpp')
-rw-r--r-- | src/plugins/cppeditor/cppquickfixes.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 74862772e5..3465066c7f 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -141,7 +141,8 @@ enum DefPos { inline bool isQtStringLiteral(const QByteArray &id) { - return id == "QLatin1String" || id == "QLatin1Literal" || id == "QStringLiteral"; + return id == "QLatin1String" || id == "QLatin1Literal" || id == "QStringLiteral" + || id == "QByteArrayLiteral"; } inline bool isQtStringTranslation(const QByteArray &id) @@ -1110,21 +1111,20 @@ enum ActionFlags { EncloseInQLatin1CharAction = 0x1, EncloseInQLatin1StringAction = 0x2, EncloseInQStringLiteralAction = 0x4, - EncloseActionMask = EncloseInQLatin1CharAction - | EncloseInQLatin1StringAction | EncloseInQStringLiteralAction, - TranslateTrAction = 0x8, - TranslateQCoreApplicationAction = 0x10, - TranslateNoopAction = 0x20, - TranslationMask = TranslateTrAction - | TranslateQCoreApplicationAction | TranslateNoopAction, - RemoveObjectiveCAction = 0x40, - ConvertEscapeSequencesToCharAction = 0x100, - ConvertEscapeSequencesToStringAction = 0x200, - SingleQuoteAction = 0x400, - DoubleQuoteAction = 0x800 + EncloseInQByteArrayLiteralAction = 0x8, + EncloseActionMask = EncloseInQLatin1CharAction | EncloseInQLatin1StringAction + | EncloseInQStringLiteralAction | EncloseInQByteArrayLiteralAction, + TranslateTrAction = 0x10, + TranslateQCoreApplicationAction = 0x20, + TranslateNoopAction = 0x40, + TranslationMask = TranslateTrAction | TranslateQCoreApplicationAction | TranslateNoopAction, + RemoveObjectiveCAction = 0x100, + ConvertEscapeSequencesToCharAction = 0x200, + ConvertEscapeSequencesToStringAction = 0x400, + SingleQuoteAction = 0x800, + DoubleQuoteAction = 0x1000 }; - /* Convert single-character string literals into character literals with some * special cases "a" --> 'a', "'" --> '\'', "\n" --> '\n', "\"" --> '"'. */ static QByteArray stringToCharEscapeSequences(const QByteArray &content) @@ -1160,6 +1160,8 @@ static QString stringLiteralReplacement(unsigned actions) return QLatin1String("QLatin1String"); if (actions & EncloseInQStringLiteralAction) return QLatin1String("QStringLiteral"); + if (actions & EncloseInQByteArrayLiteralAction) + return QLatin1String("QByteArrayLiteral"); if (actions & TranslateTrAction) return QLatin1String("tr"); if (actions & TranslateQCoreApplicationAction) @@ -1350,6 +1352,9 @@ void WrapStringLiteral::doMatch(const CppQuickFixInterface &interface, QuickFixO actions = EncloseInQStringLiteralAction | objectiveCActions; result << new WrapStringLiteralOp(interface, priority, actions, msgQtStringLiteralDescription(stringLiteralReplacement(actions)), literal); + actions = EncloseInQByteArrayLiteralAction | objectiveCActions; + result << new WrapStringLiteralOp(interface, priority, actions, + msgQtStringLiteralDescription(stringLiteralReplacement(actions)), literal); } } |