1
0

shared: Introduce WildcardMatcher

Este cometimento está contido em:
Albert S. 2022-05-31 10:13:34 +02:00
ascendente 145cd150b1
cometimento edc41d6f59
3 ficheiros modificados com 50 adições e 2 eliminações

Ver ficheiro

@ -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 Ficheiro normal
Ver ficheiro

@ -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 &regexp : this->regexes)
{
if(regexp.exactMatch(haystack))
{
return true;
}
}
return false;
}

17
shared/wildcardmatcher.h Ficheiro normal
Ver ficheiro

@ -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