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
71 typedef size_t size_type;
74 static const size_type npos;
86 memcpy(start(), copy.data(), length());
90 TIXML_EXPLICIT
TiXmlString (
const char * copy) : rep_(0)
92 init( static_cast<size_type>( strlen(copy) ));
93 memcpy(start(), copy, length());
97 TIXML_EXPLICIT TiXmlString (
const char * str, size_type len) : rep_(0)
100 memcpy(start(), str, len);
110 TiXmlString& operator = (
const char * copy)
112 return assign( copy, (size_type)strlen(copy));
116 TiXmlString& operator = (
const TiXmlString & copy)
118 return assign(copy.start(), copy.length());
123 TiXmlString& operator += (
const char * suffix)
125 return append(suffix, static_cast<size_type>( strlen(suffix) ));
129 TiXmlString& operator += (
char single)
131 return append(&single, 1);
135 TiXmlString& operator += (
const TiXmlString & suffix)
137 return append(suffix.data(), suffix.length());
142 const char * c_str ()
const {
return rep_->str; }
145 const char * data ()
const {
return rep_->str; }
148 size_type length ()
const {
return rep_->size; }
151 size_type size ()
const {
return rep_->size; }
154 bool empty ()
const {
return rep_->size == 0; }
157 size_type capacity ()
const {
return rep_->capacity; }
161 const char& at (size_type index)
const
163 assert( index < length() );
164 return rep_->str[ index ];
168 char& operator [] (size_type index)
const
170 assert( index < length() );
171 return rep_->str[ index ];
175 size_type find (
char lookup)
const
177 return find(lookup, 0);
181 size_type find (
char tofind, size_type offset)
const
183 if (offset >= length())
return npos;
185 for (
const char* p = c_str() + offset; *p !=
'\0'; ++p)
187 if (*p == tofind)
return static_cast< size_type
>( p - c_str() );
205 void reserve (size_type cap);
207 TiXmlString& assign (
const char* str, size_type len);
209 TiXmlString& append (
const char* str, size_type len);
211 void swap (TiXmlString& other)
220 void init(size_type sz) { init(sz, sz); }
221 void set_size(size_type sz) { rep_->str[ rep_->size = sz ] =
'\0'; }
222 char* start()
const {
return rep_->str; }
223 char* finish()
const {
return rep_->str + rep_->size; }
227 size_type size, capacity;
231 void init(size_type sz, size_type cap)
240 const size_type bytesNeeded =
sizeof(Rep) + cap;
241 const size_type intsNeeded = ( bytesNeeded +
sizeof(int) - 1 ) /
sizeof( int );
242 rep_ =
reinterpret_cast<Rep*
>(
new int[ intsNeeded ] );
244 rep_->str[ rep_->size = sz ] =
'\0';
245 rep_->capacity = cap;
255 if (rep_ != &nullrep_)
259 delete [] (
reinterpret_cast<int*
>( rep_ ) );
271 return ( a.length() == b.length() )
272 && ( strcmp(a.c_str(), b.c_str()) == 0 );
276 return strcmp(a.c_str(), b.c_str()) < 0;
284 inline bool operator == (
const TiXmlString & a,
const char* b) {
return strcmp(a.c_str(), b) == 0; }
285 inline bool operator == (
const char* a,
const TiXmlString & b) {
return b == a; }
286 inline bool operator != (
const TiXmlString & a,
const char* b) {
return !(a == b); }
287 inline bool operator != (
const char* a,
const TiXmlString & b) {
return !(b == a); }
318 #endif // TIXML_STRING_INCLUDED
319 #endif // TIXML_USE_STL
Definition: tinystr.h:298