Commit 2fb54abd authored by Orgad Shaneh's avatar Orgad Shaneh Committed by André Hartmann

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: default avatarAndré Hartmann <aha_1980@gmx.de>
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent d600bae7
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment