From c50172e201530bb24dd568d33e7a10daa1d74117 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen <erik.verbruggen@nokia.com> Date: Tue, 29 Dec 2009 18:32:05 +0100 Subject: [PATCH] Changed string-wrapping quickfix to handle @"strings". --- src/plugins/cppeditor/cppquickfix.cpp | 19 +++++++++++++++++-- src/plugins/cppeditor/cppquickfix.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp index 9b84403a56d..ac63a3941e6 100644 --- a/src/plugins/cppeditor/cppquickfix.cpp +++ b/src/plugins/cppeditor/cppquickfix.cpp @@ -759,7 +759,7 @@ class WrapStringLiteral: public QuickFixOperation { public: WrapStringLiteral() - : stringLiteral(0) + : stringLiteral(0), isObjCStringLiteral(false) {} virtual QString description() const @@ -778,6 +778,8 @@ public: if (!stringLiteral) return -1; + isObjCStringLiteral = charAt(startOf(stringLiteral)) == QLatin1Char('@'); + // check if it is already wrapped in QLatin1String or -Literal if (index-2 < 0) return index; @@ -805,12 +807,20 @@ public: virtual void createChangeSet() { - insert(startOf(stringLiteral), "QLatin1String("); + const int startPos = startOf(stringLiteral); + const QLatin1String replacement("QLatin1String("); + + if (isObjCStringLiteral) + replace(startPos, startPos + 1, replacement); + else + insert(startPos, replacement); + insert(endOf(stringLiteral), ")"); } private: StringLiteralAST *stringLiteral; + bool isObjCStringLiteral; }; } // end of anonymous namespace @@ -1040,6 +1050,11 @@ QString QuickFixOperation::textOf(const AST *ast) const return textOf(startOf(ast), endOf(ast)); } +QChar QuickFixOperation::charAt(int offset) const +{ + return textOf(offset, offset + 1).at(0); +} + void QuickFixOperation::apply() { Range range; diff --git a/src/plugins/cppeditor/cppquickfix.h b/src/plugins/cppeditor/cppquickfix.h index e7f2b1a8962..77fcb20cfbf 100644 --- a/src/plugins/cppeditor/cppquickfix.h +++ b/src/plugins/cppeditor/cppquickfix.h @@ -116,6 +116,7 @@ protected: QString textOf(int firstOffset, int lastOffset) const; QString textOf(const CPlusPlus::AST *ast) const; + QChar charAt(int offset) const; struct Range { Range() {} -- GitLab