mirror of
https://github.com/ccxvii/mujs.git
synced 2026-09-22 07:03:36 +08:00
Handle String.replace() when the search matches the empty string.
This commit is contained in:
@@ -19,6 +19,8 @@ int js_RegExp_prototype_exec(js_State *J, int idx, const char *text)
|
||||
if (flags & JS_REGEXP_I) opts |= REG_ICASE;
|
||||
if (flags & JS_REGEXP_M) opts |= REG_NEWLINE;
|
||||
|
||||
// TODO: global and lastIndex
|
||||
|
||||
if (!regexec(prog, text, nelem(m), m, opts)) {
|
||||
js_newarray(J);
|
||||
for (i = 0; i < nelem(m) && m[i].rm_so >= 0; ++i) {
|
||||
@@ -166,6 +168,8 @@ static int Rp_test(js_State *J, int argc)
|
||||
prog = js_toregexp(J, 0, &flags);
|
||||
text = js_tostring(J, 1);
|
||||
|
||||
// TODO: global and lastIndex
|
||||
|
||||
js_pushboolean(J, !regexec(prog, text, 0, NULL, 0));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -429,10 +429,17 @@ loop:
|
||||
|
||||
if (flags & JS_REGEXP_G) {
|
||||
source = source + m[0].rm_eo;
|
||||
if (n == 0) {
|
||||
if (*source)
|
||||
sb = sb_putc(sb, *source++);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
if (!regexec(prog, source, nelem(m), m, REG_NOTBOL))
|
||||
goto loop;
|
||||
}
|
||||
|
||||
end:
|
||||
sb = sb_puts(sb, s + n);
|
||||
sb = sb_putc(sb, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user