[3940] | 1 | /* |
---|
| 2 | www.sourceforge.net/projects/tinyxml |
---|
| 3 | Original file by Yves Berquin. |
---|
| 4 | |
---|
[5819] | 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 |
---|
[3940] | 7 | damages arising from the use of this software. |
---|
| 8 | |
---|
[5819] | 9 | Permission is granted to anyone to use this software for any |
---|
| 10 | purpose, including commercial applications, and to alter it and |
---|
[3940] | 11 | redistribute it freely, subject to the following restrictions: |
---|
| 12 | |
---|
[5819] | 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 |
---|
[3940] | 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 | |
---|
[5819] | 21 | 3. This notice may not be removed or altered from any source |
---|
[3940] | 22 | distribution. |
---|
| 23 | */ |
---|
| 24 | |
---|
[5819] | 25 | /* |
---|
| 26 | * THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005. |
---|
| 27 | */ |
---|
[3940] | 28 | |
---|
[5819] | 29 | |
---|
[3940] | 30 | #ifndef TIXML_USE_STL |
---|
| 31 | |
---|
| 32 | #include "tinystr.h" |
---|
| 33 | |
---|
[5819] | 34 | // Error value for find primitive |
---|
| 35 | const TiXmlString::size_type TiXmlString::npos = static_cast< size_type >(-1); |
---|
[3940] | 36 | |
---|
[5819] | 37 | // Null rep. |
---|
| 38 | TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, '\0' }; |
---|
[3940] | 39 | |
---|
| 40 | |
---|
[5819] | 41 | void TiXmlString::reserve (size_type cap) |
---|
[3940] | 42 | { |
---|
[5819] | 43 | if (cap > capacity()) |
---|
[3940] | 44 | { |
---|
[5819] | 45 | TiXmlString tmp; |
---|
| 46 | tmp.init(length(), cap); |
---|
| 47 | memcpy(tmp.start(), data(), length()); |
---|
| 48 | swap(tmp); |
---|
[3940] | 49 | } |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
[5819] | 53 | TiXmlString& TiXmlString::assign(const char* str, size_type len) |
---|
[3940] | 54 | { |
---|
[5819] | 55 | size_type cap = capacity(); |
---|
| 56 | if (len > cap || cap > 3*(len + 8)) |
---|
[3940] | 57 | { |
---|
[5819] | 58 | TiXmlString tmp; |
---|
| 59 | tmp.init(len); |
---|
| 60 | memcpy(tmp.start(), str, len); |
---|
| 61 | swap(tmp); |
---|
| 62 | } |
---|
| 63 | else |
---|
[4491] | 64 | { |
---|
[5819] | 65 | memmove(start(), str, len); |
---|
| 66 | set_size(len); |
---|
[4491] | 67 | } |
---|
[5819] | 68 | return *this; |
---|
[3940] | 69 | } |
---|
| 70 | |
---|
| 71 | |
---|
[5819] | 72 | TiXmlString& TiXmlString::append(const char* str, size_type len) |
---|
[4491] | 73 | { |
---|
[5819] | 74 | size_type newsize = length() + len; |
---|
| 75 | if (newsize > capacity()) |
---|
[4491] | 76 | { |
---|
[5819] | 77 | reserve (newsize + capacity()); |
---|
[4491] | 78 | } |
---|
[5819] | 79 | memmove(finish(), str, len); |
---|
| 80 | set_size(newsize); |
---|
| 81 | return *this; |
---|
[4491] | 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
[5819] | 85 | TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) |
---|
[3940] | 86 | { |
---|
[5819] | 87 | TiXmlString tmp; |
---|
| 88 | tmp.reserve(a.length() + b.length()); |
---|
| 89 | tmp += a; |
---|
| 90 | tmp += b; |
---|
| 91 | return tmp; |
---|
[3940] | 92 | } |
---|
| 93 | |
---|
[5819] | 94 | TiXmlString operator + (const TiXmlString & a, const char* b) |
---|
| 95 | { |
---|
| 96 | TiXmlString tmp; |
---|
| 97 | TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) ); |
---|
| 98 | tmp.reserve(a.length() + b_len); |
---|
| 99 | tmp += a; |
---|
| 100 | tmp.append(b, b_len); |
---|
| 101 | return tmp; |
---|
| 102 | } |
---|
[3940] | 103 | |
---|
[5819] | 104 | TiXmlString operator + (const char* a, const TiXmlString & b) |
---|
[3940] | 105 | { |
---|
[5819] | 106 | TiXmlString tmp; |
---|
| 107 | TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) ); |
---|
| 108 | tmp.reserve(a_len + b.length()); |
---|
| 109 | tmp.append(a, a_len); |
---|
| 110 | tmp += b; |
---|
| 111 | return tmp; |
---|
[3940] | 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | #endif // TIXML_USE_STL |
---|