| 479 | |
| 480 | |
| 481 | char* XMLDocument::Identify( char* p, XMLNode** node ) |
| 482 | { |
| 483 | char* const start = p; |
| 484 | p = XMLUtil::SkipWhiteSpace( p ); |
| 485 | if( !p || !*p ) { |
| 486 | return p; |
| 487 | } |
| 488 | |
| 489 | // What is this thing? |
| 490 | // These strings define the matching patters: |
| 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. |
| 496 | |
| 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; |
| 502 | |
| 503 | #if defined(_MSC_VER) |
| 504 | #pragma warning ( push ) |
| 505 | #pragma warning ( disable : 4127 ) |
| 506 | #endif |
| 507 | TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool |
| 508 | TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool |
| 509 | #if defined(_MSC_VER) |
| 510 | #pragma warning (pop) |
| 511 | #endif |
| 512 | XMLNode* returnNode = 0; |
| 513 | if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { |
| 514 | returnNode = new (_commentPool.Alloc()) XMLDeclaration( this ); |
| 515 | returnNode->_memPool = &_commentPool; |
| 516 | p += xmlHeaderLen; |
| 517 | } |
| 518 | else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) { |
| 519 | returnNode = new (_commentPool.Alloc()) XMLComment( this ); |
| 520 | returnNode->_memPool = &_commentPool; |
| 521 | p += commentHeaderLen; |
| 522 | } |
| 523 | else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) { |
| 524 | XMLText* text = new (_textPool.Alloc()) XMLText( this ); |
| 525 | returnNode = text; |
| 526 | returnNode->_memPool = &_textPool; |
| 527 | p += cdataHeaderLen; |
| 528 | text->SetCData( true ); |
| 529 | } |
| 530 | else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) { |
| 531 | returnNode = new (_commentPool.Alloc()) XMLUnknown( this ); |
| 532 | returnNode->_memPool = &_commentPool; |
| 533 | p += dtdHeaderLen; |
| 534 | } |
| 535 | else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) { |
| 536 | returnNode = new (_elementPool.Alloc()) XMLElement( this ); |
| 537 | returnNode->_memPool = &_elementPool; |
| 538 | p += elementHeaderLen; |