Glob-style pattern matching class, adopted to special OMNeT++ requirements. One instance represents a pattern to match.
Pattern syntax:
The "except '.'" phrases in the above rules apply only in "dottedpath" mode (see below).
There are three option switches (see setPattern() method):
Rule details:
Public Member Functions | |
cPatternMatcher () | |
cPatternMatcher (const char *pattern, bool dottedpath, bool fullstring, bool casesensitive) | |
~cPatternMatcher () | |
void | setPattern (const char *pattern, bool dottedpath, bool fullstring, bool casesensitive) |
bool | matches (const char *line) const |
const char * | patternPrefixMatches (const char *line, int suffixoffset) const |
std::string | debugStr () const |
void | dump () const |
Static Public Member Functions | |
static bool | containsWildcards (const char *pattern) |
cPatternMatcher | ( | ) |
Constructor
cPatternMatcher | ( | const char * | pattern, |
bool | dottedpath, | ||
bool | fullstring, | ||
bool | casesensitive | ||
) |
Constructor
~cPatternMatcher | ( | ) |
Destructor
void setPattern | ( | const char * | pattern, |
bool | dottedpath, | ||
bool | fullstring, | ||
bool | casesensitive | ||
) |
Sets the pattern to be used by subsequent calls to matches(). See the general class description for the meaning of the rest of the arguments. Throws cException if the pattern is bogus.
bool matches | ( | const char * | line | ) | const |
Returns true if the line matches the pattern with the given settings. See setPattern().
const char* patternPrefixMatches | ( | const char * | line, |
int | suffixoffset | ||
) | const |
Similar to matches(): it returns non-nullptr iif (1) the pattern ends in a string literal (and not, say, '*' or '**') which contains the line suffix (which begins at suffixoffset characters of line) and (2) pattern matches the whole line, except that (3) in matching the pattern's last string literal, it is also accepted if line is shorter than the pattern. If the above conditions hold, it returns the rest of the pattern. The returned pointer is valid until the next call to this method.
This method is used by cIniFile's getEntriesWithPrefix()
, used e.g. to find RNG mapping entries for a module. For that, we have to find all ini file entries (keys) like "net.host1.gen.rng-NN"
where NN=0,1,2,... In cIniFile, every entry is a pattern ("**.host*.gen.rng-1"
, "**.*.gen.rng-0"
, etc.). So we'd invoke patternPrefixMatches("net.host1.gen.rng-", 13)
(i.e. suffix=".rng-") to find those entries (patterns) which can expand to "net.host1.gen.rng-0"
, "net.host1.gen.rng-1"
, etc.
See matches().
std::string debugStr | ( | ) | const |
Returns the internal representation of the pattern as a string. May be useful for debugging purposes.
void dump | ( | ) | const |
Prints the internal representation of the pattern on the standard output. May be useful for debugging purposes.
|
static |
Utility function to determine whether a given string contains wildcards. If it does not, a simple strcmp() might be a faster option than using cPatternMatcher.