shared: Introduce WildcardMatcher
Cette révision appartient à :
Parent
145cd150b1
révision
edc41d6f59
@ -52,7 +52,8 @@ SOURCES += sqlitesearch.cpp \
|
||||
sqlitedbservice.cpp \
|
||||
tagstripperprocessor.cpp \
|
||||
utils.cpp \
|
||||
../submodules/exile.h/exile.c
|
||||
../submodules/exile.h/exile.c \
|
||||
wildcardmatcher.cpp
|
||||
|
||||
HEADERS += sqlitesearch.h \
|
||||
concurrentqueue.h \
|
||||
@ -81,7 +82,8 @@ HEADERS += sqlitesearch.h \
|
||||
tagstripperprocessor.h \
|
||||
token.h \
|
||||
common.h \
|
||||
utils.h
|
||||
utils.h \
|
||||
wildcardmatcher.h
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
INSTALLS += target
|
||||
|
29
shared/wildcardmatcher.cpp
Fichier normal
29
shared/wildcardmatcher.cpp
Fichier normal
@ -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
Fichier normal
17
shared/wildcardmatcher.h
Fichier normal
@ -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
|
Chargement…
Référencer dans un nouveau ticket
Block a user