41 #include <sys/types.h>
50 #include "BESInternalError.h"
56 BESRegex::init(
const char *t)
59 d_preg =
static_cast<void*
>(
new regex_t);
60 int result = regcomp(
static_cast<regex_t*
>(d_preg), t, REG_EXTENDED);
63 size_t msg_len = regerror(result,
static_cast<regex_t*
>(d_preg),
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;
110 regmatch_t *pmatch =
new regmatch_t[len+1];
113 int result = regexec(
static_cast<regex_t*
>(d_preg),
114 ss.substr(pos, len-pos).c_str(), len, pmatch, 0);
116 if (result == REG_NOMATCH)
119 matchnum = pmatch[0].rm_eo - pmatch[0].rm_so;
121 delete[] pmatch; pmatch = 0;
151 regmatch_t *pmatch =
new regmatch_t[len+1];
154 int result = regexec(
static_cast<regex_t*
>(d_preg),
155 ss.substr(pos, len-pos).c_str(), len, pmatch, 0);
156 if (result == REG_NOMATCH) {
157 delete[] pmatch; pmatch = 0;
163 for (
int i = 1; i < len; ++i)
164 if (pmatch[i].rm_so != -1 && pmatch[i].rm_so < pmatch[m].rm_so)
167 matchlen = pmatch[m].rm_eo - pmatch[m].rm_so;
168 int matchpos = pmatch[m].rm_so;
170 delete[] pmatch; pmatch = 0;
exception thrown if internal error encountered
int search(const char *s, int len, int &matchlen, int pos=0)
How much of the string does the pattern matche.
int match(const char *s, int len, int pos=0)
Does the pattern match.
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.