mirror of
https://github.com/cesanta/slre.git
synced 2024-11-24 11:25:30 +00:00
Fix #14
This commit is contained in:
parent
af4f5e563c
commit
deb7c0dddf
8
slre.c
8
slre.c
@ -231,7 +231,11 @@ static int bar(const char *re, int re_len, const char *s, int s_len,
|
|||||||
if (nj > j && non_greedy) break;
|
if (nj > j && non_greedy) break;
|
||||||
} while (n1 > 0);
|
} while (n1 > 0);
|
||||||
|
|
||||||
if (n1 < 0 && re[i + step] == '*' &&
|
/*
|
||||||
|
* Even if we found one or more pattern, this branch will be executed,
|
||||||
|
* changing the next captures.
|
||||||
|
*/
|
||||||
|
if (n1 < 0 && n1 < 0 && re[i + step] == '*' &&
|
||||||
(n2 = bar(re + ni, re_len - ni, s + j, s_len - j, info, bi)) > 0) {
|
(n2 = bar(re + ni, re_len - ni, s + j, s_len - j, info, bi)) > 0) {
|
||||||
nj = j + n2;
|
nj = j + n2;
|
||||||
}
|
}
|
||||||
@ -275,7 +279,7 @@ static int bar(const char *re, int re_len, const char *s, int s_len,
|
|||||||
|
|
||||||
DBG(("CAPTURED [%.*s] [%.*s]:%d\n", step, re + i, s_len - j, s + j, n));
|
DBG(("CAPTURED [%.*s] [%.*s]:%d\n", step, re + i, s_len - j, s + j, n));
|
||||||
FAIL_IF(n < 0, n);
|
FAIL_IF(n < 0, n);
|
||||||
if (info->caps != NULL) {
|
if (info->caps != NULL && n > 0) {
|
||||||
info->caps[bi - 1].ptr = s + j;
|
info->caps[bi - 1].ptr = s + j;
|
||||||
info->caps[bi - 1].len = n;
|
info->caps[bi - 1].len = n;
|
||||||
}
|
}
|
||||||
|
10
unit_test.c
10
unit_test.c
@ -258,6 +258,16 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
/* Example more complex regular expression */
|
||||||
|
static const char * str = "aa 1234 xy\nz";
|
||||||
|
static const char * regex = "aa ([0-9]*) *([x-z]*)";
|
||||||
|
struct slre_cap caps[2];
|
||||||
|
ASSERT(slre_match(regex, str, strlen(str), caps, 2, 0) > 0);
|
||||||
|
ASSERT(caps[0].len == 4);
|
||||||
|
ASSERT(caps[1].len == 2); /* Fails here */
|
||||||
|
}
|
||||||
|
|
||||||
printf("Unit test %s (total test: %d, failed tests: %d)\n",
|
printf("Unit test %s (total test: %d, failed tests: %d)\n",
|
||||||
static_failed_tests > 0 ? "FAILED" : "PASSED",
|
static_failed_tests > 0 ? "FAILED" : "PASSED",
|
||||||
static_total_tests, static_failed_tests);
|
static_total_tests, static_failed_tests);
|
||||||
|
Loading…
Reference in New Issue
Block a user