xref: /netbsd-src/external/bsd/elftosb/dist/common/GlobMatcher.h (revision 993229b6fea628ff8b1fa09146c80b0cfb2768eb)
1 /*
2  * File:	GlobMatcher.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_GlobMatcher_h_)
8 #define _GlobMatcher_h_
9 
10 #include "StringMatcher.h"
11 
12 namespace elftosb
13 {
14 
15 /*!
16  * \brief This class uses glob pattern matching to match strings.
17  *
18  * Glob patterns:
19  *	- *	matches zero or more characters
20  *	- ?	matches any single character
21  *	- [set]	matches any character in the set
22  *	- [^set]	matches any character NOT in the set
23  *		where a set is a group of characters or ranges. a range
24  *		is written as two characters seperated with a hyphen: a-z denotes
25  *		all characters between a to z inclusive.
26  *	- [-set]	set matches a literal hypen and any character in the set
27  *	- []set]	matches a literal close bracket and any character in the set
28  *
29  *	- char	matches itself except where char is '*' or '?' or '['
30  *	- \\char	matches char, including any pattern character
31  *
32  * Examples:
33  *	- a*c		ac abc abbc ...
34  *	- a?c		acc abc aXc ...
35  *	- a[a-z]c		aac abc acc ...
36  *	- a[-a-z]c	a-c aac abc ...
37  */
38 class GlobMatcher : public StringMatcher
39 {
40 public:
41 	//! \brief Constructor.
GlobMatcher(const std::string & pattern)42 	GlobMatcher(const std::string & pattern)
43 	:	StringMatcher(), m_pattern(pattern)
44 	{
45 	}
46 
47 	//! \brief Returns whether \a testValue matches the glob pattern.
48 	virtual bool match(const std::string & testValue);
49 
50 protected:
51 	std::string m_pattern;	//!< The glob pattern to match against.
52 
53 	//! \brief Glob implementation.
54 	bool globMatch(const char * str, const char * p);
55 };
56 
57 }; // namespace elftosb
58 
59 #endif // _GlobMatcher_h_
60