Skip to content

Commit 9bdeea5

Browse files
committed
tinyxml: update to latest git version 5321a0e (v2.2.0) (https://github.com/leethomason/tinyxml2)
1 parent 2068b91 commit 9bdeea5

File tree

2 files changed

+124
-84
lines changed

2 files changed

+124
-84
lines changed

externals/tinyxml/tinyxml2.cpp

Lines changed: 80 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,6 @@ static const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
4545
static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
4646
static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
4747

48-
49-
#define DELETE_NODE( node ) { \
50-
if ( node ) { \
51-
MemPool* pool = node->_memPool; \
52-
node->~XMLNode(); \
53-
pool->Free( node ); \
54-
} \
55-
}
56-
#define DELETE_ATTRIBUTE( attrib ) { \
57-
if ( attrib ) { \
58-
MemPool* pool = attrib->_memPool; \
59-
attrib->~XMLAttribute(); \
60-
pool->Free( attrib ); \
61-
} \
62-
}
63-
6448
namespace tinyxml2
6549
{
6650

@@ -618,7 +602,7 @@ void XMLNode::DeleteChildren()
618602
XMLNode* node = _firstChild;
619603
Unlink( node );
620604

621-
DELETE_NODE( node );
605+
DeleteNode( node );
622606
}
623607
_firstChild = _lastChild = 0;
624608
}
@@ -646,7 +630,7 @@ void XMLNode::Unlink( XMLNode* child )
646630
void XMLNode::DeleteChild( XMLNode* node )
647631
{
648632
TIXMLASSERT( node->_parent == this );
649-
DELETE_NODE( node );
633+
DeleteNode( node );
650634
}
651635

652636

@@ -773,10 +757,11 @@ const XMLElement* XMLNode::LastChildElement( const char* value ) const
773757

