|
| PatternMatcher () |
| Constructor. More...
|
|
| PatternMatcher (const char *pattern, bool dottedpath, bool fullstring, bool casesensitive) |
| Constructor. More...
|
|
| ~PatternMatcher () |
| Destructor. More...
|
|
void | setPattern (const char *pattern, bool dottedpath, bool fullstring, bool casesensitive) |
| Sets the pattern to be used by subsequent calls to matches(). More...
|
|
bool | matches (const char *line) |
| Returns true if the line matches the pattern with the given settings. More...
|
|
const char * | patternPrefixMatches (const char *line, int suffixoffset) |
| 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. More...
|
|
std::string | debugStr () |
| Returns the internal representation of the pattern as a string. More...
|
|
void | dump () |
| Prints the internal representation of the pattern on the standard output. More...
|
|
Glob-style pattern matching class, adopted to special OMNeT++ requirements.
One instance represents a pattern to match.
Pattern syntax:
- ? : matches any character except '.'
- * : matches zero or more characters except '.'
- ** : matches zero or more character (any character)
- {a-z} : matches a character in range a-z
- {^a-z} : matches a character NOT in range a-z
- {32..255} : any number (ie. sequence of digits) in range 32..255 (e.g. "99")
- [32..255] : any number in square brackets in range 32..255 (e.g. "[99]")
- backslash \ : takes away the special meaning of the subsequent character
The "except '.'" phrases in the above rules apply only in "dottedpath" mode (see below).
There are three option switches (see setPattern() method):
- dottedpath: dottedpath=yes is the mode used in omnetpp.ini for matching module parameters, like this: "**.mac[*].retries=9". In this mode mode, '*' cannot "eat" dot, so it can only match one component (module name) in the path. '**' can be used to match more components. (This is similar to e.g. Java Ant's usage of the asterisk.) In dottedpath=false mode, '*' will match anything.
- fullstring: selects between full string and substring match. The pattern "ate" will match "whatever" in substring mode, but not in full string mode.
- case sensitive: selects between case sensitive and case insensitive mode.
Rule details:
- sets, negated sets: They can contain several character ranges and also enumeration of characters. For example: "{_a-zA-Z0-9}","{xyzc-f}". To include '-' in the set, put it at a position where it cannot be interpreted as character range, for example: "{a-z-}" or "{-a-z}". If you want to include '}' in the set, it must be the first character: "{}a-z}", or as a negated set: "{^}a-z}". A backslash is always taken as literal backslash (and NOT as escape character) within set definitions. When doing case-insensitive match, avoid ranges that include both alpha (a-zA-Z) and non-alpha characters, because they might cause funny results.
- numeric ranges: only nonnegative integers can be matched. The start or the end of the range (or both) can be omitted: "{10..}", "{..99}" or "{..}" are valid numeric ranges (the last one matches any number). The specification must use exactly two dots. Caveat: "*{17..19}" will match "a17","117" and "963217" as well.
const char * inet::PatternMatcher::patternPrefixMatches |
( |
const char * |
line, |
|
|
int |
suffixoffset |
|
) |
| |
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().
387 throw cRuntimeError(
"PatternMatcher: patternPrefixMatches() doesn't support case-insensitive match");
398 const char *pattstring = e.literalstring.c_str();
399 const char *p = strstr(pattstring, line + suffixoffset);
402 p += strlen(line + suffixoffset);
404 int pattsuffixlen = e.literalstring.size() - (p - pattstring);
407 return doMatch(line, 0, pattsuffixlen) ?
rest.c_str() :
nullptr;
Definition: PatternMatcher.h:82
std::string rest
Definition: PatternMatcher.h:104
std::vector< Elem > pattern
Definition: PatternMatcher.h:101
Definition: PatternMatcher.h:90
const value< double, units::C > e(1.602176487e-19)
bool doMatch(const char *line, int patternpos, int suffixlen)
Definition: PatternMatcher.cc:258
bool iscasesensitive
Definition: PatternMatcher.h:102