forked from qt-creator/qt-creator
C++: Do not add double quotes when splitting raw string litterals
Task-number: QTCREATORBUG-17717 Change-Id: Iffb34a3d77ada624dc13b8ab050ac08731d25863 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -237,7 +237,7 @@ bool MatchingText::isInCommentHelper(const QTextCursor &cursor, Token *retToken)
|
||||
return tk.isComment();
|
||||
}
|
||||
|
||||
bool MatchingText::isInStringHelper(const QTextCursor &cursor)
|
||||
Kind MatchingText::stringKindAtCursor(const QTextCursor &cursor)
|
||||
{
|
||||
int prevState = 0;
|
||||
const Tokens tokens = getTokens(cursor, prevState);
|
||||
@@ -245,15 +245,15 @@ bool MatchingText::isInStringHelper(const QTextCursor &cursor)
|
||||
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
|
||||
|
||||
if (tokens.isEmpty() || pos <= tokens.first().utf16charsBegin())
|
||||
return false;
|
||||
return T_EOF_SYMBOL;
|
||||
|
||||
if (pos >= tokens.last().utf16charsEnd()) {
|
||||
const Token tk = tokens.last();
|
||||
return tk.isStringLiteral() && prevState > 0;
|
||||
return tk.isStringLiteral() && prevState > 0 ? tk.kind() : T_EOF_SYMBOL;
|
||||
}
|
||||
|
||||
Token tk = tokenAtPosition(tokens, pos);
|
||||
return tk.isStringLiteral() && pos > tk.utf16charsBegin();
|
||||
return tk.isStringLiteral() && pos > tk.utf16charsBegin() ? tk.kind() : T_EOF_SYMBOL;
|
||||
}
|
||||
|
||||
QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QString &textToProcess,
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <cplusplus/Token.h>
|
||||
#include <cplusplus/CPlusPlusForwardDeclarations.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QTextCursor)
|
||||
@@ -46,7 +48,7 @@ public:
|
||||
static bool shouldInsertMatchingText(QChar lookAhead);
|
||||
|
||||
static bool isInCommentHelper(const QTextCursor &currsor, Token *retToken = 0);
|
||||
static bool isInStringHelper(const QTextCursor &cursor);
|
||||
static CPlusPlus::Kind stringKindAtCursor(const QTextCursor &cursor);
|
||||
|
||||
static QString insertMatchingBrace(const QTextCursor &tc, const QString &text,
|
||||
QChar lookAhead, bool skipChars, int *skippedChars);
|
||||
|
||||
@@ -56,7 +56,7 @@ bool CppAutoCompleter::isInComment(const QTextCursor &cursor) const
|
||||
|
||||
bool CppAutoCompleter::isInString(const QTextCursor &cursor) const
|
||||
{
|
||||
return CPlusPlus::MatchingText::isInStringHelper(cursor);
|
||||
return CPlusPlus::MatchingText::stringKindAtCursor(cursor) != CPlusPlus::T_EOF_SYMBOL;
|
||||
}
|
||||
|
||||
QString CppAutoCompleter::insertMatchingBrace(const QTextCursor &cursor, const QString &text,
|
||||
|
||||
@@ -804,7 +804,8 @@ bool CppEditorWidget::handleStringSplitting(QKeyEvent *e) const
|
||||
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
|
||||
QTextCursor cursor = textCursor();
|
||||
|
||||
if (CPlusPlus::MatchingText::isInStringHelper(cursor)) {
|
||||
const Kind stringKind = CPlusPlus::MatchingText::stringKindAtCursor(cursor);
|
||||
if (stringKind >= T_FIRST_STRING_LITERAL && stringKind < T_FIRST_RAW_STRING_LITERAL) {
|
||||
cursor.beginEditBlock();
|
||||
if (cursor.positionInBlock() > 0
|
||||
&& cursor.block().text().at(cursor.positionInBlock() - 1) == QLatin1Char('\\')) {
|
||||
|
||||
Reference in New Issue
Block a user