774758
const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
775759
{
776-
for( XMLNode* element=this->_next; element; element = element->_next ) {
777-
if ( element->ToElement()
778-
&& (!value || XMLUtil::StringEqual( value, element->Value() ))) {
779-
return element->ToElement();
760+
for( XMLNode* node=this->_next; node; node = node->_next ) {
761+
const XMLElement* element = node->ToElement();
762+
if ( element
763+
&& (!value || XMLUtil::StringEqual( value, node->Value() ))) {
764+
return element;
780765
}
781766
}
782767
return 0;
@@ -785,10 +770,11 @@ const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
785770

786771
const XMLElement* XMLNode::PreviousSiblingElement( const char* value ) const
787772
{
788-
for( XMLNode* element=_prev; element; element = element->_prev ) {
789-
if ( element->ToElement()
790-
&& (!value || XMLUtil::StringEqual( value, element->Value() ))) {
791-
return element->ToElement();
773+
for( XMLNode* node=_prev; node; node = node->_prev ) {
774+
const XMLElement* element = node->ToElement();
775+
if ( element
776+
&& (!value || XMLUtil::StringEqual( value, node->Value() ))) {
777+
return element;
792778
}
793779
}
794780
return 0;
@@ -825,27 +811,27 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
825811
StrPair endTag;
826812
p = node->ParseDeep( p, &endTag );
827813
if ( !p ) {
828-
DELETE_NODE( node );
814+
DeleteNode( node );
829815
node = 0;
830816
if ( !_document->Error() ) {
831817
_document->SetError( XML_ERROR_PARSING, 0, 0 );
832818
}
833819
break;
834820
}
835821

822+
XMLElement* ele = node->ToElement();
836823
// We read the end tag. Return it to the parent.
837-
if ( node->ToElement() && node->ToElement()->ClosingType() == XMLElement::CLOSING ) {
824+
if ( ele && ele->ClosingType() == XMLElement::CLOSING ) {
838825
if ( parentEnd ) {
839826
*parentEnd = static_cast<XMLElement*>(node)->_value;
840827
}
841828
node->_memPool->SetTracked(); // created and then immediately deleted.
842-
DELETE_NODE( node );
829+
DeleteNode( node );
843830
return p;
844831
}
845832

846833
// Handle an end tag returned to this level.
847834
// And handle a bunch of annoying errors.
848-
XMLElement* ele = node->ToElement();
849835
if ( ele ) {
850836
if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) {
851837
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );
@@ -863,7 +849,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
863849
}
864850
}
865851
if ( p == 0 ) {
866-
DELETE_NODE( node );
852+
DeleteNode( node );
867853
node = 0;
868854
}
869855
if ( node ) {
@@ -873,6 +859,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
873859
return 0;
874860
}
875861

862+
void XMLNode::DeleteNode( XMLNode* node )
863+
{
864+
if ( node == 0 ) {
865+
return;
866+
}
867+
MemPool* pool = node->_memPool;
868+
node->~XMLNode();
869+
pool->Free( node );
870+
}
871+
876872
// --------- XMLText ---------- //
877873
char* XMLText::ParseDeep( char* p, StrPair* )
878874
{
@@ -961,7 +957,8 @@ XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const
961957

962958
bool XMLComment::ShallowEqual( const XMLNode* compare ) const
963959
{
964-
return ( compare->ToComment() && XMLUtil::StringEqual( compare->ToComment()->Value(), Value() ));
960+
const XMLComment* comment = compare->ToComment();
961+
return ( comment && XMLUtil::StringEqual( comment->Value(), Value() ));
965962
}
966963

967964

@@ -1008,7 +1005,8 @@ XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const
10081005

10091006
bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const
10101007
{
1011-
return ( compare->ToDeclaration() && XMLUtil::StringEqual( compare->ToDeclaration()->Value(), Value() ));
1008+
const XMLDeclaration* declaration = compare->ToDeclaration();
1009+
return ( declaration && XMLUtil::StringEqual( declaration->Value(), Value() ));
10121010
}
10131011

10141012

@@ -1055,7 +1053,8 @@ XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const
10551053

10561054
bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const
10571055
{
1058-
return ( compare->ToUnknown() && XMLUtil::StringEqual( compare->ToUnknown()->Value(), Value() ));
1056+
const XMLUnknown* unknown = compare->ToUnknown();
1057+
return ( unknown && XMLUtil::StringEqual( unknown->Value(), Value() ));
10591058
}
10601059

10611060

@@ -1211,16 +1210,15 @@ XMLElement::~XMLElement()
12111210
{
12121211
while( _rootAttribute ) {
12131212
XMLAttribute* next = _rootAttribute->_next;
1214-
DELETE_ATTRIBUTE( _rootAttribute );
1213+
DeleteAttribute( _rootAttribute );
12151214
_rootAttribute = next;
12161215
}
12171216
}
12181217

12191218

12201219
XMLAttribute* XMLElement::FindAttribute( const char* name )
12211220
{
1222-
XMLAttribute* a = 0;
1223-
for( a=_rootAttribute; a; a = a->_next ) {
1221+
for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) {
12241222
if ( XMLUtil::StringEqual( a->Name(), name ) ) {
12251223
return a;
12261224
}
@@ -1231,8 +1229,7 @@ XMLAttribute* XMLElement::FindAttribute( const char* name )
12311229

12321230
const XMLAttribute* XMLElement::FindAttribute( const char* name ) const
12331231
{
1234-
XMLAttribute* a = 0;
1235-
for( a=_rootAttribute; a; a = a->_next ) {
1232+
for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) {
12361233
if ( XMLUtil::StringEqual( a->Name(), name ) ) {
12371234
return a;
12381235
}
@@ -1418,7 +1415,7 @@ void XMLElement::DeleteAttribute( const char* name )
14181415
else {
14191416
_rootAttribute = a->_next;
14201417
}
1421-
DELETE_ATTRIBUTE( a );
1418+
DeleteAttribute( a );
14221419
break;
14231420
}
14241421
prev = a;
@@ -1447,7 +1444,7 @@ char* XMLElement::ParseAttributes( char* p )
14471444

14481445
p = attrib->ParseDeep( p, _document->ProcessEntities() );
14491446
if ( !p || Attribute( attrib->Name() ) ) {
1450-
DELETE_ATTRIBUTE( attrib );
1447+
DeleteAttribute( attrib );
14511448
_document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p );
14521449
return 0;
14531450
}
@@ -1482,6 +1479,15 @@ char* XMLElement::ParseAttributes( char* p )
14821479
return p;
14831480
}
14841481

1482+
void XMLElement::DeleteAttribute( XMLAttribute* attribute )
1483+
{
1484+
if ( attribute == 0 ) {
1485+
return;
1486+
}
1487+
MemPool* pool = attribute->_memPool;
1488+
attribute->~XMLAttribute();
1489+
pool->Free( attribute );
1490+
}
14851491

14861492
//
14871493
// <ele></ele>
@@ -1571,6 +1577,32 @@ bool XMLElement::Accept( XMLVisitor* visitor ) const
15711577

15721578

15731579
// --------- XMLDocument ----------- //
1580+
1581+
// Warning: List must match 'enum XMLError'
1582+
const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
1583+
"XML_SUCCESS",
1584+
"XML_NO_ATTRIBUTE",
1585+
"XML_WRONG_ATTRIBUTE_TYPE",
1586+
"XML_ERROR_FILE_NOT_FOUND",
1587+
"XML_ERROR_FILE_COULD_NOT_BE_OPENED",
1588+
"XML_ERROR_FILE_READ_ERROR",
1589+
"XML_ERROR_ELEMENT_MISMATCH",
1590+
"XML_ERROR_PARSING_ELEMENT",
1591+
"XML_ERROR_PARSING_ATTRIBUTE",
1592+
"XML_ERROR_IDENTIFYING_TAG",
1593+
"XML_ERROR_PARSING_TEXT",
1594+
"XML_ERROR_PARSING_CDATA",
1595+
"XML_ERROR_PARSING_COMMENT",
1596+
"XML_ERROR_PARSING_DECLARATION",
1597+
"XML_ERROR_PARSING_UNKNOWN",
1598+
"XML_ERROR_EMPTY_DOCUMENT",
1599+
"XML_ERROR_MISMATCHED_ELEMENT",
1600+
"XML_ERROR_PARSING",
1601+
"XML_CAN_NOT_CONVERT_TEXT",
1602+
"XML_NO_TEXT_NODE"
1603+
};
1604+
1605+
15741606
XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
15751607
XMLNode( 0 ),
15761608
_writeBOM( false ),
@@ -1806,6 +1838,11 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 )
18061838
_errorStr2 = str2;
18071839
}
18081840

1841+
const char* XMLDocument::ErrorName() const
1842+
{
1843+
TIXMLASSERT(_errorID >= 0 && _errorID < XML_ERROR_COUNT );
1844+
return _errorNames[_errorID];
1845+
}
18091846

18101847
void XMLDocument::PrintError() const
18111848
{
@@ -1821,8 +1858,8 @@ void XMLDocument::PrintError() const
18211858
TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 );
18221859
}
18231860

1824-
printf( "XMLDocument error id=%d str1=%s str2=%s\n",
1825-
_errorID, buf1, buf2 );
1861+
printf( "XMLDocument error id=%d '%s' str1=%s str2=%s\n",
1862+
_errorID, ErrorName(), buf1, buf2 );
18261863
}
18271864
}
18281865

0 commit comments

Comments
 (0)