66fnmatch(
const char *pattern,
const char *
string,
int )
68 return PathMatchSpec(
string, pattern) ? 0 : FNM_NOMATCH;
74std::vector<std::string>
82std::vector<std::string>
83split(
const std::string &s,
const std::string &separatorChars)
85 typedef boost::char_separator<char> CharSeparator;
86 typedef boost::tokenizer<CharSeparator> Tokenizer;
88 std::vector<std::string> result;
89 CharSeparator separators(separatorChars.c_str());
90 Tokenizer tokenizer(s, separators);
92 BOOST_FOREACH (
const std::string &i, tokenizer) {
102match(
const std::string &name,
const std::string &attribute,
103 const std::vector<std::string> &patterns,
106 bool foundMatch =
false;
107 bool foundExclusion =
false;
109 if (patterns.size() == 0) {
113 BOOST_FOREACH (
const std::string &i, patterns) {
120 bool isExclusion = i[0] ==
'-' || i[0] ==
'^';
122 const std::string pattern = isExclusion ? i.substr(1) : i;
128 if (pattern.find(
":") != std::string::npos) {
130 s = name +
":" + attribute;
137 if (fnmatch(pattern.c_str(), s.c_str(), FNM_NOESCAPE) == 0) {
139 foundExclusion =
true;
147 return foundMatch && !foundExclusion;
153match(
const std::string &name,
const std::string &attribute,
154 const std::string &patterns,
157 return match(name, attribute,
split(patterns), flags);
163match(
const std::string &attribute,
const std::vector<std::string> &patterns,
166 bool foundMatch =
false;
167 bool foundExclusion =
false;
169 if (patterns.size() == 0) {
173 BOOST_FOREACH (
const std::string &i, patterns) {
180 bool isExclusion = i[0] ==
'-' || i[0] ==
'^';
182 std::string pattern = isExclusion ? i.substr(1) : i;
185 size_t pos = pattern.find(
":");
186 if (pos != std::string::npos) {
188 pattern = pattern.substr(pos + 1);
192 if (fnmatch(pattern.c_str(), attribute.c_str(), FNM_NOESCAPE) == 0) {
194 foundExclusion =
true;
202 return foundMatch && !foundExclusion;
208match(
const std::string &attribute,
const std::string &patterns,
211 return match(attribute,
split(patterns), flags);
bool match(const std::string &name, const std::string &attribute, const std::vector< std::string > &patterns, const MatchFlags flags)
Matches a <name>:<attribute> string against a set of patterns.
FIELD3D_NAMESPACE_OPEN std::vector< std::string > split(const std::string &s)
Splits a string into a vector of strings, using ',' as the separator.
Contains functions for pattern matching field name/attributes.
std::string attribute
Optional name of the attribute the field represents.
std::string name
Optional name of the field.
#define FIELD3D_NAMESPACE_SOURCE_CLOSE