Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
vul_reg_exp Class Reference

Pattern matching with regular expressions. More...

#include <vul_reg_exp.h>

Public Member Functions

 vul_reg_exp ()
 Creates an empty regular expression. More...
 
 vul_reg_exp (char const *s)
 Creates a regular expression from string s, and compiles s. More...
 
 vul_reg_exp (vul_reg_exp const &)
 Copy constructor. More...
 
 ~vul_reg_exp ()
 Frees space allocated for regular expression. More...
 
void compile (char const *)
 Compiles char* --> regexp. More...
 
bool find (char const *)
 true if regexp in char* arg. More...
 
bool find (std::string const &)
 true if regexp in char* arg. More...
 
std::ptrdiff_t start () const
 Returns the start index of the last item found. More...
 
std::ptrdiff_t end () const
 Returns the end index of the last item found. More...
 
bool operator== (vul_reg_exp const &) const
 Equality operator. More...
 
bool operator!= (vul_reg_exp const &r) const
 Inequality operator. More...
 
bool deep_equal (vul_reg_exp const &) const
 Same regexp and state?. More...
 
bool is_valid () const
 Returns true if a valid RE is compiled and ready for pattern matching. More...
 
void set_invalid ()
 Invalidates regular expression. More...
 
std::ptrdiff_t start (long n) const
 Return start index of nth submatch. More...
 
std::ptrdiff_t end (long n) const
 Return end index of nth submatch. More...
 
std::string match (int n) const
 Return nth submatch as a string. More...
 

Static Public Member Functions

static const char * protect (char c)
 Return an expression that will match precisely c. More...
 

Private Member Functions

void clear_bufs ()
 private function to clear startp[] and endp[]. More...
 

Private Attributes

const char * startp [vul_reg_exp_nsubexp]
 anchor point of start position for n-th matching regular expression. More...
 
const char * endp [vul_reg_exp_nsubexp]
 anchor point of end position for n-th matching regular expression. More...
 
char regstart
 Internal use only. More...
 
char reganch
 Internal use only. More...
 
const char * regmust
 Internal use only. More...
 
int regmlen
 Internal use only. More...
 
char * program
 
int progsize
 
const char * searchstring
 

Detailed Description

Pattern matching with regular expressions.

A regular expression allows a programmer to specify complex patterns that can be searched for and matched against the character string of a string object. In its simplest form, a regular expression is a sequence of characters used to search for exact character matches. However, many times the exact sequence to be found is not known, or only a match at the beginning or end of a string is desired. This regular expression class implements regular expression pattern matching as is found and implemented in many UNIX commands and utilities.

Example: The perl code

$filename =~ m"([a-z]+)\.cc";
print $1;

is written as follows in C++

vul_reg_exp re("([a-z]+)\\.cc");
re.find(filename);
std::cout << re.match(1);

The regular expression class provides a convenient mechanism for specifying and manipulating regular expressions. The regular expression object allows specification of such patterns by using the following regular expression metacharacters:

Definition at line 82 of file vul_reg_exp.h.

Constructor & Destructor Documentation

◆ vul_reg_exp() [1/3]

vul_reg_exp::vul_reg_exp ( )
inline

Creates an empty regular expression.

Definition at line 101 of file vul_reg_exp.h.

◆ vul_reg_exp() [2/3]

vul_reg_exp::vul_reg_exp ( char const *  s)
inline

Creates a regular expression from string s, and compiles s.

Definition at line 103 of file vul_reg_exp.h.

◆ vul_reg_exp() [3/3]

vul_reg_exp::vul_reg_exp ( vul_reg_exp const &  rxp)

Copy constructor.

Copies the given regular expression.

Definition at line 129 of file vul_reg_exp.cxx.

◆ ~vul_reg_exp()

vul_reg_exp::~vul_reg_exp ( )
inline

Frees space allocated for regular expression.

Definition at line 107 of file vul_reg_exp.h.

Member Function Documentation

◆ clear_bufs()

void vul_reg_exp::clear_bufs ( )
inlineprivate

private function to clear startp[] and endp[].

Definition at line 147 of file vul_reg_exp.h.

◆ compile()

void vul_reg_exp::compile ( char const *  exp)

