MCPcopy Create free account
hub / github.com/boostorg/build / regcomp

Function regcomp

src/engine/regexp.cpp:217–295  ·  view source on GitHub ↗

- regcomp - compile a regular expression into internal code * * We can't allocate space until we know how big the compiled form will be, * but we can't compile it (and thus know how big it is) until we've got a * place to put the code. So we cheat: we compile it twice, once with code * generation turned off and size counting turned on, and once "for real". * This also means that we don't a

Source from the content-addressed store, hash-verified

215 * of the structure of the compiled regexp.
216 */
217regexp *
218regcomp( const char *exp )
219{
220 regexp *r;
221 char *scan;
222 char *longest;
223 int32_t len;
224 int32_t flags;
225
226 if (exp == NULL)
227 FAIL("NULL argument");
228
229 /* First pass: determine size, legality. */
230#ifdef notdef
231 if (exp[0] == '.' && exp[1] == '*') exp += 2; /* aid grep */
232#endif
233 regparse = (char *)exp;
234 regnpar = 1;
235 regsize = 0;
236 regcode = &regdummy;
237 regc(MAGIC);
238 if (reg(0, &flags) == NULL)
239 return(NULL);
240
241 /* Small enough for pointer-storage convention? */
242 if (regsize >= 32767L) /* Probably could be 65535L. */
243 FAIL("regexp too big");
244
245 /* Allocate space. */
246 r = (regexp *)BJAM_MALLOC(sizeof(regexp) + regsize);
247 if (r == NULL)
248 FAIL("out of space");
249
250 /* Second pass: emit code. */
251 regparse = (char *)exp;
252 regnpar = 1;
253 regcode = r->program;
254 regc(MAGIC);
255 if (reg(0, &flags) == NULL)
256 return(NULL);
257
258 /* Dig out information for optimizations. */
259 r->regstart = '\0'; /* Worst-case defaults. */
260 r->reganch = 0;
261 r->regmust = NULL;
262 r->regmlen = 0;
263 scan = r->program+1; /* First BRANCH. */
264 if (OP(regnext(scan)) == END) { /* Only one top-level choice. */
265 scan = OPERAND(scan);
266
267 /* Starting-point info. */
268 if (OP(scan) == EXACTLY)
269 r->regstart = *OPERAND(scan);
270 else if (OP(scan) == BOL)
271 r->reganch++;
272
273 /*
274 * If there's something expensive in the r.e., find the

Callers 1

regex_compileFunction · 0.85

Calls 3

regcFunction · 0.85
regFunction · 0.85
regnextFunction · 0.85

Tested by

no test coverage detected