Locator: De-duplicate RegExp pattern generation

Change-Id: I3576e1507aebed15245e1f197995bfe9e345e32b
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Andre Hartmann
2017-09-28 20:09:27 +02:00
committed by André Hartmann
parent e0639d0696
commit 8730dbd4e6
7 changed files with 14 additions and 13 deletions

View File

@@ -100,9 +100,8 @@ QList<LocatorFilterEntry> BaseFileFilter::matchesFor(QFutureInterface<LocatorFil
QList<LocatorFilterEntry> goodEntries;
const QString entry = QDir::fromNativeSeparators(origEntry);
const EditorManager::FilePathInfo fp = EditorManager::splitLineAndColumnNumber(entry);
const QRegularExpression regexp = containsWildcard(entry)
? createWildcardRegExp(entry) : CamelHumpMatcher::createCamelHumpRegExp(entry);
const QRegularExpression regexp = createRegExp(entry);
if (!regexp.isValid()) {
d->m_current.clear(); // free memory
return betterEntries;

View File

@@ -26,6 +26,7 @@
#include "ilocatorfilter.h"
#include <coreplugin/coreconstants.h>
#include <utils/camelhumpmatcher.h>
#include <QBoxLayout>
#include <QCheckBox>
@@ -212,7 +213,7 @@ bool ILocatorFilter::containsWildcard(const QString &str)
* The regular expression contains capture groups to allow highlighting
* matched characters after a match.
*/
QRegularExpression ILocatorFilter::createWildcardRegExp(const QString &text)
static QRegularExpression createWildcardRegExp(const QString &text)
{
QString pattern = '(' + text + ')';
pattern.replace('?', ").(");
@@ -221,6 +222,12 @@ QRegularExpression ILocatorFilter::createWildcardRegExp(const QString &text)
return QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption);
}
QRegularExpression ILocatorFilter::createRegExp(const QString &text)
{
return containsWildcard(text) ? createWildcardRegExp(text)
: CamelHumpMatcher::createCamelHumpRegExp(text);
}
/*!
Specifies a title for configuration dialogs.
*/

View File

@@ -144,7 +144,7 @@ public:
static Qt::CaseSensitivity caseSensitivity(const QString &str);
static bool containsWildcard(const QString &str);
static QRegularExpression createWildcardRegExp(const QString &text);
static QRegularExpression createRegExp(const QString &text);
static QString msgConfigureDialogTitle();
static QString msgPrefixLabel();

View File

@@ -61,9 +61,8 @@ QList<LocatorFilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locat
QList<LocatorFilterEntry> goodEntries;
QList<LocatorFilterEntry> betterEntries;
const EditorManager::FilePathInfo fp = EditorManager::splitLineAndColumnNumber(entry);
const QRegularExpression regexp = containsWildcard(entry)
? createWildcardRegExp(entry) : CamelHumpMatcher::createCamelHumpRegExp(entry);
const QRegularExpression regexp = createRegExp(entry);
if (!regexp.isValid())
return goodEntries;

View File

@@ -67,9 +67,7 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
QList<Core::LocatorFilterEntry> goodEntries;
QList<Core::LocatorFilterEntry> betterEntries;
const QRegularExpression regexp = containsWildcard(entry)
? createWildcardRegExp(entry) : CamelHumpMatcher::createCamelHumpRegExp(entry);
const QRegularExpression regexp = createRegExp(entry);
if (!regexp.isValid())
return goodEntries;

View File

@@ -76,9 +76,8 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
bool hasColonColon = entry.contains(QLatin1String("::"));
const IndexItem::ItemType wanted = matchTypes();
const QRegularExpression regexp = containsWildcard(entry)
? createWildcardRegExp(entry) : CamelHumpMatcher::createCamelHumpRegExp(entry);
const QRegularExpression regexp = createRegExp(entry);
if (!regexp.isValid())
return goodEntries;

View File

@@ -61,9 +61,8 @@ QList<Core::LocatorFilterEntry> FunctionFilter::matchesFor(
QList<Core::LocatorFilterEntry> betterEntries;
QList<Core::LocatorFilterEntry> bestEntries;
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
const QRegularExpression regexp = containsWildcard(entry)
? createWildcardRegExp(entry) : CamelHumpMatcher::createCamelHumpRegExp(entry);
const QRegularExpression regexp = createRegExp(entry);
if (!regexp.isValid())
return goodEntries;