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< size_type >(-1);
00036
00037
00038 TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, '\0' };
00039
00040
00041 void TiXmlString::reserve (size_type cap)
00042 {
00043 if (cap > capacity())
00044 {
00045 TiXmlString tmp;
00046 tmp.init(length(), cap);
00047 memcpy(tmp.start(), data(), length());
00048 swap(tmp);
00049 }
00050 }
00051
00052
00053 TiXmlString& TiXmlString::assign(const char* str, size_type len)
00054 {
00055 size_type cap = capacity();
00056 if (len > cap || cap > 3*(len + 8))
00057 {
00058 TiXmlString tmp;
00059 tmp.init(len);
00060 memcpy(tmp.start(), str, len);
00061 swap(tmp);
00062 }
00063 else
00064 {
00065 memmove(start(), str, len);
00066 set_size(len);
00067 }
00068 return *this;
00069 }
00070
00071
00072 TiXmlString& TiXmlString::append(const char* str, size_type len)
00073 {
00074 size_type newsize = length() + len;
00075 if (newsize > capacity())
00076 {
00077 reserve (newsize + capacity());
00078 }
00079 memmove(finish(), str, len);
00080 set_size(newsize);
00081 return *this;
00082 }
00083
00084
00085 TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
00086 {
00087 TiXmlString tmp;
00088 tmp.reserve(a.length() + b.length());
00089 tmp += a;
00090 tmp += b;
00091 return tmp;
00092 }
00093
00094 TiXmlString operator + (const TiXmlString & a, const char* b)
00095 {
00096 TiXmlString tmp;
00097 TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
00098 tmp.reserve(a.length() + b_len);
00099 tmp += a;
00100 tmp.append(b, b_len);
00101 return tmp;
00102 }
00103
00104 TiXmlString operator + (const char* a, const TiXmlString & b)
00105 {
00106 TiXmlString tmp;
00107 TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
00108 tmp.reserve(a_len + b.length());
00109 tmp.append(a, a_len);
00110 tmp += b;
00111 return tmp;
00112 }
00113
00114
00115 #endif // TIXML_USE_STL