forked from qt-creator/qt-creator
Rename CamelHumpMatcher -> FuzzyMatcher
Change-Id: Ia8a2eeb985bcdd500b4faf9605e5092a52dad372 Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
Orgad Shaneh
parent
fc2bb852fd
commit
e9b4d3a48a
@@ -25,22 +25,21 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "camelhumpmatcher.h"
|
||||
#include "fuzzymatcher.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
|
||||
/**
|
||||
* \brief Creates a regexp that represents a specified camel hump pattern,
|
||||
* \brief Creates a regexp that represents a specified wildcard and camel hump pattern,
|
||||
* underscores are not included.
|
||||
*
|
||||
* \param pattern the camel hump pattern
|
||||
* \param caseSensitivity case sensitivity used for camel hump matching;
|
||||
* does not affect wildcard style matching
|
||||
* \param caseSensitivity case sensitivity used for camel hump matching
|
||||
* \return the regexp
|
||||
*/
|
||||
QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
||||
const QString &pattern, CamelHumpMatcher::CaseSensitivity caseSensitivity)
|
||||
QRegularExpression FuzzyMatcher::createRegExp(
|
||||
const QString &pattern, FuzzyMatcher::CaseSensitivity caseSensitivity)
|
||||
{
|
||||
if (pattern.isEmpty())
|
||||
return QRegularExpression();
|
||||
@@ -129,7 +128,7 @@ QRegularExpression CamelHumpMatcher::createCamelHumpRegExp(
|
||||
*
|
||||
* The list is minimized by combining adjacent highlighting positions to a single position.
|
||||
*/
|
||||
CamelHumpMatcher::HighlightingPositions CamelHumpMatcher::highlightingPositions(
|
||||
FuzzyMatcher::HighlightingPositions FuzzyMatcher::highlightingPositions(
|
||||
const QRegularExpressionMatch &match)
|
||||
{
|
||||
HighlightingPositions result;
|
||||
@@ -37,7 +37,7 @@ class QRegularExpressionMatch;
|
||||
class QString;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT CamelHumpMatcher
|
||||
class QTCREATOR_UTILS_EXPORT FuzzyMatcher
|
||||
{
|
||||
public:
|
||||
enum class CaseSensitivity {
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
QVector<int> lengths;
|
||||
};
|
||||
|
||||
static QRegularExpression createCamelHumpRegExp(const QString &pattern,
|
||||
static QRegularExpression createRegExp(const QString &pattern,
|
||||
CaseSensitivity caseSensitivity = CaseSensitivity::CaseInsensitive);
|
||||
static HighlightingPositions highlightingPositions(const QRegularExpressionMatch &match);
|
||||
};
|
||||
@@ -116,7 +116,7 @@ SOURCES += \
|
||||
$$PWD/utilsicons.cpp \
|
||||
$$PWD/guard.cpp \
|
||||
$$PWD/highlightingitemdelegate.cpp \
|
||||
$$PWD/camelhumpmatcher.cpp \
|
||||
$$PWD/fuzzymatcher.cpp \
|
||||
$$PWD/textutils.cpp \
|
||||
$$PWD/url.cpp
|
||||
|
||||
@@ -247,7 +247,7 @@ HEADERS += \
|
||||
$$PWD/../3rdparty/optional/optional.hpp \
|
||||
$$PWD/qtcfallthrough.h \
|
||||
$$PWD/highlightingitemdelegate.h \
|
||||
$$PWD/camelhumpmatcher.h \
|
||||
$$PWD/fuzzymatcher.h \
|
||||
$$PWD/textutils.h \
|
||||
$$PWD/predicates.h \
|
||||
$$PWD/url.h
|
||||
|
||||
@@ -52,8 +52,6 @@ Project {
|
||||
"benchmarker.h",
|
||||
"buildablehelperlibrary.cpp",
|
||||
"buildablehelperlibrary.h",
|
||||
"camelhumpmatcher.cpp",
|
||||
"camelhumpmatcher.h",
|
||||
"categorysortfiltermodel.cpp",
|
||||
"categorysortfiltermodel.h",
|
||||
"changeset.cpp",
|
||||
@@ -117,6 +115,8 @@ Project {
|
||||
"flowlayout.cpp",
|
||||
"flowlayout.h",
|
||||
"functiontraits.h",
|
||||
"fuzzymatcher.cpp",
|
||||
"fuzzymatcher.h",
|
||||
"guard.cpp",
|
||||
"guard.h",
|
||||
"highlightingitemdelegate.cpp",
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "ilocatorfilter.h"
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <utils/camelhumpmatcher.h>
|
||||
#include <utils/fuzzymatcher.h>
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QCheckBox>
|
||||
@@ -225,14 +225,14 @@ static QRegularExpression createWildcardRegExp(const QString &text)
|
||||
QRegularExpression ILocatorFilter::createRegExp(const QString &text)
|
||||
{
|
||||
return containsWildcard(text) ? createWildcardRegExp(text)
|
||||
: CamelHumpMatcher::createCamelHumpRegExp(text);
|
||||
: FuzzyMatcher::createRegExp(text);
|
||||
}
|
||||
|
||||
LocatorFilterEntry::HighlightInfo ILocatorFilter::highlightInfo(
|
||||
const QRegularExpressionMatch &match, LocatorFilterEntry::HighlightInfo::DataType dataType)
|
||||
{
|
||||
const CamelHumpMatcher::HighlightingPositions positions =
|
||||
CamelHumpMatcher::highlightingPositions(match);
|
||||
const FuzzyMatcher::HighlightingPositions positions =
|
||||
FuzzyMatcher::highlightingPositions(match);
|
||||
|
||||
return LocatorFilterEntry::HighlightInfo(positions.starts, positions.lengths, dataType);
|
||||
}
|
||||
|
||||
@@ -255,9 +255,9 @@ void GenericProposalModel::filter(const QString &prefix)
|
||||
if (prefix.isEmpty())
|
||||
return;
|
||||
|
||||
const CamelHumpMatcher::CaseSensitivity caseSensitivity =
|
||||
const FuzzyMatcher::CaseSensitivity caseSensitivity =
|
||||
convertCaseSensitivity(TextEditorSettings::completionSettings().m_caseSensitivity);
|
||||
const QRegularExpression regExp = CamelHumpMatcher::createCamelHumpRegExp(prefix, caseSensitivity);
|
||||
const QRegularExpression regExp = FuzzyMatcher::createRegExp(prefix, caseSensitivity);
|
||||
|
||||
m_currentItems.clear();
|
||||
const QString lowerPrefix = prefix.toLower();
|
||||
@@ -279,16 +279,16 @@ void GenericProposalModel::filter(const QString &prefix)
|
||||
}
|
||||
}
|
||||
|
||||
CamelHumpMatcher::CaseSensitivity
|
||||
FuzzyMatcher::CaseSensitivity
|
||||
GenericProposalModel::convertCaseSensitivity(TextEditor::CaseSensitivity textEditorCaseSensitivity)
|
||||
{
|
||||
switch (textEditorCaseSensitivity) {
|
||||
case TextEditor::CaseSensitive:
|
||||
return CamelHumpMatcher::CaseSensitivity::CaseSensitive;
|
||||
return FuzzyMatcher::CaseSensitivity::CaseSensitive;
|
||||
case TextEditor::FirstLetterCaseSensitive:
|
||||
return CamelHumpMatcher::CaseSensitivity::FirstLetterCaseSensitive;
|
||||
return FuzzyMatcher::CaseSensitivity::FirstLetterCaseSensitive;
|
||||
default:
|
||||
return CamelHumpMatcher::CaseSensitivity::CaseInsensitive;
|
||||
return FuzzyMatcher::CaseSensitivity::CaseInsensitive;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
#include <texteditor/completionsettings.h>
|
||||
#include <texteditor/texteditor_global.h>
|
||||
#include <utils/camelhumpmatcher.h>
|
||||
#include <utils/fuzzymatcher.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
bool isPrefiltered(const QString &prefix) const;
|
||||
void setPrefilterPrefix(const QString &prefix);
|
||||
|
||||
CamelHumpMatcher::CaseSensitivity convertCaseSensitivity(TextEditor::CaseSensitivity textEditorCaseSensitivity);
|
||||
FuzzyMatcher::CaseSensitivity convertCaseSensitivity(TextEditor::CaseSensitivity textEditorCaseSensitivity);
|
||||
|
||||
protected:
|
||||
QList<AssistProposalItemInterface *> m_currentItems;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import qbs
|
||||
|
||||
QtcAutotest {
|
||||
name: "CamelHumpMatcher autotest"
|
||||
Depends { name: "Utils" }
|
||||
files: "tst_camelhumpmatcher.cpp"
|
||||
}
|
||||
@@ -3,4 +3,4 @@ include(../../qttest.pri)
|
||||
|
||||
DEFINES += QTCREATOR_UTILS_LIB
|
||||
|
||||
SOURCES += tst_camelhumpmatcher.cpp
|
||||
SOURCES += tst_fuzzymatcher.cpp
|
||||
7
tests/auto/utils/fuzzymatcher/fuzzymatcher.qbs
Normal file
7
tests/auto/utils/fuzzymatcher/fuzzymatcher.qbs
Normal file
@@ -0,0 +1,7 @@
|
||||
import qbs
|
||||
|
||||
QtcAutotest {
|
||||
name: "FuzzyMatcher autotest"
|
||||
Depends { name: "Utils" }
|
||||
files: "tst_fuzzymatcher.cpp"
|
||||
}
|
||||
@@ -24,33 +24,33 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <utils/camelhumpmatcher.h>
|
||||
#include <utils/fuzzymatcher.h>
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
class tst_CamelHumpMatcher : public QObject
|
||||
class tst_FuzzyMatcher : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void camelHumpMatcher();
|
||||
void camelHumpMatcher_data();
|
||||
void fuzzyMatcher();
|
||||
void fuzzyMatcher_data();
|
||||
void highlighting();
|
||||
void highlighting_data();
|
||||
};
|
||||
|
||||
void tst_CamelHumpMatcher::camelHumpMatcher()
|
||||
void tst_FuzzyMatcher::fuzzyMatcher()
|
||||
{
|
||||
QFETCH(QString, pattern);
|
||||
QFETCH(QString, candidate);
|
||||
QFETCH(int, expectedIndex);
|
||||
|
||||
const QRegularExpression regExp = CamelHumpMatcher::createCamelHumpRegExp(pattern);
|
||||
const QRegularExpression regExp = FuzzyMatcher::createRegExp(pattern);
|
||||
const QRegularExpressionMatch match = regExp.match(candidate);
|
||||
QCOMPARE(match.capturedStart(), expectedIndex);
|
||||
}
|
||||
|
||||
void tst_CamelHumpMatcher::camelHumpMatcher_data()
|
||||
void tst_FuzzyMatcher::fuzzyMatcher_data()
|
||||
{
|
||||
QTest::addColumn<QString>("pattern");
|
||||
QTest::addColumn<QString>("candidate");
|
||||
@@ -86,17 +86,17 @@ void tst_CamelHumpMatcher::camelHumpMatcher_data()
|
||||
typedef QVector<int> MatchStart;
|
||||
typedef QVector<int> MatchLength;
|
||||
|
||||
void tst_CamelHumpMatcher::highlighting()
|
||||
void tst_FuzzyMatcher::highlighting()
|
||||
{
|
||||
QFETCH(QString, pattern);
|
||||
QFETCH(QString, candidate);
|
||||
QFETCH(MatchStart, matchStart);
|
||||
QFETCH(MatchLength, matchLength);
|
||||
|
||||
const QRegularExpression regExp = CamelHumpMatcher::createCamelHumpRegExp(pattern);
|
||||
const QRegularExpression regExp = FuzzyMatcher::createRegExp(pattern);
|
||||
const QRegularExpressionMatch match = regExp.match(candidate);
|
||||
const CamelHumpMatcher::HighlightingPositions positions =
|
||||
CamelHumpMatcher::highlightingPositions(match);
|
||||
const FuzzyMatcher::HighlightingPositions positions =
|
||||
FuzzyMatcher::highlightingPositions(match);
|
||||
|
||||
QCOMPARE(positions.starts.size(), matchStart.size());
|
||||
for (int i = 0; i < positions.starts.size(); ++i) {
|
||||
@@ -105,7 +105,7 @@ void tst_CamelHumpMatcher::highlighting()
|
||||
}
|
||||
}
|
||||
|
||||
void tst_CamelHumpMatcher::highlighting_data()
|
||||
void tst_FuzzyMatcher::highlighting_data()
|
||||
{
|
||||
QTest::addColumn<QString>("pattern");
|
||||
QTest::addColumn<QString>("candidate");
|
||||
@@ -148,5 +148,5 @@ void tst_CamelHumpMatcher::highlighting_data()
|
||||
<< MatchStart{4} << MatchLength{6};
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_CamelHumpMatcher)
|
||||
#include "tst_camelhumpmatcher.moc"
|
||||
QTEST_APPLESS_MAIN(tst_FuzzyMatcher)
|
||||
#include "tst_fuzzymatcher.moc"
|
||||
@@ -3,7 +3,7 @@ TEMPLATE = subdirs
|
||||
SUBDIRS = \
|
||||
fileutils \
|
||||
ansiescapecodehandler \
|
||||
camelhumpmatcher \
|
||||
fuzzymatcher \
|
||||
objectpool \
|
||||
stringutils \
|
||||
templateengine \
|
||||
|
||||
@@ -5,7 +5,7 @@ Project {
|
||||
references: [
|
||||
"fileutils/fileutils.qbs",
|
||||
"ansiescapecodehandler/ansiescapecodehandler.qbs",
|
||||
"camelhumpmatcher/camelhumpmatcher.qbs",
|
||||
"fuzzymatcher/fuzzymatcher.qbs",
|
||||
"stringutils/stringutils.qbs",
|
||||
"objectpool/objectpool.qbs",
|
||||
"templateengine/templateengine.qbs",
|
||||
|
||||
Reference in New Issue
Block a user