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), static_cast<char*>(NULL),
63 static_cast<size_t>(0));
64 char *msg =
new char[msg_len + 1];
65 regerror(result, static_cast<regex_t*>(d_preg), msg, msg_len);
66 string err = string(
"BESRegex error: ") + string(msg);
75 regfree(static_cast<regex_t*>(d_preg));
76 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;