MCPcopy Create free account
hub / github.com/PolygonTek/BlueshiftEngine / Identify

Method Identify

Source/ThirdParty/tinyxml2/tinyxml2.cpp:631–702  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

629
630
631char* XMLDocument::Identify( char* p, XMLNode** node )
632{
633 TIXMLASSERT( node );
634 TIXMLASSERT( p );
635 char* const start = p;
636 p = XMLUtil::SkipWhiteSpace( p );
637 if( !*p ) {
638 *node = 0;
639 TIXMLASSERT( p );
640 return p;
641 }
642
643 // These strings define the matching patterns:
644 static const char* xmlHeader = { "<?" };
645 static const char* commentHeader = { "<!--" };
646 static const char* cdataHeader = { "<![CDATA[" };
647 static const char* dtdHeader = { "<!" };
648 static const char* elementHeader = { "<" }; // and a header for everything else; check last.
649
650 static const int xmlHeaderLen = 2;
651 static const int commentHeaderLen = 4;
652 static const int cdataHeaderLen = 9;
653 static const int dtdHeaderLen = 2;
654 static const int elementHeaderLen = 1;
655
656 TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool
657 TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool
658 XMLNode* returnNode = 0;
659 if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
660 TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
661 returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );
662 returnNode->_memPool = &_commentPool;
663 p += xmlHeaderLen;
664 }
665 else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
666 TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
667 returnNode = new (_commentPool.Alloc()) XMLComment( this );
668 returnNode->_memPool = &_commentPool;
669 p += commentHeaderLen;
670 }
671 else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
672 TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
673 XMLText* text = new (_textPool.Alloc()) XMLText( this );
674 returnNode = text;
675 returnNode->_memPool = &_textPool;
676 p += cdataHeaderLen;
677 text->SetCData( true );
678 }
679 else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
680 TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
681 returnNode = new (_commentPool.Alloc()) XMLUnknown( this );
682 returnNode->_memPool = &_commentPool;
683 p += dtdHeaderLen;
684 }
685 else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
686 TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
687 returnNode = new (_elementPool.Alloc()) XMLElement( this );
688 returnNode->_memPool = &_elementPool;

Callers 1

ParseDeepMethod · 0.80

Calls 2

ItemSizeMethod · 0.45
AllocMethod · 0.45

Tested by

no test coverage detected