From 0cb6bf5b28486dea0b04a809988405d39e136052 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Sun, 12 Jul 2009 19:51:15 +0200 Subject: [PATCH] jscript: Make String_match generic. --- dlls/jscript/string.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 0c9e3d66d20..a291ea1e7de 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -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, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { - StringInstance *This = (StringInstance*)dispex; + const WCHAR *str; match_result_t *match_result; DispatchEx *regexp; DispatchEx *array; VARIANT var, *arg_var; - DWORD match_cnt, i; + DWORD length, match_cnt, i; + BSTR val_str; HRESULT hres = S_OK; 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); + 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)) + if(FAILED(hres)) { + SysFreeString(val_str); return hres; + } if(!match_cnt) { TRACE("no match\n"); if(retv) V_VT(retv) = VT_NULL; + + SysFreeString(val_str); return S_OK; } hres = create_array(dispex->ctx, match_cnt, &array); - if(FAILED(hres)) + if(FAILED(hres)) { + SysFreeString(val_str); return hres; + } V_VT(&var) = VT_BSTR; @@ -655,6 +684,8 @@ static HRESULT String_match(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM break; } + SysFreeString(val_str); + if(SUCCEEDED(hres) && retv) { V_VT(retv) = VT_DISPATCH; V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array); -- 2.11.4.GIT