forked from qt-creator/qt-creator
CamelHump: Fix case insensitive matching after the same case
For example: window -> MAINWINDOW. This was broken by the constraint that the first char must follow a non- matching case in2fb54abd03
. It was fixed for pure lowercase inf792475739
, but this fix was evidentially partial. Change-Id: I0c29b54768c40d0501f006182f2bd1ae1e94f3bf Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
André Hartmann
parent
0fb6a1479f
commit
f56b2bfe6d
@@ -65,6 +65,7 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
||||
*/
|
||||
|
||||
QString keyRegExp;
|
||||
QString plainRegExp;
|
||||
bool first = true;
|
||||
const QChar asterisk = '*';
|
||||
const QChar question = '?';
|
||||
@@ -76,12 +77,17 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
||||
keyRegExp += "(?:";
|
||||
for (const QChar &c : pattern) {
|
||||
if (!c.isLetter()) {
|
||||
if (c == question)
|
||||
if (c == question) {
|
||||
keyRegExp += '.';
|
||||
else if (c == asterisk)
|
||||
plainRegExp += '.';
|
||||
} else if (c == asterisk) {
|
||||
keyRegExp += ".*";
|
||||
else
|
||||
keyRegExp += '(' + QRegularExpression::escape(c) + ')';
|
||||
plainRegExp += ".*";
|
||||
} else {
|
||||
const QString escaped = QRegularExpression::escape(c);
|
||||
keyRegExp += '(' + escaped + ')';
|
||||
plainRegExp += escaped;
|
||||
}
|
||||
} else if (caseSensitivity == CaseSensitivity::CaseInsensitive ||
|
||||
(caseSensitivity == CaseSensitivity::FirstLetterCaseSensitive && !first)) {
|
||||
|
||||
@@ -97,6 +103,7 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
||||
keyRegExp += '|' + upperSnakeWordContinuation + '(' + upper + ')';
|
||||
}
|
||||
keyRegExp += ')';
|
||||
plainRegExp += '[' + upper + lower + ']';
|
||||
} else {
|
||||
if (!first) {
|
||||
if (c.isUpper())
|
||||
@@ -104,12 +111,14 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
||||
else
|
||||
keyRegExp += lowercaseWordContinuation;
|
||||
}
|
||||
keyRegExp += QRegularExpression::escape(c);
|
||||
const QString escaped = QRegularExpression::escape(c);
|
||||
keyRegExp += escaped;
|
||||
plainRegExp += escaped;
|
||||
}
|
||||
|
||||
first = false;
|
||||
}
|
||||
keyRegExp += ")|(" + QRegularExpression::escape(pattern) + ')';
|
||||
keyRegExp += ")|(" + plainRegExp + ')';
|
||||
|
||||
return QRegularExpression(keyRegExp);
|
||||
}
|
||||
|
@@ -79,6 +79,8 @@ void tst_CamelHumpMatcher::camelHumpMatcher_data()
|
||||
QTest::newRow("middle-after-underscore-uppercase") << "CH" << "LONG_CAMEL_HUMP" << 5;
|
||||
QTest::newRow("middle-continued") << "cahu" << "LongCamelHump" << 4;
|
||||
QTest::newRow("middle-no-hump") << "window" << "mainwindow.cpp" << 4;
|
||||
QTest::newRow("case-insensitive") << "window" << "MAINWINDOW.cpp" << 4;
|
||||
QTest::newRow("case-insensitive-2") << "wINDow" << "MainwiNdow.cpp" << 4;
|
||||
}
|
||||
|
||||
typedef QVector<int> MatchStart;
|
||||
|
Reference in New Issue
Block a user