Changeset 5819 in orxonox.OLD for trunk/src/lib/tinyxml/tinyxml.cc
- Timestamp:
- Nov 29, 2005, 11:07:43 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/tinyxml/tinyxml.cc
r4491 r5819 101 101 // Below 32 is symbolic. 102 102 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 104 110 //*ME: warning C4267: convert 'size_t' to 'int' 105 111 //*ME: Int-Cast to make compiler happy ... … … 319 325 for ( node = firstChild; node; node = node->next ) 320 326 { 321 if ( node->SValue() == _value)327 if ( strcmp( node->Value(), _value ) == 0 ) 322 328 return node; 323 329 } … … 331 337 for ( node = firstChild; node; node = node->next ) 332 338 { 333 if ( node->SValue() == _value)339 if ( strcmp( node->Value(), _value ) == 0 ) 334 340 return node; 335 341 } … … 343 349 for ( node = lastChild; node; node = node->prev ) 344 350 { 345 if ( node->SValue() == _value)351 if ( strcmp( node->Value(), _value ) == 0 ) 346 352 return node; 347 353 } … … 354 360 for ( node = lastChild; node; node = node->prev ) 355 361 { 356 if ( node->SValue() == _value)362 if ( strcmp( node->Value(), _value ) == 0 ) 357 363 return node; 358 364 } … … 417 423 for ( node = next; node; node = node->next ) 418 424 { 419 if ( node->SValue() == _value)425 if ( strcmp( node->Value(), _value ) == 0 ) 420 426 return node; 421 427 } … … 428 434 for ( node = next; node; node = node->next ) 429 435 { 430 if ( node->SValue() == _value)436 if ( strcmp( node->Value(), _value ) == 0 ) 431 437 return node; 432 438 } … … 439 445 for ( node = prev; node; node = node->prev ) 440 446 { 441 if ( node->SValue() == _value)447 if ( strcmp( node->Value(), _value ) == 0 ) 442 448 return node; 443 449 } … … 450 456 for ( node = prev; node; node = node->prev ) 451 457 { 452 if ( node->SValue() == _value)458 if ( strcmp( node->Value(), _value ) == 0 ) 453 459 return node; 454 460 } … … 716 722 { 717 723 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 719 729 SetAttribute( name, buf ); 720 730 } … … 724 734 { 725 735 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 727 741 SetAttribute( name, buf ); 728 742 } … … 866 880 867 881 882 const 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 868 895 TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT ) 869 896 { 870 897 tabsize = 4; 898 useMicrosoftBOM = false; 871 899 ClearError(); 872 900 } … … 875 903 { 876 904 tabsize = 4; 905 useMicrosoftBOM = false; 877 906 value = documentName; 878 907 ClearError(); … … 884 913 { 885 914 tabsize = 4; 915 useMicrosoftBOM = false; 886 916 value = documentName; 887 917 ClearError(); … … 942 972 value = filename; 943 973 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" ); 945 976 946 977 if ( file ) … … 964 995 data.reserve( length ); 965 996 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 ) ) 970 1013 { 971 1014 data += buf; 972 1015 } 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 } 973 1027 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; 974 1074 975 1075 Parse( data.c_str(), 0, encoding ); … … 990 1090 if ( fp ) 991 1091 { 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 } 992 1102 Print( fp, 0 ); 993 1103 fclose( fp ); … … 1135 1245 { 1136 1246 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 1138 1252 SetValue (buf); 1139 1253 } … … 1142 1256 { 1143 1257 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 1145 1263 SetValue (buf); 1146 1264 } 1147 1265 1148 constint TiXmlAttribute::IntValue() const1266 int TiXmlAttribute::IntValue() const 1149 1267 { 1150 1268 return atoi (value.c_str ()); 1151 1269 } 1152 1270 1153 constdouble TiXmlAttribute::DoubleValue() const1271 double TiXmlAttribute::DoubleValue() const 1154 1272 { 1155 1273 return atof (value.c_str ()); … … 1206 1324 1207 1325 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() ); 1326 void 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 } 1213 1345 } 1214 1346 … … 1216 1348 void TiXmlText::StreamOut( TIXML_OSTREAM * stream ) const 1217 1349 { 1218 PutString( value, stream ); 1350 if ( cdata ) 1351 { 1352 (*stream) << "<![CDATA[" << value << "]]>"; 1353 } 1354 else 1355 { 1356 PutString( value, stream ); 1357 } 1219 1358 } 1220 1359 … … 1223 1362 { 1224 1363 TiXmlNode::CopyTo( target ); 1364 target->cdata = cdata; 1225 1365 } 1226 1366
Note: See TracChangeset
for help on using the changeset viewer.