blob: 066576820516de3bae97b08f9258468f9cc136f4 [file] [log] [blame]
The Android Open Source Project562be062009-03-03 19:30:48 -08001/*
2www.sourceforge.net/projects/tinyxml
The Android Open Source Project562be062009-03-03 19:30:48 -08003
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
The Android Open Source Project562be062009-03-03 19:30:48 -080024
25#ifndef TIXML_USE_STL
26
27#include "tinystr.h"
28
29// Error value for find primitive
Dan Albertc3bbea32014-08-21 15:48:37 -070030const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1);
31
The Android Open Source Project562be062009-03-03 19:30:48 -080032
33// Null rep.
Dan Albertc3bbea32014-08-21 15:48:37 -070034TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
The Android Open Source Project562be062009-03-03 19:30:48 -080035
36
37void TiXmlString::reserve (size_type cap)
38{
39 if (cap > capacity())
40 {
41 TiXmlString tmp;
42 tmp.init(length(), cap);
43 memcpy(tmp.start(), data(), length());
44 swap(tmp);
45 }
46}
47
48
49TiXmlString& TiXmlString::assign(const char* str, size_type len)
50{
51 size_type cap = capacity();
52 if (len > cap || cap > 3*(len + 8))
53 {
54 TiXmlString tmp;
55 tmp.init(len);
56 memcpy(tmp.start(), str, len);
57 swap(tmp);
58 }
59 else
60 {
61 memmove(start(), str, len);
62 set_size(len);
63 }
64 return *this;
65}
66
67
68TiXmlString& TiXmlString::append(const char* str, size_type len)
69{
70 size_type newsize = length() + len;
71 if (newsize > capacity())
72 {
73 reserve (newsize + capacity());
74 }
75 memmove(finish(), str, len);
76 set_size(newsize);
77 return *this;
78}
79
80
81TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
82{
83 TiXmlString tmp;
84 tmp.reserve(a.length() + b.length());
85 tmp += a;
86 tmp += b;
87 return tmp;
88}
89
90TiXmlString operator + (const TiXmlString & a, const char* b)
91{
92 TiXmlString tmp;
93 TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
94 tmp.reserve(a.length() + b_len);
95 tmp += a;
96 tmp.append(b, b_len);
97 return tmp;
98}
99
100TiXmlString operator + (const char* a, const TiXmlString & b)
101{
102 TiXmlString tmp;
103 TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
104 tmp.reserve(a_len + b.length());
105 tmp.append(a, a_len);
106 tmp += b;
107 return tmp;
108}
109
110
111#endif // TIXML_USE_STL