From: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> --- dlls/msxml3/cdata.c | 44 +++---------------------------------- dlls/msxml3/comment.c | 44 +++---------------------------------- dlls/msxml3/msxml_private.h | 1 + dlls/msxml3/node.c | 42 +++++++++++++++++++++++++++++++++++ dlls/msxml3/text.c | 44 +++---------------------------------- 5 files changed, 52 insertions(+), 123 deletions(-) diff --git a/dlls/msxml3/cdata.c b/dlls/msxml3/cdata.c index 898c77af579..d11fcf2925d 100644 --- a/dlls/msxml3/cdata.c +++ b/dlls/msxml3/cdata.c @@ -573,51 +573,13 @@ static HRESULT WINAPI domcdata_insertData( return hr; } -static HRESULT WINAPI domcdata_deleteData( - IXMLDOMCDATASection *iface, - LONG offset, LONG count) +static HRESULT WINAPI domcdata_deleteData(IXMLDOMCDATASection *iface, LONG offset, LONG count) { - HRESULT hr; - LONG len = -1; - BSTR str; + domcdata *cdata = impl_from_IXMLDOMCDATASection(iface); TRACE("%p, %ld, %ld.\n", iface, offset, count); - hr = IXMLDOMCDATASection_get_length(iface, &len); - if(hr != S_OK) return hr; - - if((offset < 0) || (offset > len) || (count < 0)) - return E_INVALIDARG; - - if(len == 0) return S_OK; - - /* cutting start or end */ - if((offset == 0) || ((count + offset) >= len)) - { - if(offset == 0) - IXMLDOMCDATASection_substringData(iface, count, len - count, &str); - else - IXMLDOMCDATASection_substringData(iface, 0, offset, &str); - hr = IXMLDOMCDATASection_put_data(iface, str); - } - else - /* cutting from the inside */ - { - BSTR str_end; - - IXMLDOMCDATASection_substringData(iface, 0, offset, &str); - IXMLDOMCDATASection_substringData(iface, offset + count, len - count, &str_end); - - hr = IXMLDOMCDATASection_put_data(iface, str); - if(hr == S_OK) - hr = IXMLDOMCDATASection_appendData(iface, str_end); - - SysFreeString(str_end); - } - - SysFreeString(str); - - return hr; + return node_delete_data(cdata->node, offset, count); } static HRESULT WINAPI domcdata_replaceData( diff --git a/dlls/msxml3/comment.c b/dlls/msxml3/comment.c index fe53ac57e05..26a48d1b014 100644 --- a/dlls/msxml3/comment.c +++ b/dlls/msxml3/comment.c @@ -577,51 +577,13 @@ static HRESULT WINAPI domcomment_insertData( return hr; } -static HRESULT WINAPI domcomment_deleteData( - IXMLDOMComment *iface, - LONG offset, LONG count) +static HRESULT WINAPI domcomment_deleteData(IXMLDOMComment *iface, LONG offset, LONG count) { - HRESULT hr; - LONG len = -1; - BSTR str; + domcomment *comment = impl_from_IXMLDOMComment(iface); TRACE("%p, %ld, %ld.\n", iface, offset, count); - hr = IXMLDOMComment_get_length(iface, &len); - if(hr != S_OK) return hr; - - if((offset < 0) || (offset > len) || (count < 0)) - return E_INVALIDARG; - - if(len == 0) return S_OK; - - /* cutting start or end */ - if((offset == 0) || ((count + offset) >= len)) - { - if(offset == 0) - IXMLDOMComment_substringData(iface, count, len - count, &str); - else - IXMLDOMComment_substringData(iface, 0, offset, &str); - hr = IXMLDOMComment_put_data(iface, str); - } - else - /* cutting from the inside */ - { - BSTR str_end; - - IXMLDOMComment_substringData(iface, 0, offset, &str); - IXMLDOMComment_substringData(iface, offset + count, len - count, &str_end); - - hr = IXMLDOMComment_put_data(iface, str); - if(hr == S_OK) - hr = IXMLDOMComment_appendData(iface, str_end); - - SysFreeString(str_end); - } - - SysFreeString(str); - - return hr; + return node_delete_data(comment->node, offset, count); } static HRESULT WINAPI domcomment_replaceData( diff --git a/dlls/msxml3/msxml_private.h b/dlls/msxml3/msxml_private.h index 4346166c783..1df1c409903 100644 --- a/dlls/msxml3/msxml_private.h +++ b/dlls/msxml3/msxml_private.h @@ -330,6 +330,7 @@ extern HRESULT node_get_elements_by_tagname(struct domnode *,BSTR,IXMLDOMNodeLis extern HRESULT node_validate(struct domnode *, IXMLDOMNode *, IXMLDOMParseError **); extern void node_move_children(struct domnode *dst, struct domnode *src); extern HRESULT node_split_text(struct domnode *, LONG, IXMLDOMText **); +extern HRESULT node_delete_data(struct domnode *, LONG, LONG); extern UINT get_codepage_for_encoding(const WCHAR *encoding); diff --git a/dlls/msxml3/node.c b/dlls/msxml3/node.c index bcd331e3a83..b8c00d8f293 100644 --- a/dlls/msxml3/node.c +++ b/dlls/msxml3/node.c @@ -4630,3 +4630,45 @@ HRESULT node_split_text(struct domnode *node, LONG offset, IXMLDOMText **out) return hr; } + +HRESULT node_delete_data(struct domnode *node, LONG offset, LONG count) +{ + ULONG length = SysStringLen(node->data); + BSTR str = NULL; + + if (offset < 0 || count < 0 || offset > length) + return E_INVALIDARG; + + if (length == 0 || count == 0) + return S_OK; + + if (offset == 0) + { + if (count < length) + { + str = SysAllocStringLen(node->data + count, length - count); + if (!str) return E_OUTOFMEMORY; + } + } + else + { + if (offset + count >= length) + { + str = SysAllocStringLen(node->data, offset); + if (!str) return E_OUTOFMEMORY; + } + else + { + str = SysAllocStringLen(NULL, length - count); + if (!str) return E_OUTOFMEMORY; + memcpy(str, node->data, offset * sizeof(WCHAR)); + memcpy(str + offset, node->data + offset + count, (length - count - offset) * sizeof(WCHAR)); + str[length - count] = 0; + } + } + + SysFreeString(node->data); + node->data = str; + + return S_OK; +} diff --git a/dlls/msxml3/text.c b/dlls/msxml3/text.c index dbada1dbaa2..8fdefb5c539 100644 --- a/dlls/msxml3/text.c +++ b/dlls/msxml3/text.c @@ -639,51 +639,13 @@ static HRESULT WINAPI domtext_insertData( return hr; } -static HRESULT WINAPI domtext_deleteData( - IXMLDOMText *iface, - LONG offset, LONG count) +static HRESULT WINAPI domtext_deleteData(IXMLDOMText *iface, LONG offset, LONG count) { - HRESULT hr; - LONG len = -1; - BSTR str; + domtext *text = impl_from_IXMLDOMText(iface); TRACE("%p, %ld, %ld.\n", iface, offset, count); - hr = IXMLDOMText_get_length(iface, &len); - if(hr != S_OK) return hr; - - if((offset < 0) || (offset > len) || (count < 0)) - return E_INVALIDARG; - - if(len == 0) return S_OK; - - /* cutting start or end */ - if((offset == 0) || ((count + offset) >= len)) - { - if(offset == 0) - IXMLDOMText_substringData(iface, count, len - count, &str); - else - IXMLDOMText_substringData(iface, 0, offset, &str); - hr = IXMLDOMText_put_data(iface, str); - } - else - /* cutting from the inside */ - { - BSTR str_end; - - IXMLDOMText_substringData(iface, 0, offset, &str); - IXMLDOMText_substringData(iface, offset + count, len - count, &str_end); - - hr = IXMLDOMText_put_data(iface, str); - if(hr == S_OK) - hr = IXMLDOMText_appendData(iface, str_end); - - SysFreeString(str_end); - } - - SysFreeString(str); - - return hr; + return node_delete_data(text->node, offset, count); } static HRESULT WINAPI domtext_replaceData( -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10679