Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5817 in orxonox.OLD


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)

Location:
branches/world_entities/src/lib/tinyxml
Files:
6 edited

Legend:

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

    r4491 r5817  
    33Original file by Yves Berquin.
    44
    5 This software is provided 'as-is', without any express or implied 
    6 warranty. In no event will the authors be held liable for any 
     5This software is provided 'as-is', without any express or implied
     6warranty. In no event will the authors be held liable for any
    77damages arising from the use of this software.
    88
    9 Permission is granted to anyone to use this software for any 
    10 purpose, including commercial applications, and to alter it and 
     9Permission is granted to anyone to use this software for any
     10purpose, including commercial applications, and to alter it and
    1111redistribute it freely, subject to the following restrictions:
    1212
    13 1. The origin of this software must not be misrepresented; you must 
    14 not claim that you wrote the original software. If you use this 
    15 software in a product, an acknowledgment in the product documentation 
     131. The origin of this software must not be misrepresented; you must
     14not claim that you wrote the original software. If you use this
     15software in a product, an acknowledgment in the product documentation
    1616would be appreciated but is not required.
    1717
     
    1919must not be misrepresented as being the original software.
    2020
    21 3. This notice may not be removed or altered from any source 
     213. This notice may not be removed or altered from any source
    2222distribution.
    2323*/
    2424
    25 #include "tinyxml.h"
     25/*
     26 * THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005.
     27 */
     28
    2629
    2730#ifndef TIXML_USE_STL
    2831
    29 
    30 #include <stdlib.h>
    31 #include <string.h>
    32 #include <ctype.h>
    33 
    3432#include "tinystr.h"
    3533
    36 // TiXmlString constructor, based on a C string
    37 TiXmlString::TiXmlString (const char* instring)
     34// Error value for find primitive
     35const TiXmlString::size_type TiXmlString::npos = static_cast< size_type >(-1);
     36
     37// Null rep.
     38TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, '\0' };
     39
     40
     41void TiXmlString::reserve (size_type cap)
    3842{
    39     size_t newlen;
    40     char * newstring;
    41 
    42     if (!instring)
    43     {
    44         allocated = 0;
    45         cstring = NULL;
    46         current_length = 0;
    47         return;
    48     }
    49     newlen = strlen (instring) + 1;
    50     newstring = new char [newlen];
    51     memcpy (newstring, instring, newlen);
    52     // strcpy (newstring, instring);
    53     allocated = newlen;
    54     cstring = newstring;
    55     current_length = newlen - 1;
    56 }
    57 
    58 // TiXmlString copy constructor
    59 TiXmlString::TiXmlString (const TiXmlString& copy)
    60 {
    61     size_t newlen;
    62     char * newstring;
    63 
    64         // Prevent copy to self!
    65         if ( &copy == this )
    66                 return;
    67 
    68     if (! copy . allocated)
    69     {
    70         allocated = 0;
    71         cstring = NULL;
    72         current_length = 0;
    73         return;
    74     }
    75     newlen = copy . length () + 1;
    76     newstring = new char [newlen];
    77     // strcpy (newstring, copy . cstring);
    78     memcpy (newstring, copy . cstring, newlen);
    79     allocated = newlen;
    80     cstring = newstring;
    81     current_length = newlen - 1;
    82 }
    83 
    84 // TiXmlString = operator. Safe when assign own content
    85 void TiXmlString ::operator = (const char * content)
    86 {
    87     size_t newlen;
    88     char * newstring;
    89 
    90     if (! content)
    91     {
    92         empty_it ();
    93         return;
    94     }
    95     newlen = strlen (content) + 1;
    96     newstring = new char [newlen];
    97     // strcpy (newstring, content);
    98     memcpy (newstring, content, newlen);
    99     empty_it ();
    100     allocated = newlen;
    101     cstring = newstring;
    102     current_length = newlen - 1;
    103 }
    104 
    105 // = operator. Safe when assign own content
    106 void TiXmlString ::operator = (const TiXmlString & copy)
    107 {
    108     size_t newlen;
    109     char * newstring;
    110 
    111     if (! copy . length ())
    112     {
    113         empty_it ();
    114         return;
    115     }
    116     newlen = copy . length () + 1;
    117     newstring = new char [newlen];
    118     // strcpy (newstring, copy . c_str ());
    119     memcpy (newstring, copy . c_str (), newlen);
    120     empty_it ();
    121     allocated = newlen;
    122     cstring = newstring;
    123     current_length = newlen - 1;
     43        if (cap > capacity())
     44        {
     45                TiXmlString tmp;
     46                tmp.init(length(), cap);
     47                memcpy(tmp.start(), data(), length());
     48                swap(tmp);
     49        }
    12450}
    12551
    12652
    127 // append a const char * to an existing TiXmlString
    128 void TiXmlString::append( const char* str, size_t len )
     53TiXmlString& TiXmlString::assign(const char* str, size_type len)
    12954{
    130     char * new_string;
    131     size_t new_alloc, new_size, size_suffix;
    132        
    133         // don't use strlen - it can overrun the len passed in!
    134         const char* p = str;
    135         size_suffix = 0;
    136 
    137         while ( *p && size_suffix < (unsigned)len )
     55        size_type cap = capacity();
     56        if (len > cap || cap > 3*(len + 8))
    13857        {
    139                 ++p;
    140                 ++size_suffix;
     58                TiXmlString tmp;
     59                tmp.init(len);
     60                memcpy(tmp.start(), str, len);
     61                swap(tmp);
    14162        }
    142     if ( !size_suffix)
    143         return;
    144 
    145     new_size = length () + size_suffix + 1;
    146     // check if we need to expand
    147     if (new_size > allocated)
    148     {
    149         // compute new size
    150         new_alloc = assign_new_size (new_size);
    151 
    152         // allocate new buffer
    153         new_string = new char [new_alloc];       
    154         new_string [0] = 0;
    155 
    156         // copy the previous allocated buffer into this one
    157         if (allocated && cstring)
    158             // strcpy (new_string, cstring);
    159             memcpy (new_string, cstring, length ());
    160 
    161         // append the suffix. It does exist, otherwize we wouldn't be expanding
    162         // strncat (new_string, str, len);
    163         memcpy (new_string + length (),
    164                 str,
    165                 size_suffix);
    166 
    167         // return previsously allocated buffer if any
    168         if (allocated && cstring)
    169             delete [] cstring;
    170 
    171         // update member variables
    172         cstring = new_string;
    173         allocated = new_alloc;
    174     }
    175     else
    176     {
    177         // we know we can safely append the new string
    178         // strncat (cstring, str, len);
    179         memcpy (cstring + length (),
    180                 str,
    181                 size_suffix);
    182     }
    183     current_length = new_size - 1;
    184     cstring [current_length] = 0;
     63        else
     64        {
     65                memmove(start(), str, len);
     66                set_size(len);
     67        }
     68        return *this;
    18569}
    18670
    18771
    188 // append a const char * to an existing TiXmlString
    189 void TiXmlString::append( const char * suffix )
     72TiXmlString& TiXmlString::append(const char* str, size_type len)
    19073{
    191     char * new_string;
    192     size_t new_alloc, new_size;
    193 
    194     new_size = length () + strlen (suffix) + 1;
    195     // check if we need to expand
    196     if (new_size > allocated)
    197     {
    198         // compute new size
    199         new_alloc = assign_new_size (new_size);
    200 
    201         // allocate new buffer
    202         new_string = new char [new_alloc];       
    203         new_string [0] = 0;
    204 
    205         // copy the previous allocated buffer into this one
    206         if (allocated && cstring)
    207             memcpy (new_string, cstring, 1 + length ());
    208             // strcpy (new_string, cstring);
    209 
    210         // append the suffix. It does exist, otherwize we wouldn't be expanding
    211         // strcat (new_string, suffix);
    212         memcpy (new_string + length (),
    213                 suffix,
    214                 strlen (suffix) + 1);
    215 
    216         // return previsously allocated buffer if any
    217         if (allocated && cstring)
    218             delete [] cstring;
    219 
    220         // update member variables
    221         cstring = new_string;
    222         allocated = new_alloc;
    223     }
    224     else
    225     {
    226         // we know we can safely append the new string
    227         // strcat (cstring, suffix);
    228         memcpy (cstring + length (),
    229                 suffix,
    230                 strlen (suffix) + 1);
    231     }
    232     current_length = new_size - 1;
    233 }
    234 
    235 // Check for TiXmlString equuivalence
    236 //bool TiXmlString::operator == (const TiXmlString & compare) const
    237 //{
    238 //    return (! strcmp (c_str (), compare . c_str ()));
    239 //}
    240 
    241 //unsigned TiXmlString::length () const
    242 //{
    243 //    if (allocated)
    244 //        // return strlen (cstring);
    245 //        return current_length;
    246 //    return 0;
    247 //}
    248 
    249 
    250 unsigned TiXmlString::find (char tofind, unsigned offset) const
    251 {
    252     char * lookup;
    253 
    254     if (offset >= length ())
    255         return (unsigned) notfound;
    256     for (lookup = cstring + offset; * lookup; lookup++)
    257         if (* lookup == tofind)
    258             return (unsigned)(lookup - cstring);
    259     return (unsigned) notfound;
     74        size_type newsize = length() + len;
     75        if (newsize > capacity())
     76        {
     77                reserve (newsize + capacity());
     78        }
     79        memmove(finish(), str, len);
     80        set_size(newsize);
     81        return *this;
    26082}
    26183
    26284
    263 bool TiXmlString::operator == (const TiXmlString & compare) const
     85TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
    26486{
    265         if ( allocated && compare.allocated )
    266         {
    267                 assert( cstring );
    268                 assert( compare.cstring );
    269                 return ( strcmp( cstring, compare.cstring ) == 0 );
    270         }
    271         else if ( length() == 0 && compare.length() == 0 )
    272         {
    273                 return true;
    274         }
    275         return false;
     87        TiXmlString tmp;
     88        tmp.reserve(a.length() + b.length());
     89        tmp += a;
     90        tmp += b;
     91        return tmp;
    27692}
    27793
    278 
    279 bool TiXmlString::operator == (const char* compare) const
     94TiXmlString operator + (const TiXmlString & a, const char* b)
    28095{
    281         if ( allocated && compare && *compare )
    282         {
    283                 assert( cstring );
    284                 return ( strcmp( cstring, compare ) == 0 );
    285         }
    286         else if ( length() == 0 && (!compare || !*compare ) )   // this is a little dubious, but try to duplicate behavior in other operator==
    287         {
    288                 return true;
    289         }
    290         return false;   
     96        TiXmlString tmp;
     97        TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
     98        tmp.reserve(a.length() + b_len);
     99        tmp += a;
     100        tmp.append(b, b_len);
     101        return tmp;
    291102}
    292103
    293 
    294 bool TiXmlString::operator < (const TiXmlString & compare) const
     104TiXmlString operator + (const char* a, const TiXmlString & b)
    295105{
    296         if ( allocated && compare.allocated )
    297         {
    298                 assert( cstring );
    299                 assert( compare.cstring );
    300                 return ( strcmp( cstring, compare.cstring ) > 0 );
    301         }
    302         return false;
    303 }
    304 
    305 
    306 bool TiXmlString::operator > (const TiXmlString & compare) const
    307 {
    308         if ( allocated && compare.allocated )
    309         {
    310                 assert( cstring );
    311                 assert( compare.cstring );
    312                 return ( strcmp( cstring, compare.cstring ) < 0 );
    313         }
    314         return false;
     106        TiXmlString tmp;
     107        TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
     108        tmp.reserve(a_len + b.length());
     109        tmp.append(a, a_len);
     110        tmp += b;
     111        return tmp;
    315112}
    316113
  • branches/world_entities/src/lib/tinyxml/tinystr.h

    r4491 r5817  
    33Original file by Yves Berquin.
    44
    5 This software is provided 'as-is', without any express or implied 
    6 warranty. In no event will the authors be held liable for any 
     5This software is provided 'as-is', without any express or implied
     6warranty. In no event will the authors be held liable for any
    77damages arising from the use of this software.
    88
    9 Permission is granted to anyone to use this software for any 
    10 purpose, including commercial applications, and to alter it and 
     9Permission is granted to anyone to use this software for any
     10purpose, including commercial applications, and to alter it and
    1111redistribute it freely, subject to the following restrictions:
    1212
    13 1. The origin of this software must not be misrepresented; you must 
    14 not claim that you wrote the original software. If you use this 
    15 software in a product, an acknowledgment in the product documentation 
     131. The origin of this software must not be misrepresented; you must
     14not claim that you wrote the original software. If you use this
     15software in a product, an acknowledgment in the product documentation
    1616would be appreciated but is not required.
    1717
     
    1919must not be misrepresented as being the original software.
    2020
    21 3. This notice may not be removed or altered from any source 
     213. This notice may not be removed or altered from any source
    2222distribution.
    2323*/
    2424
    25 #include "tinyxml.h"
    26 
     25/*
     26 * THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
     27 *
     28 * - completely rewritten. compact, clean, and fast implementation.
     29 * - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
     30 * - fixed reserve() to work as per specification.
     31 * - fixed buggy compares operator==(), operator<(), and operator>()
     32 * - fixed operator+=() to take a const ref argument, following spec.
     33 * - added "copy" constructor with length, and most compare operators.
     34 * - added swap(), clear(), size(), capacity(), operator+().
     35 */
    2736
    2837#ifndef TIXML_USE_STL
     
    3140#define TIXML_STRING_INCLUDED
    3241
    33 #ifdef _MSC_VER
    34 #pragma warning( disable : 4530 )
    35 #pragma warning( disable : 4786 )
    36 #endif
    37 
    3842#include <assert.h>
     43#include <string.h>
    3944
    4045/*
    41    TiXmlString is an emulation of the std::string template.
     46   TiXmlString is an emulation of a subset of the std::string template.
    4247   Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
    4348   Only the member functions relevant to the TinyXML project have been implemented.
     
    4853{
    4954  public :
    50     // TiXmlString constructor, based on a string, mark explicit to force
    51         // us to find unnecessary casting.
    52     explicit TiXmlString (const char * instring);
    53 
    54     // TiXmlString empty constructor
    55     TiXmlString ()
    56     {
    57         allocated = 0;
    58         cstring = NULL;
    59         current_length = 0;
    60     }
    61 
    62     // TiXmlString copy constructor
    63     explicit TiXmlString (const TiXmlString& copy);
    64 
    65     // TiXmlString destructor
    66     ~ TiXmlString ()
    67     {
    68         empty_it ();
    69     }
    70 
    71     // Convert a TiXmlString into a classical char *
    72     const char * c_str () const
    73     {
    74         if (allocated)
    75             return cstring;
    76         return "";
    77     }
    78 
    79     // Return the length of a TiXmlString
    80     size_t length () const
    81         {
    82                 return ( allocated ) ? current_length : 0;
    83         }
    84 
    85     // TiXmlString = operator
    86     void operator = (const char * content);
    87 
    88     // = operator
    89     void operator = (const TiXmlString & copy);
    90 
    91     // += operator. Maps to append
    92     TiXmlString& operator += (const char * suffix)
    93     {
    94         append (suffix);
    95                 return *this;
    96     }
    97 
    98     // += operator. Maps to append
    99     TiXmlString& operator += (char single)
    100     {
    101         append (single);
    102                 return *this;
    103     }
    104 
    105     // += operator. Maps to append
    106     TiXmlString& operator += (TiXmlString & suffix)
    107     {
    108         append (suffix);
    109                 return *this;
    110     }
    111     bool operator == (const TiXmlString & compare) const;
    112     bool operator == (const char* compare) const;
    113     bool operator < (const TiXmlString & compare) const;
    114     bool operator > (const TiXmlString & compare) const;
    115 
    116     // Checks if a TiXmlString is empty
    117     bool empty () const
    118     {
    119         return length () ? false : true;
    120     }
    121 
    122     // single char extraction
    123     const char& at (unsigned index) const
    124     {
    125         assert( index < length ());
    126         return cstring [index];
    127     }
    128 
    129     // find a char in a string. Return TiXmlString::notfound if not found
    130     unsigned find (char lookup) const
    131     {
    132         return find (lookup, 0);
    133     }
    134 
    135     // find a char in a string from an offset. Return TiXmlString::notfound if not found
    136     unsigned find (char tofind, unsigned offset) const;
    137 
    138     /*  Function to reserve a big amount of data when we know we'll need it. Be aware that this
    139                 function clears the content of the TiXmlString if any exists.
    140     */
    141     void reserve (unsigned size)
    142     {
    143         empty_it ();
    144         if (size)
    145         {
    146             allocated = size;
    147             cstring = new char [size];
    148             cstring [0] = 0;
    149             current_length = 0;
    150         }
    151     }
    152 
    153     // [] operator
    154     char& operator [] (unsigned index) const
    155     {
    156         assert( index < length ());
    157         return cstring [index];
    158     }
    159 
    160     // Error value for find primitive
    161     enum {      notfound = 0xffffffff,
    162             npos = notfound };
    163 
    164     void append (const char *str, size_t len );
    165 
    166   protected :
    167 
    168     // The base string
    169     char * cstring;
    170     // Number of chars allocated
    171     size_t allocated;
    172     // Current string size
    173     size_t current_length;
    174 
    175     // New size computation. It is simplistic right now : it returns twice the amount
    176     // we need
    177     size_t assign_new_size (size_t minimum_to_allocate)
    178     {
    179         return minimum_to_allocate * 2;
    180     }
    181 
    182     // Internal function that clears the content of a TiXmlString
    183     void empty_it ()
    184     {
    185         if (cstring)
    186             delete [] cstring;
    187         cstring = NULL;
    188         allocated = 0;
    189         current_length = 0;
    190     }
    191 
    192     void append (const char *suffix );
    193 
    194     // append function for another TiXmlString
    195     void append (const TiXmlString & suffix)
    196     {
    197         append (suffix . c_str ());
    198     }
    199 
    200     // append for a single char.
    201     void append (char single)
    202     {
    203         if ( cstring && current_length < (allocated-1) )
     55        // The size type used
     56        typedef unsigned int size_type;
     57
     58        // Error value for find primitive
     59        static const size_type npos; // = -1;
     60
     61
     62        // TiXmlString empty constructor
     63        TiXmlString () : rep_(&nullrep_)
     64        {
     65        }
     66
     67        // TiXmlString copy constructor
     68        TiXmlString (const TiXmlString & copy)
     69        {
     70                init(copy.length());
     71                memcpy(start(), copy.data(), length());
     72        }
     73
     74        // TiXmlString constructor, based on a string
     75        TiXmlString (const char * copy)
     76        {
     77                init( static_cast<size_type>( strlen(copy) ));
     78                memcpy(start(), copy, length());
     79        }
     80
     81        // TiXmlString constructor, based on a string
     82        TiXmlString (const char * str, size_type len)
     83        {
     84                init(len);
     85                memcpy(start(), str, len);
     86        }
     87
     88        // TiXmlString destructor
     89        ~TiXmlString ()
     90        {
     91                quit();
     92        }
     93
     94        // = operator
     95        TiXmlString& operator = (const char * copy)
     96        {
     97                return assign( copy, (size_type)strlen(copy));
     98        }
     99
     100        // = operator
     101        TiXmlString& operator = (const TiXmlString & copy)
     102        {
     103                return assign(copy.start(), copy.length());
     104        }
     105
     106
     107        // += operator. Maps to append
     108        TiXmlString& operator += (const char * suffix)
     109        {
     110                return append(suffix, static_cast<size_type>( strlen(suffix) ));
     111        }
     112
     113        // += operator. Maps to append
     114        TiXmlString& operator += (char single)
     115        {
     116                return append(&single, 1);
     117        }
     118
     119        // += operator. Maps to append
     120        TiXmlString& operator += (const TiXmlString & suffix)
     121        {
     122                return append(suffix.data(), suffix.length());
     123        }
     124
     125
     126        // Convert a TiXmlString into a null-terminated char *
     127        const char * c_str () const { return rep_->str; }
     128
     129        // Convert a TiXmlString into a char * (need not be null terminated).
     130        const char * data () const { return rep_->str; }
     131
     132        // Return the length of a TiXmlString
     133        size_type length () const { return rep_->size; }
     134
     135        // Alias for length()
     136        size_type size () const { return rep_->size; }
     137
     138        // Checks if a TiXmlString is empty
     139        bool empty () const { return rep_->size == 0; }
     140
     141        // Return capacity of string
     142        size_type capacity () const { return rep_->capacity; }
     143
     144
     145        // single char extraction
     146        const char& at (size_type index) const
     147        {
     148                assert( index < length() );
     149                return rep_->str[ index ];
     150        }
     151
     152        // [] operator
     153        char& operator [] (size_type index) const
     154        {
     155                assert( index < length() );
     156                return rep_->str[ index ];
     157        }
     158
     159        // find a char in a string. Return TiXmlString::npos if not found
     160        size_type find (char lookup) const
     161        {
     162                return find(lookup, 0);
     163        }
     164
     165        // find a char in a string from an offset. Return TiXmlString::npos if not found
     166        size_type find (char tofind, size_type offset) const
     167        {
     168                if (offset >= length()) return npos;
     169
     170                for (const char* p = c_str() + offset; *p != '\0'; ++p)
    204171                {
    205                         cstring[ current_length ] = single;
    206                         ++current_length;
    207                         cstring[ current_length ] = 0;
     172                   if (*p == tofind) return static_cast< size_type >( p - c_str() );
     173                }
     174                return npos;
     175        }
     176
     177        void clear ()
     178        {
     179                //Lee:
     180                //The original was just too strange, though correct:
     181                //      TiXmlString().swap(*this);
     182                //Instead use the quit & re-init:
     183                quit();
     184                init(0,0);
     185        }
     186
     187        /*      Function to reserve a big amount of data when we know we'll need it. Be aware that this
     188                function DOES NOT clear the content of the TiXmlString if any exists.
     189        */
     190        void reserve (size_type cap);
     191
     192        TiXmlString& assign (const char* str, size_type len);
     193
     194        TiXmlString& append (const char* str, size_type len);
     195
     196        void swap (TiXmlString& other)
     197        {
     198                Rep* r = rep_;
     199                rep_ = other.rep_;
     200                other.rep_ = r;
     201        }
     202
     203  private:
     204
     205        void init(size_type sz) { init(sz, sz); }
     206        void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
     207        char* start() const { return rep_->str; }
     208        char* finish() const { return rep_->str + rep_->size; }
     209
     210        struct Rep
     211        {
     212                size_type size, capacity;
     213                char str[1];
     214        };
     215
     216        void init(size_type sz, size_type cap)
     217        {
     218                if (cap)
     219                {
     220                        // Lee: the original form:
     221                        //      rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
     222                        // doesn't work in some cases of new being overloaded. Switching
     223                        // to the normal allocation, although use an 'int' for systems
     224                        // that are overly picky about structure alignment.
     225                        const size_type bytesNeeded = sizeof(Rep) + cap;
     226                        const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
     227                        rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
     228
     229                        rep_->str[ rep_->size = sz ] = '\0';
     230                        rep_->capacity = cap;
    208231                }
    209232                else
    210233                {
    211                         char smallstr [2];
    212                         smallstr [0] = single;
    213                         smallstr [1] = 0;
    214                         append (smallstr);
     234                        rep_ = &nullrep_;
    215235                }
    216     }
     236        }
     237
     238        void quit()
     239        {
     240                if (rep_ != &nullrep_)
     241                {
     242                        // The rep_ is really an array of ints. (see the allocator, above).
     243                        // Cast it back before delete, so the compiler won't incorrectly call destructors.
     244                        delete [] ( reinterpret_cast<int*>( rep_ ) );
     245                }
     246        }
     247
     248        Rep * rep_;
     249        static Rep nullrep_;
    217250
    218251} ;
    219252
    220 /*
     253
     254inline bool operator == (const TiXmlString & a, const TiXmlString & b)
     255{
     256        return    ( a.length() == b.length() )                          // optimization on some platforms
     257               && ( strcmp(a.c_str(), b.c_str()) == 0 );        // actual compare
     258}
     259inline bool operator < (const TiXmlString & a, const TiXmlString & b)
     260{
     261        return strcmp(a.c_str(), b.c_str()) < 0;
     262}
     263
     264inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
     265inline bool operator >  (const TiXmlString & a, const TiXmlString & b) { return b < a; }
     266inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
     267inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
     268
     269inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
     270inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
     271inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
     272inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
     273
     274TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
     275TiXmlString operator + (const TiXmlString & a, const char* b);
     276TiXmlString operator + (const char* a, const TiXmlString & b);
     277
     278
     279/*
    221280   TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString.
    222281   Only the operators that we need for TinyXML have been developped.
     
    225284{
    226285public :
    227     TiXmlOutStream () : TiXmlString () {}
    228 
    229     // TiXmlOutStream << operator. Maps to TiXmlString::append
    230     TiXmlOutStream & operator << (const char * in)
    231     {
    232         append (in);
    233         return (* this);
    234     }
    235 
    236     // TiXmlOutStream << operator. Maps to TiXmlString::append
    237     TiXmlOutStream & operator << (const TiXmlString & in)
    238     {
    239         append (in . c_str ());
    240         return (* this);
    241     }
     286
     287        // TiXmlOutStream << operator.
     288        TiXmlOutStream & operator << (const TiXmlString & in)
     289        {
     290                *this += in;
     291                return *this;
     292        }
     293
     294        // TiXmlOutStream << operator.
     295        TiXmlOutStream & operator << (const char * in)
     296        {
     297                *this += in;
     298                return *this;
     299        }
     300
    242301} ;
    243 
    244 #ifdef _MSC_VER
    245 #pragma warning( default : 4530 )
    246 #pragma warning( default : 4786 )
    247 #endif
    248302
    249303#endif  // TIXML_STRING_INCLUDED
  • 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
  • branches/world_entities/src/lib/tinyxml/tinyxml.h

    r4491 r5817  
    2828
    2929#ifdef _MSC_VER
     30#pragma warning( push )
    3031#pragma warning( disable : 4530 )
    3132#pragma warning( disable : 4786 )
     
    6263#endif
    6364
     65// Deprecated library function hell. Compilers want to use the
     66// new safe versions. This probably doesn't fully address the problem,
     67// but it gets closer. There are too many compilers for me to fully
     68// test. If you get compilation troubles, undefine TIXML_SAFE
     69
     70#define TIXML_SAFE              // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
     71#ifdef TIXML_SAFE
     72        #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
     73                // Microsoft visual studio, version 6 and higher.
     74                //#pragma message( "Using _sn* functions." )
     75                #define TIXML_SNPRINTF _snprintf
     76                #define TIXML_SNSCANF  _snscanf
     77        #elif defined(__GNUC__) && (__GNUC__ >= 3 )
     78                // GCC version 3 and higher.s
     79                //#warning( "Using sn* functions." )
     80                #define TIXML_SNPRINTF snprintf
     81                #define TIXML_SNSCANF  snscanf
     82        #endif
     83#endif 
     84
    6485class TiXmlDocument;
    6586class TiXmlElement;
     
    7293
    7394const int TIXML_MAJOR_VERSION = 2;
    74 const int TIXML_MINOR_VERSION = 3;
    75 const int TIXML_PATCH_VERSION = 4;
     95const int TIXML_MINOR_VERSION = 4;
     96const int TIXML_PATCH_VERSION = 2;
    7697
    7798/*      Internal structure for tracking location of items
     
    206227                TIXML_ERROR_DOCUMENT_EMPTY,
    207228                TIXML_ERROR_EMBEDDED_NULL,
     229                TIXML_ERROR_PARSING_CDATA,
    208230
    209231                TIXML_ERROR_STRING_COUNT
     
    278300                else if ( *length )
    279301                {
    280                         strncpy( _value, p, *length );
     302                        //strncpy( _value, p, *length );        // lots of compilers don't like this function (unsafe),
     303                                                                                                // and the null terminator isn't needed
     304                        for( int i=0; p[i] && i<*length; ++i ) {
     305                                _value[i] = p[i];
     306                        }
    281307                        return p + (*length);
    282308                }
     
    296322        // Return true if the next characters in the stream are any of the endTag sequences.
    297323        // Ignore case only works for english, and should only be relied on when comparing
    298         // to Engilish words: StringEqual( p, "version", true ) is fine.
     324        // to English words: StringEqual( p, "version", true ) is fine.
    299325        static bool StringEqual(        const char* p,
    300326                                                                const char* endTag,
     
    421447                The subclasses will wrap this function.
    422448        */
    423         const char * Value() const { return value.c_str (); }
     449        const char *Value() const { return value.c_str (); }
     450
     451    #ifdef TIXML_USE_STL
     452        /** Return Value() as a std::string. If you only use STL,
     453            this is more efficient than calling Value().
     454                Only available in STL mode.
     455        */
     456        const std::string& ValueStr() const { return value; }
     457        #endif
    424458
    425459        /** Changes the value of the node. Defined as:
     
    589623                                                                UNKNOWN, TEXT, and DECLARATION.
    590624        */
    591         virtual int Type() const        { return type; }
     625        int Type() const        { return type; }
    592626
    593627        /** Return a pointer to the Document this node lives in.
     
    633667        // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
    634668        TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
    635 
    636         // Internal Value function returning a TIXML_STRING
    637         const TIXML_STRING& SValue() const      { return value ; }
    638669
    639670        TiXmlNode*              parent;
     
    695726        const char*             Name()  const           { return name.c_str (); }               ///< Return the name of this attribute.
    696727        const char*             Value() const           { return value.c_str (); }              ///< Return the value of this attribute.
    697         const int       IntValue() const;                                                                       ///< Return the value of this attribute, converted to an integer.
    698         const double    DoubleValue() const;                                                            ///< Return the value of this attribute, converted to a double.
     728        int                             IntValue() const;                                                                       ///< Return the value of this attribute, converted to an integer.
     729        double                  DoubleValue() const;                                                            ///< Return the value of this attribute, converted to a double.
    699730
    700731        /** QueryIntValue examines the value string. It is an alternative to the
     
    707738                which is the opposite of almost all other TinyXml calls.
    708739        */
    709         int QueryIntValue( int* value ) const;
     740        int QueryIntValue( int* _value ) const;
    710741        /// QueryDoubleValue examines the value string. See QueryIntValue().
    711         int QueryDoubleValue( double* value ) const;
     742        int QueryDoubleValue( double* _value ) const;
    712743
    713744        void SetName( const char* _name )       { name = _name; }                               ///< Set the name of this attribute.
    714745        void SetValue( const char* _value )     { value = _value; }                             ///< Set the value.
    715746
    716         void SetIntValue( int value );                                                                          ///< Set the value from an integer.
    717         void SetDoubleValue( double value );                                                            ///< Set the value from a double.
     747        void SetIntValue( int _value );                                                                         ///< Set the value from an integer.
     748        void SetDoubleValue( double _value );                                                           ///< Set the value from a double.
    718749
    719750    #ifdef TIXML_USE_STL
     
    856887                does not exist, then TIXML_NO_ATTRIBUTE is returned.
    857888        */     
    858         int QueryIntAttribute( const char* name, int* value ) const;
     889        int QueryIntAttribute( const char* name, int* _value ) const;
    859890        /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
    860         int QueryDoubleAttribute( const char* name, double* value ) const;
     891        int QueryDoubleAttribute( const char* name, double* _value ) const;
    861892        /// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
    862         int QueryDoubleAttribute( const char* name, float* value ) const {
     893        int QueryFloatAttribute( const char* name, float* _value ) const {
    863894                double d;
    864895                int result = QueryDoubleAttribute( name, &d );
    865                 *value = (float)d;
     896                if ( result == TIXML_SUCCESS ) {
     897                        *_value = (float)d;
     898                }
    866899                return result;
    867900        }
     
    870903                will be created if it does not exist, or changed if it does.
    871904        */
    872         void SetAttribute( const char* name, const char * value );
     905        void SetAttribute( const char* name, const char * _value );
    873906
    874907    #ifdef TIXML_USE_STL
     
    876909        const char* Attribute( const std::string& name, int* i ) const          { return Attribute( name.c_str(), i ); }
    877910        const char* Attribute( const std::string& name, double* d ) const       { return Attribute( name.c_str(), d ); }
    878         int QueryIntAttribute( const std::string& name, int* value ) const      { return QueryIntAttribute( name.c_str(), value ); }
    879         int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(), value ); }
     911        int QueryIntAttribute( const std::string& name, int* _value ) const     { return QueryIntAttribute( name.c_str(), _value ); }
     912        int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
    880913
    881914        /// STL std::string form.
     
    918951        TiXmlAttribute* LastAttribute()                                 { return attributeSet.Last(); }
    919952
     953        /** Convenience function for easy access to the text inside an element. Although easy
     954                and concise, GetText() is limited compared to getting the TiXmlText child
     955                and accessing it directly.
     956       
     957                If the first child of 'this' is a TiXmlText, the GetText()
     958                returns the character string of the Text node, else null is returned.
     959
     960                This is a convenient method for getting the text of simple contained text:
     961                @verbatim
     962                <foo>This is text</foo>
     963                const char* str = fooElement->GetText();
     964                @endverbatim
     965
     966                'str' will be a pointer to "This is text".
     967               
     968                Note that this function can be misleading. If the element foo was created from
     969                this XML:
     970                @verbatim
     971                <foo><b>This is text</b></foo>
     972                @endverbatim
     973
     974                then the value of str would be null. The first child node isn't a text node, it is
     975                another element. From this XML:
     976                @verbatim
     977                <foo>This is <b>text</b></foo>
     978                @endverbatim
     979                GetText() will return "This is ".
     980
     981                WARNING: GetText() accesses a child node - don't become confused with the
     982                                 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are
     983                                 safe type casts on the referenced node.
     984        */
     985        const char* GetText() const;
     986
    920987        /// Creates a new Element and returns it - the returned element is a copy.
    921988        virtual TiXmlNode* Clone() const;
     
    9871054
    9881055
    989 /** XML text. Contained in an element.
     1056/** XML text. A text node can have 2 ways to output the next. "normal" output
     1057        and CDATA. It will default to the mode it was parsed from the XML file and
     1058        you generally want to leave it alone, but you can change the output mode with
     1059        SetCDATA() and query it with CDATA().
    9901060*/
    9911061class TiXmlText : public TiXmlNode
     
    9931063        friend class TiXmlElement;
    9941064public:
    995         /// Constructor.
    996         TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
     1065        /** Constructor for text element. By default, it is treated as
     1066                normal, encoded text. If you want it be output as a CDATA text
     1067                element, set the parameter _cdata to 'true'
     1068        */
     1069        TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
    9971070        {
    9981071                SetValue( initValue );
     1072                cdata = false;
    9991073        }
    10001074        virtual ~TiXmlText() {}
     
    10051079        {
    10061080                SetValue( initValue );
     1081                cdata = false;
    10071082        }
    10081083        #endif
     
    10131088        /// Write this text object to a FILE stream.
    10141089        virtual void Print( FILE* cfile, int depth ) const;
     1090
     1091        /// Queries whether this represents text using a CDATA section.
     1092        bool CDATA()                                    { return cdata; }
     1093        /// Turns on or off a CDATA representation of text.
     1094        void SetCDATA( bool _cdata )    { cdata = _cdata; }
    10151095
    10161096        virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
     
    10291109
    10301110private:
     1111        bool cdata;                     // true if this should be input and output as a CDATA style text element
    10311112};
    10321113
     
    12071288                prefer the ErrorId, this function will fetch it.
    12081289        */
    1209         const int ErrorId()     const                           { return errorId; }
     1290        int ErrorId()   const                           { return errorId; }
    12101291
    12111292        /** Returns the location (if known) of the error. The first column is column 1,
     
    12191300        int ErrorCol()  { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow()
    12201301
    1221         /** By calling this method, with a tab size
     1302        /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())
     1303                to report the correct values for row and column. It does not change the output
     1304                or input in any way.
     1305               
     1306                By calling this method, with a tab size
    12221307                greater than 0, the row and column of each node and attribute is stored
    12231308                when the file is loaded. Very useful for tracking the DOM back in to
     
    12771362        int tabsize;
    12781363        TiXmlCursor errorLocation;
     1364        bool useMicrosoftBOM;           // the UTF-8 BOM were found when read. Note this, and try to write.
    12791365};
    12801366
     
    13641450public:
    13651451        /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
    1366         TiXmlHandle( TiXmlNode* node )                                  { this->node = node; }
     1452        TiXmlHandle( TiXmlNode* _node )                                 { this->node = _node; }
    13671453        /// Copy constructor
    13681454        TiXmlHandle( const TiXmlHandle& ref )                   { this->node = ref.node; }
     
    14191505
    14201506#ifdef _MSC_VER
    1421 #pragma warning( default : 4530 )
    1422 #pragma warning( default : 4786 )
     1507#pragma warning( pop )
    14231508#endif
    14241509
  • branches/world_entities/src/lib/tinyxml/tinyxmlerror.cc

    r4261 r5817  
    2727// The goal of the seperate error file is to make the first
    2828// step towards localization. tinyxml (currently) only supports
    29 // latin-1, but at least the error messages could now be translated.
     29// english error messages, but the could now be translated.
    3030//
    3131// It also cleans up the code a bit.
     
    4949        "Error document empty.",
    5050        "Error null (0) or unexpected EOF found in input stream.",
     51        "Error parsing CDATA.",
    5152};
  • branches/world_entities/src/lib/tinyxml/tinyxmlparser.cc

    r4491 r5817  
    718718                {
    719719                        encoding = TIXML_ENCODING_UTF8;
     720                        useMicrosoftBOM = true;
    720721                }
    721722        }
     
    786787        if ( pError && data )
    787788        {
    788                 //TiXmlParsingData data( pError, prevData );
    789789                data->Stamp( pError, encoding );
    790790                errorLocation = data->Cursor();
     
    821821        const char* commentHeader = { "<!--" };
    822822        const char* dtdHeader = { "<!" };
     823        const char* cdataHeader = { "<![CDATA[" };
    823824
    824825        if ( StringEqual( p, xmlHeader, true, encoding ) )
     
    835836                #endif
    836837                returnNode = new TiXmlComment();
     838        }
     839        else if ( StringEqual( p, cdataHeader, false, encoding ) )
     840        {
     841                #ifdef DEBUG_PARSER
     842                        TIXML_LOG( "XML parsing CDATA\n" );
     843                #endif
     844                TiXmlText* text = new TiXmlText( "" );
     845                text->SetCDATA( true );
     846                returnNode = text;
    837847        }
    838848        else if ( StringEqual( p, dtdHeader, false, encoding ) )
     
    931941                        if ( !in->good() ) return;
    932942                        assert( in->peek() == '<' );
    933                         int tagIndex = tag->length();
     943                        int tagIndex = (int) tag->length();
    934944
    935945                        bool closingTag = false;
     
    10131023        }
    10141024
    1015 //      TiXmlParsingData data( p, prevData );
    10161025        if ( data )
    10171026        {
     
    11271136        TiXmlDocument* document = GetDocument();
    11281137
     1138        // Read in text and elements in any order.
    11291139        const char* pWithWhiteSpace = p;
    1130         // Read in text and elements in any order.
    11311140        p = SkipWhiteSpace( p, encoding );
     1141
    11321142        while ( p && *p )
    11331143        {
     
    11621172                {
    11631173                        // We hit a '<'
    1164                         // Have we hit a new element or an end tag?
     1174                        // Have we hit a new element or an end tag? This could also be
     1175                        // a TiXmlText in the "CDATA" style.
    11651176                        if ( StringEqual( p, "</", false, encoding ) )
    11661177                        {
     
    11811192                        }
    11821193                }
     1194                pWithWhiteSpace = p;
    11831195                p = SkipWhiteSpace( p, encoding );
    11841196        }
     
    12221234        p = SkipWhiteSpace( p, encoding );
    12231235
    1224 //      TiXmlParsingData data( p, prevData );
    12251236        if ( data )
    12261237        {
     
    12861297        p = SkipWhiteSpace( p, encoding );
    12871298
    1288 //      TiXmlParsingData data( p, prevData );
    12891299        if ( data )
    12901300        {
     
    13151325                tabsize = document->TabSize();
    13161326
    1317 //      TiXmlParsingData data( p, prevData );
    13181327        if ( data )
    13191328        {
     
    13781387void TiXmlText::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag )
    13791388{
    1380         while ( in->good() )
    1381         {
    1382                 int c = in->peek();     
    1383                 if ( c == '<' )
    1384                         return;
     1389        if ( cdata )
     1390        {
     1391                int c = in->get();     
    13851392                if ( c <= 0 )
    13861393                {
     
    13921399
    13931400                (*tag) += (char) c;
    1394                 in->get();
     1401
     1402                if ( c == '>'
     1403                         && tag->at( tag->length() - 2 ) == ']'
     1404                         && tag->at( tag->length() - 3 ) == ']' )
     1405                {
     1406                        // All is well.
     1407                        return;         
     1408                }
     1409        }
     1410        else
     1411        {
     1412                while ( in->good() )
     1413                {
     1414                        int c = in->peek();     
     1415                        if ( c == '<' )
     1416                                return;
     1417                        if ( c <= 0 )
     1418                        {
     1419                                TiXmlDocument* document = GetDocument();
     1420                                if ( document )
     1421                                        document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
     1422                                return;
     1423                        }
     1424
     1425                        (*tag) += (char) c;
     1426                        in->get();
     1427                }
    13951428        }
    13961429}
     
    14001433{
    14011434        value = "";
    1402 //      TiXmlParsingData data( p, prevData );
     1435        TiXmlDocument* document = GetDocument();
     1436
    14031437        if ( data )
    14041438        {
     
    14061440                location = data->Cursor();
    14071441        }
    1408         bool ignoreWhite = true;
    1409 
    1410         const char* end = "<";
    1411         p = ReadText( p, &value, ignoreWhite, end, false, encoding );
    1412         if ( p )
    1413                 return p-1;     // don't truncate the '<'
    1414         return 0;
     1442
     1443        const char* const startTag = "<![CDATA[";
     1444        const char* const endTag   = "]]>";
     1445
     1446        if ( cdata || StringEqual( p, startTag, false, encoding ) )
     1447        {
     1448                cdata = true;
     1449
     1450                if ( !StringEqual( p, startTag, false, encoding ) )
     1451                {
     1452                        document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding );
     1453                        return 0;
     1454                }
     1455                p += strlen( startTag );
     1456
     1457                // Keep all the white space, ignore the encoding, etc.
     1458                while (    p && *p
     1459                                && !StringEqual( p, endTag, false, encoding )
     1460                          )
     1461                {
     1462                        value += *p;
     1463                        ++p;
     1464                }
     1465
     1466                TIXML_STRING dummy;
     1467                p = ReadText( p, &dummy, false, endTag, false, encoding );
     1468                return p;
     1469        }
     1470        else
     1471        {
     1472                bool ignoreWhite = true;
     1473
     1474                const char* end = "<";
     1475                p = ReadText( p, &value, ignoreWhite, end, false, encoding );
     1476                if ( p )
     1477                        return p-1;     // don't truncate the '<'
     1478                return 0;
     1479        }
    14151480}
    14161481
     
    14501515                return 0;
    14511516        }
    1452 //      TiXmlParsingData data( p, prevData );
    14531517        if ( data )
    14541518        {
Note: See TracChangeset for help on using the changeset viewer.