diff options
-rw-r--r-- | src/libs/utils/fuzzymatcher.cpp | 4 | ||||
-rw-r--r-- | src/plugins/coreplugin/locator/ilocatorfilter.cpp | 31 | ||||
-rw-r--r-- | src/plugins/coreplugin/locator/ilocatorfilter.h | 1 | ||||
-rw-r--r-- | tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp | 4 |
4 files changed, 5 insertions, 35 deletions
diff --git a/src/libs/utils/fuzzymatcher.cpp b/src/libs/utils/fuzzymatcher.cpp index 7c967361c9..60b5d3aaa2 100644 --- a/src/libs/utils/fuzzymatcher.cpp +++ b/src/libs/utils/fuzzymatcher.cpp @@ -78,10 +78,10 @@ QRegularExpression FuzzyMatcher::createRegExp( if (!c.isLetter()) { if (c == question) { keyRegExp += '.'; - plainRegExp += '.'; + plainRegExp += ").("; } else if (c == asterisk) { keyRegExp += ".*"; - plainRegExp += ".*"; + plainRegExp += ").*("; } else { const QString escaped = QRegularExpression::escape(c); keyRegExp += '(' + escaped + ')'; diff --git a/src/plugins/coreplugin/locator/ilocatorfilter.cpp b/src/plugins/coreplugin/locator/ilocatorfilter.cpp index 5eccc6b00c..1e74741c7e 100644 --- a/src/plugins/coreplugin/locator/ilocatorfilter.cpp +++ b/src/plugins/coreplugin/locator/ilocatorfilter.cpp @@ -194,38 +194,9 @@ Qt::CaseSensitivity ILocatorFilter::caseSensitivity(const QString &str) return str == str.toLower() ? Qt::CaseInsensitive : Qt::CaseSensitive; } -/*! - Returns whether the search term \a str contains wildcard characters. - Can be used for choosing an optimal matching strategy. -*/ -bool ILocatorFilter::containsWildcard(const QString &str) -{ - return str.contains(QLatin1Char('*')) || str.contains(QLatin1Char('?')); -} - -/*! - * \brief Returns a simple regular expression to search for \a text. - * - * \a text may contain the simple '?' and '*' wildcards known from the shell. - * '?' matches exactly one character, '*' matches a number of characters - * (including none). - * - * The regular expression contains capture groups to allow highlighting - * matched characters after a match. - */ -static QRegularExpression createWildcardRegExp(const QString &text) -{ - QString pattern = '(' + text + ')'; - pattern.replace('?', ").("); - pattern.replace('*', ").*("); - pattern.remove("()"); - return QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption); -} - QRegularExpression ILocatorFilter::createRegExp(const QString &text) { - return containsWildcard(text) ? createWildcardRegExp(text) - : FuzzyMatcher::createRegExp(text); + return FuzzyMatcher::createRegExp(text); } LocatorFilterEntry::HighlightInfo ILocatorFilter::highlightInfo( diff --git a/src/plugins/coreplugin/locator/ilocatorfilter.h b/src/plugins/coreplugin/locator/ilocatorfilter.h index 09acb1be20..828f21fb59 100644 --- a/src/plugins/coreplugin/locator/ilocatorfilter.h +++ b/src/plugins/coreplugin/locator/ilocatorfilter.h @@ -143,7 +143,6 @@ public: bool isEnabled() const; static Qt::CaseSensitivity caseSensitivity(const QString &str); - static bool containsWildcard(const QString &str); static QRegularExpression createRegExp(const QString &text); LocatorFilterEntry::HighlightInfo highlightInfo(const QRegularExpressionMatch &match, LocatorFilterEntry::HighlightInfo::DataType dataType = LocatorFilterEntry::HighlightInfo::DisplayName); diff --git a/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp b/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp index 396fb4b35d..d2aaf16c68 100644 --- a/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp +++ b/tests/auto/utils/fuzzymatcher/tst_fuzzymatcher.cpp @@ -141,9 +141,9 @@ void tst_FuzzyMatcher::highlighting_data() QTest::newRow("numbers") << "4" << "TestJust4Fun" << MatchStart{8} << MatchLength{1}; QTest::newRow("wildcard-asterisk") << "Lo*Hu" << "VeryLongCamelHump" - << MatchStart{4} << MatchLength{11}; + << MatchStart{4, 13} << MatchLength{2, 2}; QTest::newRow("wildcard-question") << "Lo?g" << "VeryLongCamelHump" - << MatchStart{4} << MatchLength{4}; + << MatchStart{4, 7} << MatchLength{2, 1}; QTest::newRow("middle-no-hump") << "window" << "mainwindow.cpp" << MatchStart{4} << MatchLength{6}; } |