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