1
2
3
4
5
6 #include <cpp2cm/cpp2cm/Filter.hpp>
7 #include <soulng/rex/Match.hpp>
8
9 namespace cpp2cm {
10
11 Filter::Filter(soulng::rex::Context& context_, Type type_, const std::u32string& pattern_) : type(type_), pattern(pattern_), nfa(soulng::rex::CompileFilePattern(context_, pattern))
12 {
13 }
14
15 void Filter::Apply(File& file)
16 {
17 bool match = soulng::rex::PatternMatch(file.Name(), nfa);
18 if (match)
19 {
20 switch (type)
21 {
22 case Type::include:
23 {
24 file.SetIncluded(true);
25 break;
26 }
27 case Type::exclude:
28 {
29 file.SetIncluded(false);
30 break;
31 }
32 }
33 }
34 }
35
36 FilterList::FilterList() : filters()
37 {
38 }
39
40 void FilterList::Add(Filter& filter)
41 {
42 filters.push_back(filter);
43 }
44
45 void FilterList::Apply(File& file)
46 {
47 for (Filter& filter : filters)
48 {
49 filter.Apply(file);
50 }
51 }
52
53 }