summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/cppeditor/cppeditor.cpp11
-rw-r--r--src/plugins/cppeditor/cppfollowsymbolundercursor.cpp5
-rw-r--r--src/plugins/cppeditor/cpphighlighter.cpp2
-rw-r--r--src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp5
-rw-r--r--src/plugins/cpptools/cppcompletionassist.cpp11
-rw-r--r--src/plugins/cpptools/cppcompletionassistprovider.cpp7
-rw-r--r--src/plugins/cpptools/cppcompletionassistprovider.h1
-rw-r--r--src/plugins/cpptools/cpptoolsreuse.cpp21
-rw-r--r--src/plugins/cpptools/cpptoolsreuse.h4
-rw-r--r--src/plugins/texteditor/codeassist/genericproposalwidget.cpp4
10 files changed, 51 insertions, 20 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 7d153fc5ce..62cf921069 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -176,11 +176,6 @@ struct CanonicalSymbol
return typeOfExpression.context();
}
- static inline bool isIdentifierChar(const QChar &ch)
- {
- return ch.isLetterOrNumber() || ch == QLatin1Char('_');
- }
-
Scope *getScopeAndExpression(const QTextCursor &cursor, QString *code)
{
return getScopeAndExpression(editor, info, cursor, code);
@@ -202,11 +197,11 @@ struct CanonicalSymbol
int pos = tc.position();
- if (!isIdentifierChar(document->characterAt(pos)))
- if (!(pos > 0 && isIdentifierChar(document->characterAt(pos - 1))))
+ if (!isValidIdentifierChar(document->characterAt(pos)))
+ if (!(pos > 0 && isValidIdentifierChar(document->characterAt(pos - 1))))
return 0;
- while (isIdentifierChar(document->characterAt(pos)))
+ while (isValidIdentifierChar(document->characterAt(pos)))
++pos;
tc.setPosition(pos);
diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp
index 5b4fc52fa6..ae3e911849 100644
--- a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp
+++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp
@@ -40,6 +40,7 @@
#include <cplusplus/TypeOfExpression.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <cpptools/functionutils.h>
+#include <cpptools/cpptoolsreuse.h>
#include <cpptools/symbolfinder.h>
#include <texteditor/basetextdocumentlayout.h>
#include <utils/qtcassert.h>
@@ -434,7 +435,7 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
QTextCursor tc = cursor;
QTextDocument *document = m_widget->document();
QChar ch = document->characterAt(tc.position());
- while (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
+ while (CppTools::isValidIdentifierChar(ch)) {
tc.movePosition(QTextCursor::NextCharacter);
ch = document->characterAt(tc.position());
}
@@ -559,7 +560,7 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
const QTextBlock block = tc.block();
int pos = cursor.positionInBlock();
QChar ch = document->characterAt(cursor.position());
- if (pos > 0 && !(ch.isLetterOrNumber() || ch == QLatin1Char('_')))
+ if (pos > 0 && !isValidIdentifierChar(ch))
--pos; // positionInBlock points to a delimiter character.
const Token tk = SimpleLexer::tokenAt(block.text(), pos,
BackwardsScanner::previousBlockState(block), true);
diff --git a/src/plugins/cppeditor/cpphighlighter.cpp b/src/plugins/cppeditor/cpphighlighter.cpp
index fc267d96c7..2617d262b3 100644
--- a/src/plugins/cppeditor/cpphighlighter.cpp
+++ b/src/plugins/cppeditor/cpphighlighter.cpp
@@ -412,7 +412,7 @@ void CppHighlighter::highlightDoxygenComment(const QString &text, int position,
++it;
const QChar *start = it;
- while (it->isLetterOrNumber() || it->unicode() == '_')
+ while (CppTools::isValidAsciiIdentifierChar(*it))
++it;
int k = CppTools::classifyDoxygenTag(start, it - start);
diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
index cd0eec7206..1b20361925 100644
--- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
+++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
@@ -919,6 +919,11 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data()
"\n"
"void h() { typedef TreeConstIterator<MyBase> const_iterator; }\n"
);
+
+ QTest::newRow("unicodeIdentifier") << _(
+ "class Foo { void $\u00FC\u4E8C\U00010302(); };\n"
+ "void Foo::@\u00FC\u4E8C\U00010302() {}\n"
+ );
}
void CppEditorPlugin::test_FollowSymbolUnderCursor()
diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp
index 70c190b9ef..77a25b1d5c 100644
--- a/src/plugins/cpptools/cppcompletionassist.cpp
+++ b/src/plugins/cpptools/cppcompletionassist.cpp
@@ -35,6 +35,7 @@
#include "cppsnapshotupdater.h"
#include "cpptoolsconstants.h"
#include "cpptoolseditorsupport.h"
+#include "cpptoolsreuse.h"
#include <coreplugin/icore.h>
#include <cppeditor/cppeditorconstants.h>
@@ -314,8 +315,7 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
while (preserveLength > 0) {
if (inEditor.startsWith(toInsert.right(preserveLength))
&& (inEditorLength == preserveLength
- || (!inEditor.at(preserveLength).isLetterOrNumber()
- && inEditor.at(preserveLength) != QLatin1Char('_')))) {
+ || !CppTools::isValidIdentifierChar(inEditor.at(preserveLength)))) {
break;
}
--preserveLength;
@@ -671,11 +671,12 @@ bool CppCompletionAssistProcessor::accepts() const
} else {
// Trigger completion after three characters of a name have been typed, when not editing an existing name
QChar characterUnderCursor = m_interface->characterAt(pos);
- if (!characterUnderCursor.isLetterOrNumber() && characterUnderCursor != QLatin1Char('_')) {
+
+ if (!isValidIdentifierChar(characterUnderCursor)) {
const int startOfName = findStartOfName(pos);
if (pos - startOfName >= 3) {
const QChar firstCharacter = m_interface->characterAt(startOfName);
- if (firstCharacter.isLetter() || firstCharacter == QLatin1Char('_')) {
+ if (isValidFirstIdentifierChar(firstCharacter)) {
// Finally check that we're not inside a comment or string (code copied from startOfOperator)
QTextCursor tc(m_interface->textDocument());
tc.setPosition(pos);
@@ -875,7 +876,7 @@ int CppCompletionAssistProcessor::findStartOfName(int pos) const
// Skip to the start of a name
do {
chr = m_interface->characterAt(--pos);
- } while (chr.isLetterOrNumber() || chr == QLatin1Char('_'));
+ } while (CppTools::isValidIdentifierChar(chr));
return pos + 1;
}
diff --git a/src/plugins/cpptools/cppcompletionassistprovider.cpp b/src/plugins/cpptools/cppcompletionassistprovider.cpp
index 11824b3b1d..c6a5dacfe4 100644
--- a/src/plugins/cpptools/cppcompletionassistprovider.cpp
+++ b/src/plugins/cpptools/cppcompletionassistprovider.cpp
@@ -29,6 +29,8 @@
#include "cppcompletionassistprovider.h"
+#include "cpptoolsreuse.h"
+
#include <cppeditor/cppeditorconstants.h>
#include <cplusplus/Token.h>
@@ -59,6 +61,11 @@ bool CppCompletionAssistProvider::isActivationCharSequence(const QString &sequen
return false;
}
+bool CppCompletionAssistProvider::isContinuationChar(const QChar &c) const
+{
+ return isValidIdentifierChar(c);
+}
+
int CppCompletionAssistProvider::activationSequenceChar(const QChar &ch,
const QChar &ch2,
const QChar &ch3,
diff --git a/src/plugins/cpptools/cppcompletionassistprovider.h b/src/plugins/cpptools/cppcompletionassistprovider.h
index 21116a456a..de91093e43 100644
--- a/src/plugins/cpptools/cppcompletionassistprovider.h
+++ b/src/plugins/cpptools/cppcompletionassistprovider.h
@@ -58,6 +58,7 @@ public:
bool supportsEditor(const Core::Id &editorId) const QTC_OVERRIDE;
int activationCharSequenceLength() const QTC_OVERRIDE;
bool isActivationCharSequence(const QString &sequence) const QTC_OVERRIDE;
+ bool isContinuationChar(const QChar &c) const QTC_OVERRIDE;
virtual TextEditor::IAssistInterface *createAssistInterface(
ProjectExplorer::Project *project, TextEditor::BaseTextEditor *editor,
diff --git a/src/plugins/cpptools/cpptoolsreuse.cpp b/src/plugins/cpptools/cpptoolsreuse.cpp
index b2d9c17d16..b71ceeecac 100644
--- a/src/plugins/cpptools/cpptoolsreuse.cpp
+++ b/src/plugins/cpptools/cpptoolsreuse.cpp
@@ -50,7 +50,7 @@ static void moveCursorToStartOrEndOfIdentifier(QTextCursor *tc,
return;
QChar ch = doc->characterAt(tc->position() - posDiff);
- while (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
+ while (isValidIdentifierChar(ch)) {
tc->movePosition(op);
ch = doc->characterAt(tc->position() - posDiff);
}
@@ -111,16 +111,31 @@ bool isOwnershipRAIIType(CPlusPlus::Symbol *symbol, const LookupContext &context
return false;
}
+bool isValidAsciiIdentifierChar(const QChar &ch)
+{
+ return ch.isLetterOrNumber() || ch == QLatin1Char(' ');
+}
+
+bool isValidFirstIdentifierChar(const QChar &ch)
+{
+ return ch.isLetter() || ch == QLatin1Char('_') || ch.isHighSurrogate() || ch.isLowSurrogate();
+}
+
+bool isValidIdentifierChar(const QChar &ch)
+{
+ return isValidFirstIdentifierChar(ch) || ch.isNumber();
+}
+
bool isValidIdentifier(const QString &s)
{
const int length = s.length();
for (int i = 0; i < length; ++i) {
const QChar &c = s.at(i);
if (i == 0) {
- if (!c.isLetter() && c != QLatin1Char('_'))
+ if (!isValidFirstIdentifierChar(c))
return false;
} else {
- if (!c.isLetterOrNumber() && c != QLatin1Char('_'))
+ if (!isValidIdentifierChar(c))
return false;
}
}
diff --git a/src/plugins/cpptools/cpptoolsreuse.h b/src/plugins/cpptools/cpptoolsreuse.h
index a0156a8093..87b1e5eb3e 100644
--- a/src/plugins/cpptools/cpptoolsreuse.h
+++ b/src/plugins/cpptools/cpptoolsreuse.h
@@ -32,6 +32,7 @@
#include "cpptools_global.h"
+QT_FORWARD_DECLARE_CLASS(QChar)
QT_FORWARD_DECLARE_CLASS(QTextCursor)
QT_FORWARD_DECLARE_CLASS(QStringRef)
@@ -48,6 +49,9 @@ void CPPTOOLS_EXPORT moveCursorToStartOfIdentifier(QTextCursor *tc);
bool CPPTOOLS_EXPORT isOwnershipRAIIType(CPlusPlus::Symbol *symbol,
const CPlusPlus::LookupContext &context);
+bool CPPTOOLS_EXPORT isValidAsciiIdentifierChar(const QChar &ch);
+bool CPPTOOLS_EXPORT isValidFirstIdentifierChar(const QChar &ch);
+bool CPPTOOLS_EXPORT isValidIdentifierChar(const QChar &ch);
bool CPPTOOLS_EXPORT isValidIdentifier(const QString &s);
bool CPPTOOLS_EXPORT isQtKeyword(const QStringRef &text);
diff --git a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp
index fd97fa3772..677e3928c7 100644
--- a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp
+++ b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp
@@ -66,8 +66,10 @@ QString cleanText(const QString &original)
int ignore = 0;
for (int i = clean.length() - 1; i >= 0; --i, ++ignore) {
const QChar &c = clean.at(i);
- if (c.isLetterOrNumber() || c == QLatin1Char('_'))
+ if (c.isLetterOrNumber() || c == QLatin1Char('_')
+ || c.isHighSurrogate() || c.isLowSurrogate()) {
break;
+ }
}
if (ignore)
clean.chop(ignore);