Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #ifndef TIXML_USE_STL
00031 
00032 #include "tinystr.h"
00033 
00034 
00035 const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1);
00036 
00037 
00038 
00039 TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
00040 
00041 
00042 void TiXmlString::reserve (size_type cap)
00043 {
00044         if (cap > capacity())
00045         {
00046                 TiXmlString tmp;
00047                 tmp.init(length(), cap);
00048                 memcpy(tmp.start(), data(), length());
00049                 swap(tmp);
00050         }
00051 }
00052 
00053 
00054 TiXmlString& TiXmlString::assign(const char* str, size_type len)
00055 {
00056         size_type cap = capacity();
00057         if (len > cap || cap > 3*(len + 8))
00058         {
00059                 TiXmlString tmp;
00060                 tmp.init(len);
00061                 memcpy(tmp.start(), str, len);
00062                 swap(tmp);
00063         }
00064         else
00065         {
00066                 memmove(start(), str, len);
00067                 set_size(len);
00068         }
00069         return *this;
00070 }
00071 
00072 
00073 TiXmlString& TiXmlString::append(const char* str, size_type len)
00074 {
00075         size_type newsize = length() + len;
00076         if (newsize > capacity())
00077         {
00078                 reserve (newsize + capacity());
00079         }
00080         memmove(finish(), str, len);
00081         set_size(newsize);
00082         return *this;
00083 }
00084 
00085 
00086 TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
00087 {
00088         TiXmlString tmp;
00089         tmp.reserve(a.length() + b.length());
00090         tmp += a;
00091         tmp += b;
00092         return tmp;
00093 }
00094 
00095 TiXmlString operator + (const TiXmlString & a, const char* b)
00096 {
00097         TiXmlString tmp;
00098         TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
00099         tmp.reserve(a.length() + b_len);
00100         tmp += a;
00101         tmp.append(b, b_len);
00102         return tmp;
00103 }
00104 
00105 TiXmlString operator + (const char* a, const TiXmlString & b)
00106 {
00107         TiXmlString tmp;
00108         TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
00109         tmp.reserve(a_len + b.length());
00110         tmp.append(a, a_len);
00111         tmp += b;
00112         return tmp;
00113 }
00114 
00115 
00116 #endif  // TIXML_USE_STL