54 # include "EST_unix.h"
59 #include "EST_String.h"
60 #include "EST_Regex.h"
88 static const char *fsf_magic=
"^$*+?[].\\";
89 static const char *fsf_magic_backslashed=
"()|<>";
90 static const char *spencer_magic=
"^$*+?[].()|\\\n";
91 static const char *spencer_magic_backslashed=
"<>";
98 EST_Regex RXidentifier(
"[A-Za-z_][0-9A-Za-z_]+");
100 EST_Regex RXdouble(
"-?\\(\\([0-9]+\\.[0-9]*\\)\\|\\([0-9]+\\)\\|\\(\\.[0-9]+\\)\\)\\([eE][---+]?[0-9]+\\)?");
107 #if NSUBEXP != EST_Regex_max_subexpressions
108 # error "EST_Regex_max_subexpressions must be equal to NSUBEXP"
114 compiled_match = NULL;
122 compiled_match = NULL;
130 compiled_match = NULL;
136 compiled_match = NULL;
143 free(compiled_match);
154 char *reg = walloc(
char,
size()*2+3);
157 int magic=0,last_was_bs=0;
158 const char * in_brackets=NULL;
159 const char *ex = (
size()==0)?
"":
str();
161 if (match && *ex !=
'^')
166 if (*e ==
'\\' && !last_was_bs)
172 magic=strchr((last_was_bs?fsf_magic_backslashed:fsf_magic), *e)!=NULL;
177 if (*e ==
']' && (e-in_brackets)>1)
182 if (strchr(spencer_magic_backslashed, *e))
191 if (strchr(spencer_magic, *e))
199 if (match && (e==ex || *(e-1) !=
'$'))
218 void * t =(
void *)hs_regcomp(reg);
224 cerr <<
"EST_Regex: can't compile '" <<
str() <<
"'\n";
233 void * t =(
void *)hs_regcomp(reg);
239 cerr <<
"EST_Regex: can't compile '" <<
str() <<
"'\n";
242 int EST_Regex::run(
const char *on,
int from,
int &start,
int &end,
int *starts,
int *ends)
247 if (compiled && from <= (
int)strlen(on))
249 if (hs_regexec((
hs_regexp *)compiled, on+from))
253 start = re->startp[0] - on;
254 end = re->endp[0]- on;
259 for (i=0; i<EST_Regex_max_subexpressions; i++)
260 starts[i] = re->startp[i]?(re->startp[i] - on):-1;
265 for (i=0; i<EST_Regex_max_subexpressions; i++)
266 ends[i] = re->endp[i]?(re->endp[i] - on):-1;
282 if (compiled_match && from <= (
int)strlen(on))
283 if (hs_regexec(re, on+from))
288 for (i=0; i<EST_Regex_max_subexpressions; i++)
289 starts[i] = re->startp[i]?(re->startp[i] - on):-1;
294 for (i=0; i<EST_Regex_max_subexpressions; i++)
295 ends[i] = re->endp[i]?(re->endp[i] - on):-1;
307 compiled_match = NULL;
316 compiled_match = NULL;
321 EST_Regex &EST_Regex::operator = (
const char *s)
325 compiled_match = NULL;