Commit 43bc4af0 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added String.replace implementation.

parent 7749951d
...@@ -1032,8 +1032,58 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI ...@@ -1032,8 +1032,58 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI
static HRESULT String_search(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, static HRESULT String_search(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{ {
FIXME("\n"); DispatchEx *regexp = NULL;
return E_NOTIMPL; const WCHAR *str, *cp;
match_result_t match;
VARIANT *arg;
DWORD length;
BSTR val_str;
HRESULT hres;
TRACE("\n");
hres = get_string_val(ctx, jsthis, ei, &str, &length, &val_str);
if(FAILED(hres))
return hres;
if(!arg_cnt(dp)) {
if(retv)
V_VT(retv) = VT_NULL;
SysFreeString(val_str);
return S_OK;
}
arg = get_arg(dp,0);
if(V_VT(arg) == VT_DISPATCH) {
regexp = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg));
if(regexp) {
if(!is_class(regexp, JSCLASS_REGEXP)) {
jsdisp_release(regexp);
regexp = NULL;
}
}
}
if(!regexp) {
hres = create_regexp_var(ctx, arg, NULL, &regexp);
if(FAILED(hres)) {
SysFreeString(val_str);
return hres;
}
}
cp = str;
hres = regexp_match_next(ctx, regexp, FALSE, str, length, &cp, NULL, NULL, NULL, &match);
SysFreeString(val_str);
jsdisp_release(regexp);
if(FAILED(hres))
return hres;
if(retv) {
V_VT(retv) = VT_I4;
V_I4(retv) = hres == S_OK ? match.str-str : -1;
}
return S_OK;
} }
/* ECMA-262 3rd Edition 15.5.4.13 */ /* ECMA-262 3rd Edition 15.5.4.13 */
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
*/ */
var m, re, b; var m, re, b, i, obj;
re = /a+/; re = /a+/;
ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex); ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex);
...@@ -409,4 +409,47 @@ m = re.exec(" "); ...@@ -409,4 +409,47 @@ m = re.exec(" ");
ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0"); ok(re.lastIndex === 0, "re.lastIndex = " + re.lastIndex + " expected 0");
ok(m === null, "m = " + m + " expected null"); ok(m === null, "m = " + m + " expected null");
re = /aa/g;
i = 'baacd'.search(re);
ok(i === 1, "'baacd'.search(re) = " + i);
ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
re.lastIndex = 2;
i = 'baacdaa'.search(re);
ok(i === 1, "'baacd'.search(re) = " + i);
ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
re = /aa/;
i = 'baacd'.search(re);
ok(i === 1, "'baacd'.search(re) = " + i);
ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
re.lastIndex = 2;
i = 'baacdaa'.search(re);
ok(i === 1, "'baacd'.search(re) = " + i);
ok(re.lastIndex === 3, "re.lastIndex = " + re.lastIndex);
re = /d/g;
re.lastIndex = 1;
i = 'abc'.search(re);
ok(i === -1, "'abc'.search(/d/g) = " + i);
i = 'abcdde'.search(/[df]/);
ok(i === 3, "'abc'.search(/[df]/) = " + i);
i = 'abcdde'.search(/[df]/, "a");
ok(i === 3, "'abc'.search(/[df]/) = " + i);
i = 'abcdde'.search("[df]");
ok(i === 3, "'abc'.search(/d*/) = " + i);
obj = {
toString: function() { return "abc"; }
};
i = String.prototype.search.call(obj, "b");
ok(i === 1, "String.prototype.seatch.apply(obj, 'b') = " + i);
i = " undefined ".search();
ok(i === null, "' undefined '.search() = " + i);
reportSuccess(); reportSuccess();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment