forked from qt-creator/qt-creator
CamelHump: Do not match first char in the middle of a word
When matching NLH against LongCamelHump do _not_ consider the N of Long as part of the match. The first character needs to meet the same requirements as the others. Change-Id: I4e7b2fe5a28296afe6f06f90e1986336fe7f3179 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
d600bae736
commit
2fb54abd03
@@ -68,6 +68,8 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
||||
bool first = true;
|
||||
const QChar asterisk = '*';
|
||||
const QChar question = '?';
|
||||
const QLatin1String uppercaseWordFirst("(?<=\\b|[a-z0-9_])");
|
||||
const QLatin1String lowercaseWordFirst("(?<=\\b|[A-Z0-9_])");
|
||||
const QLatin1String uppercaseWordContinuation("[a-z0-9_]*");
|
||||
const QLatin1String lowercaseWordContinuation("(?:[a-zA-Z0-9]*_)?");
|
||||
for (const QChar &c : pattern) {
|
||||
@@ -82,12 +84,10 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
||||
(caseSensitivity == CaseSensitivity::FirstLetterCaseSensitive && !first)) {
|
||||
|
||||
keyRegExp += "(?:";
|
||||
if (!first)
|
||||
keyRegExp += uppercaseWordContinuation;
|
||||
keyRegExp += first ? uppercaseWordFirst : uppercaseWordContinuation;
|
||||
keyRegExp += QRegularExpression::escape(c.toUpper());
|
||||
keyRegExp += '|';
|
||||
if (!first)
|
||||
keyRegExp += lowercaseWordContinuation;
|
||||
keyRegExp += first ? lowercaseWordFirst : lowercaseWordContinuation;
|
||||
keyRegExp += QRegularExpression::escape(c.toLower());
|
||||
keyRegExp += ')';
|
||||
} else {
|
||||
|
@@ -69,6 +69,10 @@ void tst_CamelHumpMatcher::camelHumpMatcher_data()
|
||||
QTest::newRow("unmatched-question-wildcard") << "Long?Ca" << "VeryLongCamelHump" << -1;
|
||||
QTest::newRow("asterix-wildcard") << "Long*Ca" << "VeryLongCamelHump" << 4;
|
||||
QTest::newRow("empty-asterix-wildcard") << "Lo*Ca" << "VeryLongCamelHump" << 4;
|
||||
QTest::newRow("no-partial") << "NCH" << "LongCamelHump" << -1;
|
||||
QTest::newRow("middle-after-number") << "CH" << "Long1CamelHump" << 5;
|
||||
QTest::newRow("middle-after-underscore") << "CH" << "long_camel_hump" << 5;
|
||||
QTest::newRow("middle-continued") << "cahu" << "LongCamelHump" << 4;
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_CamelHumpMatcher)
|
||||
|
Reference in New Issue
Block a user