Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/modules/TinyXML/tinystr.cpp

Source at commit 1307 created 9 years 5 months ago.
By meklort, Add TinyXML as a module
1/*
2www.sourceforge.net/projects/tinyxml
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any
6damages arising from the use of this software.
7
8Permission is granted to anyone to use this software for any
9purpose, including commercial applications, and to alter it and
10redistribute it freely, subject to the following restrictions:
11
121. The origin of this software must not be misrepresented; you must
13not claim that you wrote the original software. If you use this
14software in a product, an acknowledgment in the product documentation
15would be appreciated but is not required.
16
172. Altered source versions must be plainly marked as such, and
18must not be misrepresented as being the original software.
19
203. This notice may not be removed or altered from any source
21distribution.
22*/
23
24
25#ifndef TIXML_USE_STL
26
27#include "tinystr.h"
28
29// Error value for find primitive
30const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1);
31
32
33// Null rep.
34TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
35
36
37void TiXmlString::reserve (size_type cap)
38{
39if (cap > capacity())
40{
41TiXmlString tmp;
42tmp.init(length(), cap);
43memcpy(tmp.start(), data(), length());
44swap(tmp);
45}
46}
47
48
49TiXmlString& TiXmlString::assign(const char* str, size_type len)
50{
51size_type cap = capacity();
52if (len > cap || cap > 3*(len + 8))
53{
54TiXmlString tmp;
55tmp.init(len);
56memcpy(tmp.start(), str, len);
57swap(tmp);
58}
59else
60{
61memmove(start(), str, len);
62set_size(len);
63}
64return *this;
65}
66
67
68TiXmlString& TiXmlString::append(const char* str, size_type len)
69{
70size_type newsize = length() + len;
71if (newsize > capacity())
72{
73reserve (newsize + capacity());
74}
75memmove(finish(), str, len);
76set_size(newsize);
77return *this;
78}
79
80
81TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
82{
83TiXmlString tmp;
84tmp.reserve(a.length() + b.length());
85tmp += a;
86tmp += b;
87return tmp;
88}
89
90TiXmlString operator + (const TiXmlString & a, const char* b)
91{
92TiXmlString tmp;
93TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
94tmp.reserve(a.length() + b_len);
95tmp += a;
96tmp.append(b, b_len);
97return tmp;
98}
99
100TiXmlString operator + (const char* a, const TiXmlString & b)
101{
102TiXmlString tmp;
103TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
104tmp.reserve(a_len + b.length());
105tmp.append(a, a_len);
106tmp += b;
107return tmp;
108}
109
110
111#endif// TIXML_USE_STL
112

Archive Download this file

Revision: 1307