[XMLLITE] Sync with Wine Staging 1.9.16. CORE-11866

svn path=/trunk/; revision=72317
This commit is contained in:
Amine Khaldi 2016-08-18 10:54:49 +00:00
parent 8497ce4353
commit 78d4075504
2 changed files with 81 additions and 13 deletions

View file

@ -2,7 +2,7 @@
* IXmlWriter implementation * IXmlWriter implementation
* *
* Copyright 2011 Alistair Leslie-Hughes * Copyright 2011 Alistair Leslie-Hughes
* Copyright 2014 Nikolay Sivov for CodeWeavers * Copyright 2014, 2016 Nikolay Sivov for CodeWeavers
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -34,6 +34,7 @@ static const WCHAR closepiW[] = {'?','>'};
static const WCHAR ltW[] = {'<'}; static const WCHAR ltW[] = {'<'};
static const WCHAR gtW[] = {'>'}; static const WCHAR gtW[] = {'>'};
static const WCHAR spaceW[] = {' '}; static const WCHAR spaceW[] = {' '};
static const WCHAR quoteW[] = {'"'};
struct output_buffer struct output_buffer
{ {
@ -80,6 +81,7 @@ typedef struct _xmlwriter
LONG ref; LONG ref;
IMalloc *imalloc; IMalloc *imalloc;
xmlwriteroutput *output; xmlwriteroutput *output;
unsigned int indent_level;
BOOL indent; BOOL indent;
BOOL bom; BOOL bom;
BOOL omitxmldecl; BOOL omitxmldecl;
@ -273,7 +275,6 @@ static HRESULT write_output_buffer(xmlwriteroutput *output, const WCHAR *data, i
static HRESULT write_output_buffer_quoted(xmlwriteroutput *output, const WCHAR *data, int len) static HRESULT write_output_buffer_quoted(xmlwriteroutput *output, const WCHAR *data, int len)
{ {
static const WCHAR quoteW[] = {'"'};
write_output_buffer(output, quoteW, ARRAY_SIZE(quoteW)); write_output_buffer(output, quoteW, ARRAY_SIZE(quoteW));
write_output_buffer(output, data, len); write_output_buffer(output, data, len);
write_output_buffer(output, quoteW, ARRAY_SIZE(quoteW)); write_output_buffer(output, quoteW, ARRAY_SIZE(quoteW));
@ -403,10 +404,35 @@ static HRESULT writer_close_starttag(xmlwriter *writer)
if (!writer->starttagopen) return S_OK; if (!writer->starttagopen) return S_OK;
hr = write_output_buffer(writer->output, gtW, ARRAY_SIZE(gtW)); hr = write_output_buffer(writer->output, gtW, ARRAY_SIZE(gtW));
writer->starttagopen = FALSE; writer->starttagopen = FALSE;
writer->state = XmlWriterState_Content;
return hr; return hr;
} }
static void writer_inc_indent(xmlwriter *writer)
{
writer->indent_level++;
}
static void writer_dec_indent(xmlwriter *writer)
{
if (writer->indent_level)
writer->indent_level--;
}
static void write_node_indent(xmlwriter *writer)
{
static const WCHAR dblspaceW[] = {' ',' '};
static const WCHAR crlfW[] = {'\r','\n'};
unsigned int indent_level = writer->indent_level;
if (!writer->indent)
return;
if (writer->output->buffer.written)
write_output_buffer(writer->output, crlfW, ARRAY_SIZE(crlfW));
while (indent_level--)
write_output_buffer(writer->output, dblspaceW, ARRAY_SIZE(dblspaceW));
}
static HRESULT WINAPI xmlwriter_QueryInterface(IXmlWriter *iface, REFIID riid, void **ppvObject) static HRESULT WINAPI xmlwriter_QueryInterface(IXmlWriter *iface, REFIID riid, void **ppvObject)
{ {
xmlwriter *This = impl_from_IXmlWriter(iface); xmlwriter *This = impl_from_IXmlWriter(iface);
@ -473,6 +499,7 @@ static HRESULT WINAPI xmlwriter_SetOutput(IXmlWriter *iface, IUnknown *output)
IUnknown_Release(&This->output->IXmlWriterOutput_iface); IUnknown_Release(&This->output->IXmlWriterOutput_iface);
This->output = NULL; This->output = NULL;
This->bomwritten = FALSE; This->bomwritten = FALSE;
This->indent_level = 0;
} }
/* just reset current output */ /* just reset current output */
@ -544,6 +571,9 @@ static HRESULT WINAPI xmlwriter_SetProperty(IXmlWriter *iface, UINT property, LO
switch (property) switch (property)
{ {
case XmlWriterProperty_Indent:
This->indent = !!value;
break;
case XmlWriterProperty_ByteOrderMark: case XmlWriterProperty_ByteOrderMark:
This->bom = !!value; This->bom = !!value;
break; break;
@ -568,14 +598,14 @@ static HRESULT WINAPI xmlwriter_WriteAttributes(IXmlWriter *iface, IXmlReader *p
return E_NOTIMPL; return E_NOTIMPL;
} }
static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR pwszPrefix, static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR ns_prefix,
LPCWSTR pwszLocalName, LPCWSTR pwszNamespaceUri, LPCWSTR local_name, LPCWSTR ns_uri, LPCWSTR value)
LPCWSTR pwszValue)
{ {
static const WCHAR eqW[] = {'=','"'};
xmlwriter *This = impl_from_IXmlWriter(iface); xmlwriter *This = impl_from_IXmlWriter(iface);
FIXME("%p %s %s %s %s\n", This, wine_dbgstr_w(pwszPrefix), wine_dbgstr_w(pwszLocalName), TRACE("%p %s %s %s %s\n", This, debugstr_w(ns_prefix), debugstr_w(local_name),
wine_dbgstr_w(pwszNamespaceUri), wine_dbgstr_w(pwszValue)); debugstr_w(ns_uri), debugstr_w(value));
switch (This->state) switch (This->state)
{ {
@ -589,7 +619,19 @@ static HRESULT WINAPI xmlwriter_WriteAttributeString(IXmlWriter *iface, LPCWSTR
; ;
} }
return E_NOTIMPL; if (ns_prefix || ns_uri)
{
FIXME("namespaces are not supported.\n");
return E_NOTIMPL;
}
write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW));
write_output_buffer(This->output, local_name, -1);
write_output_buffer(This->output, eqW, ARRAY_SIZE(eqW));
write_output_buffer(This->output, value, -1);
write_output_buffer(This->output, quoteW, ARRAY_SIZE(quoteW));
return S_OK;
} }
static void write_cdata_section(xmlwriteroutput *output, const WCHAR *data, int len) static void write_cdata_section(xmlwriteroutput *output, const WCHAR *data, int len)
@ -626,6 +668,7 @@ static HRESULT WINAPI xmlwriter_WriteCData(IXmlWriter *iface, LPCWSTR data)
len = data ? strlenW(data) : 0; len = data ? strlenW(data) : 0;
write_node_indent(This);
if (!len) if (!len)
write_cdata_section(This->output, NULL, 0); write_cdata_section(This->output, NULL, 0);
else { else {
@ -650,21 +693,29 @@ static HRESULT WINAPI xmlwriter_WriteCData(IXmlWriter *iface, LPCWSTR data)
static HRESULT WINAPI xmlwriter_WriteCharEntity(IXmlWriter *iface, WCHAR ch) static HRESULT WINAPI xmlwriter_WriteCharEntity(IXmlWriter *iface, WCHAR ch)
{ {
static const WCHAR fmtW[] = {'&','#','x','%','x',';',0};
xmlwriter *This = impl_from_IXmlWriter(iface); xmlwriter *This = impl_from_IXmlWriter(iface);
WCHAR bufW[16];
FIXME("%p %x\n", This, ch); TRACE("%p %#x\n", This, ch);
switch (This->state) switch (This->state)
{ {
case XmlWriterState_Initial: case XmlWriterState_Initial:
return E_UNEXPECTED; return E_UNEXPECTED;
case XmlWriterState_ElemStarted:
writer_close_starttag(This);
break;
case XmlWriterState_DocClosed: case XmlWriterState_DocClosed:
return WR_E_INVALIDACTION; return WR_E_INVALIDACTION;
default: default:
; ;
} }
return E_NOTIMPL; sprintfW(bufW, fmtW, ch);
write_output_buffer(This->output, bufW, -1);
return S_OK;
} }
static HRESULT WINAPI xmlwriter_WriteChars(IXmlWriter *iface, const WCHAR *pwch, UINT cwch) static HRESULT WINAPI xmlwriter_WriteChars(IXmlWriter *iface, const WCHAR *pwch, UINT cwch)
@ -686,6 +737,7 @@ static HRESULT WINAPI xmlwriter_WriteChars(IXmlWriter *iface, const WCHAR *pwch,
return E_NOTIMPL; return E_NOTIMPL;
} }
static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment) static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment)
{ {
static const WCHAR copenW[] = {'<','!','-','-'}; static const WCHAR copenW[] = {'<','!','-','-'};
@ -707,6 +759,7 @@ static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment)
; ;
} }
write_node_indent(This);
write_output_buffer(This->output, copenW, ARRAY_SIZE(copenW)); write_output_buffer(This->output, copenW, ARRAY_SIZE(copenW));
if (comment) { if (comment) {
int len = strlenW(comment), i; int len = strlenW(comment), i;
@ -831,6 +884,8 @@ static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface)
if (!element) if (!element)
return WR_E_INVALIDACTION; return WR_E_INVALIDACTION;
writer_dec_indent(This);
if (This->starttagopen) { if (This->starttagopen) {
static WCHAR closetagW[] = {' ','/','>'}; static WCHAR closetagW[] = {' ','/','>'};
write_output_buffer(This->output, closetagW, ARRAY_SIZE(closetagW)); write_output_buffer(This->output, closetagW, ARRAY_SIZE(closetagW));
@ -838,6 +893,7 @@ static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface)
} }
else { else {
/* write full end tag */ /* write full end tag */
write_node_indent(This);
write_output_buffer(This->output, closeelementW, ARRAY_SIZE(closeelementW)); write_output_buffer(This->output, closeelementW, ARRAY_SIZE(closeelementW));
write_output_buffer(This->output, element->qname, element->len); write_output_buffer(This->output, element->qname, element->len);
write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW)); write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW));
@ -888,11 +944,19 @@ static HRESULT WINAPI xmlwriter_WriteFullEndElement(IXmlWriter *iface)
if (!element) if (!element)
return WR_E_INVALIDACTION; return WR_E_INVALIDACTION;
writer_close_starttag(This);
writer_dec_indent(This);
/* don't force full end tag to the next line */
if (This->state == XmlWriterState_ElemStarted)
This->state = XmlWriterState_Content;
else
write_node_indent(This);
/* write full end tag */ /* write full end tag */
write_output_buffer(This->output, closeelementW, ARRAY_SIZE(closeelementW)); write_output_buffer(This->output, closeelementW, ARRAY_SIZE(closeelementW));
write_output_buffer(This->output, element->qname, element->len); write_output_buffer(This->output, element->qname, element->len);
write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW)); write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW));
This->starttagopen = FALSE;
return S_OK; return S_OK;
} }
@ -984,6 +1048,7 @@ static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LP
} }
write_encoding_bom(This); write_encoding_bom(This);
write_node_indent(This);
write_output_buffer(This->output, openpiW, ARRAY_SIZE(openpiW)); write_output_buffer(This->output, openpiW, ARRAY_SIZE(openpiW));
write_output_buffer(This->output, name, -1); write_output_buffer(This->output, name, -1);
write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW)); write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW));
@ -1120,8 +1185,10 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre
push_element(This, element); push_element(This, element);
write_node_indent(This);
write_output_buffer(This->output, ltW, ARRAY_SIZE(ltW)); write_output_buffer(This->output, ltW, ARRAY_SIZE(ltW));
write_output_qname(This->output, prefix, local_name); write_output_qname(This->output, prefix, local_name);
writer_inc_indent(This);
return S_OK; return S_OK;
} }
@ -1292,6 +1359,7 @@ HRESULT WINAPI CreateXmlWriter(REFIID riid, void **obj, IMalloc *imalloc)
writer->imalloc = imalloc; writer->imalloc = imalloc;
if (imalloc) IMalloc_AddRef(imalloc); if (imalloc) IMalloc_AddRef(imalloc);
writer->output = NULL; writer->output = NULL;
writer->indent_level = 0;
writer->indent = FALSE; writer->indent = FALSE;
writer->bom = TRUE; writer->bom = TRUE;
writer->omitxmldecl = FALSE; writer->omitxmldecl = FALSE;

View file

@ -222,7 +222,7 @@ reactos/dll/win32/xinput1_1 # Synced to WineStaging-1.9.11
reactos/dll/win32/xinput1_2 # Synced to WineStaging-1.9.11 reactos/dll/win32/xinput1_2 # Synced to WineStaging-1.9.11
reactos/dll/win32/xinput1_3 # Synced to WineStaging-1.9.16 reactos/dll/win32/xinput1_3 # Synced to WineStaging-1.9.16
reactos/dll/win32/xinput9_1_0 # Synced to WineStaging-1.9.11 reactos/dll/win32/xinput9_1_0 # Synced to WineStaging-1.9.11
reactos/dll/win32/xmllite # Synced to WineStaging-1.9.11 reactos/dll/win32/xmllite # Synced to WineStaging-1.9.16
reactos/dll/cpl/inetcpl # Synced to WineStaging-1.9.11 reactos/dll/cpl/inetcpl # Synced to WineStaging-1.9.11