Orocos Real-Time Toolkit  2.6.0
tinystr.cpp
00001 /***************************************************************************
00002   tag: Peter Soetens  do nov 2 13:06:02 CET 2006  tinystr.cpp
00003 
00004                         tinystr.cpp -  description
00005                            -------------------
00006     begin                : do november 02 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@gmail.com
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 /*
00040 www.sourceforge.net/projects/tinyxml
00041 Original file by Yves Berquin.
00042 
00043 This software is provided 'as-is', without any express or implied
00044 warranty. In no event will the authors be held liable for any
00045 damages arising from the use of this software.
00046 
00047 Permission is granted to anyone to use this software for any
00048 purpose, including commercial applications, and to alter it and
00049 redistribute it freely, subject to the following restrictions:
00050 
00051 1. The origin of this software must not be misrepresented; you must
00052 not claim that you wrote the original software. If you use this
00053 software in a product, an acknowledgment in the product documentation
00054 would be appreciated but is not required.
00055 
00056 2. Altered source versions must be plainly marked as such, and
00057 must not be misrepresented as being the original software.
00058 
00059 3. This notice may not be removed or altered from any source
00060 distribution.
00061 */
00062 
00063 /*
00064  * THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005.
00065  */
00066 
00067 
00068 #ifndef TIXML_USE_STL
00069 
00070 #include "tinystr.h"
00071 
00072 namespace RTT { namespace marsh {
00073 
00074 // Error value for find primitive
00075 const TiXmlString::size_type TiXmlString::npos = static_cast< size_type >(-1);
00076 
00077 // Null rep.
00078 TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
00079 
00080 
00081 void TiXmlString::reserve (size_type cap)
00082 {
00083     if (cap > capacity())
00084     {
00085         TiXmlString tmp;
00086         tmp.init(length(), cap);
00087         memcpy(tmp.start(), data(), length());
00088         swap(tmp);
00089     }
00090 }
00091 
00092 
00093 TiXmlString& TiXmlString::assign(const char* str, size_type len)
00094 {
00095     size_type cap = capacity();
00096     if (len > cap || cap > 3*(len + 8))
00097     {
00098         TiXmlString tmp;
00099         tmp.init(len);
00100         memcpy(tmp.start(), str, len);
00101         swap(tmp);
00102     }
00103     else
00104     {
00105         memmove(start(), str, len);
00106         set_size(len);
00107     }
00108     return *this;
00109 }
00110 
00111 
00112 TiXmlString& TiXmlString::append(const char* str, size_type len)
00113 {
00114     size_type newsize = length() + len;
00115     if (newsize > capacity())
00116     {
00117         reserve (newsize + capacity());
00118     }
00119     memmove(finish(), str, len);
00120     set_size(newsize);
00121     return *this;
00122 }
00123 
00124 
00125 TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
00126 {
00127     TiXmlString tmp;
00128     tmp.reserve(a.length() + b.length());
00129     tmp += a;
00130     tmp += b;
00131     return tmp;
00132 }
00133 
00134 TiXmlString operator + (const TiXmlString & a, const char* b)
00135 {
00136     TiXmlString tmp;
00137     TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
00138     tmp.reserve(a.length() + b_len);
00139     tmp += a;
00140     tmp.append(b, b_len);
00141     return tmp;
00142 }
00143 
00144 TiXmlString operator + (const char* a, const TiXmlString & b)
00145 {
00146     TiXmlString tmp;
00147     TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
00148     tmp.reserve(a_len + b.length());
00149     tmp.append(a, a_len);
00150     tmp += b;
00151     return tmp;
00152 }
00153 
00154 }}
00155 
00156 #endif  // TIXML_USE_STL