summaryrefslogtreecommitdiffstats
path: root/logic/pathmatcher/RegexpMatcher.h
blob: f3cf90b15c346ae0f3f98260bee6125231657510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "IPathMatcher.h"
#include <QRegularExpression>

class RegexpMatcher : public IPathMatcher
{
public:
	virtual ~RegexpMatcher() {};
	RegexpMatcher(QString regexp)
	{
		m_regexp.setPattern(regexp);
		m_onlyFilenamePart = !regexp.contains('/');
	}

	virtual bool matches(const QString &string) override
	{
		if(m_onlyFilenamePart)
		{
			auto slash = string.lastIndexOf('/');
			if(slash != -1)
			{
				auto part = string.mid(slash + 1);
				return m_regexp.match(part).hasMatch();
			}
		}
		return m_regexp.match(string).hasMatch();
	}
	QRegularExpression m_regexp;
	bool m_onlyFilenamePart = false;
};