Advertisement
Guest User

Untitled

a guest
Jan 11th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 17.47 KB | None | 0 0
  1. diff -urN /tmp/tinyxml-2.5.3/tinyxml.cpp lib/tinyXML/tinyxml.cpp
  2. --- /tmp/tinyxml-2.5.3/tinyxml.cpp  2007-05-06 18:41:23.000000000 -0400
  3. +++ lib/tinyXML/tinyxml.cpp 2011-02-24 17:19:35.086853016 -0500
  4. @@ -31,22 +31,17 @@
  5.  
  6.  #include "tinyxml.h"
  7.  
  8. +#define USE_XBMC_FILESYSTEM
  9.  
  10. +#ifdef USE_XBMC_FILESYSTEM
  11. +bool TiXmlBase::condenseWhiteSpace = false;
  12. +#include "filesystem/File.h"
  13. +using namespace XFILE;
  14. +#else
  15.  bool TiXmlBase::condenseWhiteSpace = true;
  16. +#endif
  17. +
  18.  
  19. -// Microsoft compiler security
  20. -FILE* TiXmlFOpen( const char* filename, const char* mode )
  21. -{
  22. -   #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
  23. -       FILE* fp = 0;
  24. -       errno_t err = fopen_s( &fp, filename, mode );
  25. -       if ( !err && fp )
  26. -           return fp;
  27. -       return 0;
  28. -   #else
  29. -       return fopen( filename, mode );
  30. -   #endif
  31. -}
  32.  
  33.  void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString )
  34.  {
  35. @@ -56,30 +51,7 @@
  36.     {
  37.         unsigned char c = (unsigned char) str[i];
  38.  
  39. -       if (    c == '&'
  40. -            && i < ( (int)str.length() - 2 )
  41. -            && str[i+1] == '#'
  42. -            && str[i+2] == 'x' )
  43. -       {
  44. -           // Hexadecimal character reference.
  45. -           // Pass through unchanged.
  46. -           // &#xA9;   -- copyright symbol, for example.
  47. -           //
  48. -           // The -1 is a bug fix from Rob Laveaux. It keeps
  49. -           // an overflow from happening if there is no ';'.
  50. -           // There are actually 2 ways to exit this loop -
  51. -           // while fails (error case) and break (semicolon found).
  52. -           // However, there is no mechanism (currently) for
  53. -           // this function to return an error.
  54. -           while ( i<(int)str.length()-1 )
  55. -           {
  56. -               outString->append( str.c_str() + i, 1 );
  57. -               ++i;
  58. -               if ( str[i] == ';' )
  59. -                   break;
  60. -           }
  61. -       }
  62. -       else if ( c == '&' )
  63. +       if ( c == '&' )
  64.         {
  65.             outString->append( entity[0].str, entity[0].strLength );
  66.             ++i;
  67. @@ -885,6 +857,10 @@
  68.  {
  69.     tabsize = 4;
  70.     useMicrosoftBOM = false;
  71. +#ifdef HAS_ICONV  
  72. +   convertToUtf8 = false;
  73. +   iconvContext = (iconv_t) -1;
  74. +#endif
  75.     ClearError();
  76.  }
  77.  
  78. @@ -892,6 +868,10 @@
  79.  {
  80.     tabsize = 4;
  81.     useMicrosoftBOM = false;
  82. +#ifdef HAS_ICONV  
  83. +  convertToUtf8 = false;
  84. +  iconvContext = (iconv_t) -1;
  85. +#endif    
  86.     value = documentName;
  87.     ClearError();
  88.  }
  89. @@ -902,7 +882,11 @@
  90.  {
  91.     tabsize = 4;
  92.     useMicrosoftBOM = false;
  93. -    value = documentName;
  94. +#ifdef HAS_ICONV  
  95. +  convertToUtf8 = false;
  96. +  iconvContext = (iconv_t) -1;
  97. +#endif
  98. +  value = documentName;
  99.     ClearError();
  100.  }
  101.  #endif
  102. @@ -913,6 +897,16 @@
  103.     copy.CopyTo( this );
  104.  }
  105.  
  106. +TiXmlDocument::~TiXmlDocument()
  107. +{
  108. +#ifdef HAS_ICONV
  109. +  if (iconvContext != (iconv_t) -1)
  110. +  {
  111. +    iconv_close(iconvContext);
  112. +    iconvContext = (iconv_t) -1;
  113. +  }
  114. +#endif    
  115. +}
  116.  
  117.  void TiXmlDocument::operator=( const TiXmlDocument& copy )
  118.  {
  119. @@ -942,6 +936,7 @@
  120.     return SaveFile( Value() );
  121.  }
  122.  
  123. +#ifdef USE_XBMC_FILESYSTEM
  124.  bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding )
  125.  {
  126.     // There was a really terrifying little bug here. The code:
  127. @@ -954,9 +949,157 @@
  128.     TIXML_STRING filename( _filename );
  129.     value = filename;
  130.  
  131. -   // reading in binary mode so that tinyxml can normalize the EOL
  132. -   FILE* file = TiXmlFOpen( value.c_str (), "rb" );   
  133. +   CFile file;
  134. +   if (!file.Open(value))
  135. +   {
  136. +       SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
  137. +       return false;
  138. +   }
  139. +
  140. +   // Delete the existing data:
  141. +   Clear();
  142. +   location.Clear();
  143. +
  144. +   // Get the file size, so we can pre-allocate the string. HUGE speed impact.
  145. +   long length = -1;
  146. +   int64_t filelen = file.GetLength();
  147. +   if (filelen > 0)
  148. +       length = (long)filelen;
  149. +
  150. +   // We might be streaming it, correct length will be fixed by reading
  151. +   if( length < 0 )
  152. +       length = 1024;
  153. +
  154. +   // Subtle bug here. TinyXml did use fgets. But from the XML spec:
  155. +   // 2.11 End-of-Line Handling
  156. +   // <snip>
  157. +   // <quote>
  158. +   // ...the XML processor MUST behave as if it normalized all line breaks in external
  159. +   // parsed entities (including the document entity) on input, before parsing, by translating
  160. +   // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to
  161. +   // a single #xA character.
  162. +   // </quote>
  163. +   //
  164. +   // It is not clear fgets does that, and certainly isn't clear it works cross platform.
  165. +   // Generally, you expect fgets to translate from the convention of the OS to the c/unix
  166. +   // convention, and not work generally.
  167. +
  168. +   /*
  169. +   while( fgets( buf, sizeof(buf), file ) )
  170. +   {
  171. +       data += buf;
  172. +   }
  173. +   */
  174. +
  175. +   char*  buf = (char*)malloc(length+1);
  176. +   long   pos = 0;
  177. +   long   len;
  178. +   while( (len = file.Read(buf+pos, length-pos)) > 0 ) {
  179. +       pos += len;
  180. +       assert(pos <= length);
  181. +       if(pos == length) {
  182. +           length *= 2;
  183. +           buf = (char*)realloc(buf, length);
  184. +       }
  185. +   }
  186. +   length = pos;
  187. +
  188. +  file.Close();
  189. +
  190. +   // Strange case, but good to handle up front.
  191. +   if ( length == 0 )
  192. +   {
  193. +       SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
  194. +    return false;
  195. +   }
  196. +
  197. +   // If we have a file, assume it is all one big XML file, and read it in.
  198. +   // The document parser may decide the document ends sooner than the entire file, however.
  199. +   TIXML_STRING data;
  200. +   data.reserve( length );
  201. +
  202. +   const char* lastPos = buf;
  203. +   const char* p = buf;
  204. +
  205. +   buf[length] = 0;
  206. +   while( *p ) {
  207. +       assert( p < (buf+length) );
  208. +       if ( *p == 0xa ) {
  209. +           // Newline character. No special rules for this. Append all the characters
  210. +           // since the last string, and include the newline.
  211. +           data.append( lastPos, (p-lastPos+1) );  // append, include the newline
  212. +           ++p;                                    // move past the newline
  213. +           lastPos = p;                            // and point to the new buffer (may be 0)
  214. +           assert( p <= (buf+length) );
  215. +       }
  216. +       else if ( *p == 0xd ) {
  217. +           // Carriage return. Append what we have so far, then
  218. +           // handle moving forward in the buffer.
  219. +           if ( (p-lastPos) > 0 ) {
  220. +               data.append( lastPos, p-lastPos );  // do not add the CR
  221. +           }
  222. +           data += (char)0xa;                      // a proper newline
  223. +
  224. +           if ( *(p+1) == 0xa ) {
  225. +               // Carriage return - new line sequence
  226. +               p += 2;
  227. +               lastPos = p;
  228. +               assert( p <= (buf+length) );
  229. +           }
  230. +           else {
  231. +               // it was followed by something else...that is presumably characters again.
  232. +               ++p;
  233. +               lastPos = p;
  234. +               assert( p <= (buf+length) );
  235. +           }
  236. +       }
  237. +       else {
  238. +           ++p;
  239. +       }
  240. +   }
  241. +   // Handle any left over characters.
  242. +   if ( p-lastPos ) {
  243. +       data.append( lastPos, p-lastPos );
  244. +   }      
  245. +   free(buf);
  246. +   buf = 0;
  247. +
  248. +   Parse( data.c_str(), 0, encoding );
  249.  
  250. +   if (  Error() )
  251. +       return false;
  252. +   else
  253. +       return true;
  254. +}
  255. +
  256. +bool TiXmlDocument::SaveFile( const char *filename ) const
  257. +{
  258. +   XFILE::CFile file;
  259. +   if (file.OpenForWrite(filename, true))
  260. +   {
  261. +       TiXmlPrinter printer;
  262. +       Accept(&printer);
  263. +       file.Write(printer.CStr(), printer.Size());
  264. +       return true;
  265. +   }
  266. +   return false;
  267. +}
  268. +#else
  269. +
  270. +bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding )
  271. +{
  272. +   // There was a really terrifying little bug here. The code:
  273. +   //      value = filename
  274. +   // in the STL case, cause the assignment method of the std::string to
  275. +   // be called. What is strange, is that the std::string had the same
  276. +   // address as it's c_str() method, and so bad things happen. Looks
  277. +   // like a bug in the Microsoft STL implementation.
  278. +   // Add an extra string to avoid the crash.
  279. +   TIXML_STRING filename( _filename );
  280. +   value = filename;
  281. +
  282. +   // reading in binary mode so that tinyxml can normalize the EOL
  283. +   FILE* file = fopen( value.c_str(), "rb" )
  284.     if ( file )
  285.     {
  286.         bool result = LoadFile( file, encoding );
  287. @@ -970,6 +1113,20 @@
  288.     }
  289.  }
  290.  
  291. +bool TiXmlDocument::SaveFile( const char * filename ) const
  292. +{
  293. +   // The old c stuff lives on...
  294. +   FILE* fp = fopen( filename, "w" );
  295. +   if ( fp )
  296. +   {
  297. +       bool result = SaveFile( fp );
  298. +       fclose( fp );
  299. +       return result;
  300. +   }
  301. +   return false;
  302. +}
  303. +#endif
  304. +
  305.  bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding )
  306.  {
  307.     if ( !file )
  308. @@ -983,22 +1140,15 @@
  309.     location.Clear();
  310.  
  311.     // Get the file size, so we can pre-allocate the string. HUGE speed impact.
  312. -   long length = 0;
  313. -   fseek( file, 0, SEEK_END );
  314. -   length = ftell( file );
  315. -   fseek( file, 0, SEEK_SET );
  316. -
  317. -   // Strange case, but good to handle up front.
  318. -   if ( length <= 0 )
  319. -   {
  320. -       SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
  321. -       return false;
  322. +   long length = -1;
  323. +   if( fseek( file, 0, SEEK_END ) == 0 ) {
  324. +       length = ftell( file );
  325. +       fseek( file, 0, SEEK_SET );
  326.     }
  327.  
  328. -   // If we have a file, assume it is all one big XML file, and read it in.
  329. -   // The document parser may decide the document ends sooner than the entire file, however.
  330. -   TIXML_STRING data;
  331. -   data.reserve( length );
  332. +        // We might be streaming it, correct length will be fixed by reading
  333. +   if( length < 0 )
  334. +       length = 1024;
  335.  
  336.     // Subtle bug here. TinyXml did use fgets. But from the XML spec:
  337.     // 2.11 End-of-Line Handling
  338. @@ -1021,15 +1171,31 @@
  339.     }
  340.     */
  341.  
  342. -   char* buf = new char[ length+1 ];
  343. -   buf[0] = 0;
  344. +   char*  buf = (char*)malloc(length+1);
  345. +   long   pos = 0;
  346. +   long   len;
  347. +        while( (len = fread(buf+pos, 1, length-pos, file)) > 0 ) {
  348. +       pos += len;
  349. +       assert(pos <= length);
  350. +       if(pos == length) {
  351. +           length *= 2;
  352. +           buf = (char*)realloc(buf, length);
  353. +       }
  354. +   }
  355. +   length = pos;
  356.  
  357. -   if ( fread( buf, length, 1, file ) != 1 ) {
  358. -       delete [] buf;
  359. -       SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
  360. +   // Strange case, but good to handle up front.
  361. +   if ( length == 0 )
  362. +   {
  363. +       SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
  364.         return false;
  365.     }
  366.  
  367. +   // If we have a file, assume it is all one big XML file, and read it in.
  368. +   // The document parser may decide the document ends sooner than the entire file, however.
  369. +   TIXML_STRING data;
  370. +   data.reserve( length );
  371. +
  372.     const char* lastPos = buf;
  373.     const char* p = buf;
  374.  
  375. @@ -1073,7 +1239,7 @@
  376.     if ( p-lastPos ) {
  377.         data.append( lastPos, p-lastPos );
  378.     }      
  379. -   delete [] buf;
  380. +   free(buf);
  381.     buf = 0;
  382.  
  383.     Parse( data.c_str(), 0, encoding );
  384. @@ -1084,21 +1250,6 @@
  385.         return true;
  386.  }
  387.  
  388. -
  389. -bool TiXmlDocument::SaveFile( const char * filename ) const
  390. -{
  391. -   // The old c stuff lives on...
  392. -   FILE* fp = TiXmlFOpen( filename, "w" );
  393. -   if ( fp )
  394. -   {
  395. -       bool result = SaveFile( fp );
  396. -       fclose( fp );
  397. -       return result;
  398. -   }
  399. -   return false;
  400. -}
  401. -
  402. -
  403.  bool TiXmlDocument::SaveFile( FILE* fp ) const
  404.  {
  405.     if ( useMicrosoftBOM )
  406. @@ -1126,7 +1277,11 @@
  407.     target->tabsize = tabsize;
  408.     target->errorLocation = errorLocation;
  409.     target->useMicrosoftBOM = useMicrosoftBOM;
  410. -
  411. +#ifdef HAS_ICONV
  412. +   target->convertToUtf8 = convertToUtf8;
  413. +   target->iconvContext = (iconv_t) -1;
  414. +#endif
  415. +  
  416.     TiXmlNode* node = 0;
  417.     for ( node = firstChild; node; node = node->NextSibling() )
  418.     {
  419. @@ -1266,9 +1421,9 @@
  420.  {
  421.     char buf [256];
  422.     #if defined(TIXML_SNPRINTF)    
  423. -       TIXML_SNPRINTF( buf, sizeof(buf), "%lf", _value);
  424. +       TIXML_SNPRINTF( buf, sizeof(buf), "%f", _value);
  425.     #else
  426. -       sprintf (buf, "%lf", _value);
  427. +       sprintf (buf, "%f", _value);
  428.     #endif
  429.     SetValue (buf);
  430.  }
  431. diff -urN /tmp/tinyxml-2.5.3/tinyxml.h lib/tinyXML/tinyxml.h
  432. --- /tmp/tinyxml-2.5.3/tinyxml.h    2007-05-06 18:41:23.000000000 -0400
  433. +++ lib/tinyXML/tinyxml.h   2011-02-24 17:19:35.086853016 -0500
  434. @@ -38,10 +38,20 @@
  435.  #include <string.h>
  436.  #include <assert.h>
  437.  
  438. -// Help out windows:
  439. +// Help out windows (but don't mess up OSX):
  440. +#if defined( _WIN32 ) || defined(WIN32)
  441.  #if defined( _DEBUG ) && !defined( DEBUG )
  442.  #define DEBUG
  443.  #endif
  444. +#endif
  445. +
  446. +#ifndef TIXML_USE_STL
  447. +#define TIXML_USE_STL
  448. +#endif
  449. +
  450. +#ifndef HAS_ICONV
  451. +#define HAS_ICONV
  452. +#endif
  453.  
  454.  #ifdef TIXML_USE_STL
  455.     #include <string>
  456. @@ -53,6 +63,10 @@
  457.     #define TIXML_STRING        TiXmlString
  458.  #endif
  459.  
  460. +#ifdef HAS_ICONV
  461. +#include <iconv.h>
  462. +#endif
  463. +
  464.  // Deprecated library function hell. Compilers want to use the
  465.  // new safe versions. This probably doesn't fully address the problem,
  466.  // but it gets closer. There are too many compilers for me to fully
  467. @@ -287,6 +301,10 @@
  468.  
  469.  protected:
  470.  
  471. +#ifdef HAS_ICONV  
  472. +  static void ConvertToUtf8(TiXmlDocument* document, TIXML_STRING* text);
  473. +#endif
  474. +  
  475.     static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
  476.     inline static bool IsWhiteSpace( char c )      
  477.     {
  478. @@ -319,7 +337,7 @@
  479.                                     const char* endTag,         // what ends this text
  480.                                     bool ignoreCase,            // whether to ignore case in the end tag
  481.                                     TiXmlEncoding encoding );   // the current encoding
  482. -
  483. +  
  484.     // If an entity has been found, transform it into a character.
  485.     static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
  486.  
  487. @@ -763,7 +781,7 @@
  488.  
  489.     TiXmlNode*      prev;
  490.     TiXmlNode*      next;
  491. -
  492. +  
  493.  private:
  494.     TiXmlNode( const TiXmlNode& );              // not implemented.
  495.     void operator=( const TiXmlNode& base );    // not allowed.
  496. @@ -812,6 +830,7 @@
  497.     const char*     Name()  const       { return name.c_str(); }        ///< Return the name of this attribute.
  498.     const char*     Value() const       { return value.c_str(); }       ///< Return the value of this attribute.
  499.     #ifdef TIXML_USE_STL
  500. +   const std::string& NameStr() const  { return name; }                ///< Return the name of this attribute.
  501.     const std::string& ValueStr() const { return value; }               ///< Return the value of this attribute.
  502.     #endif
  503.     int             IntValue() const;                                   ///< Return the value of this attribute, converted to an integer.
  504. @@ -1398,8 +1417,8 @@
  505.     TiXmlDocument( const TiXmlDocument& copy );
  506.     void operator=( const TiXmlDocument& copy );
  507.  
  508. -   virtual ~TiXmlDocument() {}
  509. -
  510. +   virtual ~TiXmlDocument();
  511. +  
  512.     /** Load a file using the current document value.
  513.         Returns true if successful. Will delete any existing
  514.         document data before loading.
  515. @@ -1433,6 +1452,13 @@
  516.  //     return ( f.buffer && SaveFile( f.buffer ));
  517.         return SaveFile( filename.c_str() );
  518.     }
  519. +   /** Parse the given block of xml data. Returns true on success, false on error.
  520. +   */
  521. +   bool Parse(const std::string& xml)
  522. +   {
  523. +       Parse(xml.c_str(), NULL, TIXML_DEFAULT_ENCODING);
  524. +       return !Error();
  525. +   }
  526.     #endif
  527.  
  528.     /** Parse the given null terminated block of xml data. Passing in an encoding to this
  529. @@ -1532,13 +1558,19 @@
  530.     */
  531.     virtual bool Accept( TiXmlVisitor* content ) const;
  532.  
  533. +#ifdef HAS_ICONV  
  534. +   void SetConvertToUtf8(bool convert) { convertToUtf8 = convert; }
  535. +  bool convertToUtf8;
  536. +  iconv_t iconvContext;
  537. +#endif
  538. +  
  539.  protected :
  540.     // [internal use]
  541.     virtual TiXmlNode* Clone() const;
  542.     #ifdef TIXML_USE_STL
  543.     virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
  544.     #endif
  545. -
  546. +  
  547.  private:
  548.     void CopyTo( TiXmlDocument* target ) const;
  549.  
  550. diff -urN /tmp/tinyxml-2.5.3/tinyxmlparser.cpp lib/tinyXML/tinyxmlparser.cpp
  551. --- /tmp/tinyxml-2.5.3/tinyxmlparser.cpp    2007-05-06 18:41:23.000000000 -0400
  552. +++ lib/tinyXML/tinyxmlparser.cpp   2011-02-24 17:19:35.086853016 -0500
  553. @@ -26,6 +26,7 @@
  554.  #include <stddef.h>
  555.  
  556.  #include "tinyxml.h"
  557. +#include "utils/CharsetConverter.h"
  558.  
  559.  //#define DEBUG_PARSER
  560.  #if defined( DEBUG_PARSER )
  561. @@ -354,7 +355,7 @@
  562.     }
  563.     else
  564.     {
  565. -       while ( *p && IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' )
  566. +       while ( *p && (IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' ))
  567.             ++p;
  568.     }
  569.  
  570. @@ -440,7 +441,6 @@
  571.     // Presume an entity, and pull it out.
  572.      TIXML_STRING ent;
  573.     int i;
  574. -   *length = 0;
  575.  
  576.     if ( *(p+1) && *(p+1) == '#' && *(p+2) )
  577.     {
  578. @@ -525,7 +525,7 @@
  579.  
  580.     // So it wasn't an entity, its unrecognized, or something like that.
  581.     *value = *p;    // Don't put back the last one, since we return it!
  582. -   //*length = 1;  // Leave unrecognized entities - this doesn't really work.
  583. +   *length = 1;    // Leave unrecognized entities - this doesn't really work.
  584.                     // Just writes strange XML.
  585.     return p+1;
  586.  }
  587. @@ -632,10 +632,37 @@
  588.         }
  589.     }
  590.     if ( p )
  591. -       p += strlen( endTag );
  592. +       p += strlen( endTag )
  593.     return p;
  594.  }
  595.  
  596. +#ifdef HAS_ICONV
  597. +void TiXmlBase::ConvertToUtf8(TiXmlDocument* document, TIXML_STRING* text)
  598. +{
  599. +  if (!document) return;
  600. +  if (!document->convertToUtf8) return;
  601. +  if (document->iconvContext == (iconv_t) -1) return;
  602. +  
  603. +#ifdef TIXML_USE_STL
  604. +  
  605. +  size_t olen = (text->size() * 4) + 1;
  606. +  char* output = new char[olen];
  607. +  char* obuf = output;
  608. +  size_t ilen = text->size() + 1;
  609. +  const char* ibuf = (const char*) text->c_str();
  610. +  
  611. +  if (iconv_const(document->iconvContext, &ibuf, &ilen, &obuf, &olen) == (size_t) -1)
  612. +  {
  613. +    delete [] output;
  614. +    return;
  615. +  }
  616. +  
  617. +  *text = output;
  618. +  delete [] output;
  619. +#endif
  620. +}
  621. +#endif
  622. +  
  623.  #ifdef TIXML_USE_STL
  624.  
  625.  void TiXmlDocument::StreamIn( std::istream * in, TIXML_STRING * tag )
  626. @@ -779,7 +806,21 @@
  627.             else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
  628.                 encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
  629.             else
  630. +           {
  631. +#ifdef HAS_ICONV
  632. +             if (convertToUtf8)
  633. +             {
  634. +               if (iconvContext != (iconv_t) -1)
  635. +               {
  636. +                 iconv_close(iconvContext);
  637. +                 iconvContext = (iconv_t) -1;
  638. +               }
  639. +              
  640. +          iconvContext = iconv_open("UTF8", enc);
  641. +             }
  642. +#endif            
  643.                 encoding = TIXML_ENCODING_LEGACY;
  644. +           }
  645.         }
  646.  
  647.         p = SkipWhiteSpace( p, encoding );
  648. @@ -1177,7 +1218,6 @@
  649.  const char* TiXmlElement::ReadValue( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
  650.  {
  651.     TiXmlDocument* document = GetDocument();
  652. -
  653.     // Read in text and elements in any order.
  654.     const char* pWithWhiteSpace = p;
  655.     p = SkipWhiteSpace( p, encoding );
  656. @@ -1207,7 +1247,12 @@
  657.             }
  658.  
  659.             if ( !textNode->Blank() )
  660. +           {
  661.                 LinkEndChild( textNode );
  662. +#ifdef HAS_ICONV
  663. +        ConvertToUtf8(document, &textNode->value);
  664. +#endif                
  665. +           }
  666.             else
  667.                 delete textNode;
  668.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement