File indexing completed on 2026-09-27 09:31:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #ifndef TIXML_USE_STL
0026
0027 #ifndef PANDORA_TIXML_STRING_INCLUDED
0028 #define PANDORA_TIXML_STRING_INCLUDED
0029
0030 #include <assert.h>
0031 #include <string.h>
0032
0033
0034
0035
0036
0037 #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
0038
0039 #define TIXML_EXPLICIT explicit
0040 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
0041
0042 #define TIXML_EXPLICIT explicit
0043 #else
0044 #define TIXML_EXPLICIT
0045 #endif
0046
0047 namespace pandora
0048 {
0049
0050
0051
0052
0053
0054
0055
0056
0057 class TiXmlString
0058 {
0059 public :
0060
0061 typedef size_t size_type;
0062
0063
0064 static const size_type npos;
0065
0066
0067
0068 TiXmlString () : rep_(&nullrep_)
0069 {
0070 }
0071
0072
0073 TiXmlString ( const TiXmlString & copy) : rep_(0)
0074 {
0075 init(copy.length());
0076 memcpy(start(), copy.data(), length());
0077 }
0078
0079
0080 TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
0081 {
0082 init( static_cast<size_type>( strlen(copy) ));
0083 memcpy(start(), copy, length());
0084 }
0085
0086
0087 TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
0088 {
0089 init(len);
0090 memcpy(start(), str, len);
0091 }
0092
0093
0094 ~TiXmlString ()
0095 {
0096 quit();
0097 }
0098
0099 TiXmlString& operator = (const char * copy)
0100 {
0101 return assign( copy, (size_type)strlen(copy));
0102 }
0103
0104 TiXmlString& operator = (const TiXmlString & copy)
0105 {
0106 return assign(copy.start(), copy.length());
0107 }
0108
0109
0110
0111 TiXmlString& operator += (const char * suffix)
0112 {
0113 return append(suffix, static_cast<size_type>( strlen(suffix) ));
0114 }
0115
0116
0117 TiXmlString& operator += (char single)
0118 {
0119 return append(&single, 1);
0120 }
0121
0122
0123 TiXmlString& operator += (const TiXmlString & suffix)
0124 {
0125 return append(suffix.data(), suffix.length());
0126 }
0127
0128
0129
0130 const char * c_str () const { return rep_->str; }
0131
0132
0133 const char * data () const { return rep_->str; }
0134
0135
0136 size_type length () const { return rep_->size; }
0137
0138
0139 size_type size () const { return rep_->size; }
0140
0141
0142 bool empty () const { return rep_->size == 0; }
0143
0144
0145 size_type capacity () const { return rep_->capacity; }
0146
0147
0148
0149 const char& at (size_type index) const
0150 {
0151 assert( index < length() );
0152 return rep_->str[ index ];
0153 }
0154
0155
0156 char& operator [] (size_type index) const
0157 {
0158 assert( index < length() );
0159 return rep_->str[ index ];
0160 }
0161
0162
0163 size_type find (char lookup) const
0164 {
0165 return find(lookup, 0);
0166 }
0167
0168
0169 size_type find (char tofind, size_type offset) const
0170 {
0171 if (offset >= length()) return npos;
0172
0173 for (const char* p = c_str() + offset; *p != '\0'; ++p)
0174 {
0175 if (*p == tofind) return static_cast< size_type >( p - c_str() );
0176 }
0177 return npos;
0178 }
0179
0180 void clear ()
0181 {
0182
0183
0184
0185
0186 quit();
0187 init(0,0);
0188 }
0189
0190
0191
0192
0193 void reserve (size_type cap);
0194
0195 TiXmlString& assign (const char* str, size_type len);
0196
0197 TiXmlString& append (const char* str, size_type len);
0198
0199 void swap (TiXmlString& other)
0200 {
0201 Rep* r = rep_;
0202 rep_ = other.rep_;
0203 other.rep_ = r;
0204 }
0205
0206 private:
0207
0208 void init(size_type sz) { init(sz, sz); }
0209 void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
0210 char* start() const { return rep_->str; }
0211 char* finish() const { return rep_->str + rep_->size; }
0212
0213 struct Rep
0214 {
0215 size_type size, capacity;
0216 char str[1];
0217 };
0218
0219 void init(size_type sz, size_type cap)
0220 {
0221 if (cap)
0222 {
0223
0224
0225
0226
0227
0228 const size_type bytesNeeded = sizeof(Rep) + cap;
0229 const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
0230 rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
0231
0232 rep_->str[ rep_->size = sz ] = '\0';
0233 rep_->capacity = cap;
0234 }
0235 else
0236 {
0237 rep_ = &nullrep_;
0238 }
0239 }
0240
0241 void quit()
0242 {
0243 if (rep_ != &nullrep_)
0244 {
0245
0246
0247 delete [] ( reinterpret_cast<int*>( rep_ ) );
0248 }
0249 }
0250
0251 Rep * rep_;
0252 static Rep nullrep_;
0253
0254 } ;
0255
0256
0257 inline bool operator == (const TiXmlString & a, const TiXmlString & b)
0258 {
0259 return ( a.length() == b.length() )
0260 && ( strcmp(a.c_str(), b.c_str()) == 0 );
0261 }
0262 inline bool operator < (const TiXmlString & a, const TiXmlString & b)
0263 {
0264 return strcmp(a.c_str(), b.c_str()) < 0;
0265 }
0266
0267 inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
0268 inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; }
0269 inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
0270 inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
0271
0272 inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
0273 inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
0274 inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
0275 inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
0276
0277 TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
0278 TiXmlString operator + (const TiXmlString & a, const char* b);
0279 TiXmlString operator + (const char* a, const TiXmlString & b);
0280
0281
0282
0283
0284
0285
0286 class TiXmlOutStream : public TiXmlString
0287 {
0288 public :
0289
0290
0291 TiXmlOutStream & operator << (const TiXmlString & in)
0292 {
0293 *this += in;
0294 return *this;
0295 }
0296
0297
0298 TiXmlOutStream & operator << (const char * in)
0299 {
0300 *this += in;
0301 return *this;
0302 }
0303
0304 } ;
0305
0306 }
0307
0308 #endif
0309 #endif