Compiles char* --> regexp.

Compile a regular expression into internal code for later pattern matching.

Definition at line 396 of file vul_reg_exp.cxx.

◆ deep_equal()

bool vul_reg_exp::deep_equal ( vul_reg_exp const &  rxp) const

Same regexp and state?.

Returns true if have the same compiled regular expressions and the same start and end pointers.

Definition at line 172 of file vul_reg_exp.cxx.

◆ end() [1/2]

std::ptrdiff_t vul_reg_exp::end ( ) const
inline

Returns the end index of the last item found.

Definition at line 117 of file vul_reg_exp.h.

◆ end() [2/2]

std::ptrdiff_t vul_reg_exp::end ( long  n) const
inline

Return end index of nth submatch.

end(0) is the end of the full match.

Definition at line 134 of file vul_reg_exp.h.

◆ find() [1/2]

bool vul_reg_exp::find ( char const *  string)

true if regexp in char* arg.

Matches the regular expression to the given string.

Returns true if found, and sets start and end indexes accordingly.

Definition at line 952 of file vul_reg_exp.cxx.

◆ find() [2/2]

bool vul_reg_exp::find ( std::string const &  s)

true if regexp in char* arg.

Definition at line 943 of file vul_reg_exp.cxx.

◆ is_valid()

bool vul_reg_exp::is_valid ( ) const
inline

Returns true if a valid RE is compiled and ready for pattern matching.

Definition at line 125 of file vul_reg_exp.h.

◆ match()

std::string vul_reg_exp::match ( int  n) const
inline

Return nth submatch as a string.

Definition at line 136 of file vul_reg_exp.h.

◆ operator!=()

bool vul_reg_exp::operator!= ( vul_reg_exp const &  r) const
inline

Inequality operator.

Definition at line 121 of file vul_reg_exp.h.

◆ operator==()

bool vul_reg_exp::operator== ( vul_reg_exp const &  rxp) const

Equality operator.

Returns true if two regular expressions have the same compiled program for pattern matching.

Definition at line 156 of file vul_reg_exp.cxx.

◆ protect()

const char * vul_reg_exp::protect ( char  c)
static

Return an expression that will match precisely c.

The returned string is owned by the function, and will be overwritten in subsequent calls.

This should be in thread local storage.

Definition at line 327 of file vul_reg_exp.cxx.

◆ set_invalid()

void vul_reg_exp::set_invalid ( )
inline

Invalidates regular expression.

Definition at line 127 of file vul_reg_exp.h.

◆ start() [1/2]

std::ptrdiff_t vul_reg_exp::start ( ) const
inline

Returns the start index of the last item found.

Definition at line 115 of file vul_reg_exp.h.

◆ start() [2/2]

std::ptrdiff_t vul_reg_exp::start ( long  n) const
inline

Return start index of nth submatch.

start(0) is the start of the full match.

Definition at line 131 of file vul_reg_exp.h.

Member Data Documentation

◆ endp

const char* vul_reg_exp::endp[vul_reg_exp_nsubexp]
private

anchor point of end position for n-th matching regular expression.

Definition at line 87 of file vul_reg_exp.h.

◆ program

char* vul_reg_exp::program
private

Definition at line 96 of file vul_reg_exp.h.

◆ progsize

int vul_reg_exp::progsize
private

Definition at line 97 of file vul_reg_exp.h.

◆ reganch

char vul_reg_exp::reganch
private

Internal use only.

Definition at line 91 of file vul_reg_exp.h.

◆ regmlen

int vul_reg_exp::regmlen
private

Internal use only.

Definition at line 95 of file vul_reg_exp.h.

◆ regmust

const char* vul_reg_exp::regmust
private

Internal use only.

Definition at line 93 of file vul_reg_exp.h.

◆ regstart

char vul_reg_exp::regstart
private

Internal use only.

Definition at line 89 of file vul_reg_exp.h.

◆ searchstring

const char* vul_reg_exp::searchstring
private

Definition at line 98 of file vul_reg_exp.h.

◆ startp

const char* vul_reg_exp::startp[vul_reg_exp_nsubexp]
private

anchor point of start position for n-th matching regular expression.

Definition at line 85 of file vul_reg_exp.h.


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