MCPcopy Create free account
hub / github.com/NanoMichael/MicroTeX / Identify

Method Identify

src/xml/tinyxml2.cpp:498–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496
497
498char* XMLDocument::Identify( char* p, XMLNode** node ) {
499 TIXMLASSERT( node );
500 TIXMLASSERT( p );
501 char* const start = p;
502 p = XMLUtil::SkipWhiteSpace( p );
503 if( !*p ) {
504 *node = 0;
505 TIXMLASSERT( p );
506 return p;
507 }
508
509 // What is this thing?
510 // These strings define the matching patters:
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 TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool
524 TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool
525 XMLNode* returnNode = 0;
526 if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
527 TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() );
528 returnNode = new (_commentPool.Alloc()) XMLDeclaration( this );
529 returnNode->_memPool = &_commentPool;
530 p += xmlHeaderLen;
531 } else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) {
532 TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() );
533 returnNode = new (_commentPool.Alloc()) XMLComment( this );
534 returnNode->_memPool = &_commentPool;
535 p += commentHeaderLen;
536 } else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) {
537 TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
538 XMLText* text = new (_textPool.Alloc()) XMLText( this );
539 returnNode = text;
540 returnNode->_memPool = &_textPool;
541 p += cdataHeaderLen;
542 text->SetCData( true );
543 } else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) {
544 TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() );
545 returnNode = new (_commentPool.Alloc()) XMLUnknown( this );
546 returnNode->_memPool = &_commentPool;
547 p += dtdHeaderLen;
548 } else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) {
549 TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );
550 returnNode = new (_elementPool.Alloc()) XMLElement( this );
551 returnNode->_memPool = &_elementPool;
552 p += elementHeaderLen;
553 } else {
554 TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() );
555 returnNode = new (_textPool.Alloc()) XMLText( this );

Callers 1

ParseDeepMethod · 0.80

Calls 2

ItemSizeMethod · 0.80
AllocMethod · 0.80

Tested by

no test coverage detected