OSDN Git Service

Fix the issue where the Apache Tika plugin becomes enabled again when reopening the...
[winmerge-jp/winmerge-jp.git] / Src / FilterList.h
1 /**
2  * @file  FilterList.h
3  *
4  * @brief Declaration file for FilterList.
5  */
6 #pragma once
7
8 #include <vector>
9 #include <memory>
10 #include <Poco/RegularExpression.h>
11 #include "unicoder.h"
12
13 /**
14  * @brief Container for one filtering rule / compiled expression.
15  * This structure holds compiled regular expression and a original expression
16  * as a string. We need the original expression string in case we want to
17  * know which regular expression did match.
18  */
19 struct filter_item
20 {
21         std::string filterAsString; /** Original regular expression string */
22         Poco::RegularExpression regexp; /**< Compiled regular expression */
23         int _reOpts; /**< Options to set to Poco::RegularExpression */
24         filter_item(const std::string &filter, int reOpts) : filterAsString(filter), regexp(filter, reOpts), _reOpts(reOpts) {}
25         filter_item(const filter_item* item) : filterAsString(item->filterAsString), regexp(item->filterAsString, item->_reOpts), _reOpts(item->_reOpts) {}
26 };
27
28 typedef std::shared_ptr<filter_item> filter_item_ptr;
29
30 /**
31  * @brief Regular expression list.
32  * This class holds a list of regular expressions for matching strings.
33  * The class also provides simple function for matching and remembers the
34  * last matched expression.
35  */
36 class FilterList
37 {
38 public:
39         FilterList();
40         ~FilterList();
41         
42         void AddRegExp(const std::string& regularExpression, bool exclude = false);
43         void RemoveAllFilters();
44         bool HasRegExps() const;
45         bool Match(const std::string& string, int codepage = ucr::CP_UTF_8);
46         void CloneFrom(const FilterList* filterList);
47
48 private:
49         std::vector <filter_item_ptr> m_list;
50         std::vector <filter_item_ptr> m_listExclude;
51
52 };
53
54 /** 
55  * @brief Removes all expressions from the list.
56  */
57 inline void FilterList::RemoveAllFilters()
58 {
59         m_list.clear();
60         m_listExclude.clear();
61 }
62
63 /** 
64  * @brief Returns if list has any expressions.
65  * @return true if list contains one or more expressions.
66  */
67 inline bool FilterList::HasRegExps() const
68 {
69         return !m_list.empty() || !m_listExclude.empty();
70 }