From: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> --- dlls/msxml3/mxwriter.c | 237 +++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 138 deletions(-) diff --git a/dlls/msxml3/mxwriter.c b/dlls/msxml3/mxwriter.c index d8d60e863b6..c2dda9e89c9 100644 --- a/dlls/msxml3/mxwriter.c +++ b/dlls/msxml3/mxwriter.c @@ -35,15 +35,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(msxml); -static const WCHAR emptyW[] = {0}; -static const WCHAR spaceW[] = {' '}; -static const WCHAR quotW[] = {'\"'}; -static const WCHAR closetagW[] = {'>','\r','\n'}; -static const WCHAR crlfW[] = {'\r','\n'}; -static const WCHAR entityW[] = {'<','!','E','N','T','I','T','Y',' '}; -static const WCHAR publicW[] = {'P','U','B','L','I','C',' '}; -static const WCHAR systemW[] = {'S','Y','S','T','E','M',' '}; - /* should be ordered as encoding names are sorted */ typedef enum { @@ -461,9 +452,9 @@ static HRESULT write_output_buffer(mxwriter *writer, const WCHAR *data, int len) static HRESULT write_output_buffer_quoted(mxwriter *writer, const WCHAR *data, int len) { - write_output_buffer(writer, quotW, 1); + write_output_buffer(writer, L"\"", 1); write_output_buffer(writer, data, len); - write_output_buffer(writer, quotW, 1); + write_output_buffer(writer, L"\"", 1); return S_OK; } @@ -578,33 +569,27 @@ static void write_string_with_crlf(mxwriter *writer, const WCHAR *str, int len) static void write_prolog_buffer(mxwriter *writer) { - static const WCHAR versionW[] = {'<','?','x','m','l',' ','v','e','r','s','i','o','n','='}; - static const WCHAR encodingW[] = {' ','e','n','c','o','d','i','n','g','=','\"'}; - static const WCHAR standaloneW[] = {' ','s','t','a','n','d','a','l','o','n','e','=','\"'}; - static const WCHAR yesW[] = {'y','e','s','\"','?','>'}; - static const WCHAR noW[] = {'n','o','\"','?','>'}; - /* version */ - write_output_buffer(writer, versionW, ARRAY_SIZE(versionW)); + write_output_buffer(writer, L"<?xml version=", 14); write_output_buffer_quoted(writer, writer->version, -1); /* encoding */ - write_output_buffer(writer, encodingW, ARRAY_SIZE(encodingW)); + write_output_buffer(writer, L" encoding=", 10); if (writer->dest) - write_output_buffer(writer, writer->encoding, -1); + write_output_buffer_quoted(writer, writer->encoding, -1); else - write_output_buffer(writer, L"UTF-16", ARRAY_SIZE(L"UTF-16") - 1); - write_output_buffer(writer, quotW, 1); + write_output_buffer_quoted(writer, L"UTF-16", 6); /* standalone */ - write_output_buffer(writer, standaloneW, ARRAY_SIZE(standaloneW)); + write_output_buffer(writer, L" standalone=", 12); if (writer->props[MXWriter_Standalone] == VARIANT_TRUE) - write_output_buffer(writer, yesW, ARRAY_SIZE(yesW)); + write_output_buffer_quoted(writer, L"yes", 3); else - write_output_buffer(writer, noW, ARRAY_SIZE(noW)); + write_output_buffer_quoted(writer, L"no", 2); + write_output_buffer(writer, L"?>", 2); - write_output_buffer(writer, crlfW, ARRAY_SIZE(crlfW)); + write_output_buffer(writer, L"\r\n", 2); writer->newline = TRUE; } @@ -637,14 +622,12 @@ static HRESULT write_data_to_stream(mxwriter *writer) we have to close it differently. */ static void close_element_starttag(mxwriter *writer) { - static const WCHAR gtW[] = {'>'}; if (!writer->element) return; - write_output_buffer(writer, gtW, 1); + write_output_buffer(writer, L">", 1); } static void write_node_indent(mxwriter *writer) { - static const WCHAR tabW[] = {'\t'}; int indent = writer->indent; if (!writer->props[MXWriter_Indent] || writer->text) @@ -656,9 +639,9 @@ static void write_node_indent(mxwriter *writer) /* This is to workaround PI output logic that always puts newline chars, document prolog PI does that too. */ if (!writer->newline) - write_output_buffer(writer, crlfW, ARRAY_SIZE(crlfW)); + write_output_buffer(writer, L"\r\n", 2); while (indent--) - write_output_buffer(writer, tabW, 1); + write_output_buffer(writer, L"\t", 1); writer->newline = FALSE; writer->text = FALSE; @@ -1271,12 +1254,10 @@ static HRESULT WINAPI SAXContentHandler_endPrefixMapping( static void mxwriter_write_attribute(mxwriter *writer, const WCHAR *qname, int qname_len, const WCHAR *value, int value_len, BOOL escape) { - static const WCHAR eqW[] = {'='}; - /* space separator in front of every attribute */ - write_output_buffer(writer, spaceW, 1); + write_output_buffer(writer, L" ", 1); write_output_buffer(writer, qname, qname_len); - write_output_buffer(writer, eqW, 1); + write_output_buffer(writer, L"=", 1); write_output_buffer(writer, L"\"", 1); if (escape) @@ -1288,15 +1269,13 @@ static void mxwriter_write_attribute(mxwriter *writer, const WCHAR *qname, int q static void mxwriter_write_starttag(mxwriter *writer, const WCHAR *qname, int len) { - static const WCHAR ltW[] = {'<'}; - close_element_starttag(writer); - set_element_name(writer, qname ? qname : emptyW, qname ? len : 0); + set_element_name(writer, qname ? qname : L"", qname ? len : 0); write_node_indent(writer); - write_output_buffer(writer, ltW, 1); - write_output_buffer(writer, qname ? qname : emptyW, qname ? len : 0); + write_output_buffer(writer, L"<", 1); + write_output_buffer(writer, qname ? qname : L"", qname ? len : 0); writer_inc_indent(writer); } @@ -1372,18 +1351,14 @@ static HRESULT WINAPI SAXContentHandler_endElement( if (This->element) { - static const WCHAR closeW[] = {'/','>'}; - write_output_buffer(This, closeW, 2); + write_output_buffer(This, L"/>", 2); } else { - static const WCHAR closetagW[] = {'<','/'}; - static const WCHAR gtW[] = {'>'}; - write_node_indent(This); - write_output_buffer(This, closetagW, 2); + write_output_buffer(This, L"</", 2); write_output_buffer(This, QName, nQName); - write_output_buffer(This, gtW, 1); + write_output_buffer(This, L">", 1); } set_element_name(This, NULL, 0); @@ -1439,28 +1414,26 @@ static HRESULT WINAPI SAXContentHandler_processingInstruction( const WCHAR *data, int ndata) { - mxwriter *This = impl_from_ISAXContentHandler( iface ); - static const WCHAR openpiW[] = {'<','?'}; - static const WCHAR closepiW[] = {'?','>','\r','\n'}; + mxwriter *writer = impl_from_ISAXContentHandler(iface); - TRACE("(%p)->(%s %s)\n", This, debugstr_wn(target, ntarget), debugstr_wn(data, ndata)); + TRACE("%p, %s, %s.\n", iface, debugstr_wn(target, ntarget), debugstr_wn(data, ndata)); if (!target) return E_INVALIDARG; - write_node_indent(This); - write_output_buffer(This, openpiW, ARRAY_SIZE(openpiW)); + write_node_indent(writer); + write_output_buffer(writer, L"<?", 2); if (*target) - write_output_buffer(This, target, ntarget); + write_output_buffer(writer, target, ntarget); if (data && *data && ndata) { - write_output_buffer(This, spaceW, 1); - write_output_buffer(This, data, ndata); + write_output_buffer(writer, L" ", 1); + write_output_buffer(writer, data, ndata); } - write_output_buffer(This, closepiW, ARRAY_SIZE(closepiW)); - This->newline = TRUE; + write_output_buffer(writer, L"?>\r\n", 4); + writer->newline = TRUE; return S_OK; } @@ -1517,60 +1490,56 @@ static HRESULT WINAPI SAXLexicalHandler_startDTD(ISAXLexicalHandler *iface, const WCHAR *name, int name_len, const WCHAR *publicId, int publicId_len, const WCHAR *systemId, int systemId_len) { - static const WCHAR doctypeW[] = {'<','!','D','O','C','T','Y','P','E',' '}; - static const WCHAR openintW[] = {'[','\r','\n'}; + mxwriter *writer = impl_from_ISAXLexicalHandler(iface); - mxwriter *This = impl_from_ISAXLexicalHandler( iface ); - - TRACE("(%p)->(%s %s %s)\n", This, debugstr_wn(name, name_len), debugstr_wn(publicId, publicId_len), + TRACE("%p, %s. %s. %s.\n", iface, debugstr_wn(name, name_len), debugstr_wn(publicId, publicId_len), debugstr_wn(systemId, systemId_len)); if (!name) return E_INVALIDARG; - write_output_buffer(This, doctypeW, ARRAY_SIZE(doctypeW)); + write_output_buffer(writer, L"<!DOCTYPE ", 10); if (*name) { - write_output_buffer(This, name, name_len); - write_output_buffer(This, spaceW, 1); + write_output_buffer(writer, name, name_len); + write_output_buffer(writer, L" ", 1); } if (publicId) { - write_output_buffer(This, publicW, ARRAY_SIZE(publicW)); - write_output_buffer_quoted(This, publicId, publicId_len); + write_output_buffer(writer, L"PUBLIC ", 7); + write_output_buffer_quoted(writer, publicId, publicId_len); if (!systemId) return E_INVALIDARG; if (*publicId) - write_output_buffer(This, spaceW, 1); + write_output_buffer(writer, L" ", 1); - write_output_buffer_quoted(This, systemId, systemId_len); + write_output_buffer_quoted(writer, systemId, systemId_len); if (*systemId) - write_output_buffer(This, spaceW, 1); + write_output_buffer(writer, L" ", 1); } else if (systemId) { - write_output_buffer(This, systemW, ARRAY_SIZE(systemW)); - write_output_buffer_quoted(This, systemId, systemId_len); + write_output_buffer(writer, L"SYSTEM ", 7); + write_output_buffer_quoted(writer, systemId, systemId_len); if (*systemId) - write_output_buffer(This, spaceW, 1); + write_output_buffer(writer, L" ", 1); } - write_output_buffer(This, openintW, ARRAY_SIZE(openintW)); + write_output_buffer(writer, L"[\r\n", 3); return S_OK; } static HRESULT WINAPI SAXLexicalHandler_endDTD(ISAXLexicalHandler *iface) { - mxwriter *This = impl_from_ISAXLexicalHandler( iface ); - static const WCHAR closedtdW[] = {']','>','\r','\n'}; + mxwriter *writer = impl_from_ISAXLexicalHandler(iface); - TRACE("(%p)\n", This); + TRACE("%p.\n", iface); - write_output_buffer(This, closedtdW, ARRAY_SIZE(closedtdW)); + write_output_buffer(writer, L"]>\r\n", 4); return S_OK; } @@ -1591,48 +1560,44 @@ static HRESULT WINAPI SAXLexicalHandler_endEntity(ISAXLexicalHandler *iface, con static HRESULT WINAPI SAXLexicalHandler_startCDATA(ISAXLexicalHandler *iface) { - static const WCHAR scdataW[] = {'<','!','[','C','D','A','T','A','['}; - mxwriter *This = impl_from_ISAXLexicalHandler( iface ); + mxwriter *writer = impl_from_ISAXLexicalHandler(iface); - TRACE("(%p)\n", This); + TRACE("%p.\n", iface); - write_node_indent(This); - write_output_buffer(This, scdataW, ARRAY_SIZE(scdataW)); - This->cdata = TRUE; + write_node_indent(writer); + write_output_buffer(writer, L"<![CDATA[", 9); + writer->cdata = TRUE; return S_OK; } static HRESULT WINAPI SAXLexicalHandler_endCDATA(ISAXLexicalHandler *iface) { - mxwriter *This = impl_from_ISAXLexicalHandler( iface ); - static const WCHAR ecdataW[] = {']',']','>'}; + mxwriter *writer = impl_from_ISAXLexicalHandler(iface); - TRACE("(%p)\n", This); + TRACE("%p.\n", iface); - write_output_buffer(This, ecdataW, ARRAY_SIZE(ecdataW)); - This->cdata = FALSE; + write_output_buffer(writer, L"]]>", 3); + writer->cdata = FALSE; return S_OK; } static HRESULT WINAPI SAXLexicalHandler_comment(ISAXLexicalHandler *iface, const WCHAR *chars, int nchars) { - mxwriter *This = impl_from_ISAXLexicalHandler( iface ); - static const WCHAR copenW[] = {'<','!','-','-'}; - static const WCHAR ccloseW[] = {'-','-','>','\r','\n'}; + mxwriter *writer = impl_from_ISAXLexicalHandler(iface); - TRACE("(%p)->(%s:%d)\n", This, debugstr_wn(chars, nchars), nchars); + TRACE("%p, %s:%d.\n", iface, debugstr_wn(chars, nchars), nchars); if (!chars) return E_INVALIDARG; - close_element_starttag(This); - write_node_indent(This); + close_element_starttag(writer); + write_node_indent(writer); - write_output_buffer(This, copenW, ARRAY_SIZE(copenW)); + write_output_buffer(writer, L"<!--", 4); if (nchars) - write_output_buffer(This, chars, nchars); - write_output_buffer(This, ccloseW, ARRAY_SIZE(ccloseW)); + write_output_buffer(writer, chars, nchars); + write_output_buffer(writer, L"-->\r\n", 5); return S_OK; } @@ -1674,7 +1639,6 @@ static ULONG WINAPI SAXDeclHandler_Release(ISAXDeclHandler *iface) static HRESULT WINAPI SAXDeclHandler_elementDecl(ISAXDeclHandler *iface, const WCHAR *name, int n_name, const WCHAR *model, int n_model) { - static const WCHAR elementW[] = {'<','!','E','L','E','M','E','N','T',' '}; mxwriter *This = impl_from_ISAXDeclHandler( iface ); TRACE("(%p)->(%s:%d %s:%d)\n", This, debugstr_wn(name, n_name), n_name, @@ -1682,14 +1646,14 @@ static HRESULT WINAPI SAXDeclHandler_elementDecl(ISAXDeclHandler *iface, if (!name || !model) return E_INVALIDARG; - write_output_buffer(This, elementW, ARRAY_SIZE(elementW)); + write_output_buffer(This, L"<!ELEMENT ", 10); if (n_name) { write_output_buffer(This, name, n_name); - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); + write_output_buffer(This, L" ", 1); } if (n_model) write_output_buffer(This, model, n_model); - write_output_buffer(This, closetagW, ARRAY_SIZE(closetagW)); + write_output_buffer(This, L">\r\n", 3); return S_OK; } @@ -1700,38 +1664,36 @@ static HRESULT WINAPI SAXDeclHandler_attributeDecl(ISAXDeclHandler *iface, const WCHAR *value, int n_value) { mxwriter *This = impl_from_ISAXDeclHandler( iface ); - static const WCHAR attlistW[] = {'<','!','A','T','T','L','I','S','T',' '}; - static const WCHAR closetagW[] = {'>','\r','\n'}; TRACE("(%p)->(%s:%d %s:%d %s:%d %s:%d %s:%d)\n", This, debugstr_wn(element, n_element), n_element, debugstr_wn(attr, n_attr), n_attr, debugstr_wn(type, n_type), n_type, debugstr_wn(Default, n_default), n_default, debugstr_wn(value, n_value), n_value); - write_output_buffer(This, attlistW, ARRAY_SIZE(attlistW)); + write_output_buffer(This, L"<!ATTLIST ", 10); if (n_element) { write_output_buffer(This, element, n_element); - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); + write_output_buffer(This, L" ", 1); } if (n_attr) { write_output_buffer(This, attr, n_attr); - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); + write_output_buffer(This, L" ", 1); } if (n_type) { write_output_buffer(This, type, n_type); - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); + write_output_buffer(This, L" ", 1); } if (n_default) { write_output_buffer(This, Default, n_default); - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); + write_output_buffer(This, L" ", 1); } if (n_value) write_output_buffer_quoted(This, value, n_value); - write_output_buffer(This, closetagW, ARRAY_SIZE(closetagW)); + write_output_buffer(This, L">\r\n", 3); return S_OK; } @@ -1739,23 +1701,23 @@ static HRESULT WINAPI SAXDeclHandler_attributeDecl(ISAXDeclHandler *iface, static HRESULT WINAPI SAXDeclHandler_internalEntityDecl(ISAXDeclHandler *iface, const WCHAR *name, int n_name, const WCHAR *value, int n_value) { - mxwriter *This = impl_from_ISAXDeclHandler( iface ); + mxwriter *writer = impl_from_ISAXDeclHandler(iface); - TRACE("(%p)->(%s:%d %s:%d)\n", This, debugstr_wn(name, n_name), n_name, + TRACE("%p, %s:%d, %s:%d.\n", iface, debugstr_wn(name, n_name), n_name, debugstr_wn(value, n_value), n_value); if (!name || !value) return E_INVALIDARG; - write_output_buffer(This, entityW, ARRAY_SIZE(entityW)); + write_output_buffer(writer, L"<!ENTITY ", 9); if (n_name) { - write_output_buffer(This, name, n_name); - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); + write_output_buffer(writer, name, n_name); + write_output_buffer(writer, L" ", 1); } if (n_value) - write_output_buffer_quoted(This, value, n_value); + write_output_buffer_quoted(writer, value, n_value); - write_output_buffer(This, closetagW, ARRAY_SIZE(closetagW)); + write_output_buffer(writer, L">\r\n", 3); return S_OK; } @@ -1764,33 +1726,33 @@ static HRESULT WINAPI SAXDeclHandler_externalEntityDecl(ISAXDeclHandler *iface, const WCHAR *name, int n_name, const WCHAR *publicId, int n_publicId, const WCHAR *systemId, int n_systemId) { - mxwriter *This = impl_from_ISAXDeclHandler( iface ); + mxwriter *writer = impl_from_ISAXDeclHandler(iface); - TRACE("(%p)->(%s:%d %s:%d %s:%d)\n", This, debugstr_wn(name, n_name), n_name, + TRACE("%p, %s:%d, %s:%d, %s:%d.\n", iface, debugstr_wn(name, n_name), n_name, debugstr_wn(publicId, n_publicId), n_publicId, debugstr_wn(systemId, n_systemId), n_systemId); if (!name || !systemId) return E_INVALIDARG; - write_output_buffer(This, entityW, ARRAY_SIZE(entityW)); + write_output_buffer(writer, L"<!ENTITY ", 9); if (n_name) { - write_output_buffer(This, name, n_name); - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); + write_output_buffer(writer, name, n_name); + write_output_buffer(writer, L" ", 1); } if (publicId) { - write_output_buffer(This, publicW, ARRAY_SIZE(publicW)); - write_output_buffer_quoted(This, publicId, n_publicId); - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); - write_output_buffer_quoted(This, systemId, n_systemId); + write_output_buffer(writer, L"PUBLIC ", 7); + write_output_buffer_quoted(writer, publicId, n_publicId); + write_output_buffer(writer, L" ", 1); + write_output_buffer_quoted(writer, systemId, n_systemId); } else { - write_output_buffer(This, systemW, ARRAY_SIZE(systemW)); - write_output_buffer_quoted(This, systemId, n_systemId); + write_output_buffer(writer, L"SYSTEM ", 7); + write_output_buffer_quoted(writer, systemId, n_systemId); } - write_output_buffer(This, closetagW, ARRAY_SIZE(closetagW)); + write_output_buffer(writer, L">\r\n", 3); return S_OK; } @@ -2293,7 +2255,6 @@ static HRESULT WINAPI SAXDTDHandler_notationDecl(ISAXDTDHandler *iface, const WCHAR *publicid, INT n_publicid, const WCHAR *systemid, INT n_systemid) { - static const WCHAR notationW[] = {'<','!','N','O','T','A','T','I','O','N',' '}; mxwriter *This = impl_from_ISAXDTDHandler( iface ); TRACE("(%p)->(%s:%d, %s:%d, %s:%d)\n", This, debugstr_wn(name, n_name), n_name, @@ -2302,30 +2263,30 @@ static HRESULT WINAPI SAXDTDHandler_notationDecl(ISAXDTDHandler *iface, if (!name || !n_name) return E_INVALIDARG; - write_output_buffer(This, notationW, ARRAY_SIZE(notationW)); + write_output_buffer(This, L"<!NOTATION ", 11); write_output_buffer(This, name, n_name); if (!publicid && !systemid) return E_INVALIDARG; - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); + write_output_buffer(This, L" ", 1); if (publicid) { - write_output_buffer(This, publicW, ARRAY_SIZE(publicW)); + write_output_buffer(This, L"PUBLIC ", 7); write_output_buffer_quoted(This, publicid, n_publicid); if (systemid) { - write_output_buffer(This, spaceW, ARRAY_SIZE(spaceW)); + write_output_buffer(This, L" ", 1); write_output_buffer_quoted(This, systemid, n_systemid); } } else { - write_output_buffer(This, systemW, ARRAY_SIZE(systemW)); + write_output_buffer(This, L"SYSTEM ", 7); write_output_buffer_quoted(This, systemid, n_systemid); } - write_output_buffer(This, closetagW, ARRAY_SIZE(closetagW)); + write_output_buffer(This, L">\r\n", 3); return S_OK; } @@ -2771,7 +2732,7 @@ static HRESULT WINAPI MXAttributes_addAttribute(IMXAttributes *iface, attr->qname = SysAllocString(QName); attr->local = SysAllocString(localName); attr->uri = SysAllocString(uri); - attr->type = SysAllocString(type ? type : emptyW); + attr->type = SysAllocString(type ? type : L""); attr->value = SysAllocString(value); This->length++; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11066