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 keyRegExp;
|
||||||
|
QString plainRegExp;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
const QChar asterisk = '*';
|
const QChar asterisk = '*';
|
||||||
const QChar question = '?';
|
const QChar question = '?';
|
||||||
@@ -76,12 +77,17 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
|||||||
keyRegExp += "(?:";
|
keyRegExp += "(?:";
|
||||||
for (const QChar &c : pattern) {
|
for (const QChar &c : pattern) {
|
||||||
if (!c.isLetter()) {
|
if (!c.isLetter()) {
|
||||||
if (c == question)
|
if (c == question) {
|
||||||
keyRegExp += '.';
|
keyRegExp += '.';
|
||||||
else if (c == asterisk)
|
plainRegExp += '.';
|
||||||
|
} else if (c == asterisk) {
|
||||||
keyRegExp += ".*";
|
keyRegExp += ".*";
|
||||||
else
|
plainRegExp += ".*";
|
||||||
keyRegExp += '(' + QRegularExpression::escape(c) + ')';
|
} else {
|
||||||
|
const QString escaped = QRegularExpression::escape(c);
|
||||||
|
keyRegExp += '(' + escaped + ')';
|
||||||
|
plainRegExp += escaped;
|
||||||
|
}
|
||||||
} else if (caseSensitivity == CaseSensitivity::CaseInsensitive ||
|
} else if (caseSensitivity == CaseSensitivity::CaseInsensitive ||
|
||||||
(caseSensitivity == CaseSensitivity::FirstLetterCaseSensitive && !first)) {
|
(caseSensitivity == CaseSensitivity::FirstLetterCaseSensitive && !first)) {
|
||||||
|
|
||||||
@@ -97,6 +103,7 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
|||||||
keyRegExp += '|' + upperSnakeWordContinuation + '(' + upper + ')';
|
keyRegExp += '|' + upperSnakeWordContinuation + '(' + upper + ')';
|
||||||
}
|
}
|
||||||
keyRegExp += ')';
|
keyRegExp += ')';
|
||||||
|
plainRegExp += '[' + upper + lower + ']';
|
||||||
} else {
|
} else {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
if (c.isUpper())
|
if (c.isUpper())
|
||||||
@@ -104,12 +111,14 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
|||||||
else
|
else
|
||||||
keyRegExp += lowercaseWordContinuation;
|
keyRegExp += lowercaseWordContinuation;
|
||||||
}
|
}
|
||||||
keyRegExp += QRegularExpression::escape(c);
|
const QString escaped = QRegularExpression::escape(c);
|
||||||
|
keyRegExp += escaped;
|
||||||
|
plainRegExp += escaped;
|
||||||
}
|
}
|
||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
keyRegExp += ")|(" + QRegularExpression::escape(pattern) + ')';
|
keyRegExp += ")|(" + plainRegExp + ')';
|
||||||
|
|
||||||
return QRegularExpression(keyRegExp);
|
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-after-underscore-uppercase") << "CH" << "LONG_CAMEL_HUMP" << 5;
|
||||||
QTest::newRow("middle-continued") << "cahu" << "LongCamelHump" << 4;
|
QTest::newRow("middle-continued") << "cahu" << "LongCamelHump" << 4;
|
||||||
QTest::newRow("middle-no-hump") << "window" << "mainwindow.cpp" << 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;
|
typedef QVector<int> MatchStart;
|
||||||
|
Reference in New Issue
Block a user