Commit 2564862b authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/writer: Use internal function to create writer output implicitly.

parent ef7b911a
...@@ -148,6 +148,9 @@ static const char *debugstr_writer_prop(XmlWriterProperty prop) ...@@ -148,6 +148,9 @@ static const char *debugstr_writer_prop(XmlWriterProperty prop)
return prop_names[prop]; return prop_names[prop];
} }
static HRESULT create_writer_output(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding,
const WCHAR *encoding_name, xmlwriteroutput **out);
/* writer output memory allocation functions */ /* writer output memory allocation functions */
static inline void *writeroutput_alloc(xmlwriteroutput *output, size_t len) static inline void *writeroutput_alloc(xmlwriteroutput *output, size_t len)
{ {
...@@ -735,10 +738,10 @@ static HRESULT WINAPI xmlwriter_SetOutput(IXmlWriter *iface, IUnknown *output) ...@@ -735,10 +738,10 @@ static HRESULT WINAPI xmlwriter_SetOutput(IXmlWriter *iface, IUnknown *output)
} }
if (hr != S_OK || !writeroutput) { if (hr != S_OK || !writeroutput) {
/* create IXmlWriterOutput basing on supplied interface */ /* Create output for given stream. */
hr = CreateXmlWriterOutputWithEncodingName(output, This->imalloc, NULL, &writeroutput); hr = create_writer_output(output, This->imalloc, XmlEncoding_UTF8, NULL, &This->output);
if (hr != S_OK) return hr; if (hr != S_OK)
This->output = impl_from_IXmlWriterOutput(writeroutput); return hr;
} }
if (This->output->encoding == XmlEncoding_Unknown) if (This->output->encoding == XmlEncoding_Unknown)
...@@ -1795,12 +1798,12 @@ HRESULT WINAPI CreateXmlWriter(REFIID riid, void **obj, IMalloc *imalloc) ...@@ -1795,12 +1798,12 @@ HRESULT WINAPI CreateXmlWriter(REFIID riid, void **obj, IMalloc *imalloc)
} }
static HRESULT create_writer_output(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding, static HRESULT create_writer_output(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding,
const WCHAR *encoding_name, IXmlWriterOutput **output) const WCHAR *encoding_name, xmlwriteroutput **out)
{ {
xmlwriteroutput *writeroutput; xmlwriteroutput *writeroutput;
HRESULT hr; HRESULT hr;
*output = NULL; *out = NULL;
if (imalloc) if (imalloc)
writeroutput = IMalloc_Alloc(imalloc, sizeof(*writeroutput)); writeroutput = IMalloc_Alloc(imalloc, sizeof(*writeroutput));
...@@ -1833,40 +1836,52 @@ static HRESULT create_writer_output(IUnknown *stream, IMalloc *imalloc, xml_enco ...@@ -1833,40 +1836,52 @@ static HRESULT create_writer_output(IUnknown *stream, IMalloc *imalloc, xml_enco
IUnknown_QueryInterface(stream, &IID_IUnknown, (void**)&writeroutput->output); IUnknown_QueryInterface(stream, &IID_IUnknown, (void**)&writeroutput->output);
*output = &writeroutput->IXmlWriterOutput_iface; *out = writeroutput;
TRACE("returning iface %p\n", *output); TRACE("Created writer output %p\n", *out);
return S_OK; return S_OK;
} }
HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream, HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream, IMalloc *imalloc, const WCHAR *encoding,
IMalloc *imalloc, IXmlWriterOutput **out)
LPCWSTR encoding,
IXmlWriterOutput **output)
{ {
static const WCHAR utf8W[] = {'U','T','F','-','8',0}; static const WCHAR utf8W[] = {'U','T','F','-','8',0};
xmlwriteroutput *output;
xml_encoding xml_enc; xml_encoding xml_enc;
HRESULT hr;
TRACE("%p %p %s %p\n", stream, imalloc, debugstr_w(encoding), out);
TRACE("%p %p %s %p\n", stream, imalloc, debugstr_w(encoding), output); if (!stream || !out)
return E_INVALIDARG;
if (!stream || !output) return E_INVALIDARG; *out = NULL;
xml_enc = parse_encoding_name(encoding ? encoding : utf8W, -1); xml_enc = parse_encoding_name(encoding ? encoding : utf8W, -1);
return create_writer_output(stream, imalloc, xml_enc, encoding, output); if (SUCCEEDED(hr = create_writer_output(stream, imalloc, xml_enc, encoding, &output)))
*out = &output->IXmlWriterOutput_iface;
return hr;
} }
HRESULT WINAPI CreateXmlWriterOutputWithEncodingCodePage(IUnknown *stream, HRESULT WINAPI CreateXmlWriterOutputWithEncodingCodePage(IUnknown *stream, IMalloc *imalloc, UINT codepage,
IMalloc *imalloc, IXmlWriterOutput **out)
UINT codepage,
IXmlWriterOutput **output)
{ {
xmlwriteroutput *output;
xml_encoding xml_enc; xml_encoding xml_enc;
HRESULT hr;
TRACE("%p %p %u %p\n", stream, imalloc, codepage, output); TRACE("%p %p %u %p\n", stream, imalloc, codepage, out);
if (!stream || !output) return E_INVALIDARG; if (!stream || !out)
return E_INVALIDARG;
*out = NULL;
xml_enc = get_encoding_from_codepage(codepage); xml_enc = get_encoding_from_codepage(codepage);
return create_writer_output(stream, imalloc, xml_enc, NULL, output); if (SUCCEEDED(hr = create_writer_output(stream, imalloc, xml_enc, NULL, &output)))
*out = &output->IXmlWriterOutput_iface;
return hr;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment