diff --git a/src/libs/utils/camelhumpmatcher.cpp b/src/libs/utils/camelhumpmatcher.cpp index c4f0d2be2fa..7c8af9b1292 100644 --- a/src/libs/utils/camelhumpmatcher.cpp +++ b/src/libs/utils/camelhumpmatcher.cpp @@ -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 { diff --git a/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp b/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp index 8bd922e0a11..b42a46cba71 100644 --- a/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp +++ b/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp @@ -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)