xmllite/writer: Simplify single character writes.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2018-11-02 10:56:58 +03:00 committed by Alexandre Julliard
parent 4c779c07bd
commit ea927971f2
1 changed files with 25 additions and 32 deletions

View File

@ -42,11 +42,6 @@ DEFINE_GUID(IID_IXmlWriterOutput, 0xc1131708, 0x0f59, 0x477f, 0x93, 0x59, 0x7d,
static const WCHAR closeelementW[] = {'<','/'};
static const WCHAR closetagW[] = {' ','/','>'};
static const WCHAR closepiW[] = {'?','>'};
static const WCHAR ltW[] = {'<'};
static const WCHAR gtW[] = {'>'};
static const WCHAR spaceW[] = {' '};
static const WCHAR quoteW[] = {'"'};
static const WCHAR eqW[] = {'='};
static const WCHAR xmlnsW[] = {' ','x','m','l','n','s'};
static const WCHAR xmlnsuriW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','3','.','o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0};
@ -492,33 +487,31 @@ static HRESULT write_output_buffer(xmlwriteroutput *output, const WCHAR *data, i
return S_OK;
}
static HRESULT write_output_buffer_quoted(xmlwriteroutput *output, const WCHAR *data, int len)
{
write_output_buffer(output, quoteW, ARRAY_SIZE(quoteW));
if (!is_empty_string(data))
write_output_buffer(output, data, len);
write_output_buffer(output, quoteW, ARRAY_SIZE(quoteW));
return S_OK;
}
static HRESULT write_output_buffer_char(xmlwriteroutput *output, WCHAR ch)
{
return write_output_buffer(output, &ch, 1);
}
static HRESULT write_output_buffer_quoted(xmlwriteroutput *output, const WCHAR *data, int len)
{
write_output_buffer_char(output, '"');
if (!is_empty_string(data))
write_output_buffer(output, data, len);
write_output_buffer_char(output, '"');
return S_OK;
}
/* TODO: test if we need to validate char range */
static HRESULT write_output_qname(xmlwriteroutput *output, const WCHAR *prefix, int prefix_len,
const WCHAR *local_name, int local_len)
{
static const WCHAR colW[] = {':'};
assert(prefix_len >= 0 && local_len >= 0);
if (prefix_len)
write_output_buffer(output, prefix, prefix_len);
if (prefix_len && local_len)
write_output_buffer(output, colW, ARRAY_SIZE(colW));
write_output_buffer_char(output, ':');
write_output_buffer(output, local_name, local_len);
@ -645,7 +638,7 @@ static void writer_output_ns(xmlwriter *writer, struct element *element)
continue;
write_output_qname(writer->output, xmlnsW, ARRAY_SIZE(xmlnsW), ns->prefix, ns->prefix_len);
write_output_buffer(writer->output, eqW, ARRAY_SIZE(eqW));
write_output_buffer_char(writer->output, '=');
write_output_buffer_quoted(writer->output, ns->uri, -1);
}
}
@ -657,7 +650,7 @@ static HRESULT writer_close_starttag(xmlwriter *writer)
if (!writer->starttagopen) return S_OK;
writer_output_ns(writer, LIST_ENTRY(list_head(&writer->elements), struct element, entry));
hr = write_output_buffer(writer->output, gtW, ARRAY_SIZE(gtW));
hr = write_output_buffer_char(writer->output, '>');
writer->starttagopen = 0;
return hr;
}
@ -868,9 +861,9 @@ static HRESULT WINAPI xmlwriter_WriteAttributes(IXmlWriter *iface, IXmlReader *p
static void write_output_attribute(xmlwriter *writer, const WCHAR *prefix, int prefix_len,
const WCHAR *local, int local_len, const WCHAR *value)
{
write_output_buffer(writer->output, spaceW, ARRAY_SIZE(spaceW));
write_output_buffer_char(writer->output, ' ');
write_output_qname(writer->output, prefix, prefix_len, local, local_len);
write_output_buffer(writer->output, eqW, ARRAY_SIZE(eqW));
write_output_buffer_char(writer->output, '=');
write_output_buffer_quoted(writer->output, value, -1);
}
@ -1138,14 +1131,14 @@ static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment)
for (i = 0; i < len; i++) {
write_output_buffer(This->output, comment + i, 1);
if (comment[i] == '-' && (i + 1 < len) && comment[i+1] == '-')
write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW));
write_output_buffer_char(This->output, ' ');
}
}
else
write_output_buffer(This->output, comment, len);
if (len && comment[len-1] == '-')
write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW));
write_output_buffer_char(This->output, ' ');
}
write_output_buffer(This->output, ccloseW, ARRAY_SIZE(ccloseW));
@ -1194,7 +1187,7 @@ static HRESULT WINAPI xmlwriter_WriteDocType(IXmlWriter *iface, LPCWSTR name, LP
{
write_output_buffer(This->output, publicW, ARRAY_SIZE(publicW));
write_output_buffer_quoted(This->output, pubid, pubid_len);
write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW));
write_output_buffer_char(This->output, ' ');
write_output_buffer_quoted(This->output, sysid, -1);
}
else if (sysid)
@ -1269,7 +1262,7 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr
write_encoding_bom(This);
write_node_indent(This);
write_output_buffer(This->output, ltW, ARRAY_SIZE(ltW));
write_output_buffer_char(This->output, '<');
if (ns)
write_output_qname(This->output, ns->prefix, ns->prefix_len, local_name, local_len);
else
@ -1278,17 +1271,17 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr
if (!ns && (prefix_len || !is_empty_string(uri)))
{
write_output_qname(This->output, xmlnsW, ARRAY_SIZE(xmlnsW), prefix, prefix_len);
write_output_buffer(This->output, eqW, ARRAY_SIZE(eqW));
write_output_buffer_char(This->output, '=');
write_output_buffer_quoted(This->output, uri, -1);
}
if (value)
{
write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW));
write_output_buffer_char(This->output, '>');
write_output_buffer(This->output, value, -1);
write_output_buffer(This->output, closeelementW, ARRAY_SIZE(closeelementW));
write_output_qname(This->output, prefix, prefix_len, local_name, local_len);
write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW));
write_output_buffer_char(This->output, '>');
}
else
write_output_buffer(This->output, closetagW, ARRAY_SIZE(closetagW));
@ -1365,7 +1358,7 @@ static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface)
write_node_indent(This);
write_output_buffer(This->output, closeelementW, ARRAY_SIZE(closeelementW));
write_output_buffer(This->output, element->qname, element->len);
write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW));
write_output_buffer_char(This->output, '>');
}
writer_free_element(This, element);
@ -1435,7 +1428,7 @@ static HRESULT WINAPI xmlwriter_WriteFullEndElement(IXmlWriter *iface)
/* write full end tag */
write_output_buffer(This->output, closeelementW, ARRAY_SIZE(closeelementW));
write_output_buffer(This->output, element->qname, element->len);
write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW));
write_output_buffer_char(This->output, '>');
writer_free_element(This, element);
@ -1538,7 +1531,7 @@ static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LP
write_node_indent(This);
write_output_buffer(This->output, openpiW, ARRAY_SIZE(openpiW));
write_output_buffer(This->output, name, -1);
write_output_buffer(This->output, spaceW, ARRAY_SIZE(spaceW));
write_output_buffer_char(This->output, ' ');
write_output_buffer(This->output, text, -1);
write_output_buffer(This->output, closepiW, ARRAY_SIZE(closepiW));
@ -1707,7 +1700,7 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre
if (!ns && uri)
writer_push_ns(This, prefix, prefix_len, uri);
write_output_buffer(This->output, ltW, ARRAY_SIZE(ltW));
write_output_buffer_char(This->output, '<');
if (ns)
write_output_qname(This->output, ns->prefix, ns->prefix_len, local_name, local_len);
else