39 #ifndef TIXML_STRING_INCLUDED
40 #define TIXML_STRING_INCLUDED
46 typedef void* (*xmlAlloc) (
size_t size);
47 typedef void (*xmlFree) (
void*);
50 #define D_TINYXML_EXPORT __declspec(dllexport)
51 #define D_TINYXML_IMPORT __declspec(dllimport)
53 #define D_TINYXML_EXPORT __attribute__((visibility("default")))
54 #define D_TINYXML_IMPORT __attribute__((visibility("default")))
58 #ifdef _D_TINYXML_EXPORT_DLL
59 #define D_TINY_API D_TINYXML_EXPORT
61 #define D_TINY_API D_TINYXML_IMPORT
72 #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
74 #define TIXML_EXPLICIT explicit
75 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
77 #define TIXML_EXPLICIT explicit
79 #define TIXML_EXPLICIT
84 extern D_TINY_API xmlFree __free__;
85 extern D_TINY_API xmlAlloc __alloc__;
98 typedef size_t size_type;
101 static const size_type npos;
113 memcpy(start(), copy.data(), length());
117 TIXML_EXPLICIT
TiXmlString (
const char * copy) : rep_(0)
119 init(
static_cast<size_type
>( strlen(copy) ));
120 memcpy(start(), copy, length());
124 TIXML_EXPLICIT
TiXmlString (
const char * str, size_type len) : rep_(0)
127 memcpy(start(), str, len);
136 void *
operator new (
size_t size);
137 void *
operator new[](
size_t size);
138 void operator delete (
void* ptr);
139 void operator delete[](
void* ptr);
144 return assign( copy, (size_type)strlen(copy));
150 return assign(copy.start(), copy.length());
157 return append(suffix,
static_cast<size_type
>( strlen(suffix) ));
163 return append(&single, 1);
169 return append(suffix.data(), suffix.length());
174 const char * c_str ()
const {
return rep_->str; }
177 const char * data ()
const {
return rep_->str; }
180 size_type length ()
const {
return rep_->size; }
183 size_type size ()
const {
return rep_->size; }
186 bool empty ()
const {
return rep_->size == 0; }
189 size_type capacity ()
const {
return rep_->capacity; }
193 const char& at (size_type index)
const
195 assert( index < length() );
196 return rep_->str[ index ];
200 char& operator [] (size_type index)
const
202 assert( index < length() );
203 return rep_->str[ index ];
207 size_type find (
char lookup)
const
209 return find(lookup, 0);
213 size_type find (
char tofind, size_type offset)
const
215 if (offset >= length())
return npos;
217 for (
const char* p = c_str() + offset; *p !=
'\0'; ++p)
219 if (*p == tofind)
return static_cast< size_type
>( p - c_str() );
237 void reserve (size_type cap);
239 TiXmlString& assign (
const char* str, size_type len);
241 TiXmlString& append (
const char* str, size_type len);
252 void init(size_type sz) { init(sz, sz); }
253 void set_size(size_type sz) { rep_->str[ rep_->size = sz ] =
'\0'; }
254 char* start()
const {
return rep_->str; }
255 char* finish()
const {
return rep_->str + rep_->size; }
259 size_type size, capacity;
263 void* Malloc(size_type size);
264 void Free(
void* ptr);
266 void init(size_type sz, size_type cap)
275 const size_type bytesNeeded =
sizeof(Rep) + cap;
276 const size_type intsNeeded = ( bytesNeeded +
sizeof(int) - 1 ) /
sizeof( int );
278 rep_ =
reinterpret_cast<Rep*
>(Malloc(intsNeeded *
sizeof (
int)));
280 rep_->str[ rep_->size = sz ] =
'\0';
281 rep_->capacity = cap;
291 if (rep_ != &nullrep_)
308 return ( a.length() == b.length() )
309 && ( strcmp(a.c_str(), b.c_str()) == 0 );
311 inline bool operator < (
const TiXmlString & a,
const TiXmlString & b)
313 return strcmp(a.c_str(), b.c_str()) < 0;
316 inline bool operator != (
const TiXmlString & a,
const TiXmlString & b) {
return !(a == b); }
317 inline bool operator > (
const TiXmlString & a,
const TiXmlString & b) {
return b < a; }
318 inline bool operator <= (
const TiXmlString & a,
const TiXmlString & b) {
return !(b < a); }
319 inline bool operator >= (
const TiXmlString & a,
const TiXmlString & b) {
return !(a < b); }
321 inline bool operator == (
const TiXmlString & a,
const char* b) {
return strcmp(a.c_str(), b) == 0; }
322 inline bool operator == (
const char* a,
const TiXmlString & b) {
return b == a; }
323 inline bool operator != (
const TiXmlString & a,
const char* b) {
return !(a == b); }
324 inline bool operator != (
const char* a,
const TiXmlString & b) {
return !(b == a); }
326 TiXmlString operator + (
const TiXmlString & a,
const TiXmlString & b);
327 TiXmlString operator + (
const TiXmlString & a,
const char* b);
328 TiXmlString operator + (
const char* a,
const TiXmlString & b);
357 #endif // TIXML_STRING_INCLUDED
358 #endif // TIXML_USE_STL