casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions
casa::RegexBase Class Reference

Abstract interface class to regular expressions for String. More...

#include <RegexBase.h>

Inheritance diagram for casa::RegexBase:
casa::Regex

List of all members.

Public Member Functions

virtual ~RegexBase ()
 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.
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.
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.
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.

Detailed Description

Abstract interface class to regular expressions for String.

Intended use:

Internal

Review Status

Reviewed By:
Friso Olnon
Date Reviewed:
1995/03/20
Test programs:
tRegex

Prerequisite

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

Definition at line 132 of file RegexBase.h.


Constructor & Destructor Documentation

virtual casa::RegexBase::~RegexBase ( ) [virtual]

Destructor.


Member Function Documentation

virtual String::size_type casa::RegexBase::find ( const Char s,
String::size_type  len,
Int matchlen,
String::size_type  pos = 0 
) const [pure virtual]

Search string s of length len, starting at position pos.

Returned is the address of the first character of the substring found (or String::npos if not found). The matched length is returned in matchlen

Implemented in casa::Regex.

virtual String::size_type casa::RegexBase::match ( const Char s,
String::size_type  len,
String::size_type  pos = 0 
) const [virtual]

Match the string s of length len starting at position pos.

Return the first matched character pointer, or String::npos if no match.

Reimplemented in casa::Regex.

virtual String::size_type casa::RegexBase::rfind ( const Char s,
String::size_type  len,
Int matchlen,
String::size_type  pos = String::npos 
) const [virtual]

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 casa::RegexBase::search ( const Char s,
String::size_type  len,
Int matchlen,
Int  pos = 0 
) const [virtual]

Search string s of length len, starting at position pos.

Returned is the address of the first character of the substring found (or String::npos if not found). The matched length is returned in matchlen. If pos<0 do a reverse find.

Reimplemented in casa::Regex.


The documentation for this class was generated from the following file: