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