jscript: Make do_attribute_tag_format generic.

This commit is contained in:
Piotr Caban 2009-07-12 22:05:00 +02:00 committed by Alexandre Julliard
parent 0ee06df4b0
commit 16b38c457d
1 changed files with 30 additions and 10 deletions

View File

@ -177,43 +177,63 @@ static HRESULT do_attribute_tag_format(DispatchEx *dispex, LCID lcid, WORD flags
= {'<','%','s',' ','%','s','=','\"','%','s','\"','>','%','s','<','/','%','s','>',0}; = {'<','%','s',' ','%','s','=','\"','%','s','\"','>','%','s','<','/','%','s','>',0};
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
StringInstance *string; const WCHAR *str;
BSTR ret, attr_value; DWORD length;
BSTR attr_value, val_str = NULL;
HRESULT hres; HRESULT hres;
if(!is_class(dispex, JSCLASS_STRING)) { if(!is_class(dispex, JSCLASS_STRING)) {
WARN("this is not a string object\n"); VARIANT this;
return E_NOTIMPL;
}
string = (StringInstance*) dispex; 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;
}
if(arg_cnt(dp)) { if(arg_cnt(dp)) {
hres = to_string(dispex->ctx, get_arg(dp, 0), ei, &attr_value); hres = to_string(dispex->ctx, get_arg(dp, 0), ei, &attr_value);
if(FAILED(hres)) if(FAILED(hres)) {
SysFreeString(val_str);
return hres; return hres;
}
} }
else { else {
attr_value = SysAllocString(undefinedW); attr_value = SysAllocString(undefinedW);
if(!attr_value) if(!attr_value) {
SysFreeString(val_str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
}
} }
if(retv) { if(retv) {
ret = SysAllocStringLen(NULL, string->length + 2*strlenW(tagname) BSTR ret = SysAllocStringLen(NULL, length + 2*strlenW(tagname)
+ strlenW(attr) + SysStringLen(attr_value) + 9); + strlenW(attr) + SysStringLen(attr_value) + 9);
if(!ret) { if(!ret) {
SysFreeString(attr_value); SysFreeString(attr_value);
SysFreeString(val_str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
sprintfW(ret, tagfmtW, tagname, attr, attr_value, string->str, tagname); sprintfW(ret, tagfmtW, tagname, attr, attr_value, str, tagname);
V_VT(retv) = VT_BSTR; V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret; V_BSTR(retv) = ret;
} }
SysFreeString(attr_value); SysFreeString(attr_value);
SysFreeString(val_str);
return S_OK; return S_OK;
} }