jscript: Make String_split generic.
This commit is contained in:
parent
2f28956f06
commit
09e1b37fea
@ -1085,28 +1085,40 @@ static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
|
|||||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
|
||||||
{
|
{
|
||||||
match_result_t *match_result = NULL;
|
match_result_t *match_result = NULL;
|
||||||
DWORD match_cnt, i, match_len = 0;
|
DWORD length, match_cnt, i, match_len = 0;
|
||||||
StringInstance *string;
|
const WCHAR *str, *ptr, *ptr2;
|
||||||
const WCHAR *ptr, *ptr2;
|
|
||||||
VARIANT *arg, var;
|
VARIANT *arg, var;
|
||||||
DispatchEx *array;
|
DispatchEx *array;
|
||||||
BSTR match_str = NULL;
|
BSTR val_str = NULL, match_str = NULL;
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
TRACE("\n");
|
TRACE("\n");
|
||||||
|
|
||||||
if(!is_class(dispex, JSCLASS_STRING)) {
|
|
||||||
FIXME("not String this\n");
|
|
||||||
return E_NOTIMPL;
|
|
||||||
}
|
|
||||||
|
|
||||||
string = (StringInstance*)dispex;
|
|
||||||
|
|
||||||
if(arg_cnt(dp) != 1) {
|
if(arg_cnt(dp) != 1) {
|
||||||
FIXME("unsupported args\n");
|
FIXME("unsupported args\n");
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
return hres;
|
||||||
|
|
||||||
|
str = val_str;
|
||||||
|
length = SysStringLen(val_str);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
StringInstance *this = (StringInstance*)dispex;
|
||||||
|
|
||||||
|
str = this->str;
|
||||||
|
length = this->length;
|
||||||
|
}
|
||||||
|
|
||||||
arg = get_arg(dp, 0);
|
arg = get_arg(dp, 0);
|
||||||
switch(V_VT(arg)) {
|
switch(V_VT(arg)) {
|
||||||
case VT_DISPATCH: {
|
case VT_DISPATCH: {
|
||||||
@ -1115,10 +1127,12 @@ static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
|
|||||||
regexp = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg));
|
regexp = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg));
|
||||||
if(regexp) {
|
if(regexp) {
|
||||||
if(is_class(regexp, JSCLASS_REGEXP)) {
|
if(is_class(regexp, JSCLASS_REGEXP)) {
|
||||||
hres = regexp_match(regexp, string->str, string->length, TRUE, &match_result, &match_cnt);
|
hres = regexp_match(regexp, str, length, TRUE, &match_result, &match_cnt);
|
||||||
jsdisp_release(regexp);
|
jsdisp_release(regexp);
|
||||||
if(FAILED(hres))
|
if(FAILED(hres)) {
|
||||||
|
SysFreeString(val_str);
|
||||||
return hres;
|
return hres;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
jsdisp_release(regexp);
|
jsdisp_release(regexp);
|
||||||
@ -1126,8 +1140,10 @@ static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
hres = to_string(dispex->ctx, arg, ei, &match_str);
|
hres = to_string(dispex->ctx, arg, ei, &match_str);
|
||||||
if(FAILED(hres))
|
if(FAILED(hres)) {
|
||||||
|
SysFreeString(val_str);
|
||||||
return hres;
|
return hres;
|
||||||
|
}
|
||||||
|
|
||||||
match_len = SysStringLen(match_str);
|
match_len = SysStringLen(match_str);
|
||||||
if(!match_len) {
|
if(!match_len) {
|
||||||
@ -1139,7 +1155,7 @@ static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
|
|||||||
hres = create_array(dispex->ctx, 0, &array);
|
hres = create_array(dispex->ctx, 0, &array);
|
||||||
|
|
||||||
if(SUCCEEDED(hres)) {
|
if(SUCCEEDED(hres)) {
|
||||||
ptr = string->str;
|
ptr = str;
|
||||||
for(i=0;; i++) {
|
for(i=0;; i++) {
|
||||||
if(match_result) {
|
if(match_result) {
|
||||||
if(i == match_cnt)
|
if(i == match_cnt)
|
||||||
@ -1177,7 +1193,7 @@ static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(SUCCEEDED(hres) && (match_str || match_result)) {
|
if(SUCCEEDED(hres) && (match_str || match_result)) {
|
||||||
DWORD len = (string->str+string->length) - ptr;
|
DWORD len = (str+length) - ptr;
|
||||||
|
|
||||||
if(len || match_str) {
|
if(len || match_str) {
|
||||||
V_VT(&var) = VT_BSTR;
|
V_VT(&var) = VT_BSTR;
|
||||||
@ -1193,6 +1209,7 @@ static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
|
|||||||
}
|
}
|
||||||
|
|
||||||
SysFreeString(match_str);
|
SysFreeString(match_str);
|
||||||
|
SysFreeString(val_str);
|
||||||
heap_free(match_result);
|
heap_free(match_result);
|
||||||
|
|
||||||
if(SUCCEEDED(hres) && retv) {
|
if(SUCCEEDED(hres) && retv) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user