update TinyXML to v2.6.2

This commit is contained in:
XhmikosR 2012-09-08 12:05:51 +03:00 committed by Daniel Marjamäki
parent 511c5a62e7
commit ea941adae2
7 changed files with 105 additions and 61 deletions

View File

@ -286,5 +286,14 @@ Changes in version 2.1.5
- tibur found a bug in end tag parsing - tibur found a bug in end tag parsing
2.6.2
- Switched over to VC 2010
- Fixed up all the build issues arising from that. (Lots of latent build problems.)
- Removed the old, now unmaintained and likely not working, build files.
- Fixed some static analysis issues reported by orbitcowboy from cppcheck.
- Bayard 95 sent in analysis from a different analyzer - fixes applied from that as well.
- Tim Kosse sent a patch fixing an infinite loop.
- Ma Anguo identified a doc issue.
- Eddie Cohen identified a missing qualifier resulting in a compilation error on some systems.
- Fixed a line ending bug. (What year is this? Can we all agree on a format for text files? Please? ...oh well.)

View File

@ -1,6 +1,5 @@
/* /*
www.sourceforge.net/projects/tinyxml www.sourceforge.net/projects/tinyxml
Original file by Yves Berquin.
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,10 +21,6 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
/*
* THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005.
*/
#ifndef TIXML_USE_STL #ifndef TIXML_USE_STL

View File

@ -1,6 +1,5 @@
/* /*
www.sourceforge.net/projects/tinyxml www.sourceforge.net/projects/tinyxml
Original file by Yves Berquin.
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -22,17 +21,6 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
/*
* THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
*
* - completely rewritten. compact, clean, and fast implementation.
* - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
* - fixed reserve() to work as per specification.
* - fixed buggy compares operator==(), operator<(), and operator>()
* - fixed operator+=() to take a const ref argument, following spec.
* - added "copy" constructor with length, and most compare operators.
* - added swap(), clear(), size(), capacity(), operator+().
*/
#ifndef TIXML_USE_STL #ifndef TIXML_USE_STL
@ -106,13 +94,11 @@ class TiXmlString
quit(); quit();
} }
// = operator
TiXmlString& operator = (const char * copy) TiXmlString& operator = (const char * copy)
{ {
return assign( copy, (size_type)strlen(copy)); return assign( copy, (size_type)strlen(copy));
} }
// = operator
TiXmlString& operator = (const TiXmlString & copy) TiXmlString& operator = (const TiXmlString & copy)
{ {
return assign(copy.start(), copy.length()); return assign(copy.start(), copy.length());

View File

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/tinyxml www.sourceforge.net/projects/tinyxml
Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) Original code by Lee Thomason (www.grinninglizard.com)
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -191,7 +191,8 @@ TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node )
if ( node->Type() == TiXmlNode::TINYXML_DOCUMENT ) if ( node->Type() == TiXmlNode::TINYXML_DOCUMENT )
{ {
delete node; delete node;
if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); if ( GetDocument() )
GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0; return 0;
} }
@ -214,7 +215,8 @@ TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis )
{ {
if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT )
{ {
if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); if ( GetDocument() )
GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0; return 0;
} }
TiXmlNode* node = addThis.Clone(); TiXmlNode* node = addThis.Clone();
@ -232,7 +234,8 @@ TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode&
} }
if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT )
{ {
if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); if ( GetDocument() )
GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0; return 0;
} }
@ -264,7 +267,8 @@ TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& a
} }
if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT )
{ {
if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); if ( GetDocument() )
GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0; return 0;
} }
@ -544,10 +548,11 @@ TiXmlElement::TiXmlElement( const TiXmlElement& copy)
} }
void TiXmlElement::operator=( const TiXmlElement& base ) TiXmlElement& TiXmlElement::operator=( const TiXmlElement& base )
{ {
ClearThis(); ClearThis();
base.CopyTo( this ); base.CopyTo( this );
return *this;
} }
@ -662,6 +667,45 @@ int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const
} }
int TiXmlElement::QueryUnsignedAttribute( const char* name, unsigned* value ) const
{
const TiXmlAttribute* node = attributeSet.Find( name );
if ( !node )
return TIXML_NO_ATTRIBUTE;
int ival = 0;
int result = node->QueryIntValue( &ival );
*value = (unsigned)ival;
return result;
}
int TiXmlElement::QueryBoolAttribute( const char* name, bool* bval ) const
{
const TiXmlAttribute* node = attributeSet.Find( name );
if ( !node )
return TIXML_NO_ATTRIBUTE;
int result = TIXML_WRONG_TYPE;
if ( StringEqual( node->Value(), "true", true, TIXML_ENCODING_UNKNOWN )
|| StringEqual( node->Value(), "yes", true, TIXML_ENCODING_UNKNOWN )
|| StringEqual( node->Value(), "1", true, TIXML_ENCODING_UNKNOWN ) )
{
*bval = true;
result = TIXML_SUCCESS;
}
else if ( StringEqual( node->Value(), "false", true, TIXML_ENCODING_UNKNOWN )
|| StringEqual( node->Value(), "no", true, TIXML_ENCODING_UNKNOWN )
|| StringEqual( node->Value(), "0", true, TIXML_ENCODING_UNKNOWN ) )
{
*bval = false;
result = TIXML_SUCCESS;
}
return result;
}
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
int TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const int TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const
{ {
@ -899,10 +943,11 @@ TiXmlDocument::TiXmlDocument( const TiXmlDocument& copy ) : TiXmlNode( TiXmlNode
} }
void TiXmlDocument::operator=( const TiXmlDocument& copy ) TiXmlDocument& TiXmlDocument::operator=( const TiXmlDocument& copy )
{ {
Clear(); Clear();
copy.CopyTo( this ); copy.CopyTo( this );
return *this;
} }
@ -1171,7 +1216,7 @@ void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) cons
if (value.find ('\"') == TIXML_STRING::npos) { if (value.find ('\"') == TIXML_STRING::npos) {
if ( cfile ) { if ( cfile ) {
fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
} }
if ( str ) { if ( str ) {
(*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\""; (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
@ -1179,7 +1224,7 @@ void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) cons
} }
else { else {
if ( cfile ) { if ( cfile ) {
fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() );
} }
if ( str ) { if ( str ) {
(*str) += n; (*str) += "='"; (*str) += v; (*str) += "'"; (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'";
@ -1241,10 +1286,11 @@ TiXmlComment::TiXmlComment( const TiXmlComment& copy ) : TiXmlNode( TiXmlNode::T
} }
void TiXmlComment::operator=( const TiXmlComment& base ) TiXmlComment& TiXmlComment::operator=( const TiXmlComment& base )
{ {
Clear(); Clear();
base.CopyTo( this ); base.CopyTo( this );
return *this;
} }
@ -1361,10 +1407,11 @@ TiXmlDeclaration::TiXmlDeclaration( const TiXmlDeclaration& copy )
} }
void TiXmlDeclaration::operator=( const TiXmlDeclaration& copy ) TiXmlDeclaration& TiXmlDeclaration::operator=( const TiXmlDeclaration& copy )
{ {
Clear(); Clear();
copy.CopyTo( this ); copy.CopyTo( this );
return *this;
} }

View File

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/tinyxml www.sourceforge.net/projects/tinyxml
Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) Original code by Lee Thomason (www.grinninglizard.com)
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -26,8 +26,6 @@ distribution.
#ifndef TINYXML_INCLUDED #ifndef TINYXML_INCLUDED
#define TINYXML_INCLUDED #define TINYXML_INCLUDED
#define TIXML_USE_STL
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning( push ) #pragma warning( push )
#pragma warning( disable : 4530 ) #pragma warning( disable : 4530 )
@ -93,7 +91,7 @@ class TiXmlParsingData;
const int TIXML_MAJOR_VERSION = 2; const int TIXML_MAJOR_VERSION = 2;
const int TIXML_MINOR_VERSION = 6; const int TIXML_MINOR_VERSION = 6;
const int TIXML_PATCH_VERSION = 1; const int TIXML_PATCH_VERSION = 2;
/* Internal structure for tracking location of items /* Internal structure for tracking location of items
in the XML file. in the XML file.
@ -148,7 +146,7 @@ public:
virtual bool Visit( const TiXmlText& /*text*/ ) { return true; } virtual bool Visit( const TiXmlText& /*text*/ ) { return true; }
/// Visit a comment node /// Visit a comment node
virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; } virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; }
/// Visit an unknow node /// Visit an unknown node
virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; } virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; }
}; };
@ -680,8 +678,8 @@ public:
#endif #endif
/** Query the type (as an enumerated value, above) of this node. /** Query the type (as an enumerated value, above) of this node.
The possible types are: DOCUMENT, ELEMENT, COMMENT, The possible types are: TINYXML_DOCUMENT, TINYXML_ELEMENT, TINYXML_COMMENT,
UNKNOWN, TEXT, and DECLARATION. TINYXML_UNKNOWN, TINYXML_TEXT, and TINYXML_DECLARATION.
*/ */
int Type() const { return type; } int Type() const { return type; }
@ -952,7 +950,7 @@ public:
TiXmlElement( const TiXmlElement& ); TiXmlElement( const TiXmlElement& );
void operator=( const TiXmlElement& base ); TiXmlElement& operator=( const TiXmlElement& base );
virtual ~TiXmlElement(); virtual ~TiXmlElement();
@ -985,6 +983,13 @@ public:
does not exist, then TIXML_NO_ATTRIBUTE is returned. does not exist, then TIXML_NO_ATTRIBUTE is returned.
*/ */
int QueryIntAttribute( const char* name, int* _value ) const; int QueryIntAttribute( const char* name, int* _value ) const;
/// QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().
int QueryUnsignedAttribute( const char* name, unsigned* _value ) const;
/** QueryBoolAttribute examines the attribute - see QueryIntAttribute().
Note that '1', 'true', or 'yes' are considered true, while '0', 'false'
and 'no' are considered false.
*/
int QueryBoolAttribute( const char* name, bool* _value ) const;
/// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
int QueryDoubleAttribute( const char* name, double* _value ) const; int QueryDoubleAttribute( const char* name, double* _value ) const;
/// QueryFloatAttribute examines the attribute - see QueryIntAttribute(). /// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
@ -1164,7 +1169,7 @@ public:
SetValue( _value ); SetValue( _value );
} }
TiXmlComment( const TiXmlComment& ); TiXmlComment( const TiXmlComment& );
void operator=( const TiXmlComment& base ); TiXmlComment& operator=( const TiXmlComment& base );
virtual ~TiXmlComment() {} virtual ~TiXmlComment() {}
@ -1178,8 +1183,8 @@ public:
*/ */
virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
/** Walk the XML tree visiting this node and all of its children. /** Walk the XML tree visiting this node and all of its children.
*/ */
@ -1229,7 +1234,7 @@ public:
#endif #endif
TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); } TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); }
void operator=( const TiXmlText& base ) { base.CopyTo( this ); } TiXmlText& operator=( const TiXmlText& base ) { base.CopyTo( this ); return *this; }
// Write this text object to a FILE stream. // Write this text object to a FILE stream.
virtual void Print( FILE* cfile, int depth ) const; virtual void Print( FILE* cfile, int depth ) const;
@ -1296,7 +1301,7 @@ public:
const char* _standalone ); const char* _standalone );
TiXmlDeclaration( const TiXmlDeclaration& copy ); TiXmlDeclaration( const TiXmlDeclaration& copy );
void operator=( const TiXmlDeclaration& copy ); TiXmlDeclaration& operator=( const TiXmlDeclaration& copy );
virtual ~TiXmlDeclaration() {} virtual ~TiXmlDeclaration() {}
@ -1353,7 +1358,7 @@ public:
virtual ~TiXmlUnknown() {} virtual ~TiXmlUnknown() {}
TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); } TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); }
void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); } TiXmlUnknown& operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); return *this; }
/// Creates a copy of this Unknown and returns it. /// Creates a copy of this Unknown and returns it.
virtual TiXmlNode* Clone() const; virtual TiXmlNode* Clone() const;
@ -1362,8 +1367,8 @@ public:
virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
/** Walk the XML tree visiting this node and all of its children. /** Walk the XML tree visiting this node and all of its children.
*/ */
@ -1399,7 +1404,7 @@ public:
#endif #endif
TiXmlDocument( const TiXmlDocument& copy ); TiXmlDocument( const TiXmlDocument& copy );
void operator=( const TiXmlDocument& copy ); TiXmlDocument& operator=( const TiXmlDocument& copy );
virtual ~TiXmlDocument() {} virtual ~TiXmlDocument() {}
@ -1637,7 +1642,7 @@ public:
TiXmlHandle( TiXmlNode* _node ) { this->node = _node; } TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
/// Copy constructor /// Copy constructor
TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; } TiXmlHandle operator=( const TiXmlHandle& ref ) { if ( &ref != this ) this->node = ref.node; return *this; }
/// Return a handle to the first child node. /// Return a handle to the first child node.
TiXmlHandle FirstChild() const; TiXmlHandle FirstChild() const;
@ -1798,4 +1803,3 @@ private:
#endif #endif
#endif #endif

View File

@ -31,7 +31,7 @@ distribution.
// It also cleans up the code a bit. // It also cleans up the code a bit.
// //
const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] = const char* TiXmlBase::errorString[ TiXmlBase::TIXML_ERROR_STRING_COUNT ] =
{ {
"No error", "No error",
"Error", "Error",

View File

@ -1,6 +1,6 @@
/* /*
www.sourceforge.net/projects/tinyxml www.sourceforge.net/projects/tinyxml
Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) Original code by Lee Thomason (www.grinninglizard.com)
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
@ -40,7 +40,7 @@ distribution.
// Note tha "PutString" hardcodes the same list. This // Note tha "PutString" hardcodes the same list. This
// is less flexible than it appears. Changing the entries // is less flexible than it appears. Changing the entries
// or order will break putstring. // or order will break putstring.
TiXmlBase::Entity TiXmlBase::entity[ NUM_ENTITY ] = TiXmlBase::Entity TiXmlBase::entity[ TiXmlBase::NUM_ENTITY ] =
{ {
{ "&amp;", 5, '&' }, { "&amp;", 5, '&' },
{ "&lt;", 4, '<' }, { "&lt;", 4, '<' },
@ -174,7 +174,7 @@ class TiXmlParsingData
public: public:
void Stamp( const char* now, TiXmlEncoding encoding ); void Stamp( const char* now, TiXmlEncoding encoding );
const TiXmlCursor& Cursor() { return cursor; } const TiXmlCursor& Cursor() const { return cursor; }
private: private:
// Only used by the document! // Only used by the document!
@ -631,9 +631,9 @@ const char* TiXmlBase::ReadText( const char* p,
} }
} }
} }
if ( p && *p ) if ( p && *p )
p += strlen( endTag ); p += strlen( endTag );
return p; return ( p && *p ) ? p : 0;
} }
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
@ -1298,9 +1298,10 @@ const char* TiXmlUnknown::Parse( const char* p, TiXmlParsingData* data, TiXmlEnc
if ( !p ) if ( !p )
{ {
if ( document ) document->SetError( TIXML_ERROR_PARSING_UNKNOWN, 0, 0, encoding ); if ( document )
document->SetError( TIXML_ERROR_PARSING_UNKNOWN, 0, 0, encoding );
} }
if ( *p == '>' ) if ( p && *p == '>' )
return p+1; return p+1;
return p; return p;
} }
@ -1350,7 +1351,8 @@ const char* TiXmlComment::Parse( const char* p, TiXmlParsingData* data, TiXmlEnc
if ( !StringEqual( p, startTag, false, encoding ) ) if ( !StringEqual( p, startTag, false, encoding ) )
{ {
document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding ); if ( document )
document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding );
return 0; return 0;
} }
p += strlen( startTag ); p += strlen( startTag );
@ -1512,7 +1514,8 @@ const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncodi
if ( !StringEqual( p, startTag, false, encoding ) ) if ( !StringEqual( p, startTag, false, encoding ) )
{ {
document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding ); if ( document )
document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding );
return 0; return 0;
} }
p += strlen( startTag ); p += strlen( startTag );
@ -1536,7 +1539,7 @@ const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncodi
const char* end = "<"; const char* end = "<";
p = ReadText( p, &value, ignoreWhite, end, false, encoding ); p = ReadText( p, &value, ignoreWhite, end, false, encoding );
if ( p ) if ( p && *p )
return p-1; // don't truncate the '<' return p-1; // don't truncate the '<'
return 0; return 0;
} }