summaryrefslogtreecommitdiffstats
path: root/common/ExcludesListMatcher.h
blob: 31398a89539af9f53fe3848249fd0751cfd802c9 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * File:	ExcludesListMatcher.h
 *
 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
 * See included license file for license details.
 */
#if !defined(_ExcludesListMatcher_h_)
#define _ExcludesListMatcher_h_

#include "GlobMatcher.h"
#include <vector>
#include <string>

namespace elftosb
{

/*!
 * \brief Matches strings using a series of include and exclude glob patterns.
 *
 * This string matcher class uses a sequential, ordered list of glob patterns to
 * determine whether a string matches.  Attached to each pattern is an include/exclude
 * action. The patterns in the list effectively form a Boolean expression. Includes
 * act as an OR operator while excludes act as an AND NOT operator.
 *
 * Examples (plus prefix is include, minus prefix is exclude):
 * - +foo: foo
 * - -foo: !foo
 * - +foo, +bar: foo || bar
 * - +foo, -bar: foo && !bar
 * - +foo, -bar, +baz: foo && !bar || baz
 *
 * The only reason for inheriting from GlobMatcher is so we can access the protected
 * globMatch() method.
 */
class ExcludesListMatcher : public GlobMatcher
{
public:
	//! \brief Default constructor.
	ExcludesListMatcher();
	
	//! \brief Destructor.
	~ExcludesListMatcher();
	
	//! \name Pattern list
	//@{
	//! \brief Add one include or exclude pattern to the end of the match list.
	void addPattern(bool isInclude, const std::string & pattern);
	//@}
	
	//! \brief Performs a single string match test against testValue.
	virtual bool match(const std::string & testValue);

protected:
	//! \brief Information about one glob pattern entry in a match list.
	struct glob_list_item_t
	{
		bool m_isInclude;	//!< True if include, false if exclude.
		std::string m_glob;	//!< The glob pattern to match.
	};
	
	typedef std::vector<glob_list_item_t> glob_list_t;
	glob_list_t m_patterns;	//!< Ordered list of include and exclude patterns.
};

}; // namespace elftosb

#endif // _ExcludesListMatcher_h_