Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/regex/regcomp.c
Show First 20 Lines • Show All 1,835 Lines • ▼ Show 20 Lines | |||||
* A char jump is the number of characters one needs to jump based on | * A char jump is the number of characters one needs to jump based on | ||||
* the value of the character from the text that was mismatched. | * the value of the character from the text that was mismatched. | ||||
*/ | */ | ||||
static void | static void | ||||
computejumps(struct parse *p, struct re_guts *g) | computejumps(struct parse *p, struct re_guts *g) | ||||
{ | { | ||||
int ch; | int ch; | ||||
int mindex; | int mindex; | ||||
int cmin, cmax; | |||||
/* | |||||
* For UTF-8 we process only the first 128 characters corresponding to | |||||
* the POSIX locale. | |||||
*/ | |||||
cmin = MB_CUR_MAX == 1 ? CHAR_MIN : 0; | |||||
cmax = MB_CUR_MAX == 1 ? CHAR_MAX : 127; | |||||
/* Avoid making errors worse */ | /* Avoid making errors worse */ | ||||
if (p->error != 0) | if (p->error != 0) | ||||
return; | return; | ||||
g->charjump = (int*) malloc((NC + 1) * sizeof(int)); | g->charjump = (int *)malloc((cmax - cmin + 1) * sizeof(int)); | ||||
if (g->charjump == NULL) /* Not a fatal error */ | if (g->charjump == NULL) /* Not a fatal error */ | ||||
return; | return; | ||||
/* Adjust for signed chars, if necessary */ | /* Adjust for signed chars, if necessary */ | ||||
g->charjump = &g->charjump[-(CHAR_MIN)]; | g->charjump = &g->charjump[-(cmin)]; | ||||
/* If the character does not exist in the pattern, the jump | /* If the character does not exist in the pattern, the jump | ||||
* is equal to the number of characters in the pattern. | * is equal to the number of characters in the pattern. | ||||
*/ | */ | ||||
for (ch = CHAR_MIN; ch < (CHAR_MAX + 1); ch++) | for (ch = cmin; ch < cmax + 1; ch++) | ||||
g->charjump[ch] = g->mlen; | g->charjump[ch] = g->mlen; | ||||
/* If the character does exist, compute the jump that would | /* If the character does exist, compute the jump that would | ||||
* take us to the last character in the pattern equal to it | * take us to the last character in the pattern equal to it | ||||
* (notice that we match right to left, so that last character | * (notice that we match right to left, so that last character | ||||
* is the first one that would be matched). | * is the first one that would be matched). | ||||
*/ | */ | ||||
for (mindex = 0; mindex < g->mlen; mindex++) | for (mindex = 0; mindex < g->mlen; mindex++) | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |