ref: d68a6f342486ebf65e78e26fc45089c9fe96df1d
parent: 8898715c8319aa25d0bd316fedfaddbd42587bf4
author: Tor Andersson <[email protected]>
date: Fri Feb 21 13:32:35 EST 2014
More robust BoL handling.
--- a/regex.c
+++ b/regex.c
@@ -772,7 +772,7 @@
/* Match */
struct estate {
- int icase, newline;
+ int icase, newline, notbol;
const char *bol;
Resub *m;
};
@@ -919,10 +919,10 @@
s += n;
break;
case I_BOL:
- if (s == g->bol)
+ if (s == g->bol && !g->notbol)
break;
if (g->newline)
- if (isnewline(s[-1]))
+ if (s > g->bol && isnewline(s[-1]))
break;
return 0;
case I_EOL:
@@ -933,13 +933,13 @@
break;
return 0;
case I_WORD:
- n = !(s == g->bol) && iswordchar(s[-1]);
+ n = s > g->bol && iswordchar(s[-1]);
n ^= iswordchar(s[0]);
if (n)
break;
return 0;
case I_NWORD:
- n = !(s == g->bol) && iswordchar(s[-1]);
+ n = s > g->bol && iswordchar(s[-1]);
n ^= iswordchar(s[0]);
if (!n)
break;
@@ -974,7 +974,8 @@
g.icase = prog->icase;
g.newline = prog->newline;
- g.bol = eflags & REG_NOTBOL ? NULL : s;
+ g.notbol = eflags & REG_NOTBOL;
+ g.bol = s;
g.m = m ? m : gm;
for (i = 0; i < n; ++i)
g.m[i].sp = g.m[i].ep = NULL;