From ca79a93d0758d375698084fa8f63eae5cb458ecb Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Thu, 17 Oct 2013 07:30:46 -0700 Subject: [PATCH] Fixed https://github.com/cesanta/slre/issues/6 --- slre.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/slre.c b/slre.c index 5ebdc6b..0060513 100644 --- a/slre.c +++ b/slre.c @@ -218,17 +218,22 @@ static int bar(const char *re, int re_len, const char *s, int s_len, ni++; } - while ((n1 = bar(re + i, step, s + j2, s_len - j2, info, bi)) > 0) { + do { + n1 = bar(re + i, step, s + j2, s_len - j2, info, bi); + j2 += n1 > 0 ? n1 : 0; + if (re[i + step] == '+' && n1 < 0) break; + if (ni >= re_len) { /* After quantifier, there is nothing */ - nj = j2 + n1; - } else if ((n2 = bar(re + ni, re_len - ni, s + j2 + n1, - s_len - (j2 + n1), info, bi)) >= 0) { - nj = j2 + n1 + n2; + nj = j2; + } else if ((n2 = bar(re + ni, re_len - ni, s + j2, + s_len - j2, info, bi)) >= 0) { + /* Regex after quantifier matched */ + nj = j2 + n2; } if (nj > j && non_greedy) break; - j2 += n1; - } + } while (n1 > 0); + DBG(("STAR/PLUS END: %d %d %d\n", j, nj, re_len - ni)); FAIL_IF(re[i + step] == '+' && nj == j, SLRE_NO_MATCH);