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