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


rospack
Author(s): Brian Gerkey/gerkey@willowgarage.com, Morgan Quigley/mquigley@cs.stanford.edu
autogenerated on Fri Jan 3 2014 11:51:40