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 |
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
is written as follows in C++
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:
() Saves a matched expression and uses it in a later match
Note that more than one of these metacharacters can be used in a single regular expression in order to create complex search patterns. For example, the pattern [^ab1-9] says to match any character sequence that does not begin with the characters "a", "b", or the characters "1" through "9".
Definition at line 82 of file vul_reg_exp.h.
|
inline |
Creates an empty regular expression.
Definition at line 101 of file vul_reg_exp.h.
|
inline |
Creates a regular expression from string s, and compiles s.
Definition at line 103 of file vul_reg_exp.h.
| 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.
|
inline |
Frees space allocated for regular expression.
Definition at line 107 of file vul_reg_exp.h.
|
inlineprivate |
private function to clear startp[] and endp[].
Definition at line 147 of file vul_reg_exp.h.
| 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.
| 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.
|
inline |
Returns the end index of the last item found.
Definition at line 117 of file vul_reg_exp.h.
|
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.
| 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.
| 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.
|
inline |
Returns true if a valid RE is compiled and ready for pattern matching.
Definition at line 125 of file vul_reg_exp.h.
|
inline |
Return nth submatch as a string.
Definition at line 136 of file vul_reg_exp.h.
|
inline |
Inequality operator.
Definition at line 121 of file vul_reg_exp.h.
| 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.
|
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.
|
inline |
Invalidates regular expression.
Definition at line 127 of file vul_reg_exp.h.
|
inline |
Returns the start index of the last item found.
Definition at line 115 of file vul_reg_exp.h.
|
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.
|
private |
anchor point of end position for n-th matching regular expression.
Definition at line 87 of file vul_reg_exp.h.
|
private |
Definition at line 96 of file vul_reg_exp.h.
|
private |
Definition at line 97 of file vul_reg_exp.h.
|
private |
Internal use only.
Definition at line 91 of file vul_reg_exp.h.
|
private |
Internal use only.
Definition at line 95 of file vul_reg_exp.h.
|
private |
Internal use only.
Definition at line 93 of file vul_reg_exp.h.
|
private |
Internal use only.
Definition at line 89 of file vul_reg_exp.h.
|
private |
Definition at line 98 of file vul_reg_exp.h.
|
private |
anchor point of start position for n-th matching regular expression.
Definition at line 85 of file vul_reg_exp.h.
1.8.15