shared: Introduce WildcardMatcher
这个提交包含在:
父节点
145cd150b1
当前提交
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
普通文件
29
shared/wildcardmatcher.cpp
普通文件
@ -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
普通文件
17
shared/wildcardmatcher.h
普通文件
@ -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
|
正在加载...
在新工单中引用
屏蔽一个用户