| 534 | |
| 535 | |
| 536 | char* XMLDocument::Identify( char* p, XMLNode** node ) |
| 537 | { |
| 538 | TIXMLASSERT( node ); |
| 539 | TIXMLASSERT( p ); |
| 540 | char* const start = p; |
| 541 | p = XMLUtil::SkipWhiteSpace( p ); |
| 542 | if( !*p ) { |
| 543 | *node = 0; |
| 544 | TIXMLASSERT( p ); |
| 545 | return p; |
| 546 | } |
| 547 | |
| 548 | // What is this thing? |
| 549 | // These strings define the matching patters: |
| 550 | static const char* xmlHeader = { "<?" }; |
| 551 | static const char* commentHeader = { "<!--" }; |
| 552 | static const char* dtdHeader = { "<!" }; |
| 553 | static const char* cdataHeader = { "<![CDATA[" }; |
| 554 | static const char* elementHeader = { "<" }; // and a header for everything else; check last. |
| 555 | |
| 556 | static const int xmlHeaderLen = 2; |
| 557 | static const int commentHeaderLen = 4; |
| 558 | static const int dtdHeaderLen = 2; |
| 559 | static const int cdataHeaderLen = 9; |
| 560 | static const int elementHeaderLen = 1; |
| 561 | |
| 562 | TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool |
| 563 | TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool |
| 564 | XMLNode* returnNode = 0; |
| 565 | if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { |
| 566 | TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() ); |
| 567 | returnNode = new (_commentPool.Alloc()) XMLDeclaration( this ); |
| 568 | returnNode->_memPool = &_commentPool; |
| 569 | p += xmlHeaderLen; |
| 570 | } |
| 571 | else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) { |
| 572 | TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() ); |
| 573 | returnNode = new (_commentPool.Alloc()) XMLComment( this ); |
| 574 | returnNode->_memPool = &_commentPool; |
| 575 | p += commentHeaderLen; |
| 576 | } |
| 577 | else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) { |
| 578 | TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() ); |
| 579 | XMLText* text = new (_textPool.Alloc()) XMLText( this ); |
| 580 | returnNode = text; |
| 581 | returnNode->_memPool = &_textPool; |
| 582 | p += cdataHeaderLen; |
| 583 | text->SetCData( true ); |
| 584 | } |
| 585 | else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) { |
| 586 | TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() ); |
| 587 | returnNode = new (_commentPool.Alloc()) XMLUnknown( this ); |
| 588 | returnNode->_memPool = &_commentPool; |
| 589 | p += dtdHeaderLen; |
| 590 | } |
| 591 | else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) { |
| 592 | TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() ); |
| 593 | returnNode = new (_elementPool.Alloc()) XMLElement( this ); |