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