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


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29