Logo ROOT   6.16/01
Reference Guide
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TRegexp Class Reference

Regular expression class.

'^' // start-of-line anchor
'$' // end-of-line anchor
'.' // matches any character
'[' // start a character class
']' // end a character class
'^' // negates character class if 1st character
'*' // Kleene closure (matches 0 or more)
'+' // Positive closure (1 or more)
'?' // Optional closure (0 or 1)

Note that the '|' operator (union) is not supported, nor are parentheses (grouping). Therefore "a|b" does not match "a".

Standard classes like [:alnum:], [:alpha:], etc. are not supported, only [a-zA-Z], [^ntf] and so on.

Definition at line 31 of file TRegexp.h.

Public Types

enum  EStatVal { kOK = 0 , kIllegal , kNomem , kToolong }
 

Public Member Functions

 TRegexp (const char *re, Bool_t wildcard=kFALSE)
 Create a regular expression from the input string. More...
 
 TRegexp (const TRegexp &re)
 Copy ctor. More...
 
 TRegexp (const TString &re)
 Create a regular expression from a TString. More...
 
virtual ~TRegexp ()
 Destructor. More...
 
Ssiz_t Index (const TString &str, Ssiz_t *len, Ssiz_t start=0) const
 Find the first occurrence of the regexp in string and return the position, or -1 if there is no match. More...
 
TRegexpoperator= (const char *re)
 Assignment operator taking a char* and assigning it to a regexp. More...
 
TRegexpoperator= (const TRegexp &re)
 Assignment operator. More...
 
TRegexpoperator= (const TString &re)
 Assignment operator taking a TString. More...
 
EStatVal Status ()
 Check status of regexp. More...
 

Private Member Functions

void CopyPattern (const TRegexp &re)
 Copy the regular expression pattern. More...
 
void GenPattern (const char *re)
 Generate the regular expression pattern. More...
 
const char * MakeWildcard (const char *re)
 This routine transforms a wildcarding regular expression into a general regular expression used for pattern matching. More...
 

Private Attributes

Pattern_tfPattern
 
EStatVal fStat
 

Static Private Attributes

static const unsigned fgMaxpat = 2048
 

#include <TRegexp.h>

Member Enumeration Documentation

◆ EStatVal

Enumerator
kOK 
kIllegal 
kNomem 
kToolong 

Definition at line 34 of file TRegexp.h.

Constructor & Destructor Documentation

◆ TRegexp() [1/3]

TRegexp::TRegexp ( const char *  re,
Bool_t  wildcard = kFALSE 
)

Create a regular expression from the input string.

If wildcard is true then the input string will first be interpreted as a wildcard expression by MakeWildcard(), and the result then interpreted as a regular expression.

Definition at line 51 of file TRegexp.cxx.

◆ TRegexp() [2/3]

TRegexp::TRegexp ( const TString re)

Create a regular expression from a TString.

Definition at line 62 of file TRegexp.cxx.

◆ TRegexp() [3/3]

TRegexp::TRegexp ( const TRegexp re)

Copy ctor.

Definition at line 70 of file TRegexp.cxx.

◆ ~TRegexp()

TRegexp::~TRegexp ( )
virtual

Destructor.

Definition at line 78 of file TRegexp.cxx.

Member Function Documentation

◆ CopyPattern()

void TRegexp::CopyPattern ( const TRegexp re)
private

Copy the regular expression pattern.

Definition at line 128 of file TRegexp.cxx.

◆ GenPattern()

void TRegexp::GenPattern ( const char *  re)
private

Generate the regular expression pattern.

Definition at line 118 of file TRegexp.cxx.

◆ Index()

Ssiz_t TRegexp::Index ( const TString string,
Ssiz_t len,
Ssiz_t  i = 0 
) const

Find the first occurrence of the regexp in string and return the position, or -1 if there is no match.

Len is length of the matched string and i is the offset at which the matching should start.

Definition at line 209 of file TRegexp.cxx.

◆ MakeWildcard()

const char * TRegexp::MakeWildcard ( const char *  re)
private

This routine transforms a wildcarding regular expression into a general regular expression used for pattern matching.

When using wildcards the regular expression is assumed to be preceded by a "^" (BOL) and terminated by a "$" (EOL). Also, all "*"'s and "?"'s (closures) are assumed to be preceded by a "." (i.e. any character, except "/"'s) and all .'s are escaped (so *.ps is different from *.eps). The special treatment of "/" allows the easy matching of pathnames, e.g. "*.root" will match "aap.root", but not "pipo/aap.root".

Definition at line 145 of file TRegexp.cxx.

◆ operator=() [1/3]

TRegexp & TRegexp::operator= ( const char *  re)

Assignment operator taking a char* and assigning it to a regexp.

Definition at line 98 of file TRegexp.cxx.

◆ operator=() [2/3]

TRegexp & TRegexp::operator= ( const TRegexp re)

Assignment operator.

Definition at line 86 of file TRegexp.cxx.

◆ operator=() [3/3]

TRegexp & TRegexp::operator= ( const TString re)

Assignment operator taking a TString.

Definition at line 108 of file TRegexp.cxx.

◆ Status()

TRegexp::EStatVal TRegexp::Status ( )

Check status of regexp.

Definition at line 231 of file TRegexp.cxx.

Member Data Documentation

◆ fgMaxpat

const unsigned TRegexp::fgMaxpat = 2048
staticprivate

Definition at line 39 of file TRegexp.h.

◆ fPattern

Pattern_t* TRegexp::fPattern
private

Definition at line 37 of file TRegexp.h.

◆ fStat

EStatVal TRegexp::fStat
private

Definition at line 38 of file TRegexp.h.


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