Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/reader.c | 138 ++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 85 deletions(-)
diff --git a/dlls/xmllite/reader.c b/dlls/xmllite/reader.c index eddc4d8eec0..a463934202a 100644 --- a/dlls/xmllite/reader.c +++ b/dlls/xmllite/reader.c @@ -83,17 +83,6 @@ typedef enum StringValue_Last } XmlReaderStringValue;
-static const WCHAR usasciiW[] = {'U','S','-','A','S','C','I','I',0}; -static const WCHAR utf16W[] = {'U','T','F','-','1','6',0}; -static const WCHAR utf8W[] = {'U','T','F','-','8',0}; - -static const WCHAR dblquoteW[] = {'"',0}; -static const WCHAR quoteW[] = {''',0}; -static const WCHAR ltW[] = {'<',0}; -static const WCHAR gtW[] = {'>',0}; -static const WCHAR commentW[] = {'<','!','-','-',0}; -static const WCHAR piW[] = {'<','?',0}; - BOOL is_namestartchar(WCHAR ch);
static const char *debugstr_nodetype(XmlNodeType nodetype) @@ -153,10 +142,11 @@ struct xml_encoding_data UINT cp; };
-static const struct xml_encoding_data xml_encoding_map[] = { - { usasciiW, XmlEncoding_USASCII, 20127 }, - { utf16W, XmlEncoding_UTF16, 1200 }, - { utf8W, XmlEncoding_UTF8, CP_UTF8 }, +static const struct xml_encoding_data xml_encoding_map[] = +{ + { L"US-ASCII", XmlEncoding_USASCII, 20127 }, + { L"UTF-16", XmlEncoding_UTF16, 1200 }, + { L"UTF-8", XmlEncoding_UTF8, CP_UTF8 }, };
const WCHAR *get_encoding_name(xml_encoding encoding) @@ -221,11 +211,11 @@ typedef struct } strval;
static WCHAR emptyW[] = {0}; -static WCHAR xmlW[] = {'x','m','l',0}; -static WCHAR xmlnsW[] = {'x','m','l','n','s',0}; -static const strval strval_empty = { emptyW }; -static const strval strval_xml = { xmlW, 3 }; -static const strval strval_xmlns = { xmlnsW, 5 }; +static WCHAR xmlW[] = L"xml"; +static WCHAR xmlnsW[] = L"xmlns"; +static const strval strval_empty = { (WCHAR *)emptyW, 0 }; +static const strval strval_xml = { (WCHAR *)xmlW, 3 }; +static const strval strval_xmlns = { (WCHAR *)xmlnsW, 5 };
struct reader_position { @@ -1185,11 +1175,10 @@ static int reader_skipspaces(xmlreader *reader) /* [26] VersionNum ::= '1.' [0-9]+ */ static HRESULT reader_parse_versionnum(xmlreader *reader, strval *val) { - static const WCHAR onedotW[] = {'1','.',0}; WCHAR *ptr, *ptr2; UINT start;
- if (reader_cmp(reader, onedotW)) return WC_E_XMLDECL; + if (reader_cmp(reader, L"1.")) return WC_E_XMLDECL;
start = reader_get_cur(reader); /* skip "1." */ @@ -1211,19 +1200,22 @@ static HRESULT reader_parse_versionnum(xmlreader *reader, strval *val) /* [25] Eq ::= S? '=' S? */ static HRESULT reader_parse_eq(xmlreader *reader) { - static const WCHAR eqW[] = {'=',0}; reader_skipspaces(reader); - if (reader_cmp(reader, eqW)) return WC_E_EQUAL; + if (reader_cmp(reader, L"=")) return WC_E_EQUAL; /* skip '=' */ reader_skipn(reader, 1); reader_skipspaces(reader); return S_OK; }
+static BOOL reader_is_quote(xmlreader *reader) +{ + return !reader_cmp(reader, L"'") || !reader_cmp(reader, L"""); +} + /* [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"') */ static HRESULT reader_parse_versioninfo(xmlreader *reader) { - static const WCHAR versionW[] = {'v','e','r','s','i','o','n',0}; struct reader_position position; strval val, name; HRESULT hr; @@ -1231,7 +1223,7 @@ static HRESULT reader_parse_versioninfo(xmlreader *reader) if (!reader_skipspaces(reader)) return WC_E_WHITESPACE;
position = reader->position; - if (reader_cmp(reader, versionW)) return WC_E_XMLDECL; + if (reader_cmp(reader, L"version")) return WC_E_XMLDECL; reader_init_strvalue(reader_get_cur(reader), 7, &name); /* skip 'version' */ reader_skipn(reader, 7); @@ -1239,7 +1231,7 @@ static HRESULT reader_parse_versioninfo(xmlreader *reader) hr = reader_parse_eq(reader); if (FAILED(hr)) return hr;
- if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW)) + if (!reader_is_quote(reader)) return WC_E_QUOTE; /* skip "'"|'"' */ reader_skipn(reader, 1); @@ -1247,7 +1239,7 @@ static HRESULT reader_parse_versioninfo(xmlreader *reader) hr = reader_parse_versionnum(reader, &val); if (FAILED(hr)) return hr;
- if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW)) + if (!reader_is_quote(reader)) return WC_E_QUOTE;
/* skip "'"|'"' */ @@ -1299,7 +1291,6 @@ static HRESULT reader_parse_encname(xmlreader *reader, strval *val) /* [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" ) */ static HRESULT reader_parse_encdecl(xmlreader *reader) { - static const WCHAR encodingW[] = {'e','n','c','o','d','i','n','g',0}; struct reader_position position; strval name, val; HRESULT hr; @@ -1307,7 +1298,7 @@ static HRESULT reader_parse_encdecl(xmlreader *reader) if (!reader_skipspaces(reader)) return S_FALSE;
position = reader->position; - if (reader_cmp(reader, encodingW)) return S_FALSE; + if (reader_cmp(reader, L"encoding")) return S_FALSE; name.str = reader_get_ptr(reader); name.start = reader_get_cur(reader); name.len = 8; @@ -1317,7 +1308,7 @@ static HRESULT reader_parse_encdecl(xmlreader *reader) hr = reader_parse_eq(reader); if (FAILED(hr)) return hr;
- if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW)) + if (!reader_is_quote(reader)) return WC_E_QUOTE; /* skip "'"|'"' */ reader_skipn(reader, 1); @@ -1325,7 +1316,7 @@ static HRESULT reader_parse_encdecl(xmlreader *reader) hr = reader_parse_encname(reader, &val); if (FAILED(hr)) return hr;
- if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW)) + if (!reader_is_quote(reader)) return WC_E_QUOTE;
/* skip "'"|'"' */ @@ -1337,9 +1328,6 @@ static HRESULT reader_parse_encdecl(xmlreader *reader) /* [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"')) */ static HRESULT reader_parse_sddecl(xmlreader *reader) { - static const WCHAR standaloneW[] = {'s','t','a','n','d','a','l','o','n','e',0}; - static const WCHAR yesW[] = {'y','e','s',0}; - static const WCHAR noW[] = {'n','o',0}; struct reader_position position; strval name, val; UINT start; @@ -1348,7 +1336,7 @@ static HRESULT reader_parse_sddecl(xmlreader *reader) if (!reader_skipspaces(reader)) return S_FALSE;
position = reader->position; - if (reader_cmp(reader, standaloneW)) return S_FALSE; + if (reader_cmp(reader, L"standalone")) return S_FALSE; reader_init_strvalue(reader_get_cur(reader), 10, &name); /* skip 'standalone' */ reader_skipn(reader, 10); @@ -1356,21 +1344,21 @@ static HRESULT reader_parse_sddecl(xmlreader *reader) hr = reader_parse_eq(reader); if (FAILED(hr)) return hr;
- if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW)) + if (!reader_is_quote(reader)) return WC_E_QUOTE; /* skip "'"|'"' */ reader_skipn(reader, 1);
- if (reader_cmp(reader, yesW) && reader_cmp(reader, noW)) + if (reader_cmp(reader, L"yes") && reader_cmp(reader, L"no")) return WC_E_XMLDECL;
start = reader_get_cur(reader); /* skip 'yes'|'no' */ - reader_skipn(reader, reader_cmp(reader, yesW) ? 2 : 3); + reader_skipn(reader, reader_cmp(reader, L"yes") ? 2 : 3); reader_init_strvalue(start, reader_get_cur(reader)-start, &val); TRACE("standalone=%s\n", debug_strval(reader, &val));
- if (reader_cmp(reader, quoteW) && reader_cmp(reader, dblquoteW)) + if (!reader_is_quote(reader)) return WC_E_QUOTE; /* skip "'"|'"' */ reader_skipn(reader, 1); @@ -1381,13 +1369,10 @@ static HRESULT reader_parse_sddecl(xmlreader *reader) /* [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' */ static HRESULT reader_parse_xmldecl(xmlreader *reader) { - static const WCHAR xmldeclW[] = {'<','?','x','m','l',' ',0}; - static const WCHAR declcloseW[] = {'?','>',0}; struct reader_position position; HRESULT hr;
- /* check if we have "<?xml " */ - if (reader_cmp(reader, xmldeclW)) + if (reader_cmp(reader, L"<?xml ")) return S_FALSE;
reader_skipn(reader, 2); @@ -1406,7 +1391,7 @@ static HRESULT reader_parse_xmldecl(xmlreader *reader) return hr;
reader_skipspaces(reader); - if (reader_cmp(reader, declcloseW)) + if (reader_cmp(reader, L"?>")) return WC_E_XMLDECL;
/* skip '?>' */ @@ -1605,8 +1590,7 @@ static HRESULT reader_parse_name(xmlreader *reader, strval *name) /* [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) */ static HRESULT reader_parse_pitarget(xmlreader *reader, strval *target) { - static const WCHAR xmlW[] = {'x','m','l'}; - static const strval xmlval = { (WCHAR*)xmlW, 3 }; + static const strval xmlval = { (WCHAR *)L"xml", 3 }; strval name; WCHAR *ptr; HRESULT hr; @@ -1762,9 +1746,9 @@ static HRESULT reader_parse_misc(xmlreader *reader)
if (is_wchar_space(*cur)) hr = reader_parse_whitespace(reader); - else if (!reader_cmp(reader, commentW)) + else if (!reader_cmp(reader, L"<!--")) hr = reader_parse_comment(reader); - else if (!reader_cmp(reader, piW)) + else if (!reader_cmp(reader, L"<?")) hr = reader_parse_pi(reader); else break; @@ -1829,8 +1813,8 @@ static HRESULT reader_parse_pub_literal(xmlreader *reader, strval *literal) /* [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral */ static HRESULT reader_parse_externalid(xmlreader *reader) { - static WCHAR systemW[] = {'S','Y','S','T','E','M',0}; - static WCHAR publicW[] = {'P','U','B','L','I','C',0}; + static WCHAR systemW[] = L"SYSTEM"; + static WCHAR publicW[] = L"PUBLIC"; struct reader_position position = reader->position; strval name, sys; HRESULT hr; @@ -1882,13 +1866,11 @@ static HRESULT reader_parse_externalid(xmlreader *reader) /* [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>' */ static HRESULT reader_parse_dtd(xmlreader *reader) { - static const WCHAR doctypeW[] = {'<','!','D','O','C','T','Y','P','E',0}; strval name; WCHAR *cur; HRESULT hr;
- /* check if we have "<!DOCTYPE" */ - if (reader_cmp(reader, doctypeW)) return S_FALSE; + if (reader_cmp(reader, L"<!DOCTYPE")) return S_FALSE; reader_shrink(reader);
/* DTD processing is not allowed by default */ @@ -2042,16 +2024,11 @@ static HRESULT reader_parse_qname(xmlreader *reader, strval *prefix, strval *loc
static WCHAR get_predefined_entity(const xmlreader *reader, const strval *name) { - static const WCHAR entltW[] = {'l','t'}; - static const WCHAR entgtW[] = {'g','t'}; - static const WCHAR entampW[] = {'a','m','p'}; - static const WCHAR entaposW[] = {'a','p','o','s'}; - static const WCHAR entquotW[] = {'q','u','o','t'}; - static const strval lt = { (WCHAR*)entltW, 2 }; - static const strval gt = { (WCHAR*)entgtW, 2 }; - static const strval amp = { (WCHAR*)entampW, 3 }; - static const strval apos = { (WCHAR*)entaposW, 4 }; - static const strval quot = { (WCHAR*)entquotW, 4 }; + static const strval lt = { (WCHAR *)L"lt", 2 }; + static const strval gt = { (WCHAR *)L"gt", 2 }; + static const strval amp = { (WCHAR *)L"amp", 3 }; + static const strval apos = { (WCHAR *)L"apos", 4 }; + static const strval quot = { (WCHAR *)L"quot", 4 }; WCHAR *str = reader_get_strptr(reader, name);
switch (*str) @@ -2270,12 +2247,10 @@ static HRESULT reader_parse_stag(xmlreader *reader, strval *prefix, strval *loca
for (;;) { - static const WCHAR endW[] = {'/','>',0}; - reader_skipspaces(reader);
/* empty element */ - if ((reader->is_empty_element = !reader_cmp(reader, endW))) + if ((reader->is_empty_element = !reader_cmp(reader, L"/>"))) { struct element *element = &reader->empty_element;
@@ -2294,7 +2269,7 @@ static HRESULT reader_parse_stag(xmlreader *reader, strval *prefix, strval *loca }
/* got a start tag */ - if (!reader_cmp(reader, gtW)) + if (!reader_cmp(reader, L">")) { /* skip '>' */ reader_skipn(reader, 1); @@ -2317,7 +2292,7 @@ static HRESULT reader_parse_element(xmlreader *reader) { case XmlReadResumeState_Initial: /* check if we are really on element */ - if (reader_cmp(reader, ltW)) return S_FALSE; + if (reader_cmp(reader, L"<")) return S_FALSE;
/* skip '<' */ reader_skipn(reader, 1); @@ -2371,7 +2346,7 @@ static HRESULT reader_parse_endtag(xmlreader *reader)
reader_skipspaces(reader);
- if (reader_cmp(reader, gtW)) return WC_E_GREATERTHAN; + if (reader_cmp(reader, L">")) return WC_E_GREATERTHAN;
/* skip '>' */ reader_skipn(reader, 1); @@ -2473,8 +2448,6 @@ static HRESULT reader_parse_chardata(xmlreader *reader) position = reader->position; while (*ptr) { - static const WCHAR ampW[] = {'&',0}; - /* CDATA closing sequence ']]>' is not allowed */ if (ptr[0] == ']' && ptr[1] == ']' && ptr[2] == '>') return WC_E_CDSECTEND; @@ -2495,7 +2468,7 @@ static HRESULT reader_parse_chardata(xmlreader *reader) /* this covers a case when text has leading whitespace chars */ if (!is_wchar_space(*ptr)) reader->nodetype = XmlNodeType_Text;
- if (!reader_cmp(reader, ampW)) + if (!reader_cmp(reader, L"&")) reader_parse_reference(reader); else reader_skipn(reader, 1); @@ -2509,9 +2482,6 @@ static HRESULT reader_parse_chardata(xmlreader *reader) /* [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* */ static HRESULT reader_parse_content(xmlreader *reader) { - static const WCHAR cdstartW[] = {'<','!','[','C','D','A','T','A','[',0}; - static const WCHAR etagW[] = {'<','/',0}; - if (reader->resumestate != XmlReadResumeState_Initial) { switch (reader->resumestate) @@ -2533,19 +2503,19 @@ static HRESULT reader_parse_content(xmlreader *reader) reader_shrink(reader);
/* handle end tag here, it indicates end of content as well */ - if (!reader_cmp(reader, etagW)) + if (!reader_cmp(reader, L"</")) return reader_parse_endtag(reader);
- if (!reader_cmp(reader, commentW)) + if (!reader_cmp(reader, L"<!--")) return reader_parse_comment(reader);
- if (!reader_cmp(reader, piW)) + if (!reader_cmp(reader, L"<?")) return reader_parse_pi(reader);
- if (!reader_cmp(reader, cdstartW)) + if (!reader_cmp(reader, L"<![CDATA[")) return reader_parse_cdata(reader);
- if (!reader_cmp(reader, ltW)) + if (!reader_cmp(reader, L"<")) return reader_parse_element(reader);
/* what's left must be CharData */ @@ -3002,10 +2972,8 @@ static HRESULT WINAPI xmlreader_MoveToNextAttribute(IXmlReader* iface)
static void reader_get_attribute_ns_uri(xmlreader *reader, struct attribute *attr, const WCHAR **uri, UINT *len) { - static const WCHAR xmlns_uriW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','3','.','o','r','g','/', - '2','0','0','0','/','x','m','l','n','s','/',0}; - static const WCHAR xml_uriW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','3','.','o','r','g','/', - 'X','M','L','/','1','9','9','8','/','n','a','m','e','s','p','a','c','e',0}; + static const WCHAR xmlns_uriW[] = L"http://www.w3.org/2000/xmlns/"; + static const WCHAR xml_uriW[] = L"http://www.w3.org/XML/1998/namespace";
/* Check for reserved prefixes first */ if ((strval_eq(reader, &attr->prefix, &strval_empty) && strval_eq(reader, &attr->localname, &strval_xmlns)) ||