casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
casacore::RegexBase Class Referenceabstract

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

#include <RegexBase.h>

Inheritance diagram for casacore::RegexBase:
casacore::Regex

Public Member Functions

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

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' Casacore 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 Casacore 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 casacore::RegexBase::~RegexBase ( )
virtual

Destructor.

Member Function Documentation

virtual String::size_type casacore::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 casacore::Regex.

virtual String::size_type casacore::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 casacore::Regex.

virtual String::size_type casacore::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 casacore::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 casacore::Regex.


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