39 #ifndef TIXML_STRING_INCLUDED
40 #define TIXML_STRING_INCLUDED
49 #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
51 #define TIXML_EXPLICIT explicit
52 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
54 #define TIXML_EXPLICIT explicit
56 #define TIXML_EXPLICIT
59 namespace CEGUITinyXML
72 typedef size_t size_type;
75 static const size_type npos;
87 memcpy(start(), copy.data(), length());
93 init( static_cast<size_type>( strlen(copy) ));
94 memcpy(start(), copy, length());
98 TIXML_EXPLICIT
TiXmlString (
const char * str, size_type len)
101 memcpy(start(), str, len);
113 return assign( copy, (size_type)strlen(copy));
119 return assign(copy.start(), copy.length());
126 return append(suffix, static_cast<size_type>( strlen(suffix) ));
132 return append(&single, 1);
138 return append(suffix.data(), suffix.length());
143 const char * c_str ()
const {
return rep_->str; }
146 const char * data ()
const {
return rep_->str; }
149 size_type length ()
const {
return rep_->size; }
152 size_type size ()
const {
return rep_->size; }
155 bool empty ()
const {
return rep_->size == 0; }
158 size_type capacity ()
const {
return rep_->capacity; }
162 const char& at (size_type index)
const
164 assert( index < length() );
165 return rep_->str[ index ];
169 char& operator [] (size_type index)
const
171 assert( index < length() );
172 return rep_->str[ index ];
176 size_type find (
char lookup)
const
178 return find(lookup, 0);
182 size_type find (
char tofind, size_type offset)
const
184 if (offset >= length())
return npos;
186 for (
const char* p = c_str() + offset; *p !=
'\0'; ++p)
188 if (*p == tofind)
return static_cast< size_type
>( p - c_str() );
206 void reserve (size_type cap);
208 TiXmlString& assign (
const char* str, size_type len);
210 TiXmlString& append (
const char* str, size_type len);
221 void init(size_type sz) { init(sz, sz); }
222 void set_size(size_type sz) { rep_->str[ rep_->size = sz ] =
'\0'; }
223 char* start()
const {
return rep_->str; }
224 char* finish()
const {
return rep_->str + rep_->size; }
228 size_type size, capacity;
232 void init(size_type sz, size_type cap)
241 const size_type bytesNeeded =
sizeof(Rep) + cap;
242 const size_type intsNeeded = ( bytesNeeded +
sizeof(int) - 1 ) /
sizeof( int );
243 rep_ =
reinterpret_cast<Rep*
>(
new int[ intsNeeded ] );
245 rep_->str[ rep_->size = sz ] =
'\0';
246 rep_->capacity = cap;
256 if (rep_ != &nullrep_)
260 delete [] (
reinterpret_cast<int*
>( rep_ ) );
272 return ( a.length() == b.length() )
273 && ( strcmp(a.c_str(), b.c_str()) == 0 );
275 inline bool operator < (
const TiXmlString & a,
const TiXmlString & b)
277 return strcmp(a.c_str(), b.c_str()) < 0;
280 inline bool operator != (
const TiXmlString & a,
const TiXmlString & b) {
return !(a == b); }
281 inline bool operator > (
const TiXmlString & a,
const TiXmlString & b) {
return b < a; }
282 inline bool operator <= (
const TiXmlString & a,
const TiXmlString & b) {
return !(b < a); }
283 inline bool operator >= (
const TiXmlString & a,
const TiXmlString & b) {
return !(a < b); }
285 inline bool operator == (
const TiXmlString & a,
const char* b) {
return strcmp(a.c_str(), b) == 0; }
286 inline bool operator == (
const char* a,
const TiXmlString & b) {
return b == a; }
287 inline bool operator != (
const TiXmlString & a,
const char* b) {
return !(a == b); }
288 inline bool operator != (
const char* a,
const TiXmlString & b) {
return !(b == a); }
290 TiXmlString operator + (
const TiXmlString & a,
const TiXmlString & b);
291 TiXmlString operator + (
const TiXmlString & a,
const char* b);
292 TiXmlString operator + (
const char* a,
const TiXmlString & b);
320 #endif // TIXML_STRING_INCLUDED
321 #endif // TIXML_USE_STL