bug fixes
This commit is contained in:
parent
0448ebed7a
commit
2d191fbf94
1 changed files with 10 additions and 7 deletions
17
regex.c
17
regex.c
|
@ -134,7 +134,6 @@ bool regex_match(char *haystack, char *needle)
|
|||
bool bv[states] = { };
|
||||
// acceptance state
|
||||
accept = states - 1;
|
||||
na = false;
|
||||
|
||||
// first, decativate all states
|
||||
for (st = 0; st < states; st++)
|
||||
|
@ -154,12 +153,14 @@ bool regex_match(char *haystack, char *needle)
|
|||
if (needle[st] == '(')
|
||||
{
|
||||
// at start of group, look at variants and quantifier
|
||||
for (var = needle + st + 1; *var && *var != ')'; var = next_var(var))
|
||||
for (var = needle + st + 1;
|
||||
*var && *var != ')';
|
||||
var = next_var(var))
|
||||
bv[var - needle] = true;
|
||||
if (*var == ')')
|
||||
var++;
|
||||
q = quant(*var);
|
||||
if (strchr("*?", q))
|
||||
if (q && strchr("*?", q))
|
||||
bv[var + 1 - needle] = true;
|
||||
}
|
||||
else if (needle[st] == '|')
|
||||
|
@ -182,7 +183,7 @@ bool regex_match(char *haystack, char *needle)
|
|||
fprintf(stderr, "quant %c\n", q);
|
||||
fprintf(stderr, "suffix \"%s\"\n", needle + (q ? st + 2 : st + 1));
|
||||
nneedl = start_of_group(needle, needle + st);
|
||||
if (strchr("+*", q) && !bv[nneedl - needle])
|
||||
if (q && strchr("+*", q) && !bv[nneedl - needle])
|
||||
{
|
||||
// spicy: if the quantifier allows multiple occurences, we have to activate a previous state
|
||||
fprintf(stderr, "start of group: \"%s\"\n", nneedl);
|
||||
|
@ -197,7 +198,7 @@ bool regex_match(char *haystack, char *needle)
|
|||
// check if current needle is optional
|
||||
nneedl = next_char(needle + st);
|
||||
q = *nneedl;
|
||||
if (strchr("?*", q))
|
||||
if (q && strchr("?*", q))
|
||||
bv[nneedl + 1 - needle] = true;
|
||||
}
|
||||
}
|
||||
|
@ -206,10 +207,12 @@ bool regex_match(char *haystack, char *needle)
|
|||
for (st = accept; st > 0; st--)
|
||||
{
|
||||
// skip beginnings of groups b/c they have been handled before
|
||||
if (!bv[st-1] || needle[st-1] == '(')
|
||||
if (!bv[st-1])
|
||||
continue;
|
||||
// perform match for active state
|
||||
bv[st-1] = false;
|
||||
if (needle[st-1] == '(')
|
||||
continue;
|
||||
m = char_match(*haystack, needle + st-1, &nneedl);
|
||||
q = quant(*nneedl);
|
||||
fprintf(stderr, "state %lu: \"%s\" ~ \"%s\" => %b\n", st-1, haystack, needle + st - 1, m);
|
||||
|
@ -218,7 +221,7 @@ bool regex_match(char *haystack, char *needle)
|
|||
na = false;
|
||||
if (q)
|
||||
nneedl++;
|
||||
if (strchr("*+", q))
|
||||
if (q && strchr("*+", q))
|
||||
bv[st-1] = true;
|
||||
bv[nneedl - needle] = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue