diff options
author | 2016-09-03 14:40:41 +0200 | |
---|---|---|
committer | 2016-09-03 14:40:41 +0200 | |
commit | fe95be105b61612362e958be0d83d8bae7f3aba9 (patch) | |
tree | 6d30f81d90d50b1fbc5aa4a83719dcb2ea007a2a | |
parent | 73793c599cd22e8a265bd4d8d19a50d2c9104dd5 (diff) |
Update PugiXML (nw)
-rw-r--r-- | 3rdparty/pugixml/.codecov.yml | 2 | ||||
-rw-r--r-- | 3rdparty/pugixml/Makefile | 4 | ||||
-rw-r--r-- | 3rdparty/pugixml/scripts/nuget.autopkg | 18 | ||||
-rw-r--r-- | 3rdparty/pugixml/scripts/nuget_build.bat | 4 | ||||
-rw-r--r-- | 3rdparty/pugixml/src/pugixml.cpp | 91 | ||||
-rw-r--r-- | 3rdparty/pugixml/src/pugixml.hpp | 6 | ||||
-rw-r--r-- | 3rdparty/pugixml/tests/test_document.cpp | 2 | ||||
-rw-r--r-- | 3rdparty/pugixml/tests/test_parse.cpp | 24 |
8 files changed, 132 insertions, 19 deletions
diff --git a/3rdparty/pugixml/.codecov.yml b/3rdparty/pugixml/.codecov.yml new file mode 100644 index 00000000000..230b4ed788e --- /dev/null +++ b/3rdparty/pugixml/.codecov.yml @@ -0,0 +1,2 @@ +comment: false + diff --git a/3rdparty/pugixml/Makefile b/3rdparty/pugixml/Makefile index b9e597e1d79..673aaee3a19 100644 --- a/3rdparty/pugixml/Makefile +++ b/3rdparty/pugixml/Makefile @@ -14,7 +14,7 @@ EXECUTABLE=$(BUILD)/test VERSION=$(shell sed -n 's/.*version \(.*\).*/\1/p' src/pugiconfig.hpp) RELEASE=$(shell git ls-files src docs/*.html docs/*.css docs/samples docs/images scripts contrib CMakeLists.txt readme.txt) -CXXFLAGS=-g -Wall -Wextra -Werror -pedantic -Wundef -Wshadow -Wold-style-cast -Wcast-align +CXXFLAGS=-g -Wall -Wextra -Werror -pedantic -Wundef -Wshadow -Wcast-align -Wcast-qual -Wold-style-cast LDFLAGS= ifeq ($(config),release) @@ -61,7 +61,7 @@ ifeq ($(config),coverage) test: $(EXECUTABLE) -@find $(BUILD) -name '*.gcda' -exec rm {} + ./$(EXECUTABLE) - @gcov -b -o $(BUILD)/src/ pugixml.cpp.gcda | sed -e '/./{H;$!d;}' -e 'x;/pugixml.cpp/!d;' + @gcov -o $(BUILD)/src/ pugixml.cpp.gcda | sed -e '/./{H;$!d;}' -e 'x;/pugixml.cpp/!d;' @find . -name '*.gcov' -and -not -name 'pugixml.cpp.gcov' -exec rm {} + else test: $(EXECUTABLE) diff --git a/3rdparty/pugixml/scripts/nuget.autopkg b/3rdparty/pugixml/scripts/nuget.autopkg index b42d76b09f0..1a3fc228870 100644 --- a/3rdparty/pugixml/scripts/nuget.autopkg +++ b/3rdparty/pugixml/scripts/nuget.autopkg @@ -1,3 +1,9 @@ +configurations { + Toolset { + key: "PlatformToolset"; + choices: { v140, v120, v110, v100 }; + } +} nuget { nuspec { id = pugixml; @@ -24,9 +30,13 @@ nuget { files { include: { "..\src\*.hpp" }; - [x86,release] { lib: vs2015\Win32_Release\pugixml.lib; } - [x86,debug] { lib: vs2015\Win32_Debug\pugixml.lib; } - [x64,release] { lib: vs2015\x64_Release\pugixml.lib; } - [x64,debug] { lib: vs2015\x64_Debug\pugixml.lib; } + [x86,v120,release] { lib: vs2013\x32\pugixmls.lib; } + [x86,v120,debug] { lib: vs2013\x32\pugixmlsd.lib; } + [x64,v120,release] { lib: vs2013\x64\pugixmls.lib; } + [x64,v120,debug] { lib: vs2013\x64\pugixmlsd.lib; } + [x86,v140,release] { lib: vs2015\Win32_Release\pugixml.lib; } + [x86,v140,debug] { lib: vs2015\Win32_Debug\pugixml.lib; } + [x64,v140,release] { lib: vs2015\x64_Release\pugixml.lib; } + [x64,v140,debug] { lib: vs2015\x64_Debug\pugixml.lib; } } } diff --git a/3rdparty/pugixml/scripts/nuget_build.bat b/3rdparty/pugixml/scripts/nuget_build.bat index ab3c98421fd..588f036f88e 100644 --- a/3rdparty/pugixml/scripts/nuget_build.bat +++ b/3rdparty/pugixml/scripts/nuget_build.bat @@ -2,6 +2,10 @@ cd %~dp0 "%VS140COMNTOOLS%\VsMSBuildCmd.bat" && ^ +msbuild pugixml_vs2013_static.vcxproj /t:Rebuild /p:Configuration=Debug /p:Platform=x86 /v:minimal /nologo && ^ +msbuild pugixml_vs2013_static.vcxproj /t:Rebuild /p:Configuration=Release /p:Platform=x86 /v:minimal /nologo && ^ +msbuild pugixml_vs2013_static.vcxproj /t:Rebuild /p:Configuration=Debug /p:Platform=x64 /v:minimal /nologo && ^ +msbuild pugixml_vs2013_static.vcxproj /t:Rebuild /p:Configuration=Release /p:Platform=x64 /v:minimal /nologo && ^ msbuild pugixml_vs2015.vcxproj /t:Rebuild /p:Configuration=Debug /p:Platform=x86 /v:minimal /nologo && ^ msbuild pugixml_vs2015.vcxproj /t:Rebuild /p:Configuration=Release /p:Platform=x86 /v:minimal /nologo && ^ msbuild pugixml_vs2015.vcxproj /t:Rebuild /p:Configuration=Debug /p:Platform=x64 /v:minimal /nologo && ^ diff --git a/3rdparty/pugixml/src/pugixml.cpp b/3rdparty/pugixml/src/pugixml.cpp index fc4870179d1..d2f0d6b9a2b 100644 --- a/3rdparty/pugixml/src/pugixml.cpp +++ b/3rdparty/pugixml/src/pugixml.cpp @@ -1895,8 +1895,67 @@ PUGI__NS_BEGIN return is_little_endian() ? encoding_utf32_le : encoding_utf32_be; } - PUGI__FN xml_encoding guess_buffer_encoding(uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) + PUGI__FN bool parse_declaration_encoding(const uint8_t* data, size_t size, const uint8_t*& out_encoding, size_t& out_length) { + #define PUGI__SCANCHAR(ch) { if (offset >= size || data[offset] != ch) return false; offset++; } + #define PUGI__SCANCHARTYPE(ct) { while (offset < size && PUGI__IS_CHARTYPE(data[offset], ct)) offset++; } + + // check if we have a non-empty XML declaration + if (size < 6 || !((data[0] == '<') & (data[1] == '?') & (data[2] == 'x') & (data[3] == 'm') & (data[4] == 'l') && PUGI__IS_CHARTYPE(data[5], ct_space))) + return false; + + // scan XML declaration until the encoding field + for (size_t i = 6; i + 1 < size; ++i) + { + // declaration can not contain ? in quoted values + if (data[i] == '?') + return false; + + if (data[i] == 'e' && data[i + 1] == 'n') + { + size_t offset = i; + + // encoding follows the version field which can't contain 'en' so this has to be the encoding if XML is well formed + PUGI__SCANCHAR('e'); PUGI__SCANCHAR('n'); PUGI__SCANCHAR('c'); PUGI__SCANCHAR('o'); + PUGI__SCANCHAR('d'); PUGI__SCANCHAR('i'); PUGI__SCANCHAR('n'); PUGI__SCANCHAR('g'); + + // S? = S? + PUGI__SCANCHARTYPE(ct_space); + PUGI__SCANCHAR('='); + PUGI__SCANCHARTYPE(ct_space); + + // the only two valid delimiters are ' and " + uint8_t delimiter = (offset < size && data[offset] == '"') ? '"' : '\''; + + PUGI__SCANCHAR(delimiter); + + size_t start = offset; + + out_encoding = data + offset; + + PUGI__SCANCHARTYPE(ct_symbol); + + out_length = offset - start; + + PUGI__SCANCHAR(delimiter); + + return true; + } + } + + return false; + + #undef PUGI__SCANCHAR + #undef PUGI__SCANCHARTYPE + } + + PUGI__FN xml_encoding guess_buffer_encoding(const uint8_t* data, size_t size) + { + // skip encoding autodetection if input buffer is too small + if (size < 4) return encoding_utf8; + + uint8_t d0 = data[0], d1 = data[1], d2 = data[2], d3 = data[3]; + // look for BOM in first few bytes if (d0 == 0 && d1 == 0 && d2 == 0xfe && d3 == 0xff) return encoding_utf32_be; if (d0 == 0xff && d1 == 0xfe && d2 == 0 && d3 == 0) return encoding_utf32_le; @@ -1909,13 +1968,32 @@ PUGI__NS_BEGIN if (d0 == 0x3c && d1 == 0 && d2 == 0 && d3 == 0) return encoding_utf32_le; if (d0 == 0 && d1 == 0x3c && d2 == 0 && d3 == 0x3f) return encoding_utf16_be; if (d0 == 0x3c && d1 == 0 && d2 == 0x3f && d3 == 0) return encoding_utf16_le; - if (d0 == 0x3c && d1 == 0x3f && d2 == 0x78 && d3 == 0x6d) return encoding_utf8; // look for utf16 < followed by node name (this may fail, but is better than utf8 since it's zero terminated so early) if (d0 == 0 && d1 == 0x3c) return encoding_utf16_be; if (d0 == 0x3c && d1 == 0) return encoding_utf16_le; - // no known BOM detected, assume utf8 + // no known BOM detected; parse declaration + const uint8_t* enc = 0; + size_t enc_length = 0; + + if (d0 == 0x3c && d1 == 0x3f && d2 == 0x78 && d3 == 0x6d && parse_declaration_encoding(data, size, enc, enc_length)) + { + // iso-8859-1 (case-insensitive) + if (enc_length == 10 + && (enc[0] | ' ') == 'i' && (enc[1] | ' ') == 's' && (enc[2] | ' ') == 'o' + && enc[3] == '-' && enc[4] == '8' && enc[5] == '8' && enc[6] == '5' && enc[7] == '9' + && enc[8] == '-' && enc[9] == '1') + return encoding_latin1; + + // latin1 (case-insensitive) + if (enc_length == 6 + && (enc[0] | ' ') == 'l' && (enc[1] | ' ') == 'a' && (enc[2] | ' ') == 't' + && (enc[3] | ' ') == 'i' && (enc[4] | ' ') == 'n' + && enc[5] == '1') + return encoding_latin1; + } + return encoding_utf8; } @@ -1933,15 +2011,10 @@ PUGI__NS_BEGIN // only do autodetection if no explicit encoding is requested if (encoding != encoding_auto) return encoding; - // skip encoding autodetection if input buffer is too small - if (size < 4) return encoding_utf8; - // try to guess encoding (based on XML specification, Appendix F.1) const uint8_t* data = static_cast<const uint8_t*>(contents); - PUGI__DMC_VOLATILE uint8_t d0 = data[0], d1 = data[1], d2 = data[2], d3 = data[3]; - - return guess_buffer_encoding(d0, d1, d2, d3); + return guess_buffer_encoding(data, size); } PUGI__FN bool get_mutable_buffer(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) diff --git a/3rdparty/pugixml/src/pugixml.hpp b/3rdparty/pugixml/src/pugixml.hpp index 9c41b14643c..09bd6923dbc 100644 --- a/3rdparty/pugixml/src/pugixml.hpp +++ b/3rdparty/pugixml/src/pugixml.hpp @@ -273,7 +273,7 @@ namespace pugi // Construct writer from a FILE* object; void* is used to avoid header dependencies on stdio xml_writer_file(void* file); - virtual void write(const void* data, size_t size) override; + virtual void write(const void* data, size_t size); private: void* file; @@ -288,7 +288,7 @@ namespace pugi xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream); xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream); - virtual void write(const void* data, size_t size) override; + virtual void write(const void* data, size_t size); private: std::basic_ostream<char, std::char_traits<char> >* narrow_stream; @@ -1214,7 +1214,7 @@ namespace pugi explicit xpath_exception(const xpath_parse_result& result); // Get error message - virtual const char* what() const throw() override; + virtual const char* what() const throw(); // Get parse result const xpath_parse_result& result() const; diff --git a/3rdparty/pugixml/tests/test_document.cpp b/3rdparty/pugixml/tests/test_document.cpp index b442126677f..73a36f561ff 100644 --- a/3rdparty/pugixml/tests/test_document.cpp +++ b/3rdparty/pugixml/tests/test_document.cpp @@ -915,7 +915,7 @@ TEST(document_contents_preserve_latin1) { // parse into document (preserve comments, declaration and whitespace pcdata) xml_document doc; - CHECK(doc.load_buffer(files[src].data, files[src].size, parse_default | parse_ws_pcdata | parse_declaration | parse_comments, files[src].encoding)); + CHECK(doc.load_buffer(files[src].data, files[src].size, parse_default | parse_ws_pcdata | parse_declaration | parse_comments)); // compare saved document with the original (raw formatting, without extra declaration, write bom if it was in original file) CHECK(test_save_narrow(doc, format_raw | format_no_declaration | format_write_bom, files[dst].encoding, files[dst].data, files[dst].size)); diff --git a/3rdparty/pugixml/tests/test_parse.cpp b/3rdparty/pugixml/tests/test_parse.cpp index dc709a2e801..f199eb9645a 100644 --- a/3rdparty/pugixml/tests/test_parse.cpp +++ b/3rdparty/pugixml/tests/test_parse.cpp @@ -1182,3 +1182,27 @@ TEST(parse_embed_pcdata) CHECK_NODE_EX(doc, STR("<node>\n\t<key>value</key>\n\t<child>\n\t\t<inner1>value1</inner1>\n\t\t<inner2>value2</inner2>outer</child>\n\t<two>text<data />\n\t</two>\n</node>\n"), STR("\t"), format_indent); } } + +TEST(parse_encoding_detect) +{ + char test[] = "<?xml version='1.0' encoding='utf-8'?><n/>"; + + xml_document doc; + CHECK(doc.load_buffer(test, sizeof(test))); +} + +TEST(parse_encoding_detect_latin1) +{ + char test0[] = "<?xml version='1.0' encoding='utf-8'?><n/>"; + char test1[] = "<?xml version='1.0' encoding='iso-8859-1'?><n/>"; + char test2[] = "<?xml version='1.0' encoding = \"latin1\"?><n/>"; + char test3[] = "<?xml version='1.0' encoding='ISO-8859-1'?><n/>"; + char test4[] = "<?xml version='1.0' encoding = \"LATIN1\"?><n/>"; + + xml_document doc; + CHECK(doc.load_buffer(test0, sizeof(test0)).encoding == encoding_utf8); + CHECK(doc.load_buffer(test1, sizeof(test1)).encoding == encoding_latin1); + CHECK(doc.load_buffer(test2, sizeof(test2)).encoding == encoding_latin1); + CHECK(doc.load_buffer(test3, sizeof(test3)).encoding == encoding_latin1); + CHECK(doc.load_buffer(test4, sizeof(test4)).encoding == encoding_latin1); +} |