Lee Thomason (grinliz) | 2812986 | 2012-02-25 21:11:20 -0800 | [diff] [blame] | 1 | /*
|
| 2 | Original code by Lee Thomason (www.grinninglizard.com)
|
| 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 | */
|
Lee Thomason (grinliz) | 9c38d13 | 2012-02-24 21:50:50 -0800 | [diff] [blame] | 23 |
|
U-Lama\Lee | 560bd47 | 2011-12-28 19:42:49 -0800 | [diff] [blame] | 24 | #include "tinyxml2.h"
|
| 25 |
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 26 | #include <new> // yes, this one new style header, is in the Android SDK.
|
Anton Indrawan | f59e2d6 | 2014-11-18 20:50:42 +0100 | [diff] [blame] | 27 | #if defined(ANDROID_NDK) || defined(__QNXNTO__)
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 28 | # include <stddef.h>
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 29 | #else
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 30 | # include <cstddef>
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 31 | #endif
|
U-Lama\Lee | 560bd47 | 2011-12-28 19:42:49 -0800 | [diff] [blame] | 32 |
|
Lee Thomason | 53db4a6 | 2015-06-11 22:52:08 -0700 | [diff] [blame] | 33 | #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
|
Dmitry-Me | 1ca593c | 2015-06-22 12:49:32 +0300 | [diff] [blame] | 34 | // Microsoft Visual Studio, version 2005 and higher. Not WinCE.
|
Lee Thomason | 53db4a6 | 2015-06-11 22:52:08 -0700 | [diff] [blame] | 35 | /*int _snprintf_s(
|
| 36 | char *buffer,
|
| 37 | size_t sizeOfBuffer,
|
| 38 | size_t count,
|
| 39 | const char *format [,
|
| 40 | argument] ...
|
| 41 | );*/
|
| 42 | inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
|
| 43 | {
|
| 44 | va_list va;
|
| 45 | va_start( va, format );
|
| 46 | int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
|
| 47 | va_end( va );
|
| 48 | return result;
|
| 49 | }
|
| 50 |
|
| 51 | inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va )
|
| 52 | {
|
| 53 | int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
|
| 54 | return result;
|
| 55 | }
|
| 56 |
|
| 57 | #define TIXML_VSCPRINTF _vscprintf
|
| 58 | #define TIXML_SSCANF sscanf_s
|
| 59 | #elif defined _MSC_VER
|
| 60 | // Microsoft Visual Studio 2003 and earlier or WinCE
|
| 61 | #define TIXML_SNPRINTF _snprintf
|
| 62 | #define TIXML_VSNPRINTF _vsnprintf
|
| 63 | #define TIXML_SSCANF sscanf
|
Lee Thomason | aa8566b | 2015-06-19 16:52:40 -0700 | [diff] [blame] | 64 | #if (_MSC_VER < 1400 ) && (!defined WINCE)
|
Lee Thomason | 53db4a6 | 2015-06-11 22:52:08 -0700 | [diff] [blame] | 65 | // Microsoft Visual Studio 2003 and not WinCE.
|
| 66 | #define TIXML_VSCPRINTF _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have.
|
| 67 | #else
|
| 68 | // Microsoft Visual Studio 2003 and earlier or WinCE.
|
| 69 | inline int TIXML_VSCPRINTF( const char* format, va_list va )
|
| 70 | {
|
| 71 | int len = 512;
|
| 72 | for (;;) {
|
| 73 | len = len*2;
|
| 74 | char* str = new char[len]();
|
| 75 | const int required = _vsnprintf(str, len, format, va);
|
| 76 | delete[] str;
|
| 77 | if ( required != -1 ) {
|
| 78 | len = required;
|
| 79 | break;
|
| 80 | }
|
| 81 | }
|
| 82 | return len;
|
| 83 | }
|
| 84 | #endif
|
| 85 | #else
|
| 86 | // GCC version 3 and higher
|
| 87 | //#warning( "Using sn* functions." )
|
| 88 | #define TIXML_SNPRINTF snprintf
|
| 89 | #define TIXML_VSNPRINTF vsnprintf
|
| 90 | inline int TIXML_VSCPRINTF( const char* format, va_list va )
|
| 91 | {
|
| 92 | int len = vsnprintf( 0, 0, format, va );
|
| 93 | return len;
|
| 94 | }
|
| 95 | #define TIXML_SSCANF sscanf
|
| 96 | #endif
|
| 97 |
|
| 98 |
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 99 | static const char LINE_FEED = (char)0x0a; // all line endings are normalized to LF
|
Lee Thomason | fde6a75 | 2012-01-14 18:08:12 -0800 | [diff] [blame] | 100 | static const char LF = LINE_FEED;
|
| 101 | static const char CARRIAGE_RETURN = (char)0x0d; // CR gets filtered out
|
| 102 | static const char CR = CARRIAGE_RETURN;
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 103 | static const char SINGLE_QUOTE = '\'';
|
| 104 | static const char DOUBLE_QUOTE = '\"';
|
Lee Thomason | fde6a75 | 2012-01-14 18:08:12 -0800 | [diff] [blame] | 105 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 106 | // Bunch of unicode info at:
|
| 107 | // http://www.unicode.org/faq/utf_bom.html
|
| 108 | // ef bb bf (Microsoft "lead bytes") - designates UTF-8
|
| 109 |
|
| 110 | static const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
|
| 111 | static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
|
| 112 | static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 113 |
|
Kevin Wojniak | 04c22d2 | 2012-11-08 11:02:22 -0800 | [diff] [blame] | 114 | namespace tinyxml2
|
| 115 | {
|
| 116 |
|
Lee Thomason | 8ee7989 | 2012-01-25 17:44:30 -0800 | [diff] [blame] | 117 | struct Entity {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 118 | const char* pattern;
|
| 119 | int length;
|
| 120 | char value;
|
Lee Thomason | 8ee7989 | 2012-01-25 17:44:30 -0800 | [diff] [blame] | 121 | };
|
| 122 |
|
| 123 | static const int NUM_ENTITIES = 5;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 124 | static const Entity entities[NUM_ENTITIES] = {
|
| 125 | { "quot", 4, DOUBLE_QUOTE },
|
| 126 | { "amp", 3, '&' },
|
| 127 | { "apos", 4, SINGLE_QUOTE },
|
| 128 | { "lt", 2, '<' },
|
| 129 | { "gt", 2, '>' }
|
Lee Thomason | 8ee7989 | 2012-01-25 17:44:30 -0800 | [diff] [blame] | 130 | };
|
| 131 |
|
Lee Thomason | fde6a75 | 2012-01-14 18:08:12 -0800 | [diff] [blame] | 132 |
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 133 | StrPair::~StrPair()
|
| 134 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 135 | Reset();
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 136 | }
|
| 137 |
|
| 138 |
|
Lee Thomason | 2965880 | 2014-11-27 22:31:11 -0800 | [diff] [blame] | 139 | void StrPair::TransferTo( StrPair* other )
|
Dmitry-Me | 08b40dd | 2014-11-10 11:17:21 +0300 | [diff] [blame] | 140 | {
|
Lee Thomason | 2965880 | 2014-11-27 22:31:11 -0800 | [diff] [blame] | 141 | if ( this == other ) {
|
Dmitry-Me | 08b40dd | 2014-11-10 11:17:21 +0300 | [diff] [blame] | 142 | return;
|
| 143 | }
|
| 144 | // This in effect implements the assignment operator by "moving"
|
| 145 | // ownership (as in auto_ptr).
|
| 146 |
|
Lee Thomason | 2965880 | 2014-11-27 22:31:11 -0800 | [diff] [blame] | 147 | TIXMLASSERT( other->_flags == 0 );
|
| 148 | TIXMLASSERT( other->_start == 0 );
|
| 149 | TIXMLASSERT( other->_end == 0 );
|
Dmitry-Me | 08b40dd | 2014-11-10 11:17:21 +0300 | [diff] [blame] | 150 |
|
Lee Thomason | 2965880 | 2014-11-27 22:31:11 -0800 | [diff] [blame] | 151 | other->Reset();
|
Dmitry-Me | 08b40dd | 2014-11-10 11:17:21 +0300 | [diff] [blame] | 152 |
|
Lee Thomason | 2965880 | 2014-11-27 22:31:11 -0800 | [diff] [blame] | 153 | other->_flags = _flags;
|
| 154 | other->_start = _start;
|
| 155 | other->_end = _end;
|
Dmitry-Me | 08b40dd | 2014-11-10 11:17:21 +0300 | [diff] [blame] | 156 |
|
| 157 | _flags = 0;
|
| 158 | _start = 0;
|
| 159 | _end = 0;
|
| 160 | }
|
| 161 |
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 162 | void StrPair::Reset()
|
| 163 | {
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 164 | if ( _flags & NEEDS_DELETE ) {
|
| 165 | delete [] _start;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 166 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 167 | _flags = 0;
|
| 168 | _start = 0;
|
| 169 | _end = 0;
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 170 | }
|
| 171 |
|
| 172 |
|
| 173 | void StrPair::SetStr( const char* str, int flags )
|
| 174 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 175 | Reset();
|
| 176 | size_t len = strlen( str );
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 177 | _start = new char[ len+1 ];
|
| 178 | memcpy( _start, str, len+1 );
|
| 179 | _end = _start + len;
|
| 180 | _flags = flags | NEEDS_DELETE;
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 181 | }
|
| 182 |
|
| 183 |
|
| 184 | char* StrPair::ParseText( char* p, const char* endTag, int strFlags )
|
| 185 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 186 | TIXMLASSERT( endTag && *endTag );
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 187 |
|
Dmitry-Me | ec19a0e | 2014-08-25 11:05:55 +0400 | [diff] [blame] | 188 | char* start = p;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 189 | char endChar = *endTag;
|
| 190 | size_t length = strlen( endTag );
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 191 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 192 | // Inner loop of text parsing.
|
| 193 | while ( *p ) {
|
| 194 | if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) {
|
| 195 | Set( start, p, strFlags );
|
| 196 | return p + length;
|
| 197 | }
|
| 198 | ++p;
|
| 199 | }
|
| 200 | return 0;
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 201 | }
|
| 202 |
|
| 203 |
|
| 204 | char* StrPair::ParseName( char* p )
|
| 205 | {
|
Dmitry-Me | 9fb2b0f | 2014-09-23 17:27:39 +0400 | [diff] [blame] | 206 | if ( !p || !(*p) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 207 | return 0;
|
| 208 | }
|
JayXon | ee525db | 2014-12-24 04:01:42 -0500 | [diff] [blame] | 209 | if ( !XMLUtil::IsNameStartChar( *p ) ) {
|
| 210 | return 0;
|
| 211 | }
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 212 |
|
Dmitry-Me | 9fb2b0f | 2014-09-23 17:27:39 +0400 | [diff] [blame] | 213 | char* const start = p;
|
JayXon | ee525db | 2014-12-24 04:01:42 -0500 | [diff] [blame] | 214 | ++p;
|
| 215 | while ( *p && XMLUtil::IsNameChar( *p ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 216 | ++p;
|
| 217 | }
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 218 |
|
JayXon | ee525db | 2014-12-24 04:01:42 -0500 | [diff] [blame] | 219 | Set( start, p, 0 );
|
| 220 | return p;
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 221 | }
|
| 222 |
|
| 223 |
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 224 | void StrPair::CollapseWhitespace()
|
| 225 | {
|
Dmitry-Me | 67a5bb0 | 2014-08-20 10:01:53 +0400 | [diff] [blame] | 226 | // Adjusting _start would cause undefined behavior on delete[]
|
| 227 | TIXMLASSERT( ( _flags & NEEDS_DELETE ) == 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 228 | // Trim leading space.
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 229 | _start = XMLUtil::SkipWhiteSpace( _start );
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 230 |
|
Dmitry-Me | bb836dc | 2014-12-24 11:54:05 +0300 | [diff] [blame] | 231 | if ( *_start ) {
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 232 | char* p = _start; // the read pointer
|
| 233 | char* q = _start; // the write pointer
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 234 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 235 | while( *p ) {
|
| 236 | if ( XMLUtil::IsWhiteSpace( *p )) {
|
| 237 | p = XMLUtil::SkipWhiteSpace( p );
|
| 238 | if ( *p == 0 ) {
|
| 239 | break; // don't write to q; this trims the trailing space.
|
| 240 | }
|
| 241 | *q = ' ';
|
| 242 | ++q;
|
| 243 | }
|
| 244 | *q = *p;
|
| 245 | ++q;
|
| 246 | ++p;
|
| 247 | }
|
| 248 | *q = 0;
|
| 249 | }
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 250 | }
|
| 251 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 252 |
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 253 | const char* StrPair::GetStr()
|
| 254 | {
|
Dmitry-Me | 5ffa73e | 2015-01-01 17:47:40 +0300 | [diff] [blame] | 255 | TIXMLASSERT( _start );
|
| 256 | TIXMLASSERT( _end );
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 257 | if ( _flags & NEEDS_FLUSH ) {
|
| 258 | *_end = 0;
|
| 259 | _flags ^= NEEDS_FLUSH;
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 260 |
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 261 | if ( _flags ) {
|
| 262 | char* p = _start; // the read pointer
|
| 263 | char* q = _start; // the write pointer
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 264 |
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 265 | while( p < _end ) {
|
| 266 | if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 267 | // CR-LF pair becomes LF
|
| 268 | // CR alone becomes LF
|
| 269 | // LF-CR becomes LF
|
| 270 | if ( *(p+1) == LF ) {
|
| 271 | p += 2;
|
| 272 | }
|
| 273 | else {
|
| 274 | ++p;
|
| 275 | }
|
| 276 | *q++ = LF;
|
| 277 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 278 | else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 279 | if ( *(p+1) == CR ) {
|
| 280 | p += 2;
|
| 281 | }
|
| 282 | else {
|
| 283 | ++p;
|
| 284 | }
|
| 285 | *q++ = LF;
|
| 286 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 287 | else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 288 | // Entities handled by tinyXML2:
|
| 289 | // - special entities in the entity table [in/out]
|
| 290 | // - numeric character reference [in]
|
| 291 | // 中 or 中
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 292 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 293 | if ( *(p+1) == '#' ) {
|
Dmitry-Me | 63f3de1 | 2014-08-21 12:33:19 +0400 | [diff] [blame] | 294 | const int buflen = 10;
|
| 295 | char buf[buflen] = { 0 };
|
| 296 | int len = 0;
|
Dmitry-Me | 6f51c80 | 2015-03-14 13:25:03 +0300 | [diff] [blame] | 297 | char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
|
| 298 | if ( adjusted == 0 ) {
|
| 299 | *q = *p;
|
| 300 | ++p;
|
| 301 | ++q;
|
| 302 | }
|
| 303 | else {
|
| 304 | TIXMLASSERT( 0 <= len && len <= buflen );
|
| 305 | TIXMLASSERT( q + len <= adjusted );
|
| 306 | p = adjusted;
|
| 307 | memcpy( q, buf, len );
|
| 308 | q += len;
|
| 309 | }
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 310 | }
|
| 311 | else {
|
Dmitry-Me | 764545e | 2015-05-20 10:29:24 +0300 | [diff] [blame] | 312 | bool entityFound = false;
|
| 313 | for( int i = 0; i < NUM_ENTITIES; ++i ) {
|
Dmitry-Me | d048f1e | 2014-10-01 10:30:16 +0400 | [diff] [blame] | 314 | const Entity& entity = entities[i];
|
| 315 | if ( strncmp( p + 1, entity.pattern, entity.length ) == 0
|
| 316 | && *( p + entity.length + 1 ) == ';' ) {
|
| 317 | // Found an entity - convert.
|
| 318 | *q = entity.value;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 319 | ++q;
|
Dmitry-Me | d048f1e | 2014-10-01 10:30:16 +0400 | [diff] [blame] | 320 | p += entity.length + 2;
|
Dmitry-Me | 764545e | 2015-05-20 10:29:24 +0300 | [diff] [blame] | 321 | entityFound = true;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 322 | break;
|
| 323 | }
|
| 324 | }
|
Dmitry-Me | 764545e | 2015-05-20 10:29:24 +0300 | [diff] [blame] | 325 | if ( !entityFound ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 326 | // fixme: treat as error?
|
| 327 | ++p;
|
| 328 | ++q;
|
| 329 | }
|
| 330 | }
|
| 331 | }
|
| 332 | else {
|
| 333 | *q = *p;
|
| 334 | ++p;
|
| 335 | ++q;
|
| 336 | }
|
| 337 | }
|
| 338 | *q = 0;
|
| 339 | }
|
| 340 | // The loop below has plenty going on, and this
|
| 341 | // is a less useful mode. Break it out.
|
Dmitry-Me | 5420e54 | 2015-05-20 10:51:26 +0300 | [diff] [blame] | 342 | if ( _flags & NEEDS_WHITESPACE_COLLAPSING ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 343 | CollapseWhitespace();
|
| 344 | }
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 345 | _flags = (_flags & NEEDS_DELETE);
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 346 | }
|
Dmitry-Me | 5ffa73e | 2015-01-01 17:47:40 +0300 | [diff] [blame] | 347 | TIXMLASSERT( _start );
|
Lee Thomason | 120b3a6 | 2012-10-12 10:06:59 -0700 | [diff] [blame] | 348 | return _start;
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 349 | }
|
| 350 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 351 |
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 352 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 353 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 354 | // --------- XMLUtil ----------- //
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 355 |
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 356 | const char* XMLUtil::ReadBOM( const char* p, bool* bom )
|
| 357 | {
|
Dmitry-Me | bb836dc | 2014-12-24 11:54:05 +0300 | [diff] [blame] | 358 | TIXMLASSERT( p );
|
| 359 | TIXMLASSERT( bom );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 360 | *bom = false;
|
| 361 | const unsigned char* pu = reinterpret_cast<const unsigned char*>(p);
|
| 362 | // Check for BOM:
|
| 363 | if ( *(pu+0) == TIXML_UTF_LEAD_0
|
| 364 | && *(pu+1) == TIXML_UTF_LEAD_1
|
| 365 | && *(pu+2) == TIXML_UTF_LEAD_2 ) {
|
| 366 | *bom = true;
|
| 367 | p += 3;
|
| 368 | }
|
Dmitry-Me | bb836dc | 2014-12-24 11:54:05 +0300 | [diff] [blame] | 369 | TIXMLASSERT( p );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 370 | return p;
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 371 | }
|
| 372 |
|
| 373 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 374 | void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length )
|
| 375 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 376 | const unsigned long BYTE_MASK = 0xBF;
|
| 377 | const unsigned long BYTE_MARK = 0x80;
|
| 378 | const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 379 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 380 | if (input < 0x80) {
|
| 381 | *length = 1;
|
| 382 | }
|
| 383 | else if ( input < 0x800 ) {
|
| 384 | *length = 2;
|
| 385 | }
|
| 386 | else if ( input < 0x10000 ) {
|
| 387 | *length = 3;
|
| 388 | }
|
| 389 | else if ( input < 0x200000 ) {
|
| 390 | *length = 4;
|
| 391 | }
|
| 392 | else {
|
Dmitry-Me | 2f465c4 | 2015-03-16 11:08:23 +0300 | [diff] [blame] | 393 | *length = 0; // This code won't convert this correctly anyway.
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 394 | return;
|
| 395 | }
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 396 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 397 | output += *length;
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 398 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 399 | // Scary scary fall throughs.
|
| 400 | switch (*length) {
|
| 401 | case 4:
|
| 402 | --output;
|
| 403 | *output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
| 404 | input >>= 6;
|
| 405 | case 3:
|
| 406 | --output;
|
| 407 | *output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
| 408 | input >>= 6;
|
| 409 | case 2:
|
| 410 | --output;
|
| 411 | *output = (char)((input | BYTE_MARK) & BYTE_MASK);
|
| 412 | input >>= 6;
|
| 413 | case 1:
|
| 414 | --output;
|
| 415 | *output = (char)(input | FIRST_BYTE_MARK[*length]);
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 416 | break;
|
Dmitry-Me | 33bb764 | 2015-03-14 17:14:00 +0300 | [diff] [blame] | 417 | default:
|
| 418 | TIXMLASSERT( false );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 419 | }
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 420 | }
|
| 421 |
|
| 422 |
|
| 423 | const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
|
| 424 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 425 | // Presume an entity, and pull it out.
|
| 426 | *length = 0;
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 427 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 428 | if ( *(p+1) == '#' && *(p+2) ) {
|
| 429 | unsigned long ucs = 0;
|
Dmitry-Me | bbaf1e1 | 2015-01-12 14:07:10 +0300 | [diff] [blame] | 430 | TIXMLASSERT( sizeof( ucs ) >= 4 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 431 | ptrdiff_t delta = 0;
|
| 432 | unsigned mult = 1;
|
Lee Thomason | 7e67bc8 | 2015-01-12 14:05:12 -0800 | [diff] [blame] | 433 | static const char SEMICOLON = ';';
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 434 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 435 | if ( *(p+2) == 'x' ) {
|
| 436 | // Hexadecimal.
|
Dmitry-Me | 6acc9a5 | 2015-01-15 13:27:47 +0300 | [diff] [blame] | 437 | const char* q = p+3;
|
| 438 | if ( !(*q) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 439 | return 0;
|
| 440 | }
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 441 |
|
Lee Thomason | 7e67bc8 | 2015-01-12 14:05:12 -0800 | [diff] [blame] | 442 | q = strchr( q, SEMICOLON );
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 443 |
|
Dmitry-Me | 9f56e12 | 2015-01-12 10:07:54 +0300 | [diff] [blame] | 444 | if ( !q ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 445 | return 0;
|
| 446 | }
|
Lee Thomason | 7e67bc8 | 2015-01-12 14:05:12 -0800 | [diff] [blame] | 447 | TIXMLASSERT( *q == SEMICOLON );
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 448 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 449 | delta = q-p;
|
| 450 | --q;
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 451 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 452 | while ( *q != 'x' ) {
|
Lee Thomason | 7265b76 | 2015-03-15 16:11:47 -0700 | [diff] [blame] | 453 | unsigned int digit = 0;
|
| 454 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 455 | if ( *q >= '0' && *q <= '9' ) {
|
Dmitry-Me | bab9b6d | 2015-03-14 16:41:46 +0300 | [diff] [blame] | 456 | digit = *q - '0';
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 457 | }
|
| 458 | else if ( *q >= 'a' && *q <= 'f' ) {
|
Dmitry-Me | bab9b6d | 2015-03-14 16:41:46 +0300 | [diff] [blame] | 459 | digit = *q - 'a' + 10;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 460 | }
|
| 461 | else if ( *q >= 'A' && *q <= 'F' ) {
|
Dmitry-Me | bab9b6d | 2015-03-14 16:41:46 +0300 | [diff] [blame] | 462 | digit = *q - 'A' + 10;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 463 | }
|
| 464 | else {
|
| 465 | return 0;
|
| 466 | }
|
Dmitry-Me | 3dc797b | 2015-03-16 11:06:46 +0300 | [diff] [blame] | 467 | TIXMLASSERT( digit >= 0 && digit < 16);
|
Dmitry-Me | bab9b6d | 2015-03-14 16:41:46 +0300 | [diff] [blame] | 468 | TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
|
| 469 | const unsigned int digitScaled = mult * digit;
|
| 470 | TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
|
| 471 | ucs += digitScaled;
|
Dmitry-Me | bbaf1e1 | 2015-01-12 14:07:10 +0300 | [diff] [blame] | 472 | TIXMLASSERT( mult <= UINT_MAX / 16 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 473 | mult *= 16;
|
| 474 | --q;
|
| 475 | }
|
| 476 | }
|
| 477 | else {
|
| 478 | // Decimal.
|
Dmitry-Me | 6acc9a5 | 2015-01-15 13:27:47 +0300 | [diff] [blame] | 479 | const char* q = p+2;
|
| 480 | if ( !(*q) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 481 | return 0;
|
| 482 | }
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 483 |
|
Lee Thomason | 7e67bc8 | 2015-01-12 14:05:12 -0800 | [diff] [blame] | 484 | q = strchr( q, SEMICOLON );
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 485 |
|
Dmitry-Me | 9f56e12 | 2015-01-12 10:07:54 +0300 | [diff] [blame] | 486 | if ( !q ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 487 | return 0;
|
| 488 | }
|
Lee Thomason | 7e67bc8 | 2015-01-12 14:05:12 -0800 | [diff] [blame] | 489 | TIXMLASSERT( *q == SEMICOLON );
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 490 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 491 | delta = q-p;
|
| 492 | --q;
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 493 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 494 | while ( *q != '#' ) {
|
| 495 | if ( *q >= '0' && *q <= '9' ) {
|
Dmitry-Me | bab9b6d | 2015-03-14 16:41:46 +0300 | [diff] [blame] | 496 | const unsigned int digit = *q - '0';
|
Dmitry-Me | 3dc797b | 2015-03-16 11:06:46 +0300 | [diff] [blame] | 497 | TIXMLASSERT( digit >= 0 && digit < 10);
|
Dmitry-Me | bab9b6d | 2015-03-14 16:41:46 +0300 | [diff] [blame] | 498 | TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
|
| 499 | const unsigned int digitScaled = mult * digit;
|
| 500 | TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
|
| 501 | ucs += digitScaled;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 502 | }
|
| 503 | else {
|
| 504 | return 0;
|
| 505 | }
|
Dmitry-Me | bbaf1e1 | 2015-01-12 14:07:10 +0300 | [diff] [blame] | 506 | TIXMLASSERT( mult <= UINT_MAX / 10 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 507 | mult *= 10;
|
| 508 | --q;
|
| 509 | }
|
| 510 | }
|
| 511 | // convert the UCS to UTF-8
|
| 512 | ConvertUTF32ToUTF8( ucs, value, length );
|
| 513 | return p + delta + 1;
|
| 514 | }
|
| 515 | return p+1;
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 516 | }
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 517 |
|
| 518 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 519 | void XMLUtil::ToStr( int v, char* buffer, int bufferSize )
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 520 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 521 | TIXML_SNPRINTF( buffer, bufferSize, "%d", v );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 522 | }
|
| 523 |
|
| 524 |
|
| 525 | void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize )
|
| 526 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 527 | TIXML_SNPRINTF( buffer, bufferSize, "%u", v );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 528 | }
|
| 529 |
|
| 530 |
|
| 531 | void XMLUtil::ToStr( bool v, char* buffer, int bufferSize )
|
| 532 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 533 | TIXML_SNPRINTF( buffer, bufferSize, "%d", v ? 1 : 0 );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 534 | }
|
| 535 |
|
Lee Thomason | c3708cc | 2014-01-14 12:30:03 -0800 | [diff] [blame] | 536 | /*
|
| 537 | ToStr() of a number is a very tricky topic.
|
| 538 | https://github.com/leethomason/tinyxml2/issues/106
|
| 539 | */
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 540 | void XMLUtil::ToStr( float v, char* buffer, int bufferSize )
|
| 541 | {
|
Lee Thomason | c3708cc | 2014-01-14 12:30:03 -0800 | [diff] [blame] | 542 | TIXML_SNPRINTF( buffer, bufferSize, "%.8g", v );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 543 | }
|
| 544 |
|
| 545 |
|
| 546 | void XMLUtil::ToStr( double v, char* buffer, int bufferSize )
|
| 547 | {
|
Lee Thomason | c3708cc | 2014-01-14 12:30:03 -0800 | [diff] [blame] | 548 | TIXML_SNPRINTF( buffer, bufferSize, "%.17g", v );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 549 | }
|
| 550 |
|
| 551 |
|
| 552 | bool XMLUtil::ToInt( const char* str, int* value )
|
| 553 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 554 | if ( TIXML_SSCANF( str, "%d", value ) == 1 ) {
|
| 555 | return true;
|
| 556 | }
|
| 557 | return false;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 558 | }
|
| 559 |
|
| 560 | bool XMLUtil::ToUnsigned( const char* str, unsigned *value )
|
| 561 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 562 | if ( TIXML_SSCANF( str, "%u", value ) == 1 ) {
|
| 563 | return true;
|
| 564 | }
|
| 565 | return false;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 566 | }
|
| 567 |
|
| 568 | bool XMLUtil::ToBool( const char* str, bool* value )
|
| 569 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 570 | int ival = 0;
|
| 571 | if ( ToInt( str, &ival )) {
|
| 572 | *value = (ival==0) ? false : true;
|
| 573 | return true;
|
| 574 | }
|
| 575 | if ( StringEqual( str, "true" ) ) {
|
| 576 | *value = true;
|
| 577 | return true;
|
| 578 | }
|
| 579 | else if ( StringEqual( str, "false" ) ) {
|
| 580 | *value = false;
|
| 581 | return true;
|
| 582 | }
|
| 583 | return false;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 584 | }
|
| 585 |
|
| 586 |
|
| 587 | bool XMLUtil::ToFloat( const char* str, float* value )
|
| 588 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 589 | if ( TIXML_SSCANF( str, "%f", value ) == 1 ) {
|
| 590 | return true;
|
| 591 | }
|
| 592 | return false;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 593 | }
|
| 594 |
|
| 595 | bool XMLUtil::ToDouble( const char* str, double* value )
|
| 596 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 597 | if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) {
|
| 598 | return true;
|
| 599 | }
|
| 600 | return false;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 601 | }
|
| 602 |
|
| 603 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 604 | char* XMLDocument::Identify( char* p, XMLNode** node )
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 605 | {
|
Dmitry-Me | 0238466 | 2015-03-03 16:02:13 +0300 | [diff] [blame] | 606 | TIXMLASSERT( node );
|
| 607 | TIXMLASSERT( p );
|
Dmitry-Me | 9fb2b0f | 2014-09-23 17:27:39 +0400 | [diff] [blame] | 608 | char* const start = p;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 609 | p = XMLUtil::SkipWhiteSpace( p );
|
Dmitry-Me | bb836dc | 2014-12-24 11:54:05 +0300 | [diff] [blame] | 610 | if( !*p ) {
|
Dmitry-Me | 9fcb876 | 2015-03-05 17:53:34 +0300 | [diff] [blame] | 611 | *node = 0;
|
| 612 | TIXMLASSERT( p );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 613 | return p;
|
| 614 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 615 |
|
Dmitry-Me | 962083b | 2015-05-26 11:38:30 +0300 | [diff] [blame] | 616 | // These strings define the matching patterns:
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 617 | static const char* xmlHeader = { "<?" };
|
| 618 | static const char* commentHeader = { "<!--" };
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 619 | static const char* cdataHeader = { "<![CDATA[" };
|
Dmitry-Me | c505e13 | 2015-03-30 09:54:36 +0300 | [diff] [blame] | 620 | static const char* dtdHeader = { "<!" };
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 621 | static const char* elementHeader = { "<" }; // and a header for everything else; check last.
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 622 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 623 | static const int xmlHeaderLen = 2;
|
| 624 | static const int commentHeaderLen = 4;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 625 | static const int cdataHeaderLen = 9;
|
Dmitry-Me | c505e13 | 2015-03-30 09:54:36 +0300 | [diff] [blame] | 626 | static const int dtdHeaderLen = 2;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 627 | static const int elementHeaderLen = 1;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 628 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 629 | TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool
|
| 630 | TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool
|
Dmitry-Me | 9fb2b0f | 2014-09-23 17:27:39 +0400 | [diff] [blame] | 631 | XMLNode* returnNode = 0;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 632 | if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 633 | TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 634 | returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );
|
| 635 | returnNode->_memPool = &_commentPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 636 | p += xmlHeaderLen;
|
| 637 | }
|
| 638 | else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 639 | TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 640 | returnNode = new (_commentPool.Alloc()) XMLComment( this );
|
| 641 | returnNode->_memPool = &_commentPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 642 | p += commentHeaderLen;
|
| 643 | }
|
| 644 | else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 645 | TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 646 | XMLText* text = new (_textPool.Alloc()) XMLText( this );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 647 | returnNode = text;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 648 | returnNode->_memPool = &_textPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 649 | p += cdataHeaderLen;
|
| 650 | text->SetCData( true );
|
| 651 | }
|
| 652 | else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 653 | TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 654 | returnNode = new (_commentPool.Alloc()) XMLUnknown( this );
|
| 655 | returnNode->_memPool = &_commentPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 656 | p += dtdHeaderLen;
|
| 657 | }
|
| 658 | else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 659 | TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 660 | returnNode = new (_elementPool.Alloc()) XMLElement( this );
|
| 661 | returnNode->_memPool = &_elementPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 662 | p += elementHeaderLen;
|
| 663 | }
|
| 664 | else {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 665 | TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 666 | returnNode = new (_textPool.Alloc()) XMLText( this );
|
| 667 | returnNode->_memPool = &_textPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 668 | p = start; // Back it up, all the text counts.
|
| 669 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 670 |
|
Dmitry-Me | 0238466 | 2015-03-03 16:02:13 +0300 | [diff] [blame] | 671 | TIXMLASSERT( returnNode );
|
| 672 | TIXMLASSERT( p );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 673 | *node = returnNode;
|
| 674 | return p;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 675 | }
|
| 676 |
|
| 677 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 678 | bool XMLDocument::Accept( XMLVisitor* visitor ) const
|
| 679 | {
|
Dmitry-Me | bbaf1e1 | 2015-01-12 14:07:10 +0300 | [diff] [blame] | 680 | TIXMLASSERT( visitor );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 681 | if ( visitor->VisitEnter( *this ) ) {
|
| 682 | for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) {
|
| 683 | if ( !node->Accept( visitor ) ) {
|
| 684 | break;
|
| 685 | }
|
| 686 | }
|
| 687 | }
|
| 688 | return visitor->VisitExit( *this );
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 689 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 690 |
|
| 691 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 692 | // --------- XMLNode ----------- //
|
| 693 |
|
| 694 | XMLNode::XMLNode( XMLDocument* doc ) :
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 695 | _document( doc ),
|
| 696 | _parent( 0 ),
|
| 697 | _firstChild( 0 ), _lastChild( 0 ),
|
Thomas Roß | 6189231 | 2013-05-12 14:07:38 +0200 | [diff] [blame] | 698 | _prev( 0 ), _next( 0 ),
|
| 699 | _memPool( 0 )
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 700 | {
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 701 | }
|
| 702 |
|
| 703 |
|
| 704 | XMLNode::~XMLNode()
|
| 705 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 706 | DeleteChildren();
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 707 | if ( _parent ) {
|
| 708 | _parent->Unlink( this );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 709 | }
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 710 | }
|
| 711 |
|
Michael Daumling | 2162688 | 2013-10-22 17:03:37 +0200 | [diff] [blame] | 712 | const char* XMLNode::Value() const
|
| 713 | {
|
Lee Thomason | 8549202 | 2015-05-22 11:07:45 -0700 | [diff] [blame] | 714 | // Catch an edge case: XMLDocuments don't have a a Value. Carefully return nullptr.
|
Sarat Addepalli | 9c3122b | 2015-05-19 12:49:32 +0530 | [diff] [blame] | 715 | if ( this->ToDocument() )
|
Sarat Addepalli | 96b4346 | 2015-05-20 10:36:06 +0530 | [diff] [blame] | 716 | return 0;
|
Michael Daumling | 2162688 | 2013-10-22 17:03:37 +0200 | [diff] [blame] | 717 | return _value.GetStr();
|
| 718 | }
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 719 |
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 720 | void XMLNode::SetValue( const char* str, bool staticMem )
|
| 721 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 722 | if ( staticMem ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 723 | _value.SetInternedStr( str );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 724 | }
|
| 725 | else {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 726 | _value.SetStr( str );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 727 | }
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 728 | }
|
| 729 |
|
| 730 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 731 | void XMLNode::DeleteChildren()
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 732 | {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 733 | while( _firstChild ) {
|
Dmitry-Me | 9614f8f | 2015-04-08 10:06:06 +0300 | [diff] [blame] | 734 | TIXMLASSERT( _lastChild );
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 735 | TIXMLASSERT( _firstChild->_document == _document );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 736 | XMLNode* node = _firstChild;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 737 | Unlink( node );
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 738 |
|
Dmitry-Me | e3225b1 | 2014-09-03 11:03:11 +0400 | [diff] [blame] | 739 | DeleteNode( node );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 740 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 741 | _firstChild = _lastChild = 0;
|
Lee Thomason | d923c67 | 2012-01-23 08:44:25 -0800 | [diff] [blame] | 742 | }
|
| 743 |
|
| 744 |
|
| 745 | void XMLNode::Unlink( XMLNode* child )
|
| 746 | {
|
Dmitry-Me | bb836dc | 2014-12-24 11:54:05 +0300 | [diff] [blame] | 747 | TIXMLASSERT( child );
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 748 | TIXMLASSERT( child->_document == _document );
|
Dmitry-Me | 9614f8f | 2015-04-08 10:06:06 +0300 | [diff] [blame] | 749 | TIXMLASSERT( child->_parent == this );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 750 | if ( child == _firstChild ) {
|
| 751 | _firstChild = _firstChild->_next;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 752 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 753 | if ( child == _lastChild ) {
|
| 754 | _lastChild = _lastChild->_prev;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 755 | }
|
Lee Thomason | d923c67 | 2012-01-23 08:44:25 -0800 | [diff] [blame] | 756 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 757 | if ( child->_prev ) {
|
| 758 | child->_prev->_next = child->_next;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 759 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 760 | if ( child->_next ) {
|
| 761 | child->_next->_prev = child->_prev;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 762 | }
|
Lee Thomason | 3b7927e | 2013-10-26 21:50:46 -0700 | [diff] [blame] | 763 | child->_parent = 0;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 764 | }
|
| 765 |
|
| 766 |
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 767 | void XMLNode::DeleteChild( XMLNode* node )
|
| 768 | {
|
Dmitry-Me | bb836dc | 2014-12-24 11:54:05 +0300 | [diff] [blame] | 769 | TIXMLASSERT( node );
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 770 | TIXMLASSERT( node->_document == _document );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 771 | TIXMLASSERT( node->_parent == this );
|
Dmitry-Me | e3225b1 | 2014-09-03 11:03:11 +0400 | [diff] [blame] | 772 | DeleteNode( node );
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 773 | }
|
| 774 |
|
| 775 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 776 | XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
|
| 777 | {
|
Dmitry-Me | ed2a407 | 2014-12-12 10:38:48 +0300 | [diff] [blame] | 778 | TIXMLASSERT( addThis );
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 779 | if ( addThis->_document != _document ) {
|
| 780 | TIXMLASSERT( false );
|
| 781 | return 0;
|
| 782 | }
|
Lee Thomason | 3cebdc4 | 2015-01-05 17:16:28 -0800 | [diff] [blame] | 783 | InsertChildPreamble( addThis );
|
Lee Thomason | 3b7927e | 2013-10-26 21:50:46 -0700 | [diff] [blame] | 784 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 785 | if ( _lastChild ) {
|
| 786 | TIXMLASSERT( _firstChild );
|
| 787 | TIXMLASSERT( _lastChild->_next == 0 );
|
| 788 | _lastChild->_next = addThis;
|
| 789 | addThis->_prev = _lastChild;
|
| 790 | _lastChild = addThis;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 791 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 792 | addThis->_next = 0;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 793 | }
|
| 794 | else {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 795 | TIXMLASSERT( _firstChild == 0 );
|
| 796 | _firstChild = _lastChild = addThis;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 797 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 798 | addThis->_prev = 0;
|
| 799 | addThis->_next = 0;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 800 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 801 | addThis->_parent = this;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 802 | return addThis;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 803 | }
|
| 804 |
|
| 805 |
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 806 | XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis )
|
| 807 | {
|
Dmitry-Me | ed2a407 | 2014-12-12 10:38:48 +0300 | [diff] [blame] | 808 | TIXMLASSERT( addThis );
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 809 | if ( addThis->_document != _document ) {
|
| 810 | TIXMLASSERT( false );
|
| 811 | return 0;
|
| 812 | }
|
Lee Thomason | 3cebdc4 | 2015-01-05 17:16:28 -0800 | [diff] [blame] | 813 | InsertChildPreamble( addThis );
|
Lee Thomason | 3b7927e | 2013-10-26 21:50:46 -0700 | [diff] [blame] | 814 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 815 | if ( _firstChild ) {
|
| 816 | TIXMLASSERT( _lastChild );
|
| 817 | TIXMLASSERT( _firstChild->_prev == 0 );
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 818 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 819 | _firstChild->_prev = addThis;
|
| 820 | addThis->_next = _firstChild;
|
| 821 | _firstChild = addThis;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 822 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 823 | addThis->_prev = 0;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 824 | }
|
| 825 | else {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 826 | TIXMLASSERT( _lastChild == 0 );
|
| 827 | _firstChild = _lastChild = addThis;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 828 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 829 | addThis->_prev = 0;
|
| 830 | addThis->_next = 0;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 831 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 832 | addThis->_parent = this;
|
Dmitry-Me | 9fb2b0f | 2014-09-23 17:27:39 +0400 | [diff] [blame] | 833 | return addThis;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 834 | }
|
| 835 |
|
| 836 |
|
| 837 | XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
|
| 838 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 839 | TIXMLASSERT( addThis );
|
| 840 | if ( addThis->_document != _document ) {
|
| 841 | TIXMLASSERT( false );
|
| 842 | return 0;
|
| 843 | }
|
Lee Thomason | 3b7927e | 2013-10-26 21:50:46 -0700 | [diff] [blame] | 844 |
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 845 | TIXMLASSERT( afterThis );
|
Lee Thomason | 3b7927e | 2013-10-26 21:50:46 -0700 | [diff] [blame] | 846 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 847 | if ( afterThis->_parent != this ) {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 848 | TIXMLASSERT( false );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 849 | return 0;
|
| 850 | }
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 851 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 852 | if ( afterThis->_next == 0 ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 853 | // The last node or the only node.
|
| 854 | return InsertEndChild( addThis );
|
| 855 | }
|
Lee Thomason | 3cebdc4 | 2015-01-05 17:16:28 -0800 | [diff] [blame] | 856 | InsertChildPreamble( addThis );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 857 | addThis->_prev = afterThis;
|
| 858 | addThis->_next = afterThis->_next;
|
| 859 | afterThis->_next->_prev = addThis;
|
| 860 | afterThis->_next = addThis;
|
| 861 | addThis->_parent = this;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 862 | return addThis;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 863 | }
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 868 | const XMLElement* XMLNode::FirstChildElement( const char* value ) const
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 869 | {
|
Dmitry-Me | 2667aab | 2015-04-03 10:56:59 +0300 | [diff] [blame] | 870 | for( const XMLNode* node = _firstChild; node; node = node->_next ) {
|
| 871 | const XMLElement* element = node->ToElement();
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 872 | if ( element ) {
|
| 873 | if ( !value || XMLUtil::StringEqual( element->Name(), value ) ) {
|
| 874 | return element;
|
| 875 | }
|
| 876 | }
|
| 877 | }
|
| 878 | return 0;
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 879 | }
|
| 880 |
|
| 881 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 882 | const XMLElement* XMLNode::LastChildElement( const char* value ) const
|
| 883 | {
|
Dmitry-Me | 2667aab | 2015-04-03 10:56:59 +0300 | [diff] [blame] | 884 | for( const XMLNode* node = _lastChild; node; node = node->_prev ) {
|
| 885 | const XMLElement* element = node->ToElement();
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 886 | if ( element ) {
|
| 887 | if ( !value || XMLUtil::StringEqual( element->Name(), value ) ) {
|
| 888 | return element;
|
| 889 | }
|
| 890 | }
|
| 891 | }
|
| 892 | return 0;
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 893 | }
|
| 894 |
|
| 895 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 896 | const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
|
| 897 | {
|
Dmitry-Me | 2667aab | 2015-04-03 10:56:59 +0300 | [diff] [blame] | 898 | for( const XMLNode* node = _next; node; node = node->_next ) {
|
Dmitry-Me | b6b4e82 | 2014-08-27 17:17:47 +0400 | [diff] [blame] | 899 | const XMLElement* element = node->ToElement();
|
| 900 | if ( element
|
| 901 | && (!value || XMLUtil::StringEqual( value, node->Value() ))) {
|
| 902 | return element;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 903 | }
|
| 904 | }
|
| 905 | return 0;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 906 | }
|
| 907 |
|
| 908 |
|
| 909 | const XMLElement* XMLNode::PreviousSiblingElement( const char* value ) const
|
| 910 | {
|
Dmitry-Me | 2667aab | 2015-04-03 10:56:59 +0300 | [diff] [blame] | 911 | for( const XMLNode* node = _prev; node; node = node->_prev ) {
|
Dmitry-Me | b6b4e82 | 2014-08-27 17:17:47 +0400 | [diff] [blame] | 912 | const XMLElement* element = node->ToElement();
|
| 913 | if ( element
|
| 914 | && (!value || XMLUtil::StringEqual( value, node->Value() ))) {
|
| 915 | return element;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 916 | }
|
| 917 | }
|
| 918 | return 0;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 919 | }
|
| 920 |
|
| 921 |
|
Lee Thomason (grinliz) | 7468f11 | 2012-02-24 08:56:50 -0800 | [diff] [blame] | 922 | char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 923 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 924 | // This is a recursive method, but thinking about it "at the current level"
|
| 925 | // it is a pretty simple flat list:
|
| 926 | // <foo/>
|
| 927 | // <!-- comment -->
|
| 928 | //
|
| 929 | // With a special case:
|
| 930 | // <foo>
|
| 931 | // </foo>
|
| 932 | // <!-- comment -->
|
| 933 | //
|
| 934 | // Where the closing element (/foo) *must* be the next thing after the opening
|
| 935 | // element, and the names must match. BUT the tricky bit is that the closing
|
| 936 | // element will be read by the child.
|
| 937 | //
|
| 938 | // 'endTag' is the end tag for this node, it is returned by a call to a child.
|
| 939 | // 'parentEnd' is the end tag for the parent, which is filled in and returned.
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 940 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 941 | while( p && *p ) {
|
| 942 | XMLNode* node = 0;
|
Lee Thomason | d627776 | 2012-02-22 16:00:12 -0800 | [diff] [blame] | 943 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 944 | p = _document->Identify( p, &node );
|
Dmitry-Me | 9fcb876 | 2015-03-05 17:53:34 +0300 | [diff] [blame] | 945 | if ( node == 0 ) {
|
| 946 | break;
|
| 947 | }
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 948 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 949 | StrPair endTag;
|
| 950 | p = node->ParseDeep( p, &endTag );
|
| 951 | if ( !p ) {
|
Dmitry-Me | e3225b1 | 2014-09-03 11:03:11 +0400 | [diff] [blame] | 952 | DeleteNode( node );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 953 | if ( !_document->Error() ) {
|
| 954 | _document->SetError( XML_ERROR_PARSING, 0, 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 955 | }
|
| 956 | break;
|
| 957 | }
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 958 |
|
Sarat Addepalli | 3df007e | 2015-05-20 10:43:51 +0530 | [diff] [blame] | 959 | XMLDeclaration* decl = node->ToDeclaration();
|
Sarat Addepalli | a0f499d | 2015-05-18 09:25:17 +0530 | [diff] [blame] | 960 | if ( decl ) {
|
Sarat Addepalli | 2f0d173 | 2015-05-19 09:02:16 +0530 | [diff] [blame] | 961 | // A declaration can only be the first child of a document.
|
| 962 | // Set error, if document already has children.
|
| 963 | if ( !_document->NoChildren() ) {
|
| 964 | _document->SetError( XML_ERROR_PARSING_DECLARATION, decl->Value(), 0);
|
| 965 | DeleteNode( decl );
|
| 966 | break;
|
| 967 | }
|
Sarat Addepalli | a0f499d | 2015-05-18 09:25:17 +0530 | [diff] [blame] | 968 | }
|
Sarat Addepalli | 2f0d173 | 2015-05-19 09:02:16 +0530 | [diff] [blame] | 969 |
|
Dmitry-Me | b6b4e82 | 2014-08-27 17:17:47 +0400 | [diff] [blame] | 970 | XMLElement* ele = node->ToElement();
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 971 | if ( ele ) {
|
JayXon | e4bf6e3 | 2014-12-26 01:00:24 -0500 | [diff] [blame] | 972 | // We read the end tag. Return it to the parent.
|
| 973 | if ( ele->ClosingType() == XMLElement::CLOSING ) {
|
| 974 | if ( parentEnd ) {
|
| 975 | ele->_value.TransferTo( parentEnd );
|
| 976 | }
|
| 977 | node->_memPool->SetTracked(); // created and then immediately deleted.
|
| 978 | DeleteNode( node );
|
| 979 | return p;
|
| 980 | }
|
| 981 |
|
| 982 | // Handle an end tag returned to this level.
|
| 983 | // And handle a bunch of annoying errors.
|
Dmitry-Me | 9fb2b0f | 2014-09-23 17:27:39 +0400 | [diff] [blame] | 984 | bool mismatch = false;
|
Dmitry-Me | 3ae4f3e | 2015-01-09 15:44:16 +0300 | [diff] [blame] | 985 | if ( endTag.Empty() ) {
|
| 986 | if ( ele->ClosingType() == XMLElement::OPEN ) {
|
| 987 | mismatch = true;
|
| 988 | }
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 989 | }
|
Dmitry-Me | 3ae4f3e | 2015-01-09 15:44:16 +0300 | [diff] [blame] | 990 | else {
|
| 991 | if ( ele->ClosingType() != XMLElement::OPEN ) {
|
| 992 | mismatch = true;
|
| 993 | }
|
| 994 | else if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() ) ) {
|
Dmitry-Me | 9fb2b0f | 2014-09-23 17:27:39 +0400 | [diff] [blame] | 995 | mismatch = true;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 996 | }
|
| 997 | }
|
Dmitry-Me | 9fb2b0f | 2014-09-23 17:27:39 +0400 | [diff] [blame] | 998 | if ( mismatch ) {
|
| 999 | _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );
|
JayXon | dbfdd8f | 2014-12-12 20:07:14 -0500 | [diff] [blame] | 1000 | DeleteNode( node );
|
| 1001 | break;
|
Dmitry-Me | 9fb2b0f | 2014-09-23 17:27:39 +0400 | [diff] [blame] | 1002 | }
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1003 | }
|
JayXon | dbfdd8f | 2014-12-12 20:07:14 -0500 | [diff] [blame] | 1004 | InsertEndChild( node );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1005 | }
|
| 1006 | return 0;
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1007 | }
|
| 1008 |
|
Dmitry-Me | e3225b1 | 2014-09-03 11:03:11 +0400 | [diff] [blame] | 1009 | void XMLNode::DeleteNode( XMLNode* node )
|
| 1010 | {
|
| 1011 | if ( node == 0 ) {
|
| 1012 | return;
|
| 1013 | }
|
| 1014 | MemPool* pool = node->_memPool;
|
| 1015 | node->~XMLNode();
|
| 1016 | pool->Free( node );
|
| 1017 | }
|
| 1018 |
|
Lee Thomason | 3cebdc4 | 2015-01-05 17:16:28 -0800 | [diff] [blame] | 1019 | void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const
|
Dmitry-Me | 74e3940 | 2015-01-01 16:26:17 +0300 | [diff] [blame] | 1020 | {
|
| 1021 | TIXMLASSERT( insertThis );
|
| 1022 | TIXMLASSERT( insertThis->_document == _document );
|
| 1023 |
|
| 1024 | if ( insertThis->_parent )
|
| 1025 | insertThis->_parent->Unlink( insertThis );
|
| 1026 | else
|
| 1027 | insertThis->_memPool->SetTracked();
|
| 1028 | }
|
| 1029 |
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 1030 | // --------- XMLText ---------- //
|
Lee Thomason (grinliz) | 7468f11 | 2012-02-24 08:56:50 -0800 | [diff] [blame] | 1031 | char* XMLText::ParseDeep( char* p, StrPair* )
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 1032 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1033 | const char* start = p;
|
| 1034 | if ( this->CData() ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1035 | p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1036 | if ( !p ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1037 | _document->SetError( XML_ERROR_PARSING_CDATA, start, 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1038 | }
|
| 1039 | return p;
|
| 1040 | }
|
| 1041 | else {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1042 | int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES;
|
| 1043 | if ( _document->WhitespaceMode() == COLLAPSE_WHITESPACE ) {
|
Dmitry-Me | 5420e54 | 2015-05-20 10:51:26 +0300 | [diff] [blame] | 1044 | flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1045 | }
|
Lee Thomason (grinliz) | bc1bfb7 | 2012-08-20 22:00:38 -0700 | [diff] [blame] | 1046 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1047 | p = _value.ParseText( p, "<", flags );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1048 | if ( p && *p ) {
|
| 1049 | return p-1;
|
Dmitry-Me | 257e11b | 2015-01-09 15:50:47 +0300 | [diff] [blame] | 1050 | }
|
| 1051 | if ( !p ) {
|
Dmitry-Me | 7a7e5dc | 2015-01-01 17:58:35 +0300 | [diff] [blame] | 1052 | _document->SetError( XML_ERROR_PARSING_TEXT, start, 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1053 | }
|
| 1054 | }
|
| 1055 | return 0;
|
Lee Thomason | 5492a1c | 2012-01-23 15:32:10 -0800 | [diff] [blame] | 1056 | }
|
| 1057 |
|
| 1058 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1059 | XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const
|
| 1060 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1061 | if ( !doc ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1062 | doc = _document;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1063 | }
|
| 1064 | XMLText* text = doc->NewText( Value() ); // fixme: this will always allocate memory. Intern?
|
| 1065 | text->SetCData( this->CData() );
|
| 1066 | return text;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1067 | }
|
| 1068 |
|
| 1069 |
|
| 1070 | bool XMLText::ShallowEqual( const XMLNode* compare ) const
|
| 1071 | {
|
Dmitry-Me | 6d202ff | 2014-09-26 14:21:00 +0400 | [diff] [blame] | 1072 | const XMLText* text = compare->ToText();
|
| 1073 | return ( text && XMLUtil::StringEqual( text->Value(), Value() ) );
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1074 | }
|
| 1075 |
|
| 1076 |
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 1077 | bool XMLText::Accept( XMLVisitor* visitor ) const
|
| 1078 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1079 | TIXMLASSERT( visitor );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1080 | return visitor->Visit( *this );
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 1081 | }
|
| 1082 |
|
| 1083 |
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1084 | // --------- XMLComment ---------- //
|
| 1085 |
|
Lee Thomason | e442230 | 2012-01-20 17:59:50 -0800 | [diff] [blame] | 1086 | XMLComment::XMLComment( XMLDocument* doc ) : XMLNode( doc )
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1087 | {
|
| 1088 | }
|
| 1089 |
|
| 1090 |
|
Lee Thomason | ce0763e | 2012-01-11 15:43:54 -0800 | [diff] [blame] | 1091 | XMLComment::~XMLComment()
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1092 | {
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1093 | }
|
| 1094 |
|
| 1095 |
|
Lee Thomason (grinliz) | 7468f11 | 2012-02-24 08:56:50 -0800 | [diff] [blame] | 1096 | char* XMLComment::ParseDeep( char* p, StrPair* )
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1097 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1098 | // Comment parses as text.
|
| 1099 | const char* start = p;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1100 | p = _value.ParseText( p, "-->", StrPair::COMMENT );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1101 | if ( p == 0 ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1102 | _document->SetError( XML_ERROR_PARSING_COMMENT, start, 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1103 | }
|
| 1104 | return p;
|
U-Lama\Lee | 4cee611 | 2011-12-31 14:58:18 -0800 | [diff] [blame] | 1105 | }
|
| 1106 |
|
| 1107 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1108 | XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const
|
| 1109 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1110 | if ( !doc ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1111 | doc = _document;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1112 | }
|
| 1113 | XMLComment* comment = doc->NewComment( Value() ); // fixme: this will always allocate memory. Intern?
|
| 1114 | return comment;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1115 | }
|
| 1116 |
|
| 1117 |
|
| 1118 | bool XMLComment::ShallowEqual( const XMLNode* compare ) const
|
| 1119 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1120 | TIXMLASSERT( compare );
|
Dmitry-Me | b6b4e82 | 2014-08-27 17:17:47 +0400 | [diff] [blame] | 1121 | const XMLComment* comment = compare->ToComment();
|
| 1122 | return ( comment && XMLUtil::StringEqual( comment->Value(), Value() ));
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1123 | }
|
| 1124 |
|
| 1125 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 1126 | bool XMLComment::Accept( XMLVisitor* visitor ) const
|
| 1127 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1128 | TIXMLASSERT( visitor );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1129 | return visitor->Visit( *this );
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 1130 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 1131 |
|
| 1132 |
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1133 | // --------- XMLDeclaration ---------- //
|
| 1134 |
|
| 1135 | XMLDeclaration::XMLDeclaration( XMLDocument* doc ) : XMLNode( doc )
|
| 1136 | {
|
| 1137 | }
|
| 1138 |
|
| 1139 |
|
| 1140 | XMLDeclaration::~XMLDeclaration()
|
| 1141 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1142 | //printf( "~XMLDeclaration\n" );
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1143 | }
|
| 1144 |
|
| 1145 |
|
Lee Thomason (grinliz) | 7468f11 | 2012-02-24 08:56:50 -0800 | [diff] [blame] | 1146 | char* XMLDeclaration::ParseDeep( char* p, StrPair* )
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1147 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1148 | // Declaration parses as text.
|
| 1149 | const char* start = p;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1150 | p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1151 | if ( p == 0 ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1152 | _document->SetError( XML_ERROR_PARSING_DECLARATION, start, 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1153 | }
|
| 1154 | return p;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1155 | }
|
| 1156 |
|
| 1157 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1158 | XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const
|
| 1159 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1160 | if ( !doc ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1161 | doc = _document;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1162 | }
|
| 1163 | XMLDeclaration* dec = doc->NewDeclaration( Value() ); // fixme: this will always allocate memory. Intern?
|
| 1164 | return dec;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1165 | }
|
| 1166 |
|
| 1167 |
|
| 1168 | bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const
|
| 1169 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1170 | TIXMLASSERT( compare );
|
Dmitry-Me | b6b4e82 | 2014-08-27 17:17:47 +0400 | [diff] [blame] | 1171 | const XMLDeclaration* declaration = compare->ToDeclaration();
|
| 1172 | return ( declaration && XMLUtil::StringEqual( declaration->Value(), Value() ));
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1173 | }
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1177 | bool XMLDeclaration::Accept( XMLVisitor* visitor ) const
|
| 1178 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1179 | TIXMLASSERT( visitor );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1180 | return visitor->Visit( *this );
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1181 | }
|
| 1182 |
|
| 1183 | // --------- XMLUnknown ---------- //
|
| 1184 |
|
| 1185 | XMLUnknown::XMLUnknown( XMLDocument* doc ) : XMLNode( doc )
|
| 1186 | {
|
| 1187 | }
|
| 1188 |
|
| 1189 |
|
| 1190 | XMLUnknown::~XMLUnknown()
|
| 1191 | {
|
| 1192 | }
|
| 1193 |
|
| 1194 |
|
Lee Thomason (grinliz) | 7468f11 | 2012-02-24 08:56:50 -0800 | [diff] [blame] | 1195 | char* XMLUnknown::ParseDeep( char* p, StrPair* )
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1196 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1197 | // Unknown parses as text.
|
| 1198 | const char* start = p;
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1199 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1200 | p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1201 | if ( !p ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1202 | _document->SetError( XML_ERROR_PARSING_UNKNOWN, start, 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1203 | }
|
| 1204 | return p;
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1205 | }
|
| 1206 |
|
| 1207 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1208 | XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const
|
| 1209 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1210 | if ( !doc ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1211 | doc = _document;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1212 | }
|
| 1213 | XMLUnknown* text = doc->NewUnknown( Value() ); // fixme: this will always allocate memory. Intern?
|
| 1214 | return text;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1215 | }
|
| 1216 |
|
| 1217 |
|
| 1218 | bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const
|
| 1219 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1220 | TIXMLASSERT( compare );
|
Dmitry-Me | b6b4e82 | 2014-08-27 17:17:47 +0400 | [diff] [blame] | 1221 | const XMLUnknown* unknown = compare->ToUnknown();
|
| 1222 | return ( unknown && XMLUtil::StringEqual( unknown->Value(), Value() ));
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1223 | }
|
| 1224 |
|
| 1225 |
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1226 | bool XMLUnknown::Accept( XMLVisitor* visitor ) const
|
| 1227 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1228 | TIXMLASSERT( visitor );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1229 | return visitor->Visit( *this );
|
Lee Thomason | 50f97b2 | 2012-02-11 16:33:40 -0800 | [diff] [blame] | 1230 | }
|
| 1231 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1232 | // --------- XMLAttribute ---------- //
|
Michael Daumling | 2162688 | 2013-10-22 17:03:37 +0200 | [diff] [blame] | 1233 |
|
| 1234 | const char* XMLAttribute::Name() const
|
| 1235 | {
|
| 1236 | return _name.GetStr();
|
| 1237 | }
|
| 1238 |
|
| 1239 | const char* XMLAttribute::Value() const
|
| 1240 | {
|
| 1241 | return _value.GetStr();
|
| 1242 | }
|
| 1243 |
|
Lee Thomason | 6f381b7 | 2012-03-02 12:59:39 -0800 | [diff] [blame] | 1244 | char* XMLAttribute::ParseDeep( char* p, bool processEntities )
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1245 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1246 | // Parse using the name rules: bug fix, was using ParseText before
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1247 | p = _name.ParseName( p );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1248 | if ( !p || !*p ) {
|
| 1249 | return 0;
|
| 1250 | }
|
Lee Thomason | 22aead1 | 2012-01-23 13:29:35 -0800 | [diff] [blame] | 1251 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1252 | // Skip white space before =
|
| 1253 | p = XMLUtil::SkipWhiteSpace( p );
|
Dmitry-Me | bb836dc | 2014-12-24 11:54:05 +0300 | [diff] [blame] | 1254 | if ( *p != '=' ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1255 | return 0;
|
| 1256 | }
|
Lee Thomason | 78a773d | 2012-07-02 10:10:19 -0700 | [diff] [blame] | 1257 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1258 | ++p; // move up to opening quote
|
| 1259 | p = XMLUtil::SkipWhiteSpace( p );
|
| 1260 | if ( *p != '\"' && *p != '\'' ) {
|
| 1261 | return 0;
|
| 1262 | }
|
Lee Thomason | 78a773d | 2012-07-02 10:10:19 -0700 | [diff] [blame] | 1263 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1264 | char endTag[2] = { *p, 0 };
|
| 1265 | ++p; // move past opening quote
|
Lee Thomason | 78a773d | 2012-07-02 10:10:19 -0700 | [diff] [blame] | 1266 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1267 | p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1268 | return p;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1269 | }
|
| 1270 |
|
| 1271 |
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 1272 | void XMLAttribute::SetName( const char* n )
|
| 1273 | {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1274 | _name.SetStr( n );
|
U-Stream\Lee | 09a11c5 | 2012-02-17 08:31:16 -0800 | [diff] [blame] | 1275 | }
|
| 1276 |
|
| 1277 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1278 | XMLError XMLAttribute::QueryIntValue( int* value ) const
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1279 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1280 | if ( XMLUtil::ToInt( Value(), value )) {
|
| 1281 | return XML_NO_ERROR;
|
| 1282 | }
|
| 1283 | return XML_WRONG_ATTRIBUTE_TYPE;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1284 | }
|
| 1285 |
|
| 1286 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1287 | XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1288 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1289 | if ( XMLUtil::ToUnsigned( Value(), value )) {
|
| 1290 | return XML_NO_ERROR;
|
| 1291 | }
|
| 1292 | return XML_WRONG_ATTRIBUTE_TYPE;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1293 | }
|
| 1294 |
|
| 1295 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1296 | XMLError XMLAttribute::QueryBoolValue( bool* value ) const
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1297 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1298 | if ( XMLUtil::ToBool( Value(), value )) {
|
| 1299 | return XML_NO_ERROR;
|
| 1300 | }
|
| 1301 | return XML_WRONG_ATTRIBUTE_TYPE;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1302 | }
|
| 1303 |
|
| 1304 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1305 | XMLError XMLAttribute::QueryFloatValue( float* value ) const
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1306 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1307 | if ( XMLUtil::ToFloat( Value(), value )) {
|
| 1308 | return XML_NO_ERROR;
|
| 1309 | }
|
| 1310 | return XML_WRONG_ATTRIBUTE_TYPE;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1311 | }
|
| 1312 |
|
| 1313 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1314 | XMLError XMLAttribute::QueryDoubleValue( double* value ) const
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1315 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1316 | if ( XMLUtil::ToDouble( Value(), value )) {
|
| 1317 | return XML_NO_ERROR;
|
| 1318 | }
|
| 1319 | return XML_WRONG_ATTRIBUTE_TYPE;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1320 | }
|
| 1321 |
|
| 1322 |
|
| 1323 | void XMLAttribute::SetAttribute( const char* v )
|
| 1324 | {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1325 | _value.SetStr( v );
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1326 | }
|
| 1327 |
|
| 1328 |
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1329 | void XMLAttribute::SetAttribute( int v )
|
| 1330 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1331 | char buf[BUF_SIZE];
|
| 1332 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1333 | _value.SetStr( buf );
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1334 | }
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 1335 |
|
| 1336 |
|
| 1337 | void XMLAttribute::SetAttribute( unsigned v )
|
| 1338 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1339 | char buf[BUF_SIZE];
|
| 1340 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1341 | _value.SetStr( buf );
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 1342 | }
|
| 1343 |
|
| 1344 |
|
| 1345 | void XMLAttribute::SetAttribute( bool v )
|
| 1346 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1347 | char buf[BUF_SIZE];
|
| 1348 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1349 | _value.SetStr( buf );
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 1350 | }
|
| 1351 |
|
| 1352 | void XMLAttribute::SetAttribute( double v )
|
| 1353 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1354 | char buf[BUF_SIZE];
|
| 1355 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1356 | _value.SetStr( buf );
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 1357 | }
|
| 1358 |
|
| 1359 | void XMLAttribute::SetAttribute( float v )
|
| 1360 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1361 | char buf[BUF_SIZE];
|
| 1362 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1363 | _value.SetStr( buf );
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 1364 | }
|
| 1365 |
|
Lee Thomason | dadcdfa | 2012-01-18 17:55:48 -0800 | [diff] [blame] | 1366 |
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1367 | // --------- XMLElement ---------- //
|
| 1368 | XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ),
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1369 | _closingType( 0 ),
|
| 1370 | _rootAttribute( 0 )
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1371 | {
|
| 1372 | }
|
| 1373 |
|
| 1374 |
|
| 1375 | XMLElement::~XMLElement()
|
| 1376 | {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1377 | while( _rootAttribute ) {
|
| 1378 | XMLAttribute* next = _rootAttribute->_next;
|
Dmitry-Me | e3225b1 | 2014-09-03 11:03:11 +0400 | [diff] [blame] | 1379 | DeleteAttribute( _rootAttribute );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1380 | _rootAttribute = next;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1381 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1382 | }
|
| 1383 |
|
| 1384 |
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 1385 | const XMLAttribute* XMLElement::FindAttribute( const char* name ) const
|
| 1386 | {
|
Dmitry-Me | 3659fe1 | 2014-09-04 11:33:49 +0400 | [diff] [blame] | 1387 | for( XMLAttribute* a = _rootAttribute; a; a = a->_next ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1388 | if ( XMLUtil::StringEqual( a->Name(), name ) ) {
|
| 1389 | return a;
|
| 1390 | }
|
| 1391 | }
|
| 1392 | return 0;
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 1393 | }
|
| 1394 |
|
| 1395 |
|
Lee Thomason | 8ba7f7d | 2012-03-24 13:04:04 -0700 | [diff] [blame] | 1396 | const char* XMLElement::Attribute( const char* name, const char* value ) const
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1397 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1398 | const XMLAttribute* a = FindAttribute( name );
|
| 1399 | if ( !a ) {
|
| 1400 | return 0;
|
| 1401 | }
|
| 1402 | if ( !value || XMLUtil::StringEqual( a->Value(), value )) {
|
| 1403 | return a->Value();
|
| 1404 | }
|
| 1405 | return 0;
|
Lee Thomason | 8ba7f7d | 2012-03-24 13:04:04 -0700 | [diff] [blame] | 1406 | }
|
| 1407 |
|
| 1408 |
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1409 | const char* XMLElement::GetText() const
|
| 1410 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1411 | if ( FirstChild() && FirstChild()->ToText() ) {
|
Dmitry-Me | 097339a | 2014-09-29 13:20:29 +0400 | [diff] [blame] | 1412 | return FirstChild()->Value();
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1413 | }
|
| 1414 | return 0;
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1415 | }
|
| 1416 |
|
| 1417 |
|
Uli Kusterer | 8fe342a | 2014-01-21 01:12:47 +0100 | [diff] [blame] | 1418 | void XMLElement::SetText( const char* inText )
|
| 1419 | {
|
Uli Kusterer | 869bb59 | 2014-01-21 01:36:16 +0100 | [diff] [blame] | 1420 | if ( FirstChild() && FirstChild()->ToText() )
|
Uli Kusterer | 8fe342a | 2014-01-21 01:12:47 +0100 | [diff] [blame] | 1421 | FirstChild()->SetValue( inText );
|
| 1422 | else {
|
| 1423 | XMLText* theText = GetDocument()->NewText( inText );
|
| 1424 | InsertFirstChild( theText );
|
| 1425 | }
|
| 1426 | }
|
| 1427 |
|
Lee Thomason | 5bb2d80 | 2014-01-24 10:42:57 -0800 | [diff] [blame] | 1428 |
|
| 1429 | void XMLElement::SetText( int v )
|
| 1430 | {
|
| 1431 | char buf[BUF_SIZE];
|
| 1432 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
| 1433 | SetText( buf );
|
| 1434 | }
|
| 1435 |
|
| 1436 |
|
| 1437 | void XMLElement::SetText( unsigned v )
|
| 1438 | {
|
| 1439 | char buf[BUF_SIZE];
|
| 1440 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
| 1441 | SetText( buf );
|
| 1442 | }
|
| 1443 |
|
| 1444 |
|
| 1445 | void XMLElement::SetText( bool v )
|
| 1446 | {
|
| 1447 | char buf[BUF_SIZE];
|
| 1448 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
| 1449 | SetText( buf );
|
| 1450 | }
|
| 1451 |
|
| 1452 |
|
| 1453 | void XMLElement::SetText( float v )
|
| 1454 | {
|
| 1455 | char buf[BUF_SIZE];
|
| 1456 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
| 1457 | SetText( buf );
|
| 1458 | }
|
| 1459 |
|
| 1460 |
|
| 1461 | void XMLElement::SetText( double v )
|
| 1462 | {
|
| 1463 | char buf[BUF_SIZE];
|
| 1464 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
| 1465 | SetText( buf );
|
| 1466 | }
|
| 1467 |
|
| 1468 |
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1469 | XMLError XMLElement::QueryIntText( int* ival ) const
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1470 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1471 | if ( FirstChild() && FirstChild()->ToText() ) {
|
Dmitry-Me | 097339a | 2014-09-29 13:20:29 +0400 | [diff] [blame] | 1472 | const char* t = FirstChild()->Value();
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1473 | if ( XMLUtil::ToInt( t, ival ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1474 | return XML_SUCCESS;
|
| 1475 | }
|
| 1476 | return XML_CAN_NOT_CONVERT_TEXT;
|
| 1477 | }
|
| 1478 | return XML_NO_TEXT_NODE;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1479 | }
|
| 1480 |
|
| 1481 |
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1482 | XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1483 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1484 | if ( FirstChild() && FirstChild()->ToText() ) {
|
Dmitry-Me | 097339a | 2014-09-29 13:20:29 +0400 | [diff] [blame] | 1485 | const char* t = FirstChild()->Value();
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1486 | if ( XMLUtil::ToUnsigned( t, uval ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1487 | return XML_SUCCESS;
|
| 1488 | }
|
| 1489 | return XML_CAN_NOT_CONVERT_TEXT;
|
| 1490 | }
|
| 1491 | return XML_NO_TEXT_NODE;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1492 | }
|
| 1493 |
|
| 1494 |
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1495 | XMLError XMLElement::QueryBoolText( bool* bval ) const
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1496 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1497 | if ( FirstChild() && FirstChild()->ToText() ) {
|
Dmitry-Me | 097339a | 2014-09-29 13:20:29 +0400 | [diff] [blame] | 1498 | const char* t = FirstChild()->Value();
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1499 | if ( XMLUtil::ToBool( t, bval ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1500 | return XML_SUCCESS;
|
| 1501 | }
|
| 1502 | return XML_CAN_NOT_CONVERT_TEXT;
|
| 1503 | }
|
| 1504 | return XML_NO_TEXT_NODE;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1505 | }
|
| 1506 |
|
| 1507 |
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1508 | XMLError XMLElement::QueryDoubleText( double* dval ) const
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1509 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1510 | if ( FirstChild() && FirstChild()->ToText() ) {
|
Dmitry-Me | 097339a | 2014-09-29 13:20:29 +0400 | [diff] [blame] | 1511 | const char* t = FirstChild()->Value();
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1512 | if ( XMLUtil::ToDouble( t, dval ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1513 | return XML_SUCCESS;
|
| 1514 | }
|
| 1515 | return XML_CAN_NOT_CONVERT_TEXT;
|
| 1516 | }
|
| 1517 | return XML_NO_TEXT_NODE;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1518 | }
|
| 1519 |
|
| 1520 |
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1521 | XMLError XMLElement::QueryFloatText( float* fval ) const
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1522 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1523 | if ( FirstChild() && FirstChild()->ToText() ) {
|
Dmitry-Me | 097339a | 2014-09-29 13:20:29 +0400 | [diff] [blame] | 1524 | const char* t = FirstChild()->Value();
|
MortenMacFly | 4ee49f1 | 2013-01-14 20:03:14 +0100 | [diff] [blame] | 1525 | if ( XMLUtil::ToFloat( t, fval ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1526 | return XML_SUCCESS;
|
| 1527 | }
|
| 1528 | return XML_CAN_NOT_CONVERT_TEXT;
|
| 1529 | }
|
| 1530 | return XML_NO_TEXT_NODE;
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 1531 | }
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 1535 | XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
|
| 1536 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1537 | XMLAttribute* last = 0;
|
| 1538 | XMLAttribute* attrib = 0;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1539 | for( attrib = _rootAttribute;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1540 | attrib;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1541 | last = attrib, attrib = attrib->_next ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1542 | if ( XMLUtil::StringEqual( attrib->Name(), name ) ) {
|
| 1543 | break;
|
| 1544 | }
|
| 1545 | }
|
| 1546 | if ( !attrib ) {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 1547 | TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1548 | attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
| 1549 | attrib->_memPool = &_document->_attributePool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1550 | if ( last ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1551 | last->_next = attrib;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1552 | }
|
| 1553 | else {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1554 | _rootAttribute = attrib;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1555 | }
|
| 1556 | attrib->SetName( name );
|
Lee Thomason | 5b0a677 | 2012-11-19 13:54:42 -0800 | [diff] [blame] | 1557 | attrib->_memPool->SetTracked(); // always created and linked.
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1558 | }
|
| 1559 | return attrib;
|
Lee Thomason | 1a1d4a7 | 2012-02-15 09:09:25 -0800 | [diff] [blame] | 1560 | }
|
| 1561 |
|
| 1562 |
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 1563 | void XMLElement::DeleteAttribute( const char* name )
|
| 1564 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1565 | XMLAttribute* prev = 0;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1566 | for( XMLAttribute* a=_rootAttribute; a; a=a->_next ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1567 | if ( XMLUtil::StringEqual( name, a->Name() ) ) {
|
| 1568 | if ( prev ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1569 | prev->_next = a->_next;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1570 | }
|
| 1571 | else {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1572 | _rootAttribute = a->_next;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1573 | }
|
Dmitry-Me | e3225b1 | 2014-09-03 11:03:11 +0400 | [diff] [blame] | 1574 | DeleteAttribute( a );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1575 | break;
|
| 1576 | }
|
| 1577 | prev = a;
|
| 1578 | }
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 1579 | }
|
| 1580 |
|
| 1581 |
|
Lee Thomason (grinliz) | 46a14cf | 2012-02-23 22:27:28 -0800 | [diff] [blame] | 1582 | char* XMLElement::ParseAttributes( char* p )
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1583 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1584 | const char* start = p;
|
| 1585 | XMLAttribute* prevAttribute = 0;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1586 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1587 | // Read the attributes.
|
| 1588 | while( p ) {
|
| 1589 | p = XMLUtil::SkipWhiteSpace( p );
|
Dmitry-Me | bb836dc | 2014-12-24 11:54:05 +0300 | [diff] [blame] | 1590 | if ( !(*p) ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1591 | _document->SetError( XML_ERROR_PARSING_ELEMENT, start, Name() );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1592 | return 0;
|
| 1593 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1594 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1595 | // attribute.
|
Martinsh Shaiters | c6d02f4 | 2013-01-26 21:22:57 +0200 | [diff] [blame] | 1596 | if (XMLUtil::IsNameStartChar( *p ) ) {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 1597 | TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1598 | XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
|
| 1599 | attrib->_memPool = &_document->_attributePool;
|
Lee Thomason | 5b0a677 | 2012-11-19 13:54:42 -0800 | [diff] [blame] | 1600 | attrib->_memPool->SetTracked();
|
Lee Thomason | d198322 | 2012-02-06 08:41:24 -0800 | [diff] [blame] | 1601 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1602 | p = attrib->ParseDeep( p, _document->ProcessEntities() );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1603 | if ( !p || Attribute( attrib->Name() ) ) {
|
Dmitry-Me | e3225b1 | 2014-09-03 11:03:11 +0400 | [diff] [blame] | 1604 | DeleteAttribute( attrib );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1605 | _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1606 | return 0;
|
| 1607 | }
|
| 1608 | // There is a minor bug here: if the attribute in the source xml
|
| 1609 | // document is duplicated, it will not be detected and the
|
| 1610 | // attribute will be doubly added. However, tracking the 'prevAttribute'
|
| 1611 | // avoids re-scanning the attribute list. Preferring performance for
|
| 1612 | // now, may reconsider in the future.
|
| 1613 | if ( prevAttribute ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1614 | prevAttribute->_next = attrib;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1615 | }
|
| 1616 | else {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1617 | _rootAttribute = attrib;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1618 | }
|
| 1619 | prevAttribute = attrib;
|
| 1620 | }
|
| 1621 | // end of the tag
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1622 | else if ( *p == '>' ) {
|
| 1623 | ++p;
|
| 1624 | break;
|
| 1625 | }
|
Dmitry-Me | ccd267a | 2015-04-10 15:42:54 +0300 | [diff] [blame] | 1626 | // end of the tag
|
| 1627 | else if ( *p == '/' && *(p+1) == '>' ) {
|
| 1628 | _closingType = CLOSED;
|
| 1629 | return p+2; // done; sealed element.
|
| 1630 | }
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1631 | else {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1632 | _document->SetError( XML_ERROR_PARSING_ELEMENT, start, p );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1633 | return 0;
|
| 1634 | }
|
| 1635 | }
|
| 1636 | return p;
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1637 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1638 |
|
Dmitry-Me | e3225b1 | 2014-09-03 11:03:11 +0400 | [diff] [blame] | 1639 | void XMLElement::DeleteAttribute( XMLAttribute* attribute )
|
| 1640 | {
|
| 1641 | if ( attribute == 0 ) {
|
| 1642 | return;
|
| 1643 | }
|
| 1644 | MemPool* pool = attribute->_memPool;
|
| 1645 | attribute->~XMLAttribute();
|
| 1646 | pool->Free( attribute );
|
| 1647 | }
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1648 |
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1649 | //
|
| 1650 | // <ele></ele>
|
| 1651 | // <ele>foo<b>bar</b></ele>
|
| 1652 | //
|
Lee Thomason (grinliz) | 7468f11 | 2012-02-24 08:56:50 -0800 | [diff] [blame] | 1653 | char* XMLElement::ParseDeep( char* p, StrPair* strPair )
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1654 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1655 | // Read the element name.
|
| 1656 | p = XMLUtil::SkipWhiteSpace( p );
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1657 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1658 | // The closing element is the </element> form. It is
|
| 1659 | // parsed just like a regular element then deleted from
|
| 1660 | // the DOM.
|
| 1661 | if ( *p == '/' ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1662 | _closingType = CLOSING;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1663 | ++p;
|
| 1664 | }
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1665 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1666 | p = _value.ParseName( p );
|
| 1667 | if ( _value.Empty() ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1668 | return 0;
|
| 1669 | }
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1670 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1671 | p = ParseAttributes( p );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1672 | if ( !p || !*p || _closingType ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1673 | return p;
|
| 1674 | }
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 1675 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1676 | p = XMLNode::ParseDeep( p, strPair );
|
| 1677 | return p;
|
Lee Thomason | 8a5dfee | 2012-01-18 17:43:40 -0800 | [diff] [blame] | 1678 | }
|
| 1679 |
|
| 1680 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1681 |
|
| 1682 | XMLNode* XMLElement::ShallowClone( XMLDocument* doc ) const
|
| 1683 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1684 | if ( !doc ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1685 | doc = _document;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1686 | }
|
| 1687 | XMLElement* element = doc->NewElement( Value() ); // fixme: this will always allocate memory. Intern?
|
| 1688 | for( const XMLAttribute* a=FirstAttribute(); a; a=a->Next() ) {
|
| 1689 | element->SetAttribute( a->Name(), a->Value() ); // fixme: this will always allocate memory. Intern?
|
| 1690 | }
|
| 1691 | return element;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1692 | }
|
| 1693 |
|
| 1694 |
|
| 1695 | bool XMLElement::ShallowEqual( const XMLNode* compare ) const
|
| 1696 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1697 | TIXMLASSERT( compare );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1698 | const XMLElement* other = compare->ToElement();
|
| 1699 | if ( other && XMLUtil::StringEqual( other->Value(), Value() )) {
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1700 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1701 | const XMLAttribute* a=FirstAttribute();
|
| 1702 | const XMLAttribute* b=other->FirstAttribute();
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1703 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1704 | while ( a && b ) {
|
| 1705 | if ( !XMLUtil::StringEqual( a->Value(), b->Value() ) ) {
|
| 1706 | return false;
|
| 1707 | }
|
| 1708 | a = a->Next();
|
| 1709 | b = b->Next();
|
| 1710 | }
|
| 1711 | if ( a || b ) {
|
| 1712 | // different count
|
| 1713 | return false;
|
| 1714 | }
|
| 1715 | return true;
|
| 1716 | }
|
| 1717 | return false;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1718 | }
|
| 1719 |
|
| 1720 |
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 1721 | bool XMLElement::Accept( XMLVisitor* visitor ) const
|
| 1722 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1723 | TIXMLASSERT( visitor );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1724 | if ( visitor->VisitEnter( *this, _rootAttribute ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1725 | for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) {
|
| 1726 | if ( !node->Accept( visitor ) ) {
|
| 1727 | break;
|
| 1728 | }
|
| 1729 | }
|
| 1730 | }
|
| 1731 | return visitor->VisitExit( *this );
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 1732 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 1733 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1734 |
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1735 | // --------- XMLDocument ----------- //
|
Lee Thomason | 331596e | 2014-09-11 14:56:43 -0700 | [diff] [blame] | 1736 |
|
| 1737 | // Warning: List must match 'enum XMLError'
|
| 1738 | const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
|
| 1739 | "XML_SUCCESS",
|
| 1740 | "XML_NO_ATTRIBUTE",
|
| 1741 | "XML_WRONG_ATTRIBUTE_TYPE",
|
| 1742 | "XML_ERROR_FILE_NOT_FOUND",
|
| 1743 | "XML_ERROR_FILE_COULD_NOT_BE_OPENED",
|
| 1744 | "XML_ERROR_FILE_READ_ERROR",
|
| 1745 | "XML_ERROR_ELEMENT_MISMATCH",
|
| 1746 | "XML_ERROR_PARSING_ELEMENT",
|
| 1747 | "XML_ERROR_PARSING_ATTRIBUTE",
|
| 1748 | "XML_ERROR_IDENTIFYING_TAG",
|
| 1749 | "XML_ERROR_PARSING_TEXT",
|
| 1750 | "XML_ERROR_PARSING_CDATA",
|
| 1751 | "XML_ERROR_PARSING_COMMENT",
|
| 1752 | "XML_ERROR_PARSING_DECLARATION",
|
| 1753 | "XML_ERROR_PARSING_UNKNOWN",
|
| 1754 | "XML_ERROR_EMPTY_DOCUMENT",
|
| 1755 | "XML_ERROR_MISMATCHED_ELEMENT",
|
| 1756 | "XML_ERROR_PARSING",
|
| 1757 | "XML_CAN_NOT_CONVERT_TEXT",
|
| 1758 | "XML_NO_TEXT_NODE"
|
| 1759 | };
|
| 1760 |
|
| 1761 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1762 | XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1763 | XMLNode( 0 ),
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1764 | _writeBOM( false ),
|
| 1765 | _processEntities( processEntities ),
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1766 | _errorID( XML_NO_ERROR ),
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1767 | _whitespace( whitespace ),
|
| 1768 | _errorStr1( 0 ),
|
| 1769 | _errorStr2( 0 ),
|
| 1770 | _charBuffer( 0 )
|
U-Lama\Lee | 560bd47 | 2011-12-28 19:42:49 -0800 | [diff] [blame] | 1771 | {
|
Dmitry-Me | 8dd493b | 2015-07-02 13:59:30 +0300 | [diff] [blame^] | 1772 | // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+)
|
| 1773 | _document = this;
|
U-Lama\Lee | 560bd47 | 2011-12-28 19:42:49 -0800 | [diff] [blame] | 1774 | }
|
U-Lama\Lee | e13c3e6 | 2011-12-28 14:36:55 -0800 | [diff] [blame] | 1775 |
|
| 1776 |
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1777 | XMLDocument::~XMLDocument()
|
| 1778 | {
|
Lee Thomason | f07b952 | 2014-10-30 13:25:12 -0700 | [diff] [blame] | 1779 | Clear();
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1780 | }
|
| 1781 |
|
| 1782 |
|
Martinsh Shaiters | a9d42b0 | 2013-01-30 11:14:27 +0200 | [diff] [blame] | 1783 | void XMLDocument::Clear()
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 1784 | {
|
Martinsh Shaiters | a9d42b0 | 2013-01-30 11:14:27 +0200 | [diff] [blame] | 1785 | DeleteChildren();
|
| 1786 |
|
Dmitry-Me | ab37df8 | 2014-11-28 12:08:36 +0300 | [diff] [blame] | 1787 | #ifdef DEBUG
|
| 1788 | const bool hadError = Error();
|
| 1789 | #endif
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1790 | _errorID = XML_NO_ERROR;
|
| 1791 | _errorStr1 = 0;
|
| 1792 | _errorStr2 = 0;
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 1793 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1794 | delete [] _charBuffer;
|
| 1795 | _charBuffer = 0;
|
Lee Thomason | f07b952 | 2014-10-30 13:25:12 -0700 | [diff] [blame] | 1796 |
|
| 1797 | #if 0
|
| 1798 | _textPool.Trace( "text" );
|
| 1799 | _elementPool.Trace( "element" );
|
| 1800 | _commentPool.Trace( "comment" );
|
| 1801 | _attributePool.Trace( "attribute" );
|
| 1802 | #endif
|
| 1803 |
|
| 1804 | #ifdef DEBUG
|
Dmitry-Me | ab37df8 | 2014-11-28 12:08:36 +0300 | [diff] [blame] | 1805 | if ( !hadError ) {
|
Lee Thomason | f07b952 | 2014-10-30 13:25:12 -0700 | [diff] [blame] | 1806 | TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() );
|
| 1807 | TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() );
|
| 1808 | TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() );
|
| 1809 | TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() );
|
| 1810 | }
|
| 1811 | #endif
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 1812 | }
|
| 1813 |
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1814 |
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 1815 | XMLElement* XMLDocument::NewElement( const char* name )
|
| 1816 | {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 1817 | TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1818 | XMLElement* ele = new (_elementPool.Alloc()) XMLElement( this );
|
| 1819 | ele->_memPool = &_elementPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1820 | ele->SetName( name );
|
| 1821 | return ele;
|
Lee Thomason | 2c85a71 | 2012-01-31 08:24:24 -0800 | [diff] [blame] | 1822 | }
|
| 1823 |
|
| 1824 |
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1825 | XMLComment* XMLDocument::NewComment( const char* str )
|
| 1826 | {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 1827 | TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1828 | XMLComment* comment = new (_commentPool.Alloc()) XMLComment( this );
|
| 1829 | comment->_memPool = &_commentPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1830 | comment->SetValue( str );
|
| 1831 | return comment;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1832 | }
|
| 1833 |
|
| 1834 |
|
| 1835 | XMLText* XMLDocument::NewText( const char* str )
|
| 1836 | {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 1837 | TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1838 | XMLText* text = new (_textPool.Alloc()) XMLText( this );
|
| 1839 | text->_memPool = &_textPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1840 | text->SetValue( str );
|
| 1841 | return text;
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1842 | }
|
| 1843 |
|
| 1844 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1845 | XMLDeclaration* XMLDocument::NewDeclaration( const char* str )
|
| 1846 | {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 1847 | TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1848 | XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration( this );
|
| 1849 | dec->_memPool = &_commentPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1850 | dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" );
|
| 1851 | return dec;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1852 | }
|
| 1853 |
|
| 1854 |
|
| 1855 | XMLUnknown* XMLDocument::NewUnknown( const char* str )
|
| 1856 | {
|
Dmitry-Me | e6a95ce | 2014-12-10 09:10:27 +0300 | [diff] [blame] | 1857 | TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1858 | XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown( this );
|
| 1859 | unk->_memPool = &_commentPool;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1860 | unk->SetValue( str );
|
| 1861 | return unk;
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1862 | }
|
| 1863 |
|
Dmitry-Me | 01578db | 2014-08-19 10:18:48 +0400 | [diff] [blame] | 1864 | static FILE* callfopen( const char* filepath, const char* mode )
|
| 1865 | {
|
Dmitry-Me | abb2d04 | 2014-12-09 12:59:31 +0300 | [diff] [blame] | 1866 | TIXMLASSERT( filepath );
|
| 1867 | TIXMLASSERT( mode );
|
Dmitry-Me | 01578db | 2014-08-19 10:18:48 +0400 | [diff] [blame] | 1868 | #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
|
| 1869 | FILE* fp = 0;
|
| 1870 | errno_t err = fopen_s( &fp, filepath, mode );
|
| 1871 | if ( err ) {
|
| 1872 | return 0;
|
| 1873 | }
|
| 1874 | #else
|
| 1875 | FILE* fp = fopen( filepath, mode );
|
| 1876 | #endif
|
| 1877 | return fp;
|
| 1878 | }
|
Lee Thomason | cd011bc | 2014-12-17 10:41:34 -0800 | [diff] [blame] | 1879 |
|
| 1880 | void XMLDocument::DeleteNode( XMLNode* node ) {
|
| 1881 | TIXMLASSERT( node );
|
| 1882 | TIXMLASSERT(node->_document == this );
|
| 1883 | if (node->_parent) {
|
| 1884 | node->_parent->DeleteChild( node );
|
| 1885 | }
|
| 1886 | else {
|
| 1887 | // Isn't in the tree.
|
| 1888 | // Use the parent delete.
|
| 1889 | // Also, we need to mark it tracked: we 'know'
|
| 1890 | // it was never used.
|
| 1891 | node->_memPool->SetTracked();
|
| 1892 | // Call the static XMLNode version:
|
| 1893 | XMLNode::DeleteNode(node);
|
| 1894 | }
|
| 1895 | }
|
| 1896 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 1897 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1898 | XMLError XMLDocument::LoadFile( const char* filename )
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1899 | {
|
Martinsh Shaiters | a9d42b0 | 2013-01-30 11:14:27 +0200 | [diff] [blame] | 1900 | Clear();
|
Dmitry-Me | 01578db | 2014-08-19 10:18:48 +0400 | [diff] [blame] | 1901 | FILE* fp = callfopen( filename, "rb" );
|
| 1902 | if ( !fp ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1903 | SetError( XML_ERROR_FILE_NOT_FOUND, filename, 0 );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1904 | return _errorID;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1905 | }
|
| 1906 | LoadFile( fp );
|
| 1907 | fclose( fp );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1908 | return _errorID;
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1909 | }
|
| 1910 |
|
| 1911 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1912 | XMLError XMLDocument::LoadFile( FILE* fp )
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1913 | {
|
Martinsh Shaiters | a9d42b0 | 2013-01-30 11:14:27 +0200 | [diff] [blame] | 1914 | Clear();
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1915 |
|
Daniel Marjamäki | ba4b328 | 2014-01-10 21:37:27 +0100 | [diff] [blame] | 1916 | fseek( fp, 0, SEEK_SET );
|
Dmitry-Me | 08e7f7b | 2014-07-31 15:19:14 +0400 | [diff] [blame] | 1917 | if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) {
|
Daniel Marjamäki | ba4b328 | 2014-01-10 21:37:27 +0100 | [diff] [blame] | 1918 | SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
|
| 1919 | return _errorID;
|
| 1920 | }
|
| 1921 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1922 | fseek( fp, 0, SEEK_END );
|
Dmitry-Me | acb9c9c | 2014-08-04 09:49:25 +0400 | [diff] [blame] | 1923 | const long filelength = ftell( fp );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1924 | fseek( fp, 0, SEEK_SET );
|
Dmitry-Me | acb9c9c | 2014-08-04 09:49:25 +0400 | [diff] [blame] | 1925 | if ( filelength == -1L ) {
|
| 1926 | SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
|
| 1927 | return _errorID;
|
| 1928 | }
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1929 |
|
Dmitry-Me | ca86a0f | 2015-05-25 11:29:14 +0300 | [diff] [blame] | 1930 | if ( (unsigned long)filelength >= (size_t)-1 ) {
|
Dmitry-Me | 2a8b1f5 | 2015-04-30 14:58:57 +0300 | [diff] [blame] | 1931 | // Cannot handle files which won't fit in buffer together with null terminator
|
| 1932 | SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
|
| 1933 | return _errorID;
|
| 1934 | }
|
| 1935 |
|
Dmitry-Me | 72801b8 | 2015-05-07 09:41:39 +0300 | [diff] [blame] | 1936 | if ( filelength == 0 ) {
|
Vasily Biryukov | 1cfafd0 | 2013-04-20 14:12:33 +0600 | [diff] [blame] | 1937 | SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1938 | return _errorID;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1939 | }
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 1940 |
|
Dmitry-Me | 72801b8 | 2015-05-07 09:41:39 +0300 | [diff] [blame] | 1941 | const size_t size = filelength;
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1942 | _charBuffer = new char[size+1];
|
| 1943 | size_t read = fread( _charBuffer, 1, size, fp );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1944 | if ( read != size ) {
|
| 1945 | SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1946 | return _errorID;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1947 | }
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 1948 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1949 | _charBuffer[size] = 0;
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1950 |
|
Dmitry-Me | 97476b7 | 2015-01-01 16:15:57 +0300 | [diff] [blame] | 1951 | Parse();
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1952 | return _errorID;
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1953 | }
|
| 1954 |
|
| 1955 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1956 | XMLError XMLDocument::SaveFile( const char* filename, bool compact )
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1957 | {
|
Dmitry-Me | 01578db | 2014-08-19 10:18:48 +0400 | [diff] [blame] | 1958 | FILE* fp = callfopen( filename, "w" );
|
| 1959 | if ( !fp ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1960 | SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0 );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1961 | return _errorID;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1962 | }
|
| 1963 | SaveFile(fp, compact);
|
| 1964 | fclose( fp );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1965 | return _errorID;
|
Ken Miller | 81da1fb | 2012-04-09 23:32:26 -0500 | [diff] [blame] | 1966 | }
|
| 1967 |
|
| 1968 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1969 | XMLError XMLDocument::SaveFile( FILE* fp, bool compact )
|
Ken Miller | 81da1fb | 2012-04-09 23:32:26 -0500 | [diff] [blame] | 1970 | {
|
Ant Mitchell | 189198f | 2015-03-24 16:20:36 +0000 | [diff] [blame] | 1971 | // Clear any error from the last save, otherwise it will get reported
|
| 1972 | // for *this* call.
|
| 1973 | SetError( XML_NO_ERROR, 0, 0 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1974 | XMLPrinter stream( fp, compact );
|
| 1975 | Print( &stream );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1976 | return _errorID;
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 1977 | }
|
| 1978 |
|
Lee Thomason | 1ff38e0 | 2012-02-14 18:18:16 -0800 | [diff] [blame] | 1979 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 1980 | XMLError XMLDocument::Parse( const char* p, size_t len )
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 1981 | {
|
Martinsh Shaiters | a9d42b0 | 2013-01-30 11:14:27 +0200 | [diff] [blame] | 1982 | Clear();
|
Lee Thomason | 18d68bd | 2012-01-26 18:17:26 -0800 | [diff] [blame] | 1983 |
|
Lee Thomason | 82d3200 | 2014-02-21 22:47:18 -0800 | [diff] [blame] | 1984 | if ( len == 0 || !p || !*p ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1985 | SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1986 | return _errorID;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 1987 | }
|
| 1988 | if ( len == (size_t)(-1) ) {
|
| 1989 | len = strlen( p );
|
| 1990 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 1991 | _charBuffer = new char[ len+1 ];
|
| 1992 | memcpy( _charBuffer, p, len );
|
| 1993 | _charBuffer[len] = 0;
|
Lee Thomason (grinliz) | e2bcb32 | 2012-09-17 17:58:25 -0700 | [diff] [blame] | 1994 |
|
Dmitry-Me | 97476b7 | 2015-01-01 16:15:57 +0300 | [diff] [blame] | 1995 | Parse();
|
Dmitry-Me | 9bcd9c7 | 2014-12-09 10:58:14 +0300 | [diff] [blame] | 1996 | if ( Error() ) {
|
Lee Thomason | f07b952 | 2014-10-30 13:25:12 -0700 | [diff] [blame] | 1997 | // clean up now essentially dangling memory.
|
| 1998 | // and the parse fail can put objects in the
|
| 1999 | // pools that are dead and inaccessible.
|
| 2000 | DeleteChildren();
|
| 2001 | _elementPool.Clear();
|
| 2002 | _attributePool.Clear();
|
| 2003 | _textPool.Clear();
|
| 2004 | _commentPool.Clear();
|
| 2005 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2006 | return _errorID;
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 2007 | }
|
| 2008 |
|
| 2009 |
|
PKEuS | 1c5f99e | 2013-07-06 11:28:39 +0200 | [diff] [blame] | 2010 | void XMLDocument::Print( XMLPrinter* streamer ) const
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 2011 | {
|
Dmitry-Me | 67c429e | 2015-05-08 18:08:18 +0300 | [diff] [blame] | 2012 | if ( streamer ) {
|
| 2013 | Accept( streamer );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2014 | }
|
Dmitry-Me | 67c429e | 2015-05-08 18:08:18 +0300 | [diff] [blame] | 2015 | else {
|
| 2016 | XMLPrinter stdoutStreamer( stdout );
|
| 2017 | Accept( &stdoutStreamer );
|
| 2018 | }
|
Lee Thomason | 3f57d27 | 2012-01-11 15:30:03 -0800 | [diff] [blame] | 2019 | }
|
| 2020 |
|
| 2021 |
|
Lee Thomason | 2fa8172 | 2012-11-09 12:37:46 -0800 | [diff] [blame] | 2022 | void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 )
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 2023 | {
|
Dmitry-Me | 66d2a84 | 2014-11-08 15:24:52 +0300 | [diff] [blame] | 2024 | TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2025 | _errorID = error;
|
| 2026 | _errorStr1 = str1;
|
| 2027 | _errorStr2 = str2;
|
Lee Thomason | 67d6131 | 2012-01-24 16:01:51 -0800 | [diff] [blame] | 2028 | }
|
| 2029 |
|
Lee Thomason | 331596e | 2014-09-11 14:56:43 -0700 | [diff] [blame] | 2030 | const char* XMLDocument::ErrorName() const
|
| 2031 | {
|
Dmitry-Me | 66d2a84 | 2014-11-08 15:24:52 +0300 | [diff] [blame] | 2032 | TIXMLASSERT( _errorID >= 0 && _errorID < XML_ERROR_COUNT );
|
Dmitry-Me | a1beddf | 2015-05-26 16:19:21 +0300 | [diff] [blame] | 2033 | const char* errorName = _errorNames[_errorID];
|
| 2034 | TIXMLASSERT( errorName && errorName[0] );
|
| 2035 | return errorName;
|
Lee Thomason | 331596e | 2014-09-11 14:56:43 -0700 | [diff] [blame] | 2036 | }
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2037 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 2038 | void XMLDocument::PrintError() const
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2039 | {
|
Dmitry-Me | 9bcd9c7 | 2014-12-09 10:58:14 +0300 | [diff] [blame] | 2040 | if ( Error() ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2041 | static const int LEN = 20;
|
| 2042 | char buf1[LEN] = { 0 };
|
| 2043 | char buf2[LEN] = { 0 };
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 2044 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2045 | if ( _errorStr1 ) {
|
| 2046 | TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2047 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2048 | if ( _errorStr2 ) {
|
| 2049 | TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2050 | }
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2051 |
|
Dmitry-Me | 2ad4320 | 2015-04-16 12:18:58 +0300 | [diff] [blame] | 2052 | // Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that
|
| 2053 | // causes a clang "always true" -Wtautological-constant-out-of-range-compare warning
|
| 2054 | TIXMLASSERT( 0 <= _errorID && XML_ERROR_COUNT - 1 <= INT_MAX );
|
Lee Thomason | 331596e | 2014-09-11 14:56:43 -0700 | [diff] [blame] | 2055 | printf( "XMLDocument error id=%d '%s' str1=%s str2=%s\n",
|
Dmitry-Me | 400f119 | 2015-04-07 11:51:21 +0300 | [diff] [blame] | 2056 | static_cast<int>( _errorID ), ErrorName(), buf1, buf2 );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2057 | }
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2058 | }
|
| 2059 |
|
Dmitry-Me | 97476b7 | 2015-01-01 16:15:57 +0300 | [diff] [blame] | 2060 | void XMLDocument::Parse()
|
| 2061 | {
|
| 2062 | TIXMLASSERT( NoChildren() ); // Clear() must have been called previously
|
| 2063 | TIXMLASSERT( _charBuffer );
|
Lee Thomason | 3cebdc4 | 2015-01-05 17:16:28 -0800 | [diff] [blame] | 2064 | char* p = _charBuffer;
|
Dmitry-Me | 97476b7 | 2015-01-01 16:15:57 +0300 | [diff] [blame] | 2065 | p = XMLUtil::SkipWhiteSpace( p );
|
Dmitry-Me | e28be75 | 2015-01-09 14:59:30 +0300 | [diff] [blame] | 2066 | p = const_cast<char*>( XMLUtil::ReadBOM( p, &_writeBOM ) );
|
Dmitry-Me | 97476b7 | 2015-01-01 16:15:57 +0300 | [diff] [blame] | 2067 | if ( !*p ) {
|
| 2068 | SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
| 2069 | return;
|
| 2070 | }
|
Lee Thomason | 3cebdc4 | 2015-01-05 17:16:28 -0800 | [diff] [blame] | 2071 | ParseDeep(p, 0 );
|
Dmitry-Me | 97476b7 | 2015-01-01 16:15:57 +0300 | [diff] [blame] | 2072 | }
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2073 |
|
PKEuS | 1bfb954 | 2013-08-04 13:51:17 +0200 | [diff] [blame] | 2074 | XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2075 | _elementJustOpened( false ),
|
| 2076 | _firstElement( true ),
|
| 2077 | _fp( file ),
|
PKEuS | 1bfb954 | 2013-08-04 13:51:17 +0200 | [diff] [blame] | 2078 | _depth( depth ),
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2079 | _textDepth( -1 ),
|
| 2080 | _processEntities( true ),
|
| 2081 | _compactMode( compact )
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2082 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2083 | for( int i=0; i<ENTITY_RANGE; ++i ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2084 | _entityFlag[i] = false;
|
| 2085 | _restrictedEntityFlag[i] = false;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2086 | }
|
| 2087 | for( int i=0; i<NUM_ENTITIES; ++i ) {
|
Dmitry-Me | 8b67d74 | 2014-12-22 11:35:12 +0300 | [diff] [blame] | 2088 | const char entityValue = entities[i].value;
|
| 2089 | TIXMLASSERT( 0 <= entityValue && entityValue < ENTITY_RANGE );
|
| 2090 | _entityFlag[ (unsigned char)entityValue ] = true;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2091 | }
|
Dmitry-Me | 8b67d74 | 2014-12-22 11:35:12 +0300 | [diff] [blame] | 2092 | _restrictedEntityFlag[(unsigned char)'&'] = true;
|
| 2093 | _restrictedEntityFlag[(unsigned char)'<'] = true;
|
| 2094 | _restrictedEntityFlag[(unsigned char)'>'] = true; // not required, but consistency is nice
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2095 | _buffer.Push( 0 );
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 2096 | }
|
| 2097 |
|
| 2098 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2099 | void XMLPrinter::Print( const char* format, ... )
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 2100 | {
|
| 2101 | va_list va;
|
| 2102 | va_start( va, format );
|
| 2103 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2104 | if ( _fp ) {
|
| 2105 | vfprintf( _fp, format, va );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2106 | }
|
| 2107 | else {
|
pffang | 1527cf4 | 2015-06-09 13:57:11 +0800 | [diff] [blame] | 2108 | int len = TIXML_VSCPRINTF( format, va );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2109 | // Close out and re-start the va-args
|
| 2110 | va_end( va );
|
| 2111 | va_start( va, format );
|
Dmitry-Me | 30bdc97 | 2015-01-14 08:32:23 +0300 | [diff] [blame] | 2112 | TIXMLASSERT( _buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0 );
|
Lee Thomason | a0744c8 | 2014-03-16 10:32:27 -0700 | [diff] [blame] | 2113 | char* p = _buffer.PushArr( len ) - 1; // back up over the null terminator.
|
pffang | 1527cf4 | 2015-06-09 13:57:11 +0800 | [diff] [blame] | 2114 | TIXML_VSNPRINTF( p, len+1, format, va );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2115 | }
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 2116 | va_end( va );
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2117 | }
|
| 2118 |
|
| 2119 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2120 | void XMLPrinter::PrintSpace( int depth )
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2121 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2122 | for( int i=0; i<depth; ++i ) {
|
| 2123 | Print( " " );
|
| 2124 | }
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2125 | }
|
| 2126 |
|
| 2127 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2128 | void XMLPrinter::PrintString( const char* p, bool restricted )
|
Lee Thomason | 857b868 | 2012-01-25 17:50:25 -0800 | [diff] [blame] | 2129 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2130 | // Look for runs of bytes between entities to print.
|
| 2131 | const char* q = p;
|
Lee Thomason | 857b868 | 2012-01-25 17:50:25 -0800 | [diff] [blame] | 2132 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2133 | if ( _processEntities ) {
|
Dmitry-Me | 6acc9a5 | 2015-01-15 13:27:47 +0300 | [diff] [blame] | 2134 | const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2135 | while ( *q ) {
|
Dmitry-Me | 69d521d | 2015-04-20 18:05:53 +0300 | [diff] [blame] | 2136 | TIXMLASSERT( p <= q );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2137 | // Remember, char is sometimes signed. (How many times has that bitten me?)
|
| 2138 | if ( *q > 0 && *q < ENTITY_RANGE ) {
|
| 2139 | // Check for entities. If one is found, flush
|
| 2140 | // the stream up until the entity, write the
|
| 2141 | // entity, and keep looking.
|
Dmitry-Me | 8b67d74 | 2014-12-22 11:35:12 +0300 | [diff] [blame] | 2142 | if ( flag[(unsigned char)(*q)] ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2143 | while ( p < q ) {
|
Dmitry-Me | d95172b | 2015-03-30 08:11:18 +0300 | [diff] [blame] | 2144 | const size_t delta = q - p;
|
| 2145 | // %.*s accepts type int as "precision"
|
| 2146 | const int toPrint = ( INT_MAX < delta ) ? INT_MAX : delta;
|
| 2147 | Print( "%.*s", toPrint, p );
|
| 2148 | p += toPrint;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2149 | }
|
Dmitry-Me | 39c399a | 2015-05-28 15:32:27 +0300 | [diff] [blame] | 2150 | bool entityPatternPrinted = false;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2151 | for( int i=0; i<NUM_ENTITIES; ++i ) {
|
| 2152 | if ( entities[i].value == *q ) {
|
| 2153 | Print( "&%s;", entities[i].pattern );
|
Dmitry-Me | 39c399a | 2015-05-28 15:32:27 +0300 | [diff] [blame] | 2154 | entityPatternPrinted = true;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2155 | break;
|
| 2156 | }
|
| 2157 | }
|
Dmitry-Me | 39c399a | 2015-05-28 15:32:27 +0300 | [diff] [blame] | 2158 | if ( !entityPatternPrinted ) {
|
| 2159 | // TIXMLASSERT( entityPatternPrinted ) causes gcc -Wunused-but-set-variable in release
|
| 2160 | TIXMLASSERT( false );
|
| 2161 | }
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2162 | ++p;
|
| 2163 | }
|
| 2164 | }
|
| 2165 | ++q;
|
Dmitry-Me | 69d521d | 2015-04-20 18:05:53 +0300 | [diff] [blame] | 2166 | TIXMLASSERT( p <= q );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2167 | }
|
| 2168 | }
|
| 2169 | // Flush the remaining string. This will be the entire
|
| 2170 | // string if an entity wasn't found.
|
Dmitry-Me | 69d521d | 2015-04-20 18:05:53 +0300 | [diff] [blame] | 2171 | TIXMLASSERT( p <= q );
|
| 2172 | if ( !_processEntities || ( p < q ) ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2173 | Print( "%s", p );
|
| 2174 | }
|
Lee Thomason | 857b868 | 2012-01-25 17:50:25 -0800 | [diff] [blame] | 2175 | }
|
| 2176 |
|
U-Stream\Lee | ae25a44 | 2012-02-17 17:48:16 -0800 | [diff] [blame] | 2177 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2178 | void XMLPrinter::PushHeader( bool writeBOM, bool writeDec )
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 2179 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2180 | if ( writeBOM ) {
|
PKEuS | 1bfb954 | 2013-08-04 13:51:17 +0200 | [diff] [blame] | 2181 | static const unsigned char bom[] = { TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, 0 };
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2182 | Print( "%s", bom );
|
| 2183 | }
|
| 2184 | if ( writeDec ) {
|
| 2185 | PushDeclaration( "xml version=\"1.0\"" );
|
| 2186 | }
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 2187 | }
|
| 2188 |
|
| 2189 |
|
Uli Kusterer | 593a33d | 2014-02-01 12:48:51 +0100 | [diff] [blame] | 2190 | void XMLPrinter::OpenElement( const char* name, bool compactMode )
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2191 | {
|
Dmitry-Me | a092bc1 | 2014-12-23 17:57:05 +0300 | [diff] [blame] | 2192 | SealElementIfJustOpened();
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2193 | _stack.Push( name );
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 2194 |
|
Uli Kusterer | 593a33d | 2014-02-01 12:48:51 +0100 | [diff] [blame] | 2195 | if ( _textDepth < 0 && !_firstElement && !compactMode ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2196 | Print( "\n" );
|
PKEuS | 1bfb954 | 2013-08-04 13:51:17 +0200 | [diff] [blame] | 2197 | }
|
Uli Kusterer | 593a33d | 2014-02-01 12:48:51 +0100 | [diff] [blame] | 2198 | if ( !compactMode ) {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2199 | PrintSpace( _depth );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2200 | }
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2201 |
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2202 | Print( "<%s", name );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2203 | _elementJustOpened = true;
|
| 2204 | _firstElement = false;
|
| 2205 | ++_depth;
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2206 | }
|
| 2207 |
|
| 2208 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2209 | void XMLPrinter::PushAttribute( const char* name, const char* value )
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2210 | {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2211 | TIXMLASSERT( _elementJustOpened );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2212 | Print( " %s=\"", name );
|
| 2213 | PrintString( value, false );
|
| 2214 | Print( "\"" );
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2215 | }
|
| 2216 |
|
| 2217 |
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 2218 | void XMLPrinter::PushAttribute( const char* name, int v )
|
| 2219 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2220 | char buf[BUF_SIZE];
|
| 2221 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
| 2222 | PushAttribute( name, buf );
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 2223 | }
|
| 2224 |
|
| 2225 |
|
| 2226 | void XMLPrinter::PushAttribute( const char* name, unsigned v )
|
| 2227 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2228 | char buf[BUF_SIZE];
|
| 2229 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
| 2230 | PushAttribute( name, buf );
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 2231 | }
|
| 2232 |
|
| 2233 |
|
| 2234 | void XMLPrinter::PushAttribute( const char* name, bool v )
|
| 2235 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2236 | char buf[BUF_SIZE];
|
| 2237 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
| 2238 | PushAttribute( name, buf );
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 2239 | }
|
| 2240 |
|
| 2241 |
|
| 2242 | void XMLPrinter::PushAttribute( const char* name, double v )
|
| 2243 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2244 | char buf[BUF_SIZE];
|
| 2245 | XMLUtil::ToStr( v, buf, BUF_SIZE );
|
| 2246 | PushAttribute( name, buf );
|
Lee Thomason | 7d00b9a | 2012-02-27 17:54:22 -0800 | [diff] [blame] | 2247 | }
|
| 2248 |
|
| 2249 |
|
Uli Kusterer | ca412e8 | 2014-02-01 13:35:05 +0100 | [diff] [blame] | 2250 | void XMLPrinter::CloseElement( bool compactMode )
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2251 | {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2252 | --_depth;
|
| 2253 | const char* name = _stack.Pop();
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2254 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2255 | if ( _elementJustOpened ) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2256 | Print( "/>" );
|
| 2257 | }
|
| 2258 | else {
|
Uli Kusterer | ca412e8 | 2014-02-01 13:35:05 +0100 | [diff] [blame] | 2259 | if ( _textDepth < 0 && !compactMode) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2260 | Print( "\n" );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2261 | PrintSpace( _depth );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2262 | }
|
| 2263 | Print( "</%s>", name );
|
| 2264 | }
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 2265 |
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2266 | if ( _textDepth == _depth ) {
|
| 2267 | _textDepth = -1;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2268 | }
|
Uli Kusterer | ca412e8 | 2014-02-01 13:35:05 +0100 | [diff] [blame] | 2269 | if ( _depth == 0 && !compactMode) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2270 | Print( "\n" );
|
| 2271 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2272 | _elementJustOpened = false;
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2273 | }
|
| 2274 |
|
| 2275 |
|
Dmitry-Me | a092bc1 | 2014-12-23 17:57:05 +0300 | [diff] [blame] | 2276 | void XMLPrinter::SealElementIfJustOpened()
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2277 | {
|
Dmitry-Me | a092bc1 | 2014-12-23 17:57:05 +0300 | [diff] [blame] | 2278 | if ( !_elementJustOpened ) {
|
| 2279 | return;
|
| 2280 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2281 | _elementJustOpened = false;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2282 | Print( ">" );
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2283 | }
|
| 2284 |
|
| 2285 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2286 | void XMLPrinter::PushText( const char* text, bool cdata )
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2287 | {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2288 | _textDepth = _depth-1;
|
Lee Thomason | 56bdd02 | 2012-02-09 18:16:58 -0800 | [diff] [blame] | 2289 |
|
Dmitry-Me | a092bc1 | 2014-12-23 17:57:05 +0300 | [diff] [blame] | 2290 | SealElementIfJustOpened();
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2291 | if ( cdata ) {
|
Dmitry-Me | 6a79c17 | 2015-03-31 12:18:17 +0300 | [diff] [blame] | 2292 | Print( "<![CDATA[%s]]>", text );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2293 | }
|
| 2294 | else {
|
| 2295 | PrintString( text, true );
|
| 2296 | }
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2297 | }
|
| 2298 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 2299 | void XMLPrinter::PushText( int value )
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2300 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2301 | char buf[BUF_SIZE];
|
| 2302 | XMLUtil::ToStr( value, buf, BUF_SIZE );
|
| 2303 | PushText( buf, false );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2304 | }
|
| 2305 |
|
| 2306 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 2307 | void XMLPrinter::PushText( unsigned value )
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2308 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2309 | char buf[BUF_SIZE];
|
| 2310 | XMLUtil::ToStr( value, buf, BUF_SIZE );
|
| 2311 | PushText( buf, false );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2312 | }
|
| 2313 |
|
| 2314 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 2315 | void XMLPrinter::PushText( bool value )
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2316 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2317 | char buf[BUF_SIZE];
|
| 2318 | XMLUtil::ToStr( value, buf, BUF_SIZE );
|
| 2319 | PushText( buf, false );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2320 | }
|
| 2321 |
|
| 2322 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 2323 | void XMLPrinter::PushText( float value )
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2324 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2325 | char buf[BUF_SIZE];
|
| 2326 | XMLUtil::ToStr( value, buf, BUF_SIZE );
|
| 2327 | PushText( buf, false );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2328 | }
|
| 2329 |
|
| 2330 |
|
Lee Thomason (grinliz) | 2f1f624 | 2012-09-16 11:32:34 -0700 | [diff] [blame] | 2331 | void XMLPrinter::PushText( double value )
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2332 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2333 | char buf[BUF_SIZE];
|
| 2334 | XMLUtil::ToStr( value, buf, BUF_SIZE );
|
| 2335 | PushText( buf, false );
|
Lee Thomason | 21be882 | 2012-07-15 17:27:22 -0700 | [diff] [blame] | 2336 | }
|
| 2337 |
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2338 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2339 | void XMLPrinter::PushComment( const char* comment )
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2340 | {
|
Dmitry-Me | a092bc1 | 2014-12-23 17:57:05 +0300 | [diff] [blame] | 2341 | SealElementIfJustOpened();
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2342 | if ( _textDepth < 0 && !_firstElement && !_compactMode) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2343 | Print( "\n" );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2344 | PrintSpace( _depth );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2345 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2346 | _firstElement = false;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2347 | Print( "<!--%s-->", comment );
|
Lee Thomason | 5cae897 | 2012-01-24 18:03:07 -0800 | [diff] [blame] | 2348 | }
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 2349 |
|
| 2350 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2351 | void XMLPrinter::PushDeclaration( const char* value )
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2352 | {
|
Dmitry-Me | a092bc1 | 2014-12-23 17:57:05 +0300 | [diff] [blame] | 2353 | SealElementIfJustOpened();
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2354 | if ( _textDepth < 0 && !_firstElement && !_compactMode) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2355 | Print( "\n" );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2356 | PrintSpace( _depth );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2357 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2358 | _firstElement = false;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2359 | Print( "<?%s?>", value );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2360 | }
|
| 2361 |
|
| 2362 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2363 | void XMLPrinter::PushUnknown( const char* value )
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2364 | {
|
Dmitry-Me | a092bc1 | 2014-12-23 17:57:05 +0300 | [diff] [blame] | 2365 | SealElementIfJustOpened();
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2366 | if ( _textDepth < 0 && !_firstElement && !_compactMode) {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2367 | Print( "\n" );
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2368 | PrintSpace( _depth );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2369 | }
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2370 | _firstElement = false;
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2371 | Print( "<!%s>", value );
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2372 | }
|
| 2373 |
|
| 2374 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2375 | bool XMLPrinter::VisitEnter( const XMLDocument& doc )
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 2376 | {
|
Lee Thomason | 624d43f | 2012-10-12 10:58:48 -0700 | [diff] [blame] | 2377 | _processEntities = doc.ProcessEntities();
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2378 | if ( doc.HasBOM() ) {
|
| 2379 | PushHeader( true, false );
|
| 2380 | }
|
| 2381 | return true;
|
Lee Thomason (grinliz) | 68db57e | 2012-02-21 09:08:12 -0800 | [diff] [blame] | 2382 | }
|
| 2383 |
|
| 2384 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2385 | bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 2386 | {
|
Dmitry-Me | e76b851 | 2015-04-08 13:41:40 +0300 | [diff] [blame] | 2387 | const XMLElement* parentElem = 0;
|
| 2388 | if ( element.Parent() ) {
|
| 2389 | parentElem = element.Parent()->ToElement();
|
Ant Mitchell | 7e74477 | 2015-03-24 14:33:28 +0000 | [diff] [blame] | 2390 | }
|
Dmitry-Me | e76b851 | 2015-04-08 13:41:40 +0300 | [diff] [blame] | 2391 | const bool compactMode = parentElem ? CompactMode( *parentElem ) : _compactMode;
|
Uli Kusterer | 5d1d27e | 2014-02-20 11:50:22 +0100 | [diff] [blame] | 2392 | OpenElement( element.Name(), compactMode );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2393 | while ( attribute ) {
|
| 2394 | PushAttribute( attribute->Name(), attribute->Value() );
|
| 2395 | attribute = attribute->Next();
|
| 2396 | }
|
| 2397 | return true;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 2398 | }
|
| 2399 |
|
| 2400 |
|
Uli Kusterer | ca412e8 | 2014-02-01 13:35:05 +0100 | [diff] [blame] | 2401 | bool XMLPrinter::VisitExit( const XMLElement& element )
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 2402 | {
|
Uli Kusterer | 5d1d27e | 2014-02-20 11:50:22 +0100 | [diff] [blame] | 2403 | CloseElement( CompactMode(element) );
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2404 | return true;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 2405 | }
|
| 2406 |
|
| 2407 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2408 | bool XMLPrinter::Visit( const XMLText& text )
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 2409 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2410 | PushText( text.Value(), text.CData() );
|
| 2411 | return true;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 2412 | }
|
| 2413 |
|
| 2414 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2415 | bool XMLPrinter::Visit( const XMLComment& comment )
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 2416 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2417 | PushComment( comment.Value() );
|
| 2418 | return true;
|
Lee Thomason | 751da52 | 2012-02-10 08:50:51 -0800 | [diff] [blame] | 2419 | }
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2420 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2421 | bool XMLPrinter::Visit( const XMLDeclaration& declaration )
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2422 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2423 | PushDeclaration( declaration.Value() );
|
| 2424 | return true;
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2425 | }
|
| 2426 |
|
| 2427 |
|
Lee Thomason (grinliz) | 2a1cd27 | 2012-02-24 17:37:53 -0800 | [diff] [blame] | 2428 | bool XMLPrinter::Visit( const XMLUnknown& unknown )
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2429 | {
|
Lee Thomason | a9cf3f9 | 2012-10-11 16:56:51 -0700 | [diff] [blame] | 2430 | PushUnknown( unknown.Value() );
|
| 2431 | return true;
|
Lee Thomason (grinliz) | bd0a8ac | 2012-02-20 20:14:33 -0800 | [diff] [blame] | 2432 | }
|
Kevin Wojniak | 04c22d2 | 2012-11-08 11:02:22 -0800 | [diff] [blame] | 2433 |
|
Lee Thomason | 685b895 | 2012-11-12 13:00:06 -0800 | [diff] [blame] | 2434 | } // namespace tinyxml2
|
| 2435 |
|