msxml3: Simplify ::insertData() for Text, Comment and CDATA nodes.
This commit is contained in:
parent
b8282638bb
commit
88d8218731
|
@ -585,10 +585,10 @@ static HRESULT WINAPI domcdata_appendData(
|
||||||
xmlChar *pContent;
|
xmlChar *pContent;
|
||||||
HRESULT hr = S_FALSE;
|
HRESULT hr = S_FALSE;
|
||||||
|
|
||||||
TRACE("%p\n", iface);
|
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(p == NULL || SysStringLen(p) == 0)
|
if(SysStringLen(p) == 0)
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
||||||
pContent = xmlChar_from_wchar( p );
|
pContent = xmlChar_from_wchar( p );
|
||||||
|
@ -611,16 +611,14 @@ static HRESULT WINAPI domcdata_insertData(
|
||||||
LONG offset, BSTR p)
|
LONG offset, BSTR p)
|
||||||
{
|
{
|
||||||
domcdata *This = impl_from_IXMLDOMCDATASection( iface );
|
domcdata *This = impl_from_IXMLDOMCDATASection( iface );
|
||||||
xmlChar *pXmlContent;
|
HRESULT hr;
|
||||||
BSTR sNewString;
|
BSTR data;
|
||||||
HRESULT hr = S_FALSE;
|
LONG p_len;
|
||||||
LONG nLength = 0, nLengthP = 0;
|
|
||||||
xmlChar *str = NULL;
|
|
||||||
|
|
||||||
TRACE("%p\n", This);
|
TRACE("%p %d %s\n", This, offset, debugstr_w(p));
|
||||||
|
|
||||||
/* If have a NULL or empty string, don't do anything. */
|
/* If have a NULL or empty string, don't do anything. */
|
||||||
if(SysStringLen(p) == 0)
|
if((p_len = SysStringLen(p)) == 0)
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
||||||
if(offset < 0)
|
if(offset < 0)
|
||||||
|
@ -628,48 +626,29 @@ static HRESULT WINAPI domcdata_insertData(
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
pXmlContent = xmlNodeGetContent(This->node.node);
|
hr = IXMLDOMCDATASection_get_data(iface, &data);
|
||||||
if(pXmlContent)
|
if(hr == S_OK)
|
||||||
{
|
{
|
||||||
BSTR sContent = bstr_from_xmlChar( pXmlContent );
|
LONG len = SysStringLen(data);
|
||||||
nLength = SysStringLen(sContent);
|
BSTR str;
|
||||||
nLengthP = SysStringLen(p);
|
|
||||||
|
|
||||||
if(nLength < offset)
|
if(len < offset)
|
||||||
{
|
{
|
||||||
SysFreeString(sContent);
|
SysFreeString(data);
|
||||||
xmlFree(pXmlContent);
|
|
||||||
|
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
sNewString = SysAllocStringLen(NULL, nLength + nLengthP + 1);
|
str = SysAllocStringLen(NULL, len + p_len);
|
||||||
if(sNewString)
|
/* start part, supplied string and end part */
|
||||||
{
|
memcpy(str, data, offset*sizeof(WCHAR));
|
||||||
if(offset > 0)
|
memcpy(&str[offset], p, p_len*sizeof(WCHAR));
|
||||||
memcpy(sNewString, sContent, offset * sizeof(WCHAR));
|
memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
|
||||||
|
str[len+p_len] = 0;
|
||||||
|
|
||||||
memcpy(&sNewString[offset], p, nLengthP * sizeof(WCHAR));
|
hr = IXMLDOMCDATASection_put_data(iface, str);
|
||||||
|
|
||||||
if(offset+nLengthP < nLength)
|
SysFreeString(str);
|
||||||
memcpy(&sNewString[offset+nLengthP], &sContent[offset], (nLength-offset) * sizeof(WCHAR));
|
SysFreeString(data);
|
||||||
|
|
||||||
sNewString[nLengthP + nLength] = 0;
|
|
||||||
|
|
||||||
str = xmlChar_from_wchar(sNewString);
|
|
||||||
if(str)
|
|
||||||
{
|
|
||||||
xmlNodeSetContent(This->node.node, str);
|
|
||||||
hr = S_OK;
|
|
||||||
}
|
|
||||||
heap_free(str);
|
|
||||||
|
|
||||||
SysFreeString(sNewString);
|
|
||||||
}
|
|
||||||
|
|
||||||
SysFreeString(sContent);
|
|
||||||
|
|
||||||
xmlFree(pXmlContent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
|
|
|
@ -619,16 +619,14 @@ static HRESULT WINAPI domcomment_insertData(
|
||||||
LONG offset, BSTR p)
|
LONG offset, BSTR p)
|
||||||
{
|
{
|
||||||
domcomment *This = impl_from_IXMLDOMComment( iface );
|
domcomment *This = impl_from_IXMLDOMComment( iface );
|
||||||
xmlChar *pXmlContent;
|
HRESULT hr;
|
||||||
BSTR sNewString;
|
BSTR data;
|
||||||
HRESULT hr = S_FALSE;
|
LONG p_len;
|
||||||
LONG nLength = 0, nLengthP = 0;
|
|
||||||
xmlChar *str = NULL;
|
|
||||||
|
|
||||||
TRACE("%p %d %p\n", iface, offset, p);
|
TRACE("%p %d %s\n", This, offset, debugstr_w(p));
|
||||||
|
|
||||||
/* If have a NULL or empty string, don't do anything. */
|
/* If have a NULL or empty string, don't do anything. */
|
||||||
if(SysStringLen(p) == 0)
|
if((p_len = SysStringLen(p)) == 0)
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
||||||
if(offset < 0)
|
if(offset < 0)
|
||||||
|
@ -636,48 +634,29 @@ static HRESULT WINAPI domcomment_insertData(
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
pXmlContent = xmlNodeGetContent(This->node.node);
|
hr = IXMLDOMComment_get_data(iface, &data);
|
||||||
if(pXmlContent)
|
if(hr == S_OK)
|
||||||
{
|
{
|
||||||
BSTR sContent = bstr_from_xmlChar( pXmlContent );
|
LONG len = SysStringLen(data);
|
||||||
nLength = SysStringLen(sContent);
|
BSTR str;
|
||||||
nLengthP = SysStringLen(p);
|
|
||||||
|
|
||||||
if(nLength < offset)
|
if(len < offset)
|
||||||
{
|
{
|
||||||
SysFreeString(sContent);
|
SysFreeString(data);
|
||||||
xmlFree(pXmlContent);
|
|
||||||
|
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
sNewString = SysAllocStringLen(NULL, nLength + nLengthP + 1);
|
str = SysAllocStringLen(NULL, len + p_len);
|
||||||
if(sNewString)
|
/* start part, supplied string and end part */
|
||||||
{
|
memcpy(str, data, offset*sizeof(WCHAR));
|
||||||
if(offset > 0)
|
memcpy(&str[offset], p, p_len*sizeof(WCHAR));
|
||||||
memcpy(sNewString, sContent, offset * sizeof(WCHAR));
|
memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
|
||||||
|
str[len+p_len] = 0;
|
||||||
|
|
||||||
memcpy(&sNewString[offset], p, nLengthP * sizeof(WCHAR));
|
hr = IXMLDOMComment_put_data(iface, str);
|
||||||
|
|
||||||
if(offset+nLengthP < nLength)
|
SysFreeString(str);
|
||||||
memcpy(&sNewString[offset+nLengthP], &sContent[offset], (nLength-offset) * sizeof(WCHAR));
|
SysFreeString(data);
|
||||||
|
|
||||||
sNewString[nLengthP + nLength] = 0;
|
|
||||||
|
|
||||||
str = xmlChar_from_wchar(sNewString);
|
|
||||||
if(str)
|
|
||||||
{
|
|
||||||
xmlNodeSetContent(This->node.node, str);
|
|
||||||
hr = S_OK;
|
|
||||||
}
|
|
||||||
HeapFree( GetProcessHeap(), 0, str );
|
|
||||||
|
|
||||||
SysFreeString(sNewString);
|
|
||||||
}
|
|
||||||
|
|
||||||
SysFreeString(sContent);
|
|
||||||
|
|
||||||
xmlFree(pXmlContent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
|
|
|
@ -612,16 +612,14 @@ static HRESULT WINAPI domtext_insertData(
|
||||||
LONG offset, BSTR p)
|
LONG offset, BSTR p)
|
||||||
{
|
{
|
||||||
domtext *This = impl_from_IXMLDOMText( iface );
|
domtext *This = impl_from_IXMLDOMText( iface );
|
||||||
xmlChar *pXmlContent;
|
HRESULT hr;
|
||||||
BSTR sNewString;
|
BSTR data;
|
||||||
HRESULT hr = S_FALSE;
|
LONG p_len;
|
||||||
LONG nLength = 0, nLengthP = 0;
|
|
||||||
xmlChar *str = NULL;
|
|
||||||
|
|
||||||
TRACE("%p %d %s\n", This, offset, debugstr_w(p));
|
TRACE("%p %d %s\n", This, offset, debugstr_w(p));
|
||||||
|
|
||||||
/* If have a NULL or empty string, don't do anything. */
|
/* If have a NULL or empty string, don't do anything. */
|
||||||
if(SysStringLen(p) == 0)
|
if((p_len = SysStringLen(p)) == 0)
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
||||||
if(offset < 0)
|
if(offset < 0)
|
||||||
|
@ -629,48 +627,29 @@ static HRESULT WINAPI domtext_insertData(
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
pXmlContent = xmlNodeGetContent(This->node.node);
|
hr = IXMLDOMText_get_data(iface, &data);
|
||||||
if(pXmlContent)
|
if(hr == S_OK)
|
||||||
{
|
{
|
||||||
BSTR sContent = bstr_from_xmlChar( pXmlContent );
|
LONG len = SysStringLen(data);
|
||||||
nLength = SysStringLen(sContent);
|
BSTR str;
|
||||||
nLengthP = SysStringLen(p);
|
|
||||||
|
|
||||||
if(nLength < offset)
|
if(len < offset)
|
||||||
{
|
{
|
||||||
SysFreeString(sContent);
|
SysFreeString(data);
|
||||||
xmlFree(pXmlContent);
|
|
||||||
|
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
sNewString = SysAllocStringLen(NULL, nLength + nLengthP + 1);
|
str = SysAllocStringLen(NULL, len + p_len);
|
||||||
if(sNewString)
|
/* start part, supplied string and end part */
|
||||||
{
|
memcpy(str, data, offset*sizeof(WCHAR));
|
||||||
if(offset > 0)
|
memcpy(&str[offset], p, p_len*sizeof(WCHAR));
|
||||||
memcpy(sNewString, sContent, offset * sizeof(WCHAR));
|
memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
|
||||||
|
str[len+p_len] = 0;
|
||||||
|
|
||||||
memcpy(&sNewString[offset], p, nLengthP * sizeof(WCHAR));
|
hr = IXMLDOMText_put_data(iface, str);
|
||||||
|
|
||||||
if(offset+nLengthP < nLength)
|
SysFreeString(str);
|
||||||
memcpy(&sNewString[offset+nLengthP], &sContent[offset], (nLength-offset) * sizeof(WCHAR));
|
SysFreeString(data);
|
||||||
|
|
||||||
sNewString[nLengthP + nLength] = 0;
|
|
||||||
|
|
||||||
str = xmlChar_from_wchar(sNewString);
|
|
||||||
if(str)
|
|
||||||
{
|
|
||||||
xmlNodeSetContent(This->node.node, str);
|
|
||||||
hr = S_OK;
|
|
||||||
}
|
|
||||||
heap_free(str);
|
|
||||||
|
|
||||||
SysFreeString(sNewString);
|
|
||||||
}
|
|
||||||
|
|
||||||
SysFreeString(sContent);
|
|
||||||
|
|
||||||
xmlFree(pXmlContent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
|
|
Loading…
Reference in New Issue