From bb1435d9715f85aca381b23e55c1e2bd4aa0c78a Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Tue, 26 Jan 2021 21:10:23 +0000 Subject: [PATCH] Update to tinyxml2 8.0.0 --- tinyxml2/.gitignore | 2 + tinyxml2/CMakeLists.txt | 26 ++++--- tinyxml2/dox | 2 +- tinyxml2/readme.md | 15 +++- tinyxml2/tinyxml2.cpp | 49 ++++++++++--- tinyxml2/tinyxml2.h | 31 +++++--- tinyxml2/tinyxml2/test.vcxproj | 18 ++--- tinyxml2/tinyxml2/tinyxml2.vcxproj | 18 ++--- tinyxml2/xmltest.cpp | 109 +++++++++++++++++++++++++++-- 9 files changed, 218 insertions(+), 52 deletions(-) diff --git a/tinyxml2/.gitignore b/tinyxml2/.gitignore index 1456145..3d32441 100644 --- a/tinyxml2/.gitignore +++ b/tinyxml2/.gitignore @@ -18,3 +18,5 @@ tinyxml2/temp/ *.o *.vc.db *.vc.opendb +libtinyxml2.a +xmltest diff --git a/tinyxml2/CMakeLists.txt b/tinyxml2/CMakeLists.txt index 3eedc48..9f9ab07 100644 --- a/tinyxml2/CMakeLists.txt +++ b/tinyxml2/CMakeLists.txt @@ -21,8 +21,8 @@ include(CTest) ################################ # set lib version here -set(GENERIC_LIB_VERSION "7.1.0") -set(GENERIC_LIB_SOVERSION "7") +set(GENERIC_LIB_VERSION "8.0.0") +set(GENERIC_LIB_SOVERSION "8") ################################ # Add definitions @@ -79,9 +79,15 @@ export(TARGETS tinyxml2 install(TARGETS tinyxml2 EXPORT ${CMAKE_PROJECT_NAME}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + RUNTIME + DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT tinyxml2_runtime + LIBRARY + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT tinyxml2_libraries + ARCHIVE + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT tinyxml2_libraries) if(BUILD_TESTING AND BUILD_TESTS) add_executable(xmltest xmltest.cpp) @@ -98,10 +104,10 @@ if(BUILD_TESTING AND BUILD_TESTS) add_test(NAME xmltest COMMAND xmltest WORKING_DIRECTORY $) endif() -install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT tinyxml2_headers) configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT tinyxml2_config) # uninstall target if(NOT TARGET uninstall) @@ -129,7 +135,9 @@ write_basic_package_version_file( install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}) + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME} + COMPONENT tinyxml2_config) install(EXPORT ${CMAKE_PROJECT_NAME}Targets NAMESPACE tinyxml2:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}) + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME} + COMPONENT tinyxml2_config) diff --git a/tinyxml2/dox b/tinyxml2/dox index d954a20..feebfba 100644 --- a/tinyxml2/dox +++ b/tinyxml2/dox @@ -38,7 +38,7 @@ PROJECT_NAME = "TinyXML-2" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 7.1.0 +PROJECT_NUMBER = 8.0.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/tinyxml2/readme.md b/tinyxml2/readme.md index 7dad55d..e9933aa 100644 --- a/tinyxml2/readme.md +++ b/tinyxml2/readme.md @@ -262,11 +262,24 @@ There are 2 files in TinyXML-2: And additionally a test file: * xmltest.cpp -Simply compile and run. There is a visual studio 2017 project included, a simple Makefile, +Simply compile and run. There is a visual studio 2019 project included, a simple Makefile, an Xcode project, a Code::Blocks project, and a cmake CMakeLists.txt included to help you. The top of tinyxml.h even has a simple g++ command line if you are using Unix/Linux/BSD and don't want to use a build system. +Building TinyXML-2 - Using vcpkg +-------------------------------- + +You can download and install TinyXML-2 using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager: + + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + ./bootstrap-vcpkg.sh + ./vcpkg integrate install + ./vcpkg install tinyxml2 + +The TinyXML-2 port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. + Versioning ---------- diff --git a/tinyxml2/tinyxml2.cpp b/tinyxml2/tinyxml2.cpp index 6b79917..9e7ff1a 100755 --- a/tinyxml2/tinyxml2.cpp +++ b/tinyxml2/tinyxml2.cpp @@ -617,17 +617,17 @@ bool XMLUtil::ToBool( const char* str, bool* value ) *value = (ival==0) ? false : true; return true; } - static const char* TRUE[] = { "true", "True", "TRUE", 0 }; - static const char* FALSE[] = { "false", "False", "FALSE", 0 }; + static const char* TRUE_VALS[] = { "true", "True", "TRUE", 0 }; + static const char* FALSE_VALS[] = { "false", "False", "FALSE", 0 }; - for (int i = 0; TRUE[i]; ++i) { - if (StringEqual(str, TRUE[i])) { + for (int i = 0; TRUE_VALS[i]; ++i) { + if (StringEqual(str, TRUE_VALS[i])) { *value = true; return true; } } - for (int i = 0; FALSE[i]; ++i) { - if (StringEqual(str, FALSE[i])) { + for (int i = 0; FALSE_VALS[i]; ++i) { + if (StringEqual(str, FALSE_VALS[i])) { *value = false; return true; } @@ -1961,6 +1961,39 @@ XMLAttribute* XMLElement::CreateAttribute() return attrib; } + +XMLElement* XMLElement::InsertNewChildElement(const char* name) +{ + XMLElement* node = _document->NewElement(name); + return InsertEndChild(node) ? node : 0; +} + +XMLComment* XMLElement::InsertNewComment(const char* comment) +{ + XMLComment* node = _document->NewComment(comment); + return InsertEndChild(node) ? node : 0; +} + +XMLText* XMLElement::InsertNewText(const char* text) +{ + XMLText* node = _document->NewText(text); + return InsertEndChild(node) ? node : 0; +} + +XMLDeclaration* XMLElement::InsertNewDeclaration(const char* text) +{ + XMLDeclaration* node = _document->NewDeclaration(text); + return InsertEndChild(node) ? node : 0; +} + +XMLUnknown* XMLElement::InsertNewUnknown(const char* text) +{ + XMLUnknown* node = _document->NewUnknown(text); + return InsertEndChild(node) ? node : 0; +} + + + // // // foobar @@ -2101,7 +2134,7 @@ XMLDocument::~XMLDocument() } -void XMLDocument::MarkInUse(XMLNode* node) +void XMLDocument::MarkInUse(const XMLNode* const node) { TIXMLASSERT(node); TIXMLASSERT(node->_parent == 0); @@ -2635,8 +2668,6 @@ void XMLPrinter::OpenElement( const char* name, bool compactMode ) if ( _textDepth < 0 && !_firstElement && !compactMode ) { Putc( '\n' ); - } - if ( !compactMode ) { PrintSpace( _depth ); } diff --git a/tinyxml2/tinyxml2.h b/tinyxml2/tinyxml2.h index a432f7e..1beadaa 100755 --- a/tinyxml2/tinyxml2.h +++ b/tinyxml2/tinyxml2.h @@ -98,12 +98,12 @@ distribution. /* Versioning, past 1.0.14: http://semver.org/ */ -static const int TIXML2_MAJOR_VERSION = 7; -static const int TIXML2_MINOR_VERSION = 1; +static const int TIXML2_MAJOR_VERSION = 8; +static const int TIXML2_MINOR_VERSION = 0; static const int TIXML2_PATCH_VERSION = 0; -#define TINYXML2_MAJOR_VERSION 7 -#define TINYXML2_MINOR_VERSION 1 +#define TINYXML2_MAJOR_VERSION 8 +#define TINYXML2_MINOR_VERSION 0 #define TINYXML2_PATCH_VERSION 0 // A fixed element depth limit is problematic. There needs to be a @@ -562,7 +562,7 @@ class TINYXML2_LIB XMLUtil TIXMLASSERT( p ); return p; } - static char* SkipWhiteSpace( char* p, int* curLineNumPtr ) { + static char* SkipWhiteSpace( char* const p, int* curLineNumPtr ) { return const_cast( SkipWhiteSpace( const_cast(p), curLineNumPtr ) ); } @@ -600,7 +600,7 @@ class TINYXML2_LIB XMLUtil return strncmp( p, q, nChar ) == 0; } - inline static bool IsUTF8Continuation( char p ) { + inline static bool IsUTF8Continuation( const char p ) { return ( p & 0x80 ) != 0; } @@ -1640,7 +1640,22 @@ class TINYXML2_LIB XMLElement : public XMLNode /// See QueryIntText() double DoubleText(double defaultValue = 0) const; /// See QueryIntText() - float FloatText(float defaultValue = 0) const; + float FloatText(float defaultValue = 0) const; + + /** + Convenience method to create a new XMLElement and add it as last (right) + child of this node. Returns the created and inserted element. + */ + XMLElement* InsertNewChildElement(const char* name); + /// See InsertNewChildElement() + XMLComment* InsertNewComment(const char* comment); + /// See InsertNewChildElement() + XMLText* InsertNewText(const char* text); + /// See InsertNewChildElement() + XMLDeclaration* InsertNewDeclaration(const char* text); + /// See InsertNewChildElement() + XMLUnknown* InsertNewUnknown(const char* text); + // internal: enum ElementClosingType { @@ -1894,7 +1909,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode char* Identify( char* p, XMLNode** node ); // internal - void MarkInUse(XMLNode*); + void MarkInUse(const XMLNode* const); virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const { return 0; diff --git a/tinyxml2/tinyxml2/test.vcxproj b/tinyxml2/tinyxml2/test.vcxproj index 02bec85..df15660 100644 --- a/tinyxml2/tinyxml2/test.vcxproj +++ b/tinyxml2/tinyxml2/test.vcxproj @@ -37,60 +37,60 @@ {E8FB2712-8666-4662-A5B8-2B5B0FB1A260} test - 10.0.16299.0 + 10.0 Application true Unicode - v141 + v142 Application true Unicode - v141 + v142 Application true Unicode - v141 + v142 Application true Unicode - v141 + v142 Application false true Unicode - v141 + v142 Application false true Unicode - v141 + v142 Application false true Unicode - v141 + v142 Application false true Unicode - v141 + v142 Unicode diff --git a/tinyxml2/tinyxml2/tinyxml2.vcxproj b/tinyxml2/tinyxml2/tinyxml2.vcxproj index 5a7b7ee..4e34f97 100755 --- a/tinyxml2/tinyxml2/tinyxml2.vcxproj +++ b/tinyxml2/tinyxml2/tinyxml2.vcxproj @@ -38,60 +38,60 @@ {D1C528B6-AA02-4D29-9D61-DC08E317A70D} Win32Proj tinyxml2 - 10.0.16299.0 + 10.0 StaticLibrary true Unicode - v141 + v142 DynamicLibrary true Unicode - v141 + v142 StaticLibrary true Unicode - v141 + v142 DynamicLibrary true Unicode - v141 + v142 StaticLibrary false true Unicode - v141 + v142 DynamicLibrary false true Unicode - v141 + v142 StaticLibrary false true Unicode - v141 + v142 DynamicLibrary false true Unicode - v141 + v142 StaticLibrary diff --git a/tinyxml2/xmltest.cpp b/tinyxml2/xmltest.cpp index 5a07547..adcba6d 100755 --- a/tinyxml2/xmltest.cpp +++ b/tinyxml2/xmltest.cpp @@ -968,8 +968,8 @@ int main( int argc, const char ** argv ) printer.PushAttribute("attrib-int", int(1)); printer.PushAttribute("attrib-unsigned", unsigned(2)); printer.PushAttribute("attrib-int64", int64_t(3)); - printer.PushAttribute("attrib-uint64", uint64_t(37)); - printer.PushAttribute("attrib-bool", true); + printer.PushAttribute("attrib-uint64", uint64_t(37)); + printer.PushAttribute("attrib-bool", true); printer.PushAttribute("attrib-double", 4.0); printer.CloseElement(); fclose(printerfp); @@ -989,14 +989,111 @@ int main( int argc, const char ** argv ) XMLTest("attrib-unsigned", unsigned(2), attrib->UnsignedValue(), true); attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-int64"); XMLTest("attrib-int64", int64_t(3), attrib->Int64Value(), true); - attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-uint64"); - XMLTest("attrib-uint64", uint64_t(37), attrib->Unsigned64Value(), true); - attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-bool"); + attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-uint64"); + XMLTest("attrib-uint64", uint64_t(37), attrib->Unsigned64Value(), true); + attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-bool"); XMLTest("attrib-bool", true, attrib->BoolValue(), true); attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-double"); XMLTest("attrib-double", 4.0, attrib->DoubleValue(), true); } + // Add API_testcatse :PushDeclaration();PushText();PushComment() + { + FILE* fp1 = fopen("resources/out/printer_1.xml", "w"); + XMLPrinter printer(fp1); + + printer.PushDeclaration("version = '1.0' enconding = 'utf-8'"); + + printer.OpenElement("foo"); + printer.PushAttribute("attrib-text", "text"); + + printer.OpenElement("text"); + printer.PushText("Tinyxml2"); + printer.CloseElement(); + + printer.OpenElement("int"); + printer.PushText(int(11)); + printer.CloseElement(); + + printer.OpenElement("unsigned"); + printer.PushText(unsigned(12)); + printer.CloseElement(); + + printer.OpenElement("int64_t"); + printer.PushText(int64_t(13)); + printer.CloseElement(); + + printer.OpenElement("uint64_t"); + printer.PushText(uint64_t(14)); + printer.CloseElement(); + + printer.OpenElement("bool"); + printer.PushText(true); + printer.CloseElement(); + + printer.OpenElement("float"); + printer.PushText("1.56"); + printer.CloseElement(); + + printer.OpenElement("double"); + printer.PushText("12.12"); + printer.CloseElement(); + printer.OpenElement("comment"); + printer.PushComment("this is Tinyxml2"); + printer.CloseElement(); + + printer.CloseElement(); + fclose(fp1); + } + { + XMLDocument doc; + doc.LoadFile("resources/out/printer_1.xml"); + XMLTest("XMLPrinter Stream mode: load", XML_SUCCESS, doc.ErrorID(), true); + + const XMLDocument& cdoc = doc; + + const XMLElement* root = cdoc.FirstChildElement("foo"); + + const char* text_value; + text_value = root->FirstChildElement("text")->GetText(); + XMLTest("PushText( const char* text, bool cdata=false ) test", "Tinyxml2", text_value); + + int int_value; + int_value = root->FirstChildElement("int")->IntText(); + XMLTest("PushText( int value ) test", 11, int_value); + + unsigned unsigned_value; + unsigned_value = root->FirstChildElement("unsigned")->UnsignedText(); + XMLTest("PushText( unsigned value ) test", (unsigned)12, unsigned_value); + + int64_t int64_t_value; + int64_t_value = root->FirstChildElement("int64_t")->Int64Text(); + XMLTest("PushText( int64_t value ) test", (int64_t) 13, int64_t_value); + + uint64_t uint64_t_value; + uint64_t_value = root->FirstChildElement("uint64_t")->Unsigned64Text(); + XMLTest("PushText( uint64_t value ) test", (uint64_t) 14, uint64_t_value); + + float float_value; + float_value = root->FirstChildElement("float")->FloatText(); + XMLTest("PushText( float value ) test", 1.56f, float_value); + + double double_value; + double_value = root->FirstChildElement("double")->DoubleText(); + XMLTest("PushText( double value ) test", 12.12, double_value); + + bool bool_value; + bool_value = root->FirstChildElement("bool")->BoolText(); + XMLTest("PushText( bool value ) test", true, bool_value); + + const XMLComment* comment = root->FirstChildElement("comment")->FirstChild()->ToComment(); + const char* comment_value = comment->Value(); + XMLTest("PushComment() test", "this is Tinyxml2", comment_value); + + const XMLDeclaration* declaration = cdoc.FirstChild()->ToDeclaration(); + const char* declaration_value = declaration->Value(); + XMLTest("PushDeclaration() test", "version = '1.0' enconding = 'utf-8'", declaration_value); + } } @@ -1290,7 +1387,7 @@ int main( int argc, const char ** argv ) } { - // trying to repro ]1874301]. If it doesn't go into an infinite loop, all is well. + // trying to repro [1874301]. If it doesn't go into an infinite loop, all is well. unsigned char buf[] = "