mirror of
https://github.com/leethomason/tinyxml2.git
synced 2026-07-29 15:13:01 +04:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ce9f9a3a7 | |||
| 682fda289f | |||
| e6a464942f | |||
| 98137e6936 | |||
| 111f462dc4 | |||
| aba13c50bf | |||
| e48a1310fe | |||
| 3324d04d58 | |||
| c4e29afeaf | |||
| 5c9a452c73 | |||
| fc99428a82 |
@@ -59,7 +59,7 @@ browsers or have more complete XML needs, TinyXML-2 is not the parser for you.
|
|||||||
TinyXML-1 vs. TinyXML-2
|
TinyXML-1 vs. TinyXML-2
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
TinyXML-2 long been the focus of all development. It is well tested
|
TinyXML-2 has long been the focus of all development. It is well tested
|
||||||
and should be used instead of TinyXML-1.
|
and should be used instead of TinyXML-1.
|
||||||
|
|
||||||
TinyXML-2 uses a similar API to TinyXML-1 and the same
|
TinyXML-2 uses a similar API to TinyXML-1 and the same
|
||||||
@@ -145,7 +145,7 @@ It essentially causes the XML to be parsed twice.
|
|||||||
|
|
||||||
For applications that need to know about text nodes that are composed entirely of
|
For applications that need to know about text nodes that are composed entirely of
|
||||||
whitespace, PEDANTIC_WHITESPACE is available. PEDANTIC_WHITESPACE maintains all the
|
whitespace, PEDANTIC_WHITESPACE is available. PEDANTIC_WHITESPACE maintains all the
|
||||||
whilespace between elements.
|
whitespace between elements.
|
||||||
|
|
||||||
PEDANTIC_WHITESPACE is a new mode and not as tested as the other whitespace modes.
|
PEDANTIC_WHITESPACE is a new mode and not as tested as the other whitespace modes.
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ will have the Value() of "Far & Away" when queried from the XMLText object,
|
|||||||
and will be written back to the XML stream/file as an ampersand.
|
and will be written back to the XML stream/file as an ampersand.
|
||||||
|
|
||||||
Additionally, any character can be specified by its Unicode code point:
|
Additionally, any character can be specified by its Unicode code point:
|
||||||
The syntax ` ` or ` ` are both to the non-breaking space character.
|
The syntax ` ` or ` ` both refer to the non-breaking space character.
|
||||||
This is called a 'numeric character reference'. Any numeric character reference
|
This is called a 'numeric character reference'. Any numeric character reference
|
||||||
that isn't one of the special entities above, will be read, but written as a
|
that isn't one of the special entities above, will be read, but written as a
|
||||||
regular code point. The output is correct, but the entity syntax isn't preserved.
|
regular code point. The output is correct, but the entity syntax isn't preserved.
|
||||||
@@ -270,7 +270,7 @@ tinyxml2.h files in your project and build with your other source code.
|
|||||||
|
|
||||||
There is also a CMake build included. CMake is the general build for TinyXML-2.
|
There is also a CMake build included. CMake is the general build for TinyXML-2.
|
||||||
|
|
||||||
(Additional build systems are costly to maintain, and tend to bit-rot. They are
|
(Additional build systems are costly to maintain, and tend to become outdated. They are
|
||||||
being removed over time.)
|
being removed over time.)
|
||||||
|
|
||||||
Building TinyXML-2 - Using vcpkg
|
Building TinyXML-2 - Using vcpkg
|
||||||
|
|||||||
+42
-7
@@ -32,6 +32,27 @@ distribution.
|
|||||||
# include <cstdarg>
|
# include <cstdarg>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Handle fallthrough attribute for different compilers
|
||||||
|
#ifndef __has_attribute
|
||||||
|
# define __has_attribute(x) 0
|
||||||
|
#endif
|
||||||
|
#ifndef __has_cpp_attribute
|
||||||
|
# define __has_cpp_attribute(x) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
# define TIXML_FALLTHROUGH (void(0))
|
||||||
|
#elif (__cplusplus >= 201703L && __has_cpp_attribute(fallthrough))
|
||||||
|
# define TIXML_FALLTHROUGH [[fallthrough]]
|
||||||
|
#elif __has_cpp_attribute(clang::fallthrough)
|
||||||
|
# define TIXML_FALLTHROUGH [[clang::fallthrough]]
|
||||||
|
#elif __has_attribute(fallthrough)
|
||||||
|
# define TIXML_FALLTHROUGH __attribute__((fallthrough))
|
||||||
|
#else
|
||||||
|
# define TIXML_FALLTHROUGH (void(0))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
|
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
|
||||||
// Microsoft Visual Studio, version 2005 and higher. Not WinCE.
|
// Microsoft Visual Studio, version 2005 and higher. Not WinCE.
|
||||||
/*int _snprintf_s(
|
/*int _snprintf_s(
|
||||||
@@ -93,6 +114,9 @@ distribution.
|
|||||||
#define TIXML_VSNPRINTF vsnprintf
|
#define TIXML_VSNPRINTF vsnprintf
|
||||||
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
|
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
|
||||||
{
|
{
|
||||||
|
if (!format) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int len = vsnprintf( 0, 0, format, va );
|
int len = vsnprintf( 0, 0, format, va );
|
||||||
TIXMLASSERT( len >= 0 );
|
TIXMLASSERT( len >= 0 );
|
||||||
return len;
|
return len;
|
||||||
@@ -446,17 +470,17 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length
|
|||||||
--output;
|
--output;
|
||||||
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
|
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
|
||||||
input >>= 6;
|
input >>= 6;
|
||||||
//fall through
|
TIXML_FALLTHROUGH;
|
||||||
case 3:
|
case 3:
|
||||||
--output;
|
--output;
|
||||||
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
|
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
|
||||||
input >>= 6;
|
input >>= 6;
|
||||||
//fall through
|
TIXML_FALLTHROUGH;
|
||||||
case 2:
|
case 2:
|
||||||
--output;
|
--output;
|
||||||
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
|
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
|
||||||
input >>= 6;
|
input >>= 6;
|
||||||
//fall through
|
TIXML_FALLTHROUGH;
|
||||||
case 1:
|
case 1:
|
||||||
--output;
|
--output;
|
||||||
*output = static_cast<char>(input | FIRST_BYTE_MARK[*length]);
|
*output = static_cast<char>(input | FIRST_BYTE_MARK[*length]);
|
||||||
@@ -810,7 +834,17 @@ XMLNode::XMLNode( XMLDocument* doc ) :
|
|||||||
|
|
||||||
XMLNode::~XMLNode()
|
XMLNode::~XMLNode()
|
||||||
{
|
{
|
||||||
DeleteChildren();
|
// Fast path: this node is dying, so maintaining _firstChild/_lastChild and
|
||||||
|
// sibling _prev/_next links is unnecessary. Only _parent must be zeroed to
|
||||||
|
// satisfy the MarkInUse assertion inside DeleteNode.
|
||||||
|
XMLNode *currentChild = _firstChild;
|
||||||
|
while (currentChild != NULL) {
|
||||||
|
XMLNode *next = currentChild->_next;
|
||||||
|
currentChild->_parent = 0;
|
||||||
|
DeleteNode(currentChild);
|
||||||
|
currentChild = next;
|
||||||
|
}
|
||||||
|
|
||||||
if ( _parent ) {
|
if ( _parent ) {
|
||||||
_parent->Unlink( this );
|
_parent->Unlink( this );
|
||||||
}
|
}
|
||||||
@@ -2324,8 +2358,9 @@ static FILE* callfopen( const char* filepath, const char* mode )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void XMLDocument::DeleteNode( XMLNode* node ) {
|
void XMLDocument::DeleteNode( XMLNode* node ) {
|
||||||
TIXMLASSERT( node );
|
if(node == 0) {
|
||||||
TIXMLASSERT(node->_document == this );
|
return; // check for null pointer
|
||||||
|
}
|
||||||
if (node->_parent) {
|
if (node->_parent) {
|
||||||
node->_parent->DeleteChild( node );
|
node->_parent->DeleteChild( node );
|
||||||
}
|
}
|
||||||
@@ -2635,7 +2670,7 @@ void XMLPrinter::Write( const char* data, size_t size )
|
|||||||
fwrite ( data , sizeof(char), size, _fp);
|
fwrite ( data , sizeof(char), size, _fp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char* p = _buffer.PushArr( static_cast<int>(size) ) - 1; // back up over the null terminator.
|
char* p = _buffer.PushArr( size ) - 1; // back up over the null terminator.
|
||||||
memcpy( p, data, size );
|
memcpy( p, data, size );
|
||||||
p[size] = 0;
|
p[size] = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,14 +42,6 @@ distribution.
|
|||||||
#endif
|
#endif
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/*
|
|
||||||
gcc:
|
|
||||||
g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
|
|
||||||
|
|
||||||
Formatting, Artistic Style:
|
|
||||||
AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined( _DEBUG ) || defined (__DEBUG__)
|
#if defined( _DEBUG ) || defined (__DEBUG__)
|
||||||
# ifndef TINYXML2_DEBUG
|
# ifndef TINYXML2_DEBUG
|
||||||
# define TINYXML2_DEBUG
|
# define TINYXML2_DEBUG
|
||||||
|
|||||||
@@ -2025,6 +2025,12 @@ int main( int argc, const char ** argv )
|
|||||||
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
|
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
|
||||||
XMLTest("Pedantic whitespace", true, 0 == doc.RootElement()->FirstChildElement()->GetText());
|
XMLTest("Pedantic whitespace", true, 0 == doc.RootElement()->FirstChildElement()->GetText());
|
||||||
}
|
}
|
||||||
|
//Check the robustness of the DeleteNode function in handling null pointers.
|
||||||
|
{
|
||||||
|
XMLDocument doc;
|
||||||
|
doc.DeleteNode(nullptr);
|
||||||
|
XMLTest("DeleteNode with null pointer", true, doc.Error() == XML_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
// Check sample xml can be parsed with pedantic mode
|
// Check sample xml can be parsed with pedantic mode
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user