41 #include <sys/types.h> 50 #include "BESInternalError.h" 56 BESRegex::init(
const char *t)
58 d_preg = static_cast<void*>(
new regex_t);
59 int result = regcomp(static_cast<regex_t*>(d_preg), t, REG_EXTENDED);
62 size_t msg_len = regerror(result, static_cast<regex_t*>(d_preg),
63 static_cast<char*>(NULL),
64 static_cast<size_t>(0));
65 char *msg =
new char[msg_len+1];
66 regerror(result, static_cast<regex_t*>(d_preg), msg, msg_len);
67 string err = string(
"BESRegex error: " ) + string( msg ) ;
76 regfree(static_cast<regex_t*>(d_preg));
77 delete static_cast<regex_t*>(d_preg); d_preg = 0;
105 regmatch_t *pmatch =
new regmatch_t[len+1];
108 int result = regexec(static_cast<regex_t*>(d_preg),
109 ss.substr(pos, len-pos).c_str(), len, pmatch, 0);
111 if (result == REG_NOMATCH)
114 matchnum = pmatch[0].rm_eo - pmatch[0].rm_so;
116 delete[] pmatch; pmatch = 0;
146 regmatch_t *pmatch =
new regmatch_t[len+1];
149 int result = regexec(static_cast<regex_t*>(d_preg),
150 ss.substr(pos, len-pos).c_str(), len, pmatch, 0);
151 if (result == REG_NOMATCH) {
152 delete[] pmatch; pmatch = 0;
158 for (
int i = 1; i < len; ++i)
159 if (pmatch[i].rm_so != -1 && pmatch[i].rm_so < pmatch[m].rm_so)
162 matchlen = pmatch[m].rm_eo - pmatch[m].rm_so;
163 int matchpos = pmatch[m].rm_so;
165 delete[] pmatch; pmatch = 0;
exception thrown if inernal error encountered
int match(const char *s, int len, int pos=0)
Does the pattern match.
int search(const char *s, int len, int &matchlen, int pos=0)
How much of the string does the pattern matche.
static bool size_ok(unsigned int sz, unsigned int nelem)
sanitize the size of an array. Test for integer overflow when dynamically allocating an array.