* kwset.h: Likewise.
* kwset.c: Likewise.
+2010-05-23 Bruno Haible <bruno@clisp.org>
+
+ Fix bug: A regex was not regonized when it matched the end of the last
+ line and that last line was not terminated with a newline.
+ * m-regex.c (EGexecute): Don't ignore the last byte of the buffer if it
+ is not a newline.
+ * m-fgrep.c (Fexecute): Don't assume that the buffer contains a
+ newline.
+
2010-05-23 Bruno Haible <bruno@clisp.org>
Do regex matching purely with regex, not regex + dfa + kwset.
for (beg = buf; beg < buflim; beg = end)
{
end = (const char *) memchr (beg, eol, buflim - beg);
- if (end != NULL)
- end++;
- else
+ if (end == NULL)
end = buflim;
+ /* Here, either end < buflim && *end == eol, or end == buflim. */
for (i = 0; i < cregex->pcount; i++)
{
- cregex->patterns[i].regexbuf.not_eol = 0;
+ cregex->patterns[i].regexbuf.not_eol = (end == buflim);
if (0 <= (start = re_search (&(cregex->patterns[i].regexbuf), beg,
- end - beg - 1, 0,
- end - beg - 1, &(cregex->patterns[i].regs))))
+ end - beg, 0,
+ end - beg, &(cregex->patterns[i].regs))))
{
len = cregex->patterns[i].regs.end[0] - start;
if (exact)
return start;
}
if ((!cregex->match_lines && !cregex->match_words)
- || (cregex->match_lines && len == end - beg - 1))
+ || (cregex->match_lines && len == end - beg))
goto success;
/* If -w, check if the match aligns with word boundaries.
We do this iteratively because:
while (start >= 0)
{
if ((start == 0 || !IS_WORD_CONSTITUENT ((unsigned char) beg[start - 1]))
- && (len == end - beg - 1
+ && (len == end - beg
|| !IS_WORD_CONSTITUENT ((unsigned char) beg[start + len])))
goto success;
if (len > 0)
if (len <= 0)
{
/* Try looking further on. */
- if (start == end - beg - 1)
+ if (start == end - beg)
break;
++start;
- cregex->patterns[i].regexbuf.not_eol = 0;
+ cregex->patterns[i].regexbuf.not_eol = (end == buflim);
start = re_search (&(cregex->patterns[i].regexbuf), beg,
- end - beg - 1,
- start, end - beg - 1 - start,
+ end - beg,
+ start, end - beg - start,
&(cregex->patterns[i].regs));
len = cregex->patterns[i].regs.end[0] - start;
}
}
}
} /* for Regex patterns. */
+
+ if (end < buflim)
+ end++;
} /* for (beg = end ..) */
return (size_t) -1;