nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 /* 00024 www.sourceforge.net/projects/tinyxml 00025 Original file by Yves Berquin. 00026 00027 This software is provided 'as-is', without any express or implied 00028 warranty. In no event will the authors be held liable for any 00029 damages arising from the use of this software. 00030 00031 Permission is granted to anyone to use this software for any 00032 purpose, including commercial applications, and to alter it and 00033 redistribute it freely, subject to the following restrictions: 00034 00035 1. The origin of this software must not be misrepresented; you must 00036 not claim that you wrote the original software. If you use this 00037 software in a product, an acknowledgment in the product documentation 00038 would be appreciated but is not required. 00039 00040 2. Altered source versions must be plainly marked as such, and 00041 must not be misrepresented as being the original software. 00042 00043 3. This notice may not be removed or altered from any source 00044 distribution. 00045 */ 00046 00047 /* 00048 * THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005. 00049 */ 00050 00051 00052 #ifndef TIXML_USE_STL 00053 00054 #include "tinystr.h" 00055 00056 // Error value for find primitive 00057 const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type > (-1); 00058 00059 00060 // Null rep. 00061 TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } }; 00062 00063 00064 void TiXmlString::reserve (size_type cap) 00065 { 00066 if (cap > capacity() ) 00067 { 00068 TiXmlString tmp; 00069 tmp.init (length(), cap); 00070 memcpy (tmp.start(), data(), length() ); 00071 swap (tmp); 00072 } 00073 } 00074 00075 00076 TiXmlString &TiXmlString::assign (const char *str, size_type len) 00077 { 00078 size_type cap = capacity(); 00079 00080 if (len > cap || cap > 3 * (len + 8) ) 00081 { 00082 TiXmlString tmp; 00083 tmp.init (len); 00084 memcpy (tmp.start(), str, len); 00085 swap (tmp); 00086 } 00087 else 00088 { 00089 memmove (start(), str, len); 00090 set_size (len); 00091 } 00092 00093 return *this; 00094 } 00095 00096 00097 TiXmlString &TiXmlString::append (const char *str, size_type len) 00098 { 00099 size_type newsize = length() + len; 00100 00101 if (newsize > capacity() ) 00102 { 00103 reserve (newsize + capacity() ); 00104 } 00105 00106 memmove (finish(), str, len); 00107 set_size (newsize); 00108 return *this; 00109 } 00110 00111 00112 TiXmlString operator + (const TiXmlString &a, const TiXmlString &b) 00113 { 00114 TiXmlString tmp; 00115 tmp.reserve (a.length() + b.length() ); 00116 tmp += a; 00117 tmp += b; 00118 return tmp; 00119 } 00120 00121 TiXmlString operator + (const TiXmlString &a, const char *b) 00122 { 00123 TiXmlString tmp; 00124 TiXmlString::size_type b_len = static_cast<TiXmlString::size_type> ( strlen (b) ); 00125 tmp.reserve (a.length() + b_len); 00126 tmp += a; 00127 tmp.append (b, b_len); 00128 return tmp; 00129 } 00130 00131 TiXmlString operator + (const char *a, const TiXmlString &b) 00132 { 00133 TiXmlString tmp; 00134 TiXmlString::size_type a_len = static_cast<TiXmlString::size_type> ( strlen (a) ); 00135 tmp.reserve (a_len + b.length() ); 00136 tmp.append (a, a_len); 00137 tmp += b; 00138 return tmp; 00139 } 00140 00141 00142 #endif // TIXML_USE_STL