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