From f7924757394069d47310e6fcf2471f7bdb7a9d96 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Wed, 20 Sep 2017 21:55:39 +0200 Subject: [PATCH] CamelHumpMatcher: Fix matching word continuations without hump Let the search string "window" also find "mainwindow.cpp", not just "MainWindow.cpp" Task-number: QTCREATORBUG-18957 Change-Id: Iace3111fb3ce319d916362c1f8d396844a3bc47a Reviewed-by: Nikolai Kosjar Reviewed-by: Orgad Shaneh --- src/libs/utils/camelhumpmatcher.cpp | 3 +++ tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/libs/utils/camelhumpmatcher.cpp b/src/libs/utils/camelhumpmatcher.cpp index 0661499c7a3..cb99cff1372 100644 --- a/src/libs/utils/camelhumpmatcher.cpp +++ b/src/libs/utils/camelhumpmatcher.cpp @@ -73,6 +73,7 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp( const QLatin1String uppercaseWordContinuation("[a-z0-9_]*"); const QLatin1String lowercaseWordContinuation("(?:[a-zA-Z0-9]*_)?"); const QLatin1String upperSnakeWordContinuation("[A-Z0-9]*_"); + keyRegExp += "(?:"; for (const QChar &c : pattern) { if (!c.isLetter()) { if (c == question) @@ -108,6 +109,8 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp( first = false; } + keyRegExp += ")|(" + QRegularExpression::escape(pattern) + ')'; + return QRegularExpression(keyRegExp); } diff --git a/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp b/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp index 3777c7b755f..6884ee8d7b8 100644 --- a/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp +++ b/tests/auto/utils/camelhumpmatcher/tst_camelhumpmatcher.cpp @@ -77,6 +77,7 @@ void tst_CamelHumpMatcher::camelHumpMatcher_data() QTest::newRow("middle-after-underscore") << "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-no-hump") << "window" << "mainwindow.cpp" << 4; } typedef QVector MatchStart; @@ -136,6 +137,8 @@ void tst_CamelHumpMatcher::highlighting_data() << MatchStart{4, 13} << MatchLength{2, 2}; QTest::newRow("wildcard-question") << "Lo?g" << "VeryLongCamelHump" << MatchStart{4, 7} << MatchLength{2, 1}; + QTest::newRow("middle-no-hump") << "window" << "mainwindow.cpp" + << MatchStart{4} << MatchLength{6}; } QTEST_APPLESS_MAIN(tst_CamelHumpMatcher)