Commit 19c30897 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

msxml3: Simplify ::appendData() for Text, Comment and CDATA nodes.

parent 02066602
...@@ -582,26 +582,30 @@ static HRESULT WINAPI domcdata_appendData( ...@@ -582,26 +582,30 @@ static HRESULT WINAPI domcdata_appendData(
BSTR p) BSTR p)
{ {
domcdata *This = impl_from_IXMLDOMCDATASection( iface ); domcdata *This = impl_from_IXMLDOMCDATASection( iface );
xmlChar *pContent; HRESULT hr;
HRESULT hr = S_FALSE; BSTR data;
LONG p_len;
TRACE("%p %p\n", This, debugstr_w(p)); TRACE("%p %p\n", This, debugstr_w(p));
/* Nothing to do if NULL or an Empty string passed in. */ /* Nothing to do if NULL or an Empty string passed in. */
if(SysStringLen(p) == 0) if((p_len = SysStringLen(p)) == 0) return S_OK;
return S_OK;
pContent = xmlChar_from_wchar( p ); hr = IXMLDOMCDATASection_get_data(iface, &data);
if(pContent) if(hr == S_OK)
{ {
if(xmlTextConcat(This->node.node, pContent, SysStringLen(p) ) == 0) LONG len = SysStringLen(data);
hr = S_OK; BSTR str = SysAllocStringLen(NULL, p_len + len);
else
hr = E_FAIL; memcpy(str, data, len*sizeof(WCHAR));
memcpy(&str[len], p, p_len*sizeof(WCHAR));
str[len+p_len] = 0;
hr = IXMLDOMCDATASection_put_data(iface, str);
SysFreeString(str);
SysFreeString(data);
} }
else
hr = E_FAIL;
heap_free(pContent);
return hr; return hr;
} }
......
...@@ -576,40 +576,30 @@ static HRESULT WINAPI domcomment_appendData( ...@@ -576,40 +576,30 @@ static HRESULT WINAPI domcomment_appendData(
BSTR p) BSTR p)
{ {
domcomment *This = impl_from_IXMLDOMComment( iface ); domcomment *This = impl_from_IXMLDOMComment( iface );
xmlChar *pContent; HRESULT hr;
HRESULT hr = S_FALSE; BSTR data;
LONG p_len;
TRACE("%p\n", iface); TRACE("%p %s\n", This, debugstr_w(p));
/* Nothing to do if NULL or an Empty string passed in. */ /* Nothing to do if NULL or an Empty string passed in. */
if(p == NULL || SysStringLen(p) == 0) if((p_len = SysStringLen(p)) == 0) return S_OK;
return S_OK;
pContent = xmlChar_from_wchar( p ); hr = IXMLDOMComment_get_data(iface, &data);
if(pContent) if(hr == S_OK)
{
/* Older versions of libxml < 2.6.27 didn't correctly support
xmlTextConcat on Comment nodes. Fallback to setting the
contents directly if xmlTextConcat fails.
*/
if(xmlTextConcat(This->node.node, pContent, SysStringLen(p) ) == 0)
hr = S_OK;
else
{
xmlChar *pNew;
pNew = xmlStrcat(xmlNodeGetContent(This->node.node), pContent);
if(pNew)
{ {
xmlNodeSetContent(This->node.node, pNew); LONG len = SysStringLen(data);
hr = S_OK; BSTR str = SysAllocStringLen(NULL, p_len + len);
}
else memcpy(str, data, len*sizeof(WCHAR));
hr = E_FAIL; memcpy(&str[len], p, p_len*sizeof(WCHAR));
} str[len+p_len] = 0;
HeapFree( GetProcessHeap(), 0, pContent );
hr = IXMLDOMComment_put_data(iface, str);
SysFreeString(str);
SysFreeString(data);
} }
else
hr = E_FAIL;
return hr; return hr;
} }
......
...@@ -584,25 +584,30 @@ static HRESULT WINAPI domtext_appendData( ...@@ -584,25 +584,30 @@ static HRESULT WINAPI domtext_appendData(
BSTR p) BSTR p)
{ {
domtext *This = impl_from_IXMLDOMText( iface ); domtext *This = impl_from_IXMLDOMText( iface );
xmlChar *pContent; HRESULT hr;
HRESULT hr = S_FALSE; BSTR data;
LONG p_len;
TRACE("%p\n", iface); TRACE("%p %s\n", This, debugstr_w(p));
/* Nothing to do if NULL or an Empty string passed in. */ /* Nothing to do if NULL or an Empty string passed in. */
if(SysStringLen(p) == 0) return S_OK; if((p_len = SysStringLen(p)) == 0) return S_OK;
pContent = xmlChar_from_wchar( p ); hr = IXMLDOMText_get_data(iface, &data);
if(pContent) if(hr == S_OK)
{ {
if(xmlTextConcat(This->node.node, pContent, SysStringLen(p)) == 0) LONG len = SysStringLen(data);
hr = S_OK; BSTR str = SysAllocStringLen(NULL, p_len + len);
else
hr = E_FAIL; memcpy(str, data, len*sizeof(WCHAR));
heap_free( pContent ); memcpy(&str[len], p, p_len*sizeof(WCHAR));
str[len+p_len] = 0;
hr = IXMLDOMText_put_data(iface, str);
SysFreeString(str);
SysFreeString(data);
} }
else
hr = E_FAIL;
return hr; return hr;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment