#include <vul_reg_exp.h>
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;
vul_reg_exp re("([a-z]+)\\.cc"); re.find(filename); vcl_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:
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 79 of file vul_reg_exp.h.
Public Member Functions | |
| vul_reg_exp () | |
| Creates an empty regular expression. | |
| vul_reg_exp (char const *s) | |
| Creates a regular expression from string s, and compiles s. | |
| vul_reg_exp (vul_reg_exp const &) | |
| Copy constructor. | |
| ~vul_reg_exp () | |
| Frees space allocated for regular expression. | |
| void | compile (char const *) |
| Compiles char* --> regexp. | |
| bool | find (char const *) |
| true if regexp in char* arg. | |
| bool | find (vcl_string const &) |
| true if regexp in char* arg. | |
| vcl_ptrdiff_t | start () const |
| Returns the start index of the last item found. | |
| vcl_ptrdiff_t | end () const |
| Returns the end index of the last item found. | |
| bool | operator== (vul_reg_exp const &) const |
| Equality operator. | |
| bool | operator!= (vul_reg_exp const &r) const |
| Inequality operator. | |
| bool | deep_equal (vul_reg_exp const &) const |
| Same regexp and state?. | |
| bool | is_valid () const |
| Returns true if a valid RE is compiled and ready for pattern matching. | |
| void | set_invalid () |
| Invalidates regular expression. | |
| vcl_ptrdiff_t | start (long n) const |
| Return start index of nth submatch. | |
| vcl_ptrdiff_t | end (long n) const |
| Return end index of nth submatch. | |
| vcl_string | match (int n) const |
| Return nth submatch as a string. | |
Static Public Member Functions | |
| static const char * | protect (char c) |
| Return an expression that will match precisely c. | |
Private Member Functions | |
| void | clear_bufs () |
| private function to clear startp[] and endp[]. | |
Private Attributes | |
| const char * | startp [vul_reg_exp_nsubexp] |
| anchor point of start position for n-th matching regular expression. | |
| const char * | endp [vul_reg_exp_nsubexp] |
| anchor point of end position for n-th matching regular expression. | |
| char | regstart |
| Internal use only. | |
| char | reganch |
| Internal use only. | |
| const char * | regmust |
| Internal use only. | |
| int | regmlen |
| Internal use only. | |
| char * | program |
| int | progsize |
| const char * | searchstring |
|
|
Creates an empty regular expression.
Definition at line 98 of file vul_reg_exp.h. |
|
|
Creates a regular expression from string s, and compiles s.
Definition at line 100 of file vul_reg_exp.h. |
|
|
Copy constructor.
Definition at line 126 of file vul_reg_exp.cxx. |
|
|
Frees space allocated for regular expression.
Definition at line 104 of file vul_reg_exp.h. |
|
|
private function to clear startp[] and endp[].
Definition at line 144 of file vul_reg_exp.h. |
|
|
Compiles char* --> regexp.
Definition at line 393 of file vul_reg_exp.cxx. |
|
|
Same regexp and state?.
Definition at line 169 of file vul_reg_exp.cxx. |
|
|
Return end index of nth submatch. end(0) is the end of the full match. Definition at line 131 of file vul_reg_exp.h. |
|
|
Returns the end index of the last item found.
Definition at line 114 of file vul_reg_exp.h. |
|
|
true if regexp in char* arg.
Definition at line 940 of file vul_reg_exp.cxx. |
|
|
true if regexp in char* arg. Returns true if found, and sets start and end indexes accordingly. Definition at line 949 of file vul_reg_exp.cxx. |
|
|
Returns true if a valid RE is compiled and ready for pattern matching.
Definition at line 122 of file vul_reg_exp.h. |
|
|
Return nth submatch as a string.
Definition at line 133 of file vul_reg_exp.h. |
|
|
Inequality operator.
Definition at line 118 of file vul_reg_exp.h. |
|
|
Equality operator.
Definition at line 153 of file vul_reg_exp.cxx. |
|
|
Return an expression that will match precisely c. The returned string is owned by the function, and will be overwritten in subsequent calls. Definition at line 324 of file vul_reg_exp.cxx. |
|
|
Invalidates regular expression.
Definition at line 124 of file vul_reg_exp.h. |
|
|
Return start index of nth submatch. start(0) is the start of the full match. Definition at line 128 of file vul_reg_exp.h. |
|
|
Returns the start index of the last item found.
Definition at line 112 of file vul_reg_exp.h. |
|
|
anchor point of end position for n-th matching regular expression.
Definition at line 84 of file vul_reg_exp.h. |
|
|
Definition at line 93 of file vul_reg_exp.h. |
|
|
Definition at line 94 of file vul_reg_exp.h. |
|
|
Internal use only.
Definition at line 88 of file vul_reg_exp.h. |
|
|
Internal use only.
Definition at line 92 of file vul_reg_exp.h. |
|
|
Internal use only.
Definition at line 90 of file vul_reg_exp.h. |
|
|
Internal use only.
Definition at line 86 of file vul_reg_exp.h. |
|
|
Definition at line 95 of file vul_reg_exp.h. |
|
|
anchor point of start position for n-th matching regular expression.
Definition at line 82 of file vul_reg_exp.h. |
1.4.4