Module: wine Branch: master Commit: d1658260a2baa4be183baa8eb0003e57aa715337 URL: http://source.winehq.org/git/wine.git/?a=commit;h=d1658260a2baa4be183baa8eb0...
Author: Hans Leidekker hans@codeweavers.com Date: Wed Aug 5 17:13:57 2015 +0200
xmllite: Implement CreateXmlWriterOutputWithEncodingCodePage.
---
dlls/xmllite/reader.c | 10 ++++++++++ dlls/xmllite/tests/writer.c | 19 ++++++++++++++++++ dlls/xmllite/writer.c | 44 ++++++++++++++++++++++++++++++++---------- dlls/xmllite/xmllite.spec | 2 +- dlls/xmllite/xmllite_private.h | 1 + 5 files changed, 65 insertions(+), 11 deletions(-)
diff --git a/dlls/xmllite/reader.c b/dlls/xmllite/reader.c index 2aa9d95..525b4f7 100644 --- a/dlls/xmllite/reader.c +++ b/dlls/xmllite/reader.c @@ -160,6 +160,16 @@ const WCHAR *get_encoding_name(xml_encoding encoding) return xml_encoding_map[encoding].name; }
+xml_encoding get_encoding_from_codepage(UINT codepage) +{ + int i; + for (i = 0; i < sizeof(xml_encoding_map)/sizeof(xml_encoding_map[0]); i++) + { + if (xml_encoding_map[i].cp == codepage) return xml_encoding_map[i].enc; + } + return XmlEncoding_Unknown; +} + typedef struct { char *data; diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index d81a934..577b330 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -36,6 +36,10 @@ static HRESULT (WINAPI *pCreateXmlWriterOutputWithEncodingName)(IUnknown *stream IMalloc *imalloc, LPCWSTR encoding_name, IXmlWriterOutput **output); +static HRESULT (WINAPI *pCreateXmlWriterOutputWithEncodingCodePage)(IUnknown *stream, + IMalloc *imalloc, + UINT codepage, + IXmlWriterOutput **output);
static HRESULT WINAPI testoutput_QueryInterface(IUnknown *iface, REFIID riid, void **obj) { @@ -168,6 +172,7 @@ static BOOL init_pointers(void) #define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE; MAKEFUNC(CreateXmlWriter); MAKEFUNC(CreateXmlWriterOutputWithEncodingName); + MAKEFUNC(CreateXmlWriterOutputWithEncodingCodePage); #undef MAKEFUNC
return TRUE; @@ -193,6 +198,20 @@ static void test_writeroutput(void) ok(unk != NULL, "got %p\n", unk); /* releasing 'unk' crashes on native */ IUnknown_Release(output); + + output = NULL; + hr = pCreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, ~0u, &output); + ok(hr == S_OK, "got %08x\n", hr); + IUnknown_Release(output); + + hr = pCreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, CP_UTF8, &output); + ok(hr == S_OK, "got %08x\n", hr); + unk = NULL; + hr = IUnknown_QueryInterface(output, &IID_IXmlWriterOutput, (void**)&unk); + ok(hr == S_OK, "got %08x\n", hr); + ok(unk != NULL, "got %p\n", unk); + /* releasing 'unk' crashes on native */ + IUnknown_Release(output); }
static void test_writestartdocument(void) diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 8387935..fa01553 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -1085,19 +1085,12 @@ HRESULT WINAPI CreateXmlWriter(REFIID riid, void **obj, IMalloc *imalloc) return S_OK; }
-HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream, - IMalloc *imalloc, - LPCWSTR encoding, - IXmlWriterOutput **output) +static HRESULT create_writer(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding, + IXmlWriterOutput **output) { - static const WCHAR utf8W[] = {'U','T','F','-','8',0}; xmlwriteroutput *writeroutput; HRESULT hr;
- TRACE("%p %p %s %p\n", stream, imalloc, debugstr_w(encoding), output); - - if (!stream || !output) return E_INVALIDARG; - *output = NULL;
if (imalloc) @@ -1110,7 +1103,7 @@ HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream, writeroutput->ref = 1; writeroutput->imalloc = imalloc; if (imalloc) IMalloc_AddRef(imalloc); - writeroutput->encoding = parse_encoding_name(encoding ? encoding : utf8W, -1); + writeroutput->encoding = encoding; writeroutput->stream = NULL; hr = init_output_buffer(writeroutput); if (FAILED(hr)) { @@ -1126,3 +1119,34 @@ HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
return S_OK; } + +HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream, + IMalloc *imalloc, + LPCWSTR encoding, + IXmlWriterOutput **output) +{ + static const WCHAR utf8W[] = {'U','T','F','-','8',0}; + xml_encoding xml_enc; + + TRACE("%p %p %s %p\n", stream, imalloc, debugstr_w(encoding), output); + + if (!stream || !output) return E_INVALIDARG; + + xml_enc = parse_encoding_name(encoding ? encoding : utf8W, -1); + return create_writer(stream, imalloc, xml_enc, output); +} + +HRESULT WINAPI CreateXmlWriterOutputWithEncodingCodePage(IUnknown *stream, + IMalloc *imalloc, + UINT codepage, + IXmlWriterOutput **output) +{ + xml_encoding xml_enc; + + TRACE("%p %p %u %p\n", stream, imalloc, codepage, output); + + if (!stream || !output) return E_INVALIDARG; + + xml_enc = get_encoding_from_codepage(codepage); + return create_writer(stream, imalloc, xml_enc, output); +} diff --git a/dlls/xmllite/xmllite.spec b/dlls/xmllite/xmllite.spec index 295bff6..d6ee017 100644 --- a/dlls/xmllite/xmllite.spec +++ b/dlls/xmllite/xmllite.spec @@ -2,5 +2,5 @@ @ stub CreateXmlReaderInputWithEncodingCodePage @ stdcall CreateXmlReaderInputWithEncodingName(ptr ptr ptr long ptr ptr) @ stdcall CreateXmlWriter(ptr ptr ptr) -@ stub CreateXmlWriterOutputWithEncodingCodePage +@ stdcall CreateXmlWriterOutputWithEncodingCodePage(ptr ptr long ptr) @ stdcall CreateXmlWriterOutputWithEncodingName(ptr ptr wstr ptr) diff --git a/dlls/xmllite/xmllite_private.h b/dlls/xmllite/xmllite_private.h index 7936939..3f03379 100644 --- a/dlls/xmllite/xmllite_private.h +++ b/dlls/xmllite/xmllite_private.h @@ -71,5 +71,6 @@ typedef enum xml_encoding parse_encoding_name(const WCHAR*,int) DECLSPEC_HIDDEN; HRESULT get_code_page(xml_encoding,UINT*) DECLSPEC_HIDDEN; const WCHAR *get_encoding_name(xml_encoding) DECLSPEC_HIDDEN; +xml_encoding get_encoding_from_codepage(UINT) DECLSPEC_HIDDEN;
#endif /* __XMLLITE_PRIVATE__ */