PatternMatch.cpp File Reference
`#include "PatternMatch.h"`
`#include <fnmatch.h>`

Go to the source code of this file.

## Functions

bool | match (const FieldRes *f, const std::string &patterns, const MatchFlags flags)
bool | match (const FieldRes *f, const std::vector< std::string > &patterns, const MatchFlags flags)
| Matches a field's name and attribute against a set of patterns.
bool | match (const std::string &attribute, const std::string &patterns, const MatchFlags flags)
bool | match (const std::string &attribute, const std::vector< std::string > &patterns, const MatchFlags flags)
| Matches an <attribute> string against a set of patterns.
bool | match (const std::string &name, const std::string &attribute, const std::string &patterns, const MatchFlags 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.
std::vector< std::string > | split (const std::string &s, const std::string &separatorChars)
| Splits a string into a vector of strings, given separator characters.

## Detailed Description

Contains pattern matching implementations

Definition in file PatternMatch.cpp.

## Function Documentation

## split() [1/2]

FIELD3D_NAMESPACE_OPEN std::vector< std::string > split | ( | const std::string & | s | ) |

Splits a string into a vector of strings, using ',' as the separator.

Definition at line 75 of file PatternMatch.cpp.

{
return split(s, " ");
}
split
FIELD3D_NAMESPACE_OPEN std::vector< std::string > split(const std::string &s)
Splits a string into a vector of strings, using ',' as the separator.
Definition PatternMatch.cpp:75

References split().

Referenced by match(), match(), match(), and split().

## split() [2/2]

std::vector< std::string > split | ( | const std::string & | s,
|  | const std::string & | separatorChars )

Splits a string into a vector of strings, given separator characters.

Definition at line 83 of file PatternMatch.cpp.

{
typedef boost::char_separator<char> CharSeparator;
typedef boost::tokenizer<CharSeparator> Tokenizer;
std::vector<std::string> result;
CharSeparator separators(separatorChars.c_str());
Tokenizer tokenizer(s, separators);
BOOST_FOREACH (const std::string &i, tokenizer) {
result.push_back(i);
}
return result;
}

## match() [1/6]

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.

Definition at line 102 of file PatternMatch.cpp.

{
bool foundMatch = false;
bool foundExclusion = false;
if (patterns.size() == 0) {
return flags && MatchEmptyPattern;
}
BOOST_FOREACH (const std::string &i, patterns) {
if (i.size() == 0) {
continue;
}
// Check exclusion string
bool isExclusion = i[0] == '-' || i[0] == '^';
// Update string
const std::string pattern = isExclusion ? i.substr(1) : i;
// String to match
std::string s;
// Determine type of matching
if (pattern.find(":") != std::string::npos) {
// Pattern includes separator. Match against name:attribute
s = name + ":" + attribute;
} else {
// No separator. Just match against attribute
s = attribute;
}
// Match with wildcards
if (fnmatch(pattern.c_str(), s.c_str(), FNM_NOESCAPE) == 0) {
if (isExclusion) {
foundExclusion = true;
} else {
foundMatch = true;
}
}
}
return foundMatch && !foundExclusion;
}
MatchEmptyPattern
@ MatchEmptyPattern
Definition PatternMatch.h:66

References MatchEmptyPattern.

Referenced by Sparse::CheckAllEqual< Data_T >::check(), Curve< T >::CheckTEqual::CheckTEqual(), Curve< T >::CheckTGreaterThan::CheckTGreaterThan(), match(), match(), match(), and match().

## match() [2/6]

bool match | ( | const std::string & | name,
|  | const std::string & | attribute,
|  | const std::string & | patterns,
|  | const MatchFlags | flags )

Definition at line 153 of file PatternMatch.cpp.

{
return match(name, attribute, split(patterns), flags);
}
match
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.
Definition PatternMatch.cpp:102

References match(), and split().

## match() [3/6]

bool match | ( | const std::string & | attribute,
|  | const std::vector< std::string > & | patterns,
|  | const MatchFlags | flags )

Matches an <attribute> string against a set of patterns.

Definition at line 163 of file PatternMatch.cpp.

{
bool foundMatch = false;
bool foundExclusion = false;
if (patterns.size() == 0) {
return flags && MatchEmptyPattern;
}
BOOST_FOREACH (const std::string &i, patterns) {
if (i.size() == 0) {
continue;
}
// Check exclusion string
bool isExclusion = i[0] == '-' || i[0] == '^';
// Update string
std::string pattern = isExclusion ? i.substr(1) : i;
// Determine type of matching
size_t pos = pattern.find(":");
if (pos != std::string::npos) {
// Pattern includes separator. Just use second half
pattern = pattern.substr(pos + 1);
}
// Match with wildcards
if (fnmatch(pattern.c_str(), attribute.c_str(), FNM_NOESCAPE) == 0) {
if (isExclusion) {
foundExclusion = true;
} else {
foundMatch = true;
}
}
}
return foundMatch && !foundExclusion;
}

References MatchEmptyPattern.

## match() [4/6]

bool match | ( | const std::string & | attribute,
|  | const std::string & | patterns,
|  | const MatchFlags | flags )

Definition at line 208 of file PatternMatch.cpp.

{
return match(attribute, split(patterns), flags);
}

References match(), and split().

## match() [5/6]

bool match | ( | const FieldRes * | f,
|  | const std::vector< std::string > & | patterns,
|  | const MatchFlags | flags )

Matches a field's name and attribute against a set of patterns.

Definition at line 217 of file PatternMatch.cpp.

{
return match(f->name, f->attribute, patterns, flags);
}
FieldBase::attribute
std::string attribute
Optional name of the attribute the field represents.
Definition Field.h:173
FieldBase::name
std::string name
Optional name of the field.
Definition Field.h:171

References FieldBase::attribute, match(), and FieldBase::name.

## match() [6/6]

bool match | ( | const FieldRes * | f,
|  | const std::string & | patterns,
|  | const MatchFlags | flags )

Definition at line 226 of file PatternMatch.cpp.

{
return match(f->name, f->attribute, split(patterns), flags);
}
split
std::vector< std::string > split(const std::string &s)
Splits a string into a vector of strings, using ',' as the separator.
Definition PatternMatch.cpp:75

References FieldBase::attribute, match(), FieldBase::name, and split().