summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpptoolsreuse.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2014-05-08 09:48:27 -0400
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-05-23 14:33:34 +0200
commitbb7da966b801a2884cd7cf47f640bf7ac7d775df (patch)
treea4a74a15edb1603e7a20a306bd0246665c45e88b /src/plugins/cpptools/cpptoolsreuse.cpp
parentdd61ed3345a70ef46fb38a17de36ac2bb1627081 (diff)
downloadqt-creator-bb7da966b801a2884cd7cf47f640bf7ac7d775df.tar.gz
Cpp{Tools,Editor}: Respect multi-QChar code points when handling identifiers
* Consolidate code dealing with C++ identifiers into cpptoolsreuse.h * Handle code points that are represented with two QChars Change-Id: I4fb4435aa539f65d88598cac0b50629f33f32440 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cpptoolsreuse.cpp')
-rw-r--r--src/plugins/cpptools/cpptoolsreuse.cpp21
1 files changed, 18 insertions, 3 deletions
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;
}
}