Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -urN /tmp/tinyxml-2.5.3/tinyxml.cpp lib/tinyXML/tinyxml.cpp
- --- /tmp/tinyxml-2.5.3/tinyxml.cpp 2007-05-06 18:41:23.000000000 -0400
- +++ lib/tinyXML/tinyxml.cpp 2011-02-24 17:19:35.086853016 -0500
- @@ -31,22 +31,17 @@
- #include "tinyxml.h"
- +#define USE_XBMC_FILESYSTEM
- +#ifdef USE_XBMC_FILESYSTEM
- +bool TiXmlBase::condenseWhiteSpace = false;
- +#include "filesystem/File.h"
- +using namespace XFILE;
- +#else
- bool TiXmlBase::condenseWhiteSpace = true;
- +#endif
- +
- -// 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 )
- {
- @@ -56,30 +51,7 @@
- {
- unsigned char c = (unsigned char) str[i];
- - if ( c == '&'
- - && i < ( (int)str.length() - 2 )
- - && str[i+1] == '#'
- - && str[i+2] == 'x' )
- - {
- - // Hexadecimal character reference.
- - // Pass through unchanged.
- - // © -- copyright symbol, for example.
- - //
- - // The -1 is a bug fix from Rob Laveaux. It keeps
- - // an overflow from happening if there is no ';'.
- - // There are actually 2 ways to exit this loop -
- - // while fails (error case) and break (semicolon found).
- - // However, there is no mechanism (currently) for
- - // this function to return an error.
- - while ( i<(int)str.length()-1 )
- - {
- - outString->append( str.c_str() + i, 1 );
- - ++i;
- - if ( str[i] == ';' )
- - break;
- - }
- - }
- - else if ( c == '&' )
- + if ( c == '&' )
- {
- outString->append( entity[0].str, entity[0].strLength );
- ++i;
- @@ -885,6 +857,10 @@
- {
- tabsize = 4;
- useMicrosoftBOM = false;
- +#ifdef HAS_ICONV
- + convertToUtf8 = false;
- + iconvContext = (iconv_t) -1;
- +#endif
- ClearError();
- }
- @@ -892,6 +868,10 @@
- {
- tabsize = 4;
- useMicrosoftBOM = false;
- +#ifdef HAS_ICONV
- + convertToUtf8 = false;
- + iconvContext = (iconv_t) -1;
- +#endif
- value = documentName;
- ClearError();
- }
- @@ -902,7 +882,11 @@
- {
- tabsize = 4;
- useMicrosoftBOM = false;
- - value = documentName;
- +#ifdef HAS_ICONV
- + convertToUtf8 = false;
- + iconvContext = (iconv_t) -1;
- +#endif
- + value = documentName;
- ClearError();
- }
- #endif
- @@ -913,6 +897,16 @@
- copy.CopyTo( this );
- }
- +TiXmlDocument::~TiXmlDocument()
- +{
- +#ifdef HAS_ICONV
- + if (iconvContext != (iconv_t) -1)
- + {
- + iconv_close(iconvContext);
- + iconvContext = (iconv_t) -1;
- + }
- +#endif
- +}
- void TiXmlDocument::operator=( const TiXmlDocument& copy )
- {
- @@ -942,6 +936,7 @@
- return SaveFile( Value() );
- }
- +#ifdef USE_XBMC_FILESYSTEM
- bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding )
- {
- // There was a really terrifying little bug here. The code:
- @@ -954,9 +949,157 @@
- TIXML_STRING filename( _filename );
- value = filename;
- - // reading in binary mode so that tinyxml can normalize the EOL
- - FILE* file = TiXmlFOpen( value.c_str (), "rb" );
- + CFile file;
- + if (!file.Open(value))
- + {
- + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
- + return false;
- + }
- +
- + // Delete the existing data:
- + Clear();
- + location.Clear();
- +
- + // Get the file size, so we can pre-allocate the string. HUGE speed impact.
- + long length = -1;
- + int64_t filelen = file.GetLength();
- + if (filelen > 0)
- + length = (long)filelen;
- +
- + // We might be streaming it, correct length will be fixed by reading
- + if( length < 0 )
- + length = 1024;
- +
- + // Subtle bug here. TinyXml did use fgets. But from the XML spec:
- + // 2.11 End-of-Line Handling
- + // <snip>
- + // <quote>
- + // ...the XML processor MUST behave as if it normalized all line breaks in external
- + // parsed entities (including the document entity) on input, before parsing, by translating
- + // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to
- + // a single #xA character.
- + // </quote>
- + //
- + // It is not clear fgets does that, and certainly isn't clear it works cross platform.
- + // Generally, you expect fgets to translate from the convention of the OS to the c/unix
- + // convention, and not work generally.
- +
- + /*
- + while( fgets( buf, sizeof(buf), file ) )
- + {
- + data += buf;
- + }
- + */
- +
- + char* buf = (char*)malloc(length+1);
- + long pos = 0;
- + long len;
- + while( (len = file.Read(buf+pos, length-pos)) > 0 ) {
- + pos += len;
- + assert(pos <= length);
- + if(pos == length) {
- + length *= 2;
- + buf = (char*)realloc(buf, length);
- + }
- + }
- + length = pos;
- +
- + file.Close();
- +
- + // Strange case, but good to handle up front.
- + if ( length == 0 )
- + {
- + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
- + return false;
- + }
- +
- + // If we have a file, assume it is all one big XML file, and read it in.
- + // The document parser may decide the document ends sooner than the entire file, however.
- + TIXML_STRING data;
- + data.reserve( length );
- +
- + const char* lastPos = buf;
- + const char* p = buf;
- +
- + buf[length] = 0;
- + while( *p ) {
- + assert( p < (buf+length) );
- + if ( *p == 0xa ) {
- + // Newline character. No special rules for this. Append all the characters
- + // since the last string, and include the newline.
- + data.append( lastPos, (p-lastPos+1) ); // append, include the newline
- + ++p; // move past the newline
- + lastPos = p; // and point to the new buffer (may be 0)
- + assert( p <= (buf+length) );
- + }
- + else if ( *p == 0xd ) {
- + // Carriage return. Append what we have so far, then
- + // handle moving forward in the buffer.
- + if ( (p-lastPos) > 0 ) {
- + data.append( lastPos, p-lastPos ); // do not add the CR
- + }
- + data += (char)0xa; // a proper newline
- +
- + if ( *(p+1) == 0xa ) {
- + // Carriage return - new line sequence
- + p += 2;
- + lastPos = p;
- + assert( p <= (buf+length) );
- + }
- + else {
- + // it was followed by something else...that is presumably characters again.
- + ++p;
- + lastPos = p;
- + assert( p <= (buf+length) );
- + }
- + }
- + else {
- + ++p;
- + }
- + }
- + // Handle any left over characters.
- + if ( p-lastPos ) {
- + data.append( lastPos, p-lastPos );
- + }
- + free(buf);
- + buf = 0;
- +
- + Parse( data.c_str(), 0, encoding );
- + if ( Error() )
- + return false;
- + else
- + return true;
- +}
- +
- +bool TiXmlDocument::SaveFile( const char *filename ) const
- +{
- + XFILE::CFile file;
- + if (file.OpenForWrite(filename, true))
- + {
- + TiXmlPrinter printer;
- + Accept(&printer);
- + file.Write(printer.CStr(), printer.Size());
- + return true;
- + }
- + return false;
- +}
- +#else
- +
- +bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding )
- +{
- + // There was a really terrifying little bug here. The code:
- + // value = filename
- + // in the STL case, cause the assignment method of the std::string to
- + // be called. What is strange, is that the std::string had the same
- + // address as it's c_str() method, and so bad things happen. Looks
- + // like a bug in the Microsoft STL implementation.
- + // Add an extra string to avoid the crash.
- + TIXML_STRING filename( _filename );
- + value = filename;
- +
- + // reading in binary mode so that tinyxml can normalize the EOL
- + FILE* file = fopen( value.c_str(), "rb" );
- if ( file )
- {
- bool result = LoadFile( file, encoding );
- @@ -970,6 +1113,20 @@
- }
- }
- +bool TiXmlDocument::SaveFile( const char * filename ) const
- +{
- + // The old c stuff lives on...
- + FILE* fp = fopen( filename, "w" );
- + if ( fp )
- + {
- + bool result = SaveFile( fp );
- + fclose( fp );
- + return result;
- + }
- + return false;
- +}
- +#endif
- +
- bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding )
- {
- if ( !file )
- @@ -983,22 +1140,15 @@
- location.Clear();
- // Get the file size, so we can pre-allocate the string. HUGE speed impact.
- - long length = 0;
- - fseek( file, 0, SEEK_END );
- - length = ftell( file );
- - fseek( file, 0, SEEK_SET );
- -
- - // Strange case, but good to handle up front.
- - if ( length <= 0 )
- - {
- - SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
- - return false;
- + long length = -1;
- + if( fseek( file, 0, SEEK_END ) == 0 ) {
- + length = ftell( file );
- + fseek( file, 0, SEEK_SET );
- }
- - // If we have a file, assume it is all one big XML file, and read it in.
- - // The document parser may decide the document ends sooner than the entire file, however.
- - TIXML_STRING data;
- - data.reserve( length );
- + // We might be streaming it, correct length will be fixed by reading
- + if( length < 0 )
- + length = 1024;
- // Subtle bug here. TinyXml did use fgets. But from the XML spec:
- // 2.11 End-of-Line Handling
- @@ -1021,15 +1171,31 @@
- }
- */
- - char* buf = new char[ length+1 ];
- - buf[0] = 0;
- + char* buf = (char*)malloc(length+1);
- + long pos = 0;
- + long len;
- + while( (len = fread(buf+pos, 1, length-pos, file)) > 0 ) {
- + pos += len;
- + assert(pos <= length);
- + if(pos == length) {
- + length *= 2;
- + buf = (char*)realloc(buf, length);
- + }
- + }
- + length = pos;
- - if ( fread( buf, length, 1, file ) != 1 ) {
- - delete [] buf;
- - SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
- + // Strange case, but good to handle up front.
- + if ( length == 0 )
- + {
- + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
- return false;
- }
- + // If we have a file, assume it is all one big XML file, and read it in.
- + // The document parser may decide the document ends sooner than the entire file, however.
- + TIXML_STRING data;
- + data.reserve( length );
- +
- const char* lastPos = buf;
- const char* p = buf;
- @@ -1073,7 +1239,7 @@
- if ( p-lastPos ) {
- data.append( lastPos, p-lastPos );
- }
- - delete [] buf;
- + free(buf);
- buf = 0;
- Parse( data.c_str(), 0, encoding );
- @@ -1084,21 +1250,6 @@
- return true;
- }
- -
- -bool TiXmlDocument::SaveFile( const char * filename ) const
- -{
- - // The old c stuff lives on...
- - FILE* fp = TiXmlFOpen( filename, "w" );
- - if ( fp )
- - {
- - bool result = SaveFile( fp );
- - fclose( fp );
- - return result;
- - }
- - return false;
- -}
- -
- -
- bool TiXmlDocument::SaveFile( FILE* fp ) const
- {
- if ( useMicrosoftBOM )
- @@ -1126,7 +1277,11 @@
- target->tabsize = tabsize;
- target->errorLocation = errorLocation;
- target->useMicrosoftBOM = useMicrosoftBOM;
- -
- +#ifdef HAS_ICONV
- + target->convertToUtf8 = convertToUtf8;
- + target->iconvContext = (iconv_t) -1;
- +#endif
- +
- TiXmlNode* node = 0;
- for ( node = firstChild; node; node = node->NextSibling() )
- {
- @@ -1266,9 +1421,9 @@
- {
- char buf [256];
- #if defined(TIXML_SNPRINTF)
- - TIXML_SNPRINTF( buf, sizeof(buf), "%lf", _value);
- + TIXML_SNPRINTF( buf, sizeof(buf), "%f", _value);
- #else
- - sprintf (buf, "%lf", _value);
- + sprintf (buf, "%f", _value);
- #endif
- SetValue (buf);
- }
- diff -urN /tmp/tinyxml-2.5.3/tinyxml.h lib/tinyXML/tinyxml.h
- --- /tmp/tinyxml-2.5.3/tinyxml.h 2007-05-06 18:41:23.000000000 -0400
- +++ lib/tinyXML/tinyxml.h 2011-02-24 17:19:35.086853016 -0500
- @@ -38,10 +38,20 @@
- #include <string.h>
- #include <assert.h>
- -// Help out windows:
- +// Help out windows (but don't mess up OSX):
- +#if defined( _WIN32 ) || defined(WIN32)
- #if defined( _DEBUG ) && !defined( DEBUG )
- #define DEBUG
- #endif
- +#endif
- +
- +#ifndef TIXML_USE_STL
- +#define TIXML_USE_STL
- +#endif
- +
- +#ifndef HAS_ICONV
- +#define HAS_ICONV
- +#endif
- #ifdef TIXML_USE_STL
- #include <string>
- @@ -53,6 +63,10 @@
- #define TIXML_STRING TiXmlString
- #endif
- +#ifdef HAS_ICONV
- +#include <iconv.h>
- +#endif
- +
- // Deprecated library function hell. Compilers want to use the
- // new safe versions. This probably doesn't fully address the problem,
- // but it gets closer. There are too many compilers for me to fully
- @@ -287,6 +301,10 @@
- protected:
- +#ifdef HAS_ICONV
- + static void ConvertToUtf8(TiXmlDocument* document, TIXML_STRING* text);
- +#endif
- +
- static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
- inline static bool IsWhiteSpace( char c )
- {
- @@ -319,7 +337,7 @@
- const char* endTag, // what ends this text
- bool ignoreCase, // whether to ignore case in the end tag
- TiXmlEncoding encoding ); // the current encoding
- -
- +
- // If an entity has been found, transform it into a character.
- static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
- @@ -763,7 +781,7 @@
- TiXmlNode* prev;
- TiXmlNode* next;
- -
- +
- private:
- TiXmlNode( const TiXmlNode& ); // not implemented.
- void operator=( const TiXmlNode& base ); // not allowed.
- @@ -812,6 +830,7 @@
- const char* Name() const { return name.c_str(); } ///< Return the name of this attribute.
- const char* Value() const { return value.c_str(); } ///< Return the value of this attribute.
- #ifdef TIXML_USE_STL
- + const std::string& NameStr() const { return name; } ///< Return the name of this attribute.
- const std::string& ValueStr() const { return value; } ///< Return the value of this attribute.
- #endif
- int IntValue() const; ///< Return the value of this attribute, converted to an integer.
- @@ -1398,8 +1417,8 @@
- TiXmlDocument( const TiXmlDocument& copy );
- void operator=( const TiXmlDocument& copy );
- - virtual ~TiXmlDocument() {}
- -
- + virtual ~TiXmlDocument();
- +
- /** Load a file using the current document value.
- Returns true if successful. Will delete any existing
- document data before loading.
- @@ -1433,6 +1452,13 @@
- // return ( f.buffer && SaveFile( f.buffer ));
- return SaveFile( filename.c_str() );
- }
- + /** Parse the given block of xml data. Returns true on success, false on error.
- + */
- + bool Parse(const std::string& xml)
- + {
- + Parse(xml.c_str(), NULL, TIXML_DEFAULT_ENCODING);
- + return !Error();
- + }
- #endif
- /** Parse the given null terminated block of xml data. Passing in an encoding to this
- @@ -1532,13 +1558,19 @@
- */
- virtual bool Accept( TiXmlVisitor* content ) const;
- +#ifdef HAS_ICONV
- + void SetConvertToUtf8(bool convert) { convertToUtf8 = convert; }
- + bool convertToUtf8;
- + iconv_t iconvContext;
- +#endif
- +
- protected :
- // [internal use]
- virtual TiXmlNode* Clone() const;
- #ifdef TIXML_USE_STL
- virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
- #endif
- -
- +
- private:
- void CopyTo( TiXmlDocument* target ) const;
- diff -urN /tmp/tinyxml-2.5.3/tinyxmlparser.cpp lib/tinyXML/tinyxmlparser.cpp
- --- /tmp/tinyxml-2.5.3/tinyxmlparser.cpp 2007-05-06 18:41:23.000000000 -0400
- +++ lib/tinyXML/tinyxmlparser.cpp 2011-02-24 17:19:35.086853016 -0500
- @@ -26,6 +26,7 @@
- #include <stddef.h>
- #include "tinyxml.h"
- +#include "utils/CharsetConverter.h"
- //#define DEBUG_PARSER
- #if defined( DEBUG_PARSER )
- @@ -354,7 +355,7 @@
- }
- else
- {
- - while ( *p && IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' )
- + while ( *p && (IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' ))
- ++p;
- }
- @@ -440,7 +441,6 @@
- // Presume an entity, and pull it out.
- TIXML_STRING ent;
- int i;
- - *length = 0;
- if ( *(p+1) && *(p+1) == '#' && *(p+2) )
- {
- @@ -525,7 +525,7 @@
- // So it wasn't an entity, its unrecognized, or something like that.
- *value = *p; // Don't put back the last one, since we return it!
- - //*length = 1; // Leave unrecognized entities - this doesn't really work.
- + *length = 1; // Leave unrecognized entities - this doesn't really work.
- // Just writes strange XML.
- return p+1;
- }
- @@ -632,10 +632,37 @@
- }
- }
- if ( p )
- - p += strlen( endTag );
- + p += strlen( endTag );
- return p;
- }
- +#ifdef HAS_ICONV
- +void TiXmlBase::ConvertToUtf8(TiXmlDocument* document, TIXML_STRING* text)
- +{
- + if (!document) return;
- + if (!document->convertToUtf8) return;
- + if (document->iconvContext == (iconv_t) -1) return;
- +
- +#ifdef TIXML_USE_STL
- +
- + size_t olen = (text->size() * 4) + 1;
- + char* output = new char[olen];
- + char* obuf = output;
- + size_t ilen = text->size() + 1;
- + const char* ibuf = (const char*) text->c_str();
- +
- + if (iconv_const(document->iconvContext, &ibuf, &ilen, &obuf, &olen) == (size_t) -1)
- + {
- + delete [] output;
- + return;
- + }
- +
- + *text = output;
- + delete [] output;
- +#endif
- +}
- +#endif
- +
- #ifdef TIXML_USE_STL
- void TiXmlDocument::StreamIn( std::istream * in, TIXML_STRING * tag )
- @@ -779,7 +806,21 @@
- else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
- encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
- else
- + {
- +#ifdef HAS_ICONV
- + if (convertToUtf8)
- + {
- + if (iconvContext != (iconv_t) -1)
- + {
- + iconv_close(iconvContext);
- + iconvContext = (iconv_t) -1;
- + }
- +
- + iconvContext = iconv_open("UTF8", enc);
- + }
- +#endif
- encoding = TIXML_ENCODING_LEGACY;
- + }
- }
- p = SkipWhiteSpace( p, encoding );
- @@ -1177,7 +1218,6 @@
- const char* TiXmlElement::ReadValue( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
- {
- TiXmlDocument* document = GetDocument();
- -
- // Read in text and elements in any order.
- const char* pWithWhiteSpace = p;
- p = SkipWhiteSpace( p, encoding );
- @@ -1207,7 +1247,12 @@
- }
- if ( !textNode->Blank() )
- + {
- LinkEndChild( textNode );
- +#ifdef HAS_ICONV
- + ConvertToUtf8(document, &textNode->value);
- +#endif
- + }
- else
- delete textNode;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement