tinystr.cpp
Go to the documentation of this file.
00001 /*
00002 www.sourceforge.net/projects/tinyxml
00003 
00004 This software is provided 'as-is', without any express or implied
00005 warranty. In no event will the authors be held liable for any
00006 damages arising from the use of this software.
00007 
00008 Permission is granted to anyone to use this software for any
00009 purpose, including commercial applications, and to alter it and
00010 redistribute it freely, subject to the following restrictions:
00011 
00012 1. The origin of this software must not be misrepresented; you must
00013 not claim that you wrote the original software. If you use this
00014 software in a product, an acknowledgment in the product documentation
00015 would be appreciated but is not required.
00016 
00017 2. Altered source versions must be plainly marked as such, and
00018 must not be misrepresented as being the original software.
00019 
00020 3. This notice may not be removed or altered from any source
00021 distribution.
00022 */
00023 
00024 
00025 #ifndef TIXML_USE_STL
00026 
00027 #include "tinystr.h"
00028 
00029 // Error value for find primitive
00030 const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1);
00031 
00032 
00033 // Null rep.
00034 TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
00035 
00036 
00037 void TiXmlString::reserve (size_type cap)
00038 {
00039         if (cap > capacity())
00040         {
00041                 TiXmlString tmp;
00042                 tmp.init(length(), cap);
00043                 memcpy(tmp.start(), data(), length());
00044                 swap(tmp);
00045         }
00046 }
00047 
00048 
00049 TiXmlString& TiXmlString::assign(const char* str, size_type len)
00050 {
00051         size_type cap = capacity();
00052         if (len > cap || cap > 3*(len + 8))
00053         {
00054                 TiXmlString tmp;
00055                 tmp.init(len);
00056                 memcpy(tmp.start(), str, len);
00057                 swap(tmp);
00058         }
00059         else
00060         {
00061                 memmove(start(), str, len);
00062                 set_size(len);
00063         }
00064         return *this;
00065 }
00066 
00067 
00068 TiXmlString& TiXmlString::append(const char* str, size_type len)
00069 {
00070         size_type newsize = length() + len;
00071         if (newsize > capacity())
00072         {
00073                 reserve (newsize + capacity());
00074         }
00075         memmove(finish(), str, len);
00076         set_size(newsize);
00077         return *this;
00078 }
00079 
00080 
00081 TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
00082 {
00083         TiXmlString tmp;
00084         tmp.reserve(a.length() + b.length());
00085         tmp += a;
00086         tmp += b;
00087         return tmp;
00088 }
00089 
00090 TiXmlString operator + (const TiXmlString & a, const char* b)
00091 {
00092         TiXmlString tmp;
00093         TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
00094         tmp.reserve(a.length() + b_len);
00095         tmp += a;
00096         tmp.append(b, b_len);
00097         return tmp;
00098 }
00099 
00100 TiXmlString operator + (const char* a, const TiXmlString & b)
00101 {
00102         TiXmlString tmp;
00103         TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
00104         tmp.reserve(a_len + b.length());
00105         tmp.append(a, a_len);
00106         tmp += b;
00107         return tmp;
00108 }
00109 
00110 
00111 #endif  // TIXML_USE_STL


win_tinyxml
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:28:38