jscript: Make String_replace generic.
This commit is contained in:
parent
0cb6bf5b28
commit
54a3fa842b
|
@ -794,11 +794,11 @@ static HRESULT rep_call(DispatchEx *func, const WCHAR *str, match_result_t *matc
|
||||||
static HRESULT String_replace(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
static HRESULT String_replace(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
|
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
|
||||||
{
|
{
|
||||||
|
const WCHAR *str;
|
||||||
DWORD parens_cnt = 0, parens_size=0, rep_len=0, length;
|
DWORD parens_cnt = 0, parens_size=0, rep_len=0, length;
|
||||||
BSTR rep_str = NULL, match_str = NULL, ret_str;
|
BSTR rep_str = NULL, match_str = NULL, ret_str, val_str = NULL;
|
||||||
DispatchEx *rep_func = NULL, *regexp = NULL;
|
DispatchEx *rep_func = NULL, *regexp = NULL;
|
||||||
match_result_t *parens = NULL, match;
|
match_result_t *parens = NULL, match;
|
||||||
const WCHAR *str;
|
|
||||||
strbuf_t ret = {NULL,0,0};
|
strbuf_t ret = {NULL,0,0};
|
||||||
BOOL gcheck = FALSE;
|
BOOL gcheck = FALSE;
|
||||||
VARIANT *arg_var;
|
VARIANT *arg_var;
|
||||||
|
@ -806,23 +806,36 @@ static HRESULT String_replace(DispatchEx *dispex, LCID lcid, WORD flags, DISPPAR
|
||||||
|
|
||||||
TRACE("\n");
|
TRACE("\n");
|
||||||
|
|
||||||
if(is_class(dispex, JSCLASS_STRING)) {
|
if(!is_class(dispex, JSCLASS_STRING)) {
|
||||||
StringInstance *string = (StringInstance*)dispex;
|
VARIANT this;
|
||||||
str = string->str;
|
|
||||||
length = string->length;
|
V_VT(&this) = VT_DISPATCH;
|
||||||
}else {
|
V_DISPATCH(&this) = (IDispatch*)_IDispatchEx_(dispex);
|
||||||
FIXME("not String this\n");
|
|
||||||
return E_NOTIMPL;
|
hres = to_string(dispex->ctx, &this, ei, &val_str);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
|
||||||
|
str = val_str;
|
||||||
|
length = SysStringLen(val_str);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
StringInstance *this = (StringInstance*)dispex;
|
||||||
|
|
||||||
|
str = this->str;
|
||||||
|
length = this->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!arg_cnt(dp)) {
|
if(!arg_cnt(dp)) {
|
||||||
if(retv) {
|
if(retv) {
|
||||||
ret_str = SysAllocString(str);
|
if(!val_str) {
|
||||||
if(!ret_str)
|
val_str = SysAllocStringLen(str, length);
|
||||||
|
if(!val_str)
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
V_VT(retv) = VT_BSTR;
|
V_VT(retv) = VT_BSTR;
|
||||||
V_BSTR(retv) = ret_str;
|
V_BSTR(retv) = val_str;
|
||||||
}
|
}
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
@ -842,9 +855,11 @@ static HRESULT String_replace(DispatchEx *dispex, LCID lcid, WORD flags, DISPPAR
|
||||||
|
|
||||||
default:
|
default:
|
||||||
hres = to_string(dispex->ctx, arg_var, ei, &match_str);
|
hres = to_string(dispex->ctx, arg_var, ei, &match_str);
|
||||||
if(FAILED(hres))
|
if(FAILED(hres)) {
|
||||||
|
SysFreeString(val_str);
|
||||||
return hres;
|
return hres;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(arg_cnt(dp) >= 2) {
|
if(arg_cnt(dp) >= 2) {
|
||||||
arg_var = get_arg(dp,1);
|
arg_var = get_arg(dp,1);
|
||||||
|
@ -936,6 +951,7 @@ static HRESULT String_replace(DispatchEx *dispex, LCID lcid, WORD flags, DISPPAR
|
||||||
jsdisp_release(rep_func);
|
jsdisp_release(rep_func);
|
||||||
if(regexp)
|
if(regexp)
|
||||||
jsdisp_release(regexp);
|
jsdisp_release(regexp);
|
||||||
|
SysFreeString(val_str);
|
||||||
SysFreeString(rep_str);
|
SysFreeString(rep_str);
|
||||||
SysFreeString(match_str);
|
SysFreeString(match_str);
|
||||||
heap_free(parens);
|
heap_free(parens);
|
||||||
|
|
Loading…
Reference in New Issue