TinyXml is a compact library that implements XML Parsing and Manipulation.
tinystr.cpp@0:3c1d63c20cfc, 2011-04-18 (annotated)
- Committer:
- wvd_vegt
- Date:
- Mon Apr 18 18:54:09 2011 +0000
- Revision:
- 0:3c1d63c20cfc
First Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wvd_vegt | 0:3c1d63c20cfc | 1 | /* |
wvd_vegt | 0:3c1d63c20cfc | 2 | www.sourceforge.net/projects/tinyxml |
wvd_vegt | 0:3c1d63c20cfc | 3 | Original file by Yves Berquin. |
wvd_vegt | 0:3c1d63c20cfc | 4 | |
wvd_vegt | 0:3c1d63c20cfc | 5 | This software is provided 'as-is', without any express or implied |
wvd_vegt | 0:3c1d63c20cfc | 6 | warranty. In no event will the authors be held liable for any |
wvd_vegt | 0:3c1d63c20cfc | 7 | damages arising from the use of this software. |
wvd_vegt | 0:3c1d63c20cfc | 8 | |
wvd_vegt | 0:3c1d63c20cfc | 9 | Permission is granted to anyone to use this software for any |
wvd_vegt | 0:3c1d63c20cfc | 10 | purpose, including commercial applications, and to alter it and |
wvd_vegt | 0:3c1d63c20cfc | 11 | redistribute it freely, subject to the following restrictions: |
wvd_vegt | 0:3c1d63c20cfc | 12 | |
wvd_vegt | 0:3c1d63c20cfc | 13 | 1. The origin of this software must not be misrepresented; you must |
wvd_vegt | 0:3c1d63c20cfc | 14 | not claim that you wrote the original software. If you use this |
wvd_vegt | 0:3c1d63c20cfc | 15 | software in a product, an acknowledgment in the product documentation |
wvd_vegt | 0:3c1d63c20cfc | 16 | would be appreciated but is not required. |
wvd_vegt | 0:3c1d63c20cfc | 17 | |
wvd_vegt | 0:3c1d63c20cfc | 18 | 2. Altered source versions must be plainly marked as such, and |
wvd_vegt | 0:3c1d63c20cfc | 19 | must not be misrepresented as being the original software. |
wvd_vegt | 0:3c1d63c20cfc | 20 | |
wvd_vegt | 0:3c1d63c20cfc | 21 | 3. This notice may not be removed or altered from any source |
wvd_vegt | 0:3c1d63c20cfc | 22 | distribution. |
wvd_vegt | 0:3c1d63c20cfc | 23 | */ |
wvd_vegt | 0:3c1d63c20cfc | 24 | |
wvd_vegt | 0:3c1d63c20cfc | 25 | /* |
wvd_vegt | 0:3c1d63c20cfc | 26 | * THIS FILE WAS ALTERED BY Tyge L�, 7. April 2005. |
wvd_vegt | 0:3c1d63c20cfc | 27 | */ |
wvd_vegt | 0:3c1d63c20cfc | 28 | |
wvd_vegt | 0:3c1d63c20cfc | 29 | |
wvd_vegt | 0:3c1d63c20cfc | 30 | #ifndef TIXML_USE_STL |
wvd_vegt | 0:3c1d63c20cfc | 31 | |
wvd_vegt | 0:3c1d63c20cfc | 32 | #include "tinystr.h" |
wvd_vegt | 0:3c1d63c20cfc | 33 | |
wvd_vegt | 0:3c1d63c20cfc | 34 | // Error value for find primitive |
wvd_vegt | 0:3c1d63c20cfc | 35 | const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1); |
wvd_vegt | 0:3c1d63c20cfc | 36 | |
wvd_vegt | 0:3c1d63c20cfc | 37 | |
wvd_vegt | 0:3c1d63c20cfc | 38 | // Null rep. |
wvd_vegt | 0:3c1d63c20cfc | 39 | TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } }; |
wvd_vegt | 0:3c1d63c20cfc | 40 | |
wvd_vegt | 0:3c1d63c20cfc | 41 | |
wvd_vegt | 0:3c1d63c20cfc | 42 | void TiXmlString::reserve (size_type cap) |
wvd_vegt | 0:3c1d63c20cfc | 43 | { |
wvd_vegt | 0:3c1d63c20cfc | 44 | if (cap > capacity()) |
wvd_vegt | 0:3c1d63c20cfc | 45 | { |
wvd_vegt | 0:3c1d63c20cfc | 46 | TiXmlString tmp; |
wvd_vegt | 0:3c1d63c20cfc | 47 | tmp.init(length(), cap); |
wvd_vegt | 0:3c1d63c20cfc | 48 | memcpy(tmp.start(), data(), length()); |
wvd_vegt | 0:3c1d63c20cfc | 49 | swap(tmp); |
wvd_vegt | 0:3c1d63c20cfc | 50 | } |
wvd_vegt | 0:3c1d63c20cfc | 51 | } |
wvd_vegt | 0:3c1d63c20cfc | 52 | |
wvd_vegt | 0:3c1d63c20cfc | 53 | |
wvd_vegt | 0:3c1d63c20cfc | 54 | TiXmlString& TiXmlString::assign(const char* str, size_type len) |
wvd_vegt | 0:3c1d63c20cfc | 55 | { |
wvd_vegt | 0:3c1d63c20cfc | 56 | size_type cap = capacity(); |
wvd_vegt | 0:3c1d63c20cfc | 57 | if (len > cap || cap > 3*(len + 8)) |
wvd_vegt | 0:3c1d63c20cfc | 58 | { |
wvd_vegt | 0:3c1d63c20cfc | 59 | TiXmlString tmp; |
wvd_vegt | 0:3c1d63c20cfc | 60 | tmp.init(len); |
wvd_vegt | 0:3c1d63c20cfc | 61 | memcpy(tmp.start(), str, len); |
wvd_vegt | 0:3c1d63c20cfc | 62 | swap(tmp); |
wvd_vegt | 0:3c1d63c20cfc | 63 | } |
wvd_vegt | 0:3c1d63c20cfc | 64 | else |
wvd_vegt | 0:3c1d63c20cfc | 65 | { |
wvd_vegt | 0:3c1d63c20cfc | 66 | memmove(start(), str, len); |
wvd_vegt | 0:3c1d63c20cfc | 67 | set_size(len); |
wvd_vegt | 0:3c1d63c20cfc | 68 | } |
wvd_vegt | 0:3c1d63c20cfc | 69 | return *this; |
wvd_vegt | 0:3c1d63c20cfc | 70 | } |
wvd_vegt | 0:3c1d63c20cfc | 71 | |
wvd_vegt | 0:3c1d63c20cfc | 72 | |
wvd_vegt | 0:3c1d63c20cfc | 73 | TiXmlString& TiXmlString::append(const char* str, size_type len) |
wvd_vegt | 0:3c1d63c20cfc | 74 | { |
wvd_vegt | 0:3c1d63c20cfc | 75 | size_type newsize = length() + len; |
wvd_vegt | 0:3c1d63c20cfc | 76 | if (newsize > capacity()) |
wvd_vegt | 0:3c1d63c20cfc | 77 | { |
wvd_vegt | 0:3c1d63c20cfc | 78 | reserve (newsize + capacity()); |
wvd_vegt | 0:3c1d63c20cfc | 79 | } |
wvd_vegt | 0:3c1d63c20cfc | 80 | memmove(finish(), str, len); |
wvd_vegt | 0:3c1d63c20cfc | 81 | set_size(newsize); |
wvd_vegt | 0:3c1d63c20cfc | 82 | return *this; |
wvd_vegt | 0:3c1d63c20cfc | 83 | } |
wvd_vegt | 0:3c1d63c20cfc | 84 | |
wvd_vegt | 0:3c1d63c20cfc | 85 | |
wvd_vegt | 0:3c1d63c20cfc | 86 | TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) |
wvd_vegt | 0:3c1d63c20cfc | 87 | { |
wvd_vegt | 0:3c1d63c20cfc | 88 | TiXmlString tmp; |
wvd_vegt | 0:3c1d63c20cfc | 89 | tmp.reserve(a.length() + b.length()); |
wvd_vegt | 0:3c1d63c20cfc | 90 | tmp += a; |
wvd_vegt | 0:3c1d63c20cfc | 91 | tmp += b; |
wvd_vegt | 0:3c1d63c20cfc | 92 | return tmp; |
wvd_vegt | 0:3c1d63c20cfc | 93 | } |
wvd_vegt | 0:3c1d63c20cfc | 94 | |
wvd_vegt | 0:3c1d63c20cfc | 95 | TiXmlString operator + (const TiXmlString & a, const char* b) |
wvd_vegt | 0:3c1d63c20cfc | 96 | { |
wvd_vegt | 0:3c1d63c20cfc | 97 | TiXmlString tmp; |
wvd_vegt | 0:3c1d63c20cfc | 98 | TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) ); |
wvd_vegt | 0:3c1d63c20cfc | 99 | tmp.reserve(a.length() + b_len); |
wvd_vegt | 0:3c1d63c20cfc | 100 | tmp += a; |
wvd_vegt | 0:3c1d63c20cfc | 101 | tmp.append(b, b_len); |
wvd_vegt | 0:3c1d63c20cfc | 102 | return tmp; |
wvd_vegt | 0:3c1d63c20cfc | 103 | } |
wvd_vegt | 0:3c1d63c20cfc | 104 | |
wvd_vegt | 0:3c1d63c20cfc | 105 | TiXmlString operator + (const char* a, const TiXmlString & b) |
wvd_vegt | 0:3c1d63c20cfc | 106 | { |
wvd_vegt | 0:3c1d63c20cfc | 107 | TiXmlString tmp; |
wvd_vegt | 0:3c1d63c20cfc | 108 | TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) ); |
wvd_vegt | 0:3c1d63c20cfc | 109 | tmp.reserve(a_len + b.length()); |
wvd_vegt | 0:3c1d63c20cfc | 110 | tmp.append(a, a_len); |
wvd_vegt | 0:3c1d63c20cfc | 111 | tmp += b; |
wvd_vegt | 0:3c1d63c20cfc | 112 | return tmp; |
wvd_vegt | 0:3c1d63c20cfc | 113 | } |
wvd_vegt | 0:3c1d63c20cfc | 114 | |
wvd_vegt | 0:3c1d63c20cfc | 115 | |
wvd_vegt | 0:3c1d63c20cfc | 116 | #endif // TIXML_USE_STL |