shared: Introduce WildcardMatcher
This commit is contained in:
parent
145cd150b1
commit
edc41d6f59
@ -52,7 +52,8 @@ SOURCES += sqlitesearch.cpp \
|
|||||||
sqlitedbservice.cpp \
|
sqlitedbservice.cpp \
|
||||||
tagstripperprocessor.cpp \
|
tagstripperprocessor.cpp \
|
||||||
utils.cpp \
|
utils.cpp \
|
||||||
../submodules/exile.h/exile.c
|
../submodules/exile.h/exile.c \
|
||||||
|
wildcardmatcher.cpp
|
||||||
|
|
||||||
HEADERS += sqlitesearch.h \
|
HEADERS += sqlitesearch.h \
|
||||||
concurrentqueue.h \
|
concurrentqueue.h \
|
||||||
@ -81,7 +82,8 @@ HEADERS += sqlitesearch.h \
|
|||||||
tagstripperprocessor.h \
|
tagstripperprocessor.h \
|
||||||
token.h \
|
token.h \
|
||||||
common.h \
|
common.h \
|
||||||
utils.h
|
utils.h \
|
||||||
|
wildcardmatcher.h
|
||||||
unix {
|
unix {
|
||||||
target.path = /usr/lib
|
target.path = /usr/lib
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
29
shared/wildcardmatcher.cpp
Normal file
29
shared/wildcardmatcher.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "wildcardmatcher.h"
|
||||||
|
|
||||||
|
void WildcardMatcher::setPatterns(QStringList patterns)
|
||||||
|
{
|
||||||
|
this->regexes.clear();
|
||||||
|
for(QString &str : patterns)
|
||||||
|
{
|
||||||
|
QRegExp regexp;
|
||||||
|
regexp.setPattern(str);
|
||||||
|
regexp.setPatternSyntax(QRegExp::WildcardUnix);
|
||||||
|
this->regexes.append(regexp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WildcardMatcher::WildcardMatcher()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WildcardMatcher::match(QString haystack) const
|
||||||
|
{
|
||||||
|
for(const QRegExp ®exp : this->regexes)
|
||||||
|
{
|
||||||
|
if(regexp.exactMatch(haystack))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
17
shared/wildcardmatcher.h
Normal file
17
shared/wildcardmatcher.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef WILDCARDMATCHER_H
|
||||||
|
#define WILDCARDMATCHER_H
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QRegExp>
|
||||||
|
class WildcardMatcher
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
QVector<QRegExp> regexes;
|
||||||
|
QStringList patterns;
|
||||||
|
|
||||||
|
public:
|
||||||
|
WildcardMatcher();
|
||||||
|
bool match(QString haystack) const;
|
||||||
|
void setPatterns(QStringList patterns);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WILDCARDMATCHER_H
|
Loading…
Reference in New Issue
Block a user