Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 29, 2005, 10:52:08 AM (18 years ago)
Author:
bensch
Message:

orxonox/branches/we: new tinyXML-version (version 2.4.2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/world_entities/src/lib/tinyxml/tinyxml.cc

    r4491 r5817  
    101101                        // Below 32 is symbolic.
    102102                        char buf[ 32 ];
    103                         sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) );
     103                       
     104                        #if defined(TIXML_SNPRINTF)             
     105                                TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) );
     106                        #else
     107                                sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) );
     108                        #endif         
     109
    104110                        //*ME:  warning C4267: convert 'size_t' to 'int'
    105111                        //*ME:  Int-Cast to make compiler happy ...
     
    319325        for ( node = firstChild; node; node = node->next )
    320326        {
    321                 if ( node->SValue() == _value )
     327                if ( strcmp( node->Value(), _value ) == 0 )
    322328                        return node;
    323329        }
     
    331337        for ( node = firstChild; node; node = node->next )
    332338        {
    333                 if ( node->SValue() == _value )
     339                if ( strcmp( node->Value(), _value ) == 0 )
    334340                        return node;
    335341        }
     
    343349        for ( node = lastChild; node; node = node->prev )
    344350        {
    345                 if ( node->SValue() == _value )
     351                if ( strcmp( node->Value(), _value ) == 0 )
    346352                        return node;
    347353        }
     
    354360        for ( node = lastChild; node; node = node->prev )
    355361        {
    356                 if ( node->SValue() == _value )
     362                if ( strcmp( node->Value(), _value ) == 0 )
    357363                        return node;
    358364        }
     
    417423        for ( node = next; node; node = node->next )
    418424        {
    419                 if ( node->SValue() == _value )
     425                if ( strcmp( node->Value(), _value ) == 0 )
    420426                        return node;
    421427        }
     
    428434        for ( node = next; node; node = node->next )
    429435        {
    430                 if ( node->SValue() == _value )
     436                if ( strcmp( node->Value(), _value ) == 0 )
    431437                        return node;
    432438        }
     
    439445        for ( node = prev; node; node = node->prev )
    440446        {
    441                 if ( node->SValue() == _value )
     447                if ( strcmp( node->Value(), _value ) == 0 )
    442448                        return node;
    443449        }
     
    450456        for ( node = prev; node; node = node->prev )
    451457        {
    452                 if ( node->SValue() == _value )
     458                if ( strcmp( node->Value(), _value ) == 0 )
    453459                        return node;
    454460        }
     
    716722{       
    717723        char buf[64];
    718         sprintf( buf, "%d", val );
     724        #if defined(TIXML_SNPRINTF)             
     725                TIXML_SNPRINTF( buf, sizeof(buf), "%d", val );
     726        #else
     727                sprintf( buf, "%d", val );
     728        #endif
    719729        SetAttribute( name, buf );
    720730}
     
    724734{       
    725735        char buf[256];
    726         sprintf( buf, "%f", val );
     736        #if defined(TIXML_SNPRINTF)             
     737                TIXML_SNPRINTF( buf, sizeof(buf), "%f", val );
     738        #else
     739                sprintf( buf, "%f", val );
     740        #endif
    727741        SetAttribute( name, buf );
    728742}
     
    866880
    867881
     882const char* TiXmlElement::GetText() const
     883{
     884        const TiXmlNode* child = this->FirstChild();
     885        if ( child ) {
     886                const TiXmlText* childText = child->ToText();
     887                if ( childText ) {
     888                        return childText->Value();
     889                }
     890        }
     891        return 0;
     892}
     893
     894
    868895TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT )
    869896{
    870897        tabsize = 4;
     898        useMicrosoftBOM = false;
    871899        ClearError();
    872900}
     
    875903{
    876904        tabsize = 4;
     905        useMicrosoftBOM = false;
    877906        value = documentName;
    878907        ClearError();
     
    884913{
    885914        tabsize = 4;
     915        useMicrosoftBOM = false;
    886916    value = documentName;
    887917        ClearError();
     
    942972        value = filename;
    943973
    944         FILE* file = fopen( value.c_str (), "r" );
     974        // reading in binary mode so that tinyxml can normalize the EOL
     975        FILE* file = fopen( value.c_str (), "rb" );     
    945976
    946977        if ( file )
     
    964995                data.reserve( length );
    965996
    966                 const int BUF_SIZE = 2048;
    967                 char buf[BUF_SIZE];
    968 
    969                 while( fgets( buf, BUF_SIZE, file ) )
     997                // Subtle bug here. TinyXml did use fgets. But from the XML spec:
     998                // 2.11 End-of-Line Handling
     999                // <snip>
     1000                // <quote>
     1001                // ...the XML processor MUST behave as if it normalized all line breaks in external
     1002                // parsed entities (including the document entity) on input, before parsing, by translating
     1003                // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to
     1004                // a single #xA character.
     1005                // </quote>
     1006                //
     1007                // It is not clear fgets does that, and certainly isn't clear it works cross platform.
     1008                // Generally, you expect fgets to translate from the convention of the OS to the c/unix
     1009                // convention, and not work generally.
     1010
     1011                /*
     1012                while( fgets( buf, sizeof(buf), file ) )
    9701013                {
    9711014                        data += buf;
    9721015                }
     1016                */
     1017
     1018                char* buf = new char[ length+1 ];
     1019                buf[0] = 0;
     1020
     1021                if ( fread( buf, length, 1, file ) != 1 ) {
     1022                //if ( fread( buf, 1, length, file ) != (size_t)length ) {
     1023                        SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
     1024                        fclose( file );
     1025                        return false;
     1026                }
    9731027                fclose( file );
     1028
     1029                const char* lastPos = buf;
     1030                const char* p = buf;
     1031
     1032                buf[length] = 0;
     1033                while( *p ) {
     1034                        assert( p < (buf+length) );
     1035                        if ( *p == 0xa ) {
     1036                                // Newline character. No special rules for this. Append all the characters
     1037                                // since the last string, and include the newline.
     1038                                data.append( lastPos, p-lastPos+1 );    // append, include the newline
     1039                                ++p;                                                                    // move past the newline
     1040                                lastPos = p;                                                    // and point to the new buffer (may be 0)
     1041                                assert( p <= (buf+length) );
     1042                        }
     1043                        else if ( *p == 0xd ) {
     1044                                // Carriage return. Append what we have so far, then
     1045                                // handle moving forward in the buffer.
     1046                                if ( (p-lastPos) > 0 ) {
     1047                                        data.append( lastPos, p-lastPos );      // do not add the CR
     1048                                }
     1049                                data += (char)0xa;                                              // a proper newline
     1050
     1051                                if ( *(p+1) == 0xa ) {
     1052                                        // Carriage return - new line sequence
     1053                                        p += 2;
     1054                                        lastPos = p;
     1055                                        assert( p <= (buf+length) );
     1056                                }
     1057                                else {
     1058                                        // it was followed by something else...that is presumably characters again.
     1059                                        ++p;
     1060                                        lastPos = p;
     1061                                        assert( p <= (buf+length) );
     1062                                }
     1063                        }
     1064                        else {
     1065                                ++p;
     1066                        }
     1067                }
     1068                // Handle any left over characters.
     1069                if ( p-lastPos ) {
     1070                        data.append( lastPos, p-lastPos );
     1071                }               
     1072                delete [] buf;
     1073                buf = 0;
    9741074
    9751075                Parse( data.c_str(), 0, encoding );
     
    9901090        if ( fp )
    9911091        {
     1092                if ( useMicrosoftBOM )
     1093                {
     1094                        const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
     1095                        const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
     1096                        const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
     1097
     1098                        fputc( TIXML_UTF_LEAD_0, fp );
     1099                        fputc( TIXML_UTF_LEAD_1, fp );
     1100                        fputc( TIXML_UTF_LEAD_2, fp );
     1101                }
    9921102                Print( fp, 0 );
    9931103                fclose( fp );
     
    11351245{
    11361246        char buf [64];
    1137         sprintf (buf, "%d", _value);
     1247        #if defined(TIXML_SNPRINTF)             
     1248                TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
     1249        #else
     1250                sprintf (buf, "%d", _value);
     1251        #endif
    11381252        SetValue (buf);
    11391253}
     
    11421256{
    11431257        char buf [256];
    1144         sprintf (buf, "%lf", _value);
     1258        #if defined(TIXML_SNPRINTF)             
     1259                TIXML_SNPRINTF( buf, sizeof(buf), "%lf", _value);
     1260        #else
     1261                sprintf (buf, "%lf", _value);
     1262        #endif
    11451263        SetValue (buf);
    11461264}
    11471265
    1148 const int TiXmlAttribute::IntValue() const
     1266int TiXmlAttribute::IntValue() const
    11491267{
    11501268        return atoi (value.c_str ());
    11511269}
    11521270
    1153 const double  TiXmlAttribute::DoubleValue() const
     1271double  TiXmlAttribute::DoubleValue() const
    11541272{
    11551273        return atof (value.c_str ());
     
    12061324
    12071325
    1208 void TiXmlText::Print( FILE* cfile, int /*depth*/ ) const
    1209 {
    1210         TIXML_STRING buffer;
    1211         PutString( value, &buffer );
    1212         fprintf( cfile, "%s", buffer.c_str() );
     1326void TiXmlText::Print( FILE* cfile, int depth ) const
     1327{
     1328        if ( cdata )
     1329        {
     1330                int i;
     1331                fprintf( cfile, "\n" );
     1332                for ( i=0; i<depth; i++ ) {
     1333                        fprintf( cfile, "    " );
     1334                }
     1335                fprintf( cfile, "<![CDATA[" );
     1336                fprintf( cfile, "%s", value.c_str() );  // unformatted output
     1337                fprintf( cfile, "]]>\n" );
     1338        }
     1339        else
     1340        {
     1341                TIXML_STRING buffer;
     1342                PutString( value, &buffer );
     1343                fprintf( cfile, "%s", buffer.c_str() );
     1344        }
    12131345}
    12141346
     
    12161348void TiXmlText::StreamOut( TIXML_OSTREAM * stream ) const
    12171349{
    1218         PutString( value, stream );
     1350        if ( cdata )
     1351        {
     1352                (*stream) << "<![CDATA[" << value << "]]>";
     1353        }
     1354        else
     1355        {
     1356                PutString( value, stream );
     1357        }
    12191358}
    12201359
     
    12231362{
    12241363        TiXmlNode::CopyTo( target );
     1364        target->cdata = cdata;
    12251365}
    12261366
Note: See TracChangeset for help on using the changeset viewer.