RegexBase.h
Classes
- RegexBase -- Abstract interface class to regular expressions for String (full description)
Interface
- Public Members
- virtual ~RegexBase()
- virtual String::size_type find(const Char *s, String::size_type len, Int &matchlen, String::size_type pos=0) const=0
- virtual String::size_type match(const Char *s, String::size_type len, String::size_type pos=0) const
- virtual String::size_type rfind(const Char *s, String::size_type len, Int &matchlen, String::size_type pos=String::npos) const
- virtual String::size_type search(const Char *s, String::size_type len, Int &matchlen, Int pos=0) const
Review Status
- Reviewed By:
- Friso Olnon
- Date Reviewed:
- 1995/03/20
- Programs:
- Tests:
Prerequisite
- Regular expression syntax
- String class
Synopsis
This class provides a standard abstract interface to regular expression
classes. This interface class is used in the String class, to enable
the use of different actual regular expression classes.
Actual regular expression classes should define the following
implementation (in addition, of course, to the standard constructors and
assignments):
- String::size_type find(const Char *s, String::size_type len,
Int &matchlen, String::size_type pos=0) const;
- Test if the regular expression occurs in string s.
The return value gives the position of the first substring
matching the regular expression (or String::npos if no match).
The length of that substring is returned in matchlen.
The string has len characters and the test starts at
position pos. The string may contain null characters.
The base class provides also default implementations of a few other methods
used in the String classes' aips++ extensions. These implementations
can, of course, be overwritten with more efficient specialised ones if
necessary:
- String::size_type match(const Char *s,
String::size_type len, String::size_type pos=0) const;
- Test if the regular expression matches string s.
The return value gives the length of the matching string part,
or String::npos if there is no match, or in case of an internal error.
The string has len characters and the test starts at
position pos. The string may contain null characters.
The default implementation checks if the regular expression is found
at position pos and with length (len-pos.
- String::size_type rfind(const Char *s, String::size_type len,
Int &matchlen, String::size_type pos=npos) const;
- Test if the regular expression occurs in string s,
searching reversed.
The return value gives the position of the first substring
matching the regular expression (or String::npos if no match).
The length of that substring is returned in matchlen.
The string has len characters and the test starts at
position pos (or at end of string).
The string may contain null characters. The default implementation
starts checking for the regular expression at pos (or at
the end of the string if that is less), and loops until it is
found. Looping is by decrementing the search position until begin of
string.
- String::size_type search(const Char *s, String::size_type len,
Int &matchlen, Int pos=0) const;
- Test if the regular expression occurs in string s.
The return value gives the position of the first substring
matching the regular expression (or String::npos if no match).
The length of that substring is returned in matchlen.
The string has len characters and the test starts at
position pos. The string may contain null characters.
Following the special rule for aips++ string methods extensions:
a negative position will indicate a reverse find. The default implementation
checks for the sign of pos and calls either find
or rfind.
It is advisable to provide (static) methods to create strings from
patterns and v.v., including file search patterns. See
Regex for an example.
Example
See examples in appropriate regular expression implementation
(e.g. Regex)
Motivation
To allow for different regular expression classes in String matches
To Do
Member Description
Destructor
virtual String::size_type find(const Char *s, String::size_type len, Int &matchlen, String::size_type pos=0) const=0
Search string s of length len, starting at position
pos</pos>. Returned is the address of the first character of
the substring found (or <src>String::npos if not found). The
matched length is returned in matchlen
virtual String::size_type match(const Char *s, String::size_type len, String::size_type pos=0) const
Match the string s of length len starting at
position pos. Return the first matched character pointer, or
String::npos if no match.
virtual String::size_type rfind(const Char *s, String::size_type len, Int &matchlen, String::size_type pos=String::npos) const
Do an rfind() on the string s of length len
starting at position pos. Return the position matched, or
String::npos
virtual String::size_type search(const Char *s, String::size_type len, Int &matchlen, Int pos=0) const
Search string s of length len, starting at position
pos</pos>. Returned is the address of the first character of
the substring found (or <src>String::npos if not found). The
matched length is returned in matchlen. If pos<0
do a reverse find.