Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

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 // Error value for find primitive
00035 const TiXmlString::size_type TiXmlString::npos = static_cast< size_type >(-1);
00036 
00037 // Null rep.
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

Generated on Wed Sep 5 12:54:26 2007 for DSACSS Operational Code by  doxygen 1.3.9.1