| 493 | |
| 494 | |
| 495 | char* XMLDocument::Identify( char* p, XMLNode** node ) |
| 496 | { |
| 497 | XMLNode* returnNode = 0; |
| 498 | char* start = p; |
| 499 | p = XMLUtil::SkipWhiteSpace( p ); |
| 500 | if( !p || !*p ) { |
| 501 | return p; |
| 502 | } |
| 503 | |
| 504 | // What is this thing? |
| 505 | // - Elements start with a letter or underscore, but xml is reserved. |
| 506 | // - Comments: <!-- |
| 507 | // - Decleration: <? |
| 508 | // - Everthing else is unknown to tinyxml. |
| 509 | // |
| 510 | |
| 511 | static const char* xmlHeader = { "<?" }; |
| 512 | static const char* commentHeader = { "<!--" }; |
| 513 | static const char* dtdHeader = { "<!" }; |
| 514 | static const char* cdataHeader = { "<![CDATA[" }; |
| 515 | static const char* elementHeader = { "<" }; // and a header for everything else; check last. |
| 516 | |
| 517 | static const int xmlHeaderLen = 2; |
| 518 | static const int commentHeaderLen = 4; |
| 519 | static const int dtdHeaderLen = 2; |
| 520 | static const int cdataHeaderLen = 9; |
| 521 | static const int elementHeaderLen = 1; |
| 522 | |
| 523 | #if defined(_MSC_VER) |
| 524 | #pragma warning ( push ) |
| 525 | #pragma warning ( disable : 4127 ) |
| 526 | #endif |
| 527 | TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool |
| 528 | TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool |
| 529 | #if defined(_MSC_VER) |
| 530 | #pragma warning (pop) |
| 531 | #endif |
| 532 | if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { |
| 533 | returnNode = new (_commentPool.Alloc()) XMLDeclaration( this ); |
| 534 | returnNode->_memPool = &_commentPool; |
| 535 | p += xmlHeaderLen; |
| 536 | } |
| 537 | else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) { |
| 538 | returnNode = new (_commentPool.Alloc()) XMLComment( this ); |
| 539 | returnNode->_memPool = &_commentPool; |
| 540 | p += commentHeaderLen; |
| 541 | } |
| 542 | else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) { |
| 543 | XMLText* text = new (_textPool.Alloc()) XMLText( this ); |
| 544 | returnNode = text; |
| 545 | returnNode->_memPool = &_textPool; |
| 546 | p += cdataHeaderLen; |
| 547 | text->SetCData( true ); |
| 548 | } |
| 549 | else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) { |
| 550 | returnNode = new (_commentPool.Alloc()) XMLUnknown( this ); |
| 551 | returnNode->_memPool = &_commentPool; |
| 552 | p += dtdHeaderLen; |
no test coverage detected