aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/cplusplus
diff options
context:
space:
mode:
authorDavid Schulz <[email protected]>2016-04-27 13:47:16 +0200
committerDavid Schulz <[email protected]>2016-05-25 13:56:05 +0000
commit509c977f30bbd0e517c667784db3ed8359a5a883 (patch)
treec71dc9070bf3f78a00cf010ba2b10462fa7e0a73 /src/libs/cplusplus
parent7595aaa227305950c5ce03c7a636a340671400ce (diff)
C++: Improve automatic quoting magic.
Change-Id: I5d3a15dc100ae9c03bbc49de99714da1c89cb0d8 Reviewed-by: Nikolai Kosjar <[email protected]>
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r--src/libs/cplusplus/MatchingText.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/libs/cplusplus/MatchingText.cpp b/src/libs/cplusplus/MatchingText.cpp
index 1d88f8e8bff..3ae71bea181 100644
--- a/src/libs/cplusplus/MatchingText.cpp
+++ b/src/libs/cplusplus/MatchingText.cpp
@@ -102,9 +102,22 @@ static bool insertQuote(const QChar ch, const BackwardsScanner &tk)
const int index = tk.startToken() - 1;
const Token &token = tk[index];
- // Do not insert a matching quote when we are closing an open string/char literal.
- return (ch == '"' && token.isStringLiteral() == isCompleteStringLiteral(tk, index))
- || (ch == '\'' && token.isCharLiteral() == isCompleteCharLiteral(tk, index));
+
+ // Insert an additional double quote after string literal only if previous literal was closed.
+ if (ch == '"' && token.isStringLiteral() && isCompleteStringLiteral(tk, index))
+ return true;
+
+ // Insert a matching quote after an operator.
+ if (token.isOperator())
+ return true;
+
+ if (token.isKeyword())
+ return tk.text(index) == "operator";
+
+ // Insert matching quote after identifier when identifier is a known literal prefixes
+ static const QStringList stringLiteralPrefixes = { "L", "U", "u", "u8", "R"};
+ return token.kind() == CPlusPlus::T_IDENTIFIER
+ && stringLiteralPrefixes.contains(tk.text(index));
}
static int countSkippedChars(const QString blockText, const QString &textToProcess)