From: <eg...@us...> - 2007-09-20 21:07:31
|
Revision: 744 http://opengate.svn.sourceforge.net/opengate/?rev=744&view=rev Author: egore Date: 2007-09-20 14:07:22 -0700 (Thu, 20 Sep 2007) Log Message: ----------- Update tinyxml to 2.5.3 Modified Paths: -------------- branches/ogsector/src/tinyxml/tinyxml.cpp branches/ogsector/src/tinyxml/tinyxml.h branches/ogsector/src/tinyxml/tinyxmlparser.cpp Modified: branches/ogsector/src/tinyxml/tinyxml.cpp =================================================================== --- branches/ogsector/src/tinyxml/tinyxml.cpp 2007-09-20 20:33:41 UTC (rev 743) +++ branches/ogsector/src/tinyxml/tinyxml.cpp 2007-09-20 21:07:22 UTC (rev 744) @@ -34,8 +34,22 @@ bool TiXmlBase::condenseWhiteSpace = true; -void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_STRING* outString ) +// Microsoft compiler security +FILE* TiXmlFOpen( const char* filename, const char* mode ) { + #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) + FILE* fp = 0; + errno_t err = fopen_s( &fp, filename, mode ); + if ( !err && fp ) + return fp; + return 0; + #else + return fopen( filename, mode ); + #endif +} + +void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString ) +{ int i=0; while( i<(int)str.length() ) @@ -941,7 +955,7 @@ value = filename; // reading in binary mode so that tinyxml can normalize the EOL - FILE* file = fopen( value.c_str (), "rb" ); + FILE* file = TiXmlFOpen( value.c_str (), "rb" ); if ( file ) { @@ -975,7 +989,7 @@ fseek( file, 0, SEEK_SET ); // Strange case, but good to handle up front. - if ( length == 0 ) + if ( length <= 0 ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; @@ -1074,7 +1088,7 @@ bool TiXmlDocument::SaveFile( const char * filename ) const { // The old c stuff lives on... - FILE* fp = fopen( filename, "w" ); + FILE* fp = TiXmlFOpen( filename, "w" ); if ( fp ) { bool result = SaveFile( fp ); @@ -1107,7 +1121,11 @@ TiXmlNode::CopyTo( target ); target->error = error; - target->errorDesc = errorDesc.c_str (); + target->errorId = errorId; + target->errorDesc = errorDesc; + target->tabsize = tabsize; + target->errorLocation = errorLocation; + target->useMicrosoftBOM = useMicrosoftBOM; TiXmlNode* node = 0; for ( node = firstChild; node; node = node->NextSibling() ) @@ -1197,8 +1215,8 @@ { TIXML_STRING n, v; - PutString( name, &n ); - PutString( value, &v ); + EncodeString( name, &n ); + EncodeString( value, &v ); if (value.find ('\"') == TIXML_STRING::npos) { if ( cfile ) { @@ -1221,14 +1239,14 @@ int TiXmlAttribute::QueryIntValue( int* ival ) const { - if ( sscanf( value.c_str(), "%d", ival ) == 1 ) + if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 ) return TIXML_SUCCESS; return TIXML_WRONG_TYPE; } int TiXmlAttribute::QueryDoubleValue( double* dval ) const { - if ( sscanf( value.c_str(), "%lf", dval ) == 1 ) + if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 ) return TIXML_SUCCESS; return TIXML_WRONG_TYPE; } @@ -1329,7 +1347,7 @@ else { TIXML_STRING buffer; - PutString( value, &buffer ); + EncodeString( value, &buffer ); fprintf( cfile, "%s", buffer.c_str() ); } } @@ -1822,12 +1840,16 @@ } else if ( simpleTextPrint ) { - buffer += text.Value(); + TIXML_STRING str; + TiXmlBase::EncodeString( text.ValueTStr(), &str ); + buffer += str; } else { DoIndent(); - buffer += text.Value(); + TIXML_STRING str; + TiXmlBase::EncodeString( text.ValueTStr(), &str ); + buffer += str; DoLineBreak(); } return true; Modified: branches/ogsector/src/tinyxml/tinyxml.h =================================================================== --- branches/ogsector/src/tinyxml/tinyxml.h 2007-09-20 20:33:41 UTC (rev 743) +++ branches/ogsector/src/tinyxml/tinyxml.h 2007-09-20 21:07:22 UTC (rev 744) @@ -66,16 +66,21 @@ // Microsoft visual studio, version 2005 and higher. #define TIXML_SNPRINTF _snprintf_s #define TIXML_SNSCANF _snscanf_s + #define TIXML_SSCANF sscanf_s #elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) // Microsoft visual studio, version 6 and higher. //#pragma message( "Using _sn* functions." ) #define TIXML_SNPRINTF _snprintf #define TIXML_SNSCANF _snscanf + #define TIXML_SSCANF sscanf #elif defined(__GNUC__) && (__GNUC__ >= 3 ) // GCC version 3 and higher.s //#warning( "Using sn* functions." ) #define TIXML_SNPRINTF snprintf #define TIXML_SNSCANF snscanf + #define TIXML_SSCANF sscanf + #else + #define TIXML_SSCANF sscanf #endif #endif @@ -90,7 +95,7 @@ const int TIXML_MAJOR_VERSION = 2; const int TIXML_MINOR_VERSION = 5; -const int TIXML_PATCH_VERSION = 2; +const int TIXML_PATCH_VERSION = 3; /* Internal structure for tracking location of items in the XML file. @@ -129,23 +134,23 @@ virtual ~TiXmlVisitor() {} /// Visit a document. - virtual bool VisitEnter( const TiXmlDocument& doc ) { return true; } + virtual bool VisitEnter( const TiXmlDocument& /*doc*/ ) { return true; } /// Visit a document. - virtual bool VisitExit( const TiXmlDocument& doc ) { return true; } + virtual bool VisitExit( const TiXmlDocument& /*doc*/ ) { return true; } /// Visit an element. - virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) { return true; } + virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ ) { return true; } /// Visit an element. - virtual bool VisitExit( const TiXmlElement& element ) { return true; } + virtual bool VisitExit( const TiXmlElement& /*element*/ ) { return true; } /// Visit a declaration - virtual bool Visit( const TiXmlDeclaration& declaration ) { return true; } + virtual bool Visit( const TiXmlDeclaration& /*declaration*/ ) { return true; } /// Visit a text node - virtual bool Visit( const TiXmlText& text ) { return true; } + virtual bool Visit( const TiXmlText& /*text*/ ) { return true; } /// Visit a comment node - virtual bool Visit( const TiXmlComment& comment ) { return true; } + virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; } /// Visit an unknow node - virtual bool Visit( const TiXmlUnknown& unknown ) { return true; } + virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; } }; // Only used by Attribute::Query functions @@ -254,6 +259,11 @@ TiXmlParsingData* data, TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; + /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc, + or they will be transformed into entities! + */ + static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out ); + enum { TIXML_NO_ERROR = 0, @@ -353,10 +363,6 @@ } } - // Puts a string to a stream, expanding entities as it goes. - // Note this should not contian the '<', '>', etc, or they will be transformed into entities! - static void PutString( const TIXML_STRING& str, TIXML_STRING* out ); - // Return true if the next characters in the stream are any of the endTag sequences. // Ignore case only works for english, and should only be relied on when comparing // to English words: StringEqual( p, "version", true ) is fine. @@ -491,6 +497,8 @@ const std::string& ValueStr() const { return value; } #endif + const TIXML_STRING& ValueTStr() const { return value; } + /** Changes the value of the node. Defined as: @verbatim Document: filename of the xml file @@ -514,8 +522,8 @@ TiXmlNode* Parent() { return parent; } const TiXmlNode* Parent() const { return parent; } - const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. - TiXmlNode* FirstChild() { return firstChild; } + const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. + TiXmlNode* FirstChild() { return firstChild; } const TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. /// The first child of this node with the matching 'value'. Will be null if none found. TiXmlNode* FirstChild( const char * _value ) { @@ -992,10 +1000,13 @@ } return result; } + #ifdef TIXML_USE_STL /** Template form of the attribute query which will try to read the attribute into the specified type. Very easy, very powerful, but be careful to make sure to call this with the correct type. + + NOTE: This method doesn't work correctly for 'string' types. @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE */ @@ -1011,6 +1022,21 @@ return TIXML_SUCCESS; return TIXML_WRONG_TYPE; } + /* + This is - in theory - a bug fix for "QueryValueAtribute returns truncated std::string" + but template specialization is hard to get working cross-compiler. Leaving the bug for now. + + // The above will fail for std::string because the space character is used as a seperator. + // Specialize for strings. Bug [ 1695429 ] QueryValueAtribute returns truncated std::string + template<> int QueryValueAttribute( const std::string& name, std::string* outValue ) const + { + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + *outValue = node->ValueStr(); + return TIXML_SUCCESS; + } + */ #endif /** Sets an attribute of name to a given value. The attribute Modified: branches/ogsector/src/tinyxml/tinyxmlparser.cpp =================================================================== --- branches/ogsector/src/tinyxml/tinyxmlparser.cpp 2007-09-20 20:33:41 UTC (rev 743) +++ branches/ogsector/src/tinyxml/tinyxmlparser.cpp 2007-09-20 21:07:22 UTC (rev 744) @@ -1114,8 +1114,12 @@ // elements -- read the end tag, and return. ++p; p = ReadValue( p, data, encoding ); // Note this is an Element method, and will set the error if one happens. - if ( !p || !*p ) + if ( !p || !*p ) { + // We were looking for the end tag, but found nothing. + // Fix for [ 1663758 ] Failure to report error on bad XML + if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding ); return 0; + } // We should find the end tag now if ( StringEqual( p, endTag.c_str(), false, encoding ) ) @@ -1349,7 +1353,35 @@ return 0; } p += strlen( startTag ); - p = ReadText( p, &value, false, endTag, false, encoding ); + + // [ 1475201 ] TinyXML parses entities in comments + // Oops - ReadText doesn't work, because we don't want to parse the entities. + // p = ReadText( p, &value, false, endTag, false, encoding ); + // + // from the XML spec: + /* + [Definition: Comments may appear anywhere in a document outside other markup; in addition, + they may appear within the document type declaration at places allowed by the grammar. + They are not part of the document's character data; an XML processor MAY, but need not, + make it possible for an application to retrieve the text of comments. For compatibility, + the string "--" (double-hyphen) MUST NOT occur within comments.] Parameter entity + references MUST NOT be recognized within comments. + + An example of a comment: + + <!-- declarations for <head> & <body> --> + */ + + value = ""; + // Keep all the white space. + while ( p && *p && !StringEqual( p, endTag, false, encoding ) ) + { + value.append( p, 1 ); + ++p; + } + if ( p ) + p += strlen( endTag ); + return p; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |