jscript: Make String_match generic.

This commit is contained in:
Piotr Caban 2009-07-12 19:51:15 +02:00 committed by Alexandre Julliard
parent 4881cf8de4
commit 0cb6bf5b28
1 changed files with 36 additions and 5 deletions

View File

@ -585,12 +585,13 @@ static HRESULT String_link(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS
static HRESULT String_match(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, static HRESULT String_match(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{ {
StringInstance *This = (StringInstance*)dispex; const WCHAR *str;
match_result_t *match_result; match_result_t *match_result;
DispatchEx *regexp; DispatchEx *regexp;
DispatchEx *array; DispatchEx *array;
VARIANT var, *arg_var; VARIANT var, *arg_var;
DWORD match_cnt, i; DWORD length, match_cnt, i;
BSTR val_str;
HRESULT hres = S_OK; HRESULT hres = S_OK;
TRACE("\n"); TRACE("\n");
@ -623,22 +624,50 @@ static HRESULT String_match(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
} }
} }
hres = regexp_match(regexp, This->str, This->length, FALSE, &match_result, &match_cnt); if(!is_class(dispex, JSCLASS_STRING)) {
VARIANT this;
V_VT(&this) = VT_DISPATCH;
V_DISPATCH(&this) = (IDispatch*)_IDispatchEx_(dispex);
hres = to_string(dispex->ctx, &this, ei, &val_str);
if(FAILED(hres)) {
jsdisp_release(regexp); jsdisp_release(regexp);
if(FAILED(hres))
return hres; return hres;
}
str = val_str;
length = SysStringLen(val_str);
}
else {
StringInstance *this = (StringInstance*)dispex;
str = this->str;
length = this->length;
}
hres = regexp_match(regexp, str, length, FALSE, &match_result, &match_cnt);
jsdisp_release(regexp);
if(FAILED(hres)) {
SysFreeString(val_str);
return hres;
}
if(!match_cnt) { if(!match_cnt) {
TRACE("no match\n"); TRACE("no match\n");
if(retv) if(retv)
V_VT(retv) = VT_NULL; V_VT(retv) = VT_NULL;
SysFreeString(val_str);
return S_OK; return S_OK;
} }
hres = create_array(dispex->ctx, match_cnt, &array); hres = create_array(dispex->ctx, match_cnt, &array);
if(FAILED(hres)) if(FAILED(hres)) {
SysFreeString(val_str);
return hres; return hres;
}
V_VT(&var) = VT_BSTR; V_VT(&var) = VT_BSTR;
@ -655,6 +684,8 @@ static HRESULT String_match(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
break; break;
} }
SysFreeString(val_str);
if(SUCCEEDED(hres) && retv) { if(SUCCEEDED(hres) && retv) {
V_VT(retv) = VT_DISPATCH; V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array); V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array);