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