58 std::vector<std::string>
66 std::vector<std::string>
67 split(
const std::string &s,
const std::string &separatorChars)
69 typedef boost::char_separator<char> CharSeparator;
70 typedef boost::tokenizer<CharSeparator> Tokenizer;
72 std::vector<std::string> result;
73 CharSeparator separators(separatorChars.c_str());
74 Tokenizer tokenizer(s, separators);
76 BOOST_FOREACH (
const std::string &i, tokenizer) {
86 match(
const std::string &name,
const std::string &attribute,
87 const std::vector<std::string> &patterns,
90 bool foundMatch =
false;
91 bool foundExclusion =
false;
93 if (patterns.size() == 0) {
97 BOOST_FOREACH (
const std::string &i, patterns) {
104 bool isExclusion = i[0] ==
'-' || i[0] ==
'^';
106 const std::string pattern = isExclusion ? i.substr(1) : i;
112 if (pattern.find(
":") != std::string::npos) {
114 s = name +
":" + attribute;
121 if (fnmatch(pattern.c_str(), s.c_str(), FNM_NOESCAPE) == 0) {
123 foundExclusion =
true;
131 return foundMatch && !foundExclusion;
137 match(
const std::string &name,
const std::string &attribute,
138 const std::string &patterns,
141 return match(name, attribute,
split(patterns), flags);
147 match(
const std::string &attribute,
const std::vector<std::string> &patterns,
150 bool foundMatch =
false;
151 bool foundExclusion =
false;
153 if (patterns.size() == 0) {
157 BOOST_FOREACH (
const std::string &i, patterns) {
164 bool isExclusion = i[0] ==
'-' || i[0] ==
'^';
166 std::string pattern = isExclusion ? i.substr(1) : i;
169 size_t pos = pattern.find(
":");
170 if (pos != std::string::npos) {
172 pattern = pattern.substr(pos + 1);
176 if (fnmatch(pattern.c_str(), attribute.c_str(), FNM_NOESCAPE) == 0) {
178 foundExclusion =
true;
186 return foundMatch && !foundExclusion;
192 match(
const std::string &attribute,
const std::string &patterns,
195 return match(attribute,
split(patterns), flags);
#define FIELD3D_NAMESPACE_SOURCE_CLOSE
Contains functions for pattern matching field name/attributes.
std::string attribute
Optional name of the attribute the field represents.
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.
std::string name
Optional name of the field.