XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis ) { if ( _firstChild ) { TIXMLASSERT( _lastChild ); TIXMLASSERT( _firstChild->_prev == 0 ); _firstChild->_prev = addThis; addThis->_next = _firstChild; _firstChild = addThis; addThis->_prev = 0; } else { TIXMLASSERT( _lastChild == 0 ); _firstChild = _lastChild = addThis; addThis->_prev = 0; addThis->_next = 0; } addThis->_parent = this; addThis->_memPool->SetTracked(); return addThis; }
void XMLNode::Unlink( XMLNode* child ) { TIXMLASSERT( child->_parent == this ); if ( child == _firstChild ) { _firstChild = _firstChild->_next; } if ( child == _lastChild ) { _lastChild = _lastChild->_prev; } if ( child->_prev ) { child->_prev->_next = child->_next; } if ( child->_next ) { child->_next->_prev = child->_prev; } child->_parent = 0; }
char* StrPair::ParseText( char* p, const char* endTag, int strFlags ) { TIXMLASSERT( endTag && *endTag ); char* start = p; // fixme: hides a member char endChar = *endTag; size_t length = strlen( endTag ); // Inner loop of text parsing. while ( *p ) { if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) { Set( start, p, strFlags ); return p + length; } ++p; } return 0; }
XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) { TIXMLASSERT( afterThis->_parent == this ); if ( afterThis->_parent != this ) { return 0; } if ( afterThis->_next == 0 ) { // The last node or the only node. return InsertEndChild( addThis ); } addThis->_prev = afterThis; addThis->_next = afterThis->_next; afterThis->_next->_prev = addThis; afterThis->_next = addThis; addThis->_parent = this; addThis->_memPool->SetTracked(); return addThis; }
XMLPrinter::XMLPrinter( FILE* file, bool compact ) : _elementJustOpened( false ), _firstElement( true ), _fp( file ), _depth( 0 ), _textDepth( -1 ), _processEntities( true ), _compactMode( compact ) { for( int i=0; i<ENTITY_RANGE; ++i ) { _entityFlag[i] = false; _restrictedEntityFlag[i] = false; } for( int i=0; i<NUM_ENTITIES; ++i ) { TIXMLASSERT( entities[i].value < ENTITY_RANGE ); if ( entities[i].value < ENTITY_RANGE ) { _entityFlag[ (int)entities[i].value ] = true; } } _restrictedEntityFlag[(int)'&'] = true; _restrictedEntityFlag[(int)'<'] = true; _restrictedEntityFlag[(int)'>'] = true; // not required, but consistency is nice _buffer.Push( 0 ); }
void XMLNode::DeleteChild( XMLNode* node ) { TIXMLASSERT( node->_parent == this ); DELETE_NODE( node ); }
char* XMLDocument::Identify( char* p, XMLNode** node ) { XMLNode* returnNode = 0; char* start = p; p = XMLUtil::SkipWhiteSpace( p ); if( !p || !*p ) { return p; } // What is this thing? // - Elements start with a letter or underscore, but xml is reserved. // - Comments: <!-- // - Declaration: <? // - Everything else is unknown to tinyxml. // static const char* xmlHeader = { "<?" }; static const char* commentHeader = { "<!--" }; static const char* dtdHeader = { "<!" }; static const char* cdataHeader = { "<![CDATA[" }; static const char* elementHeader = { "<" }; // and a header for everything else; check last. static const int xmlHeaderLen = 2; static const int commentHeaderLen = 4; static const int dtdHeaderLen = 2; static const int cdataHeaderLen = 9; static const int elementHeaderLen = 1; #if defined(_MSC_VER) #pragma warning ( push ) #pragma warning ( disable : 4127 ) #endif TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool #if defined(_MSC_VER) #pragma warning (pop) #endif if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { returnNode = new (_commentPool.Alloc()) XMLDeclaration( this ); returnNode->_memPool = &_commentPool; p += xmlHeaderLen; } else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) { returnNode = new (_commentPool.Alloc()) XMLComment( this ); returnNode->_memPool = &_commentPool; p += commentHeaderLen; } else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) { XMLText* text = new (_textPool.Alloc()) XMLText( this ); returnNode = text; returnNode->_memPool = &_textPool; p += cdataHeaderLen; text->SetCData( true ); } else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) { returnNode = new (_commentPool.Alloc()) XMLUnknown( this ); returnNode->_memPool = &_commentPool; p += dtdHeaderLen; } else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) { returnNode = new (_elementPool.Alloc()) XMLElement( this ); returnNode->_memPool = &_elementPool; p += elementHeaderLen; } else { returnNode = new (_textPool.Alloc()) XMLText( this ); returnNode->_memPool = &_textPool; p = start; // Back it up, all the text counts. } *node = returnNode; return p; }
const char* StrPair::GetStr() { if ( _flags & NEEDS_FLUSH ) { *_end = 0; _flags ^= NEEDS_FLUSH; if ( _flags ) { char* p = _start; // the read pointer char* q = _start; // the write pointer while( p < _end ) { if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) { // CR-LF pair becomes LF // CR alone becomes LF // LF-CR becomes LF if ( *(p+1) == LF ) { p += 2; } else { ++p; } *q++ = LF; } else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) { if ( *(p+1) == CR ) { p += 2; } else { ++p; } *q++ = LF; } else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) { // Entities handled by tinyXML2: // - special entities in the entity table [in/out] // - numeric character reference [in] // 中 or 中 if ( *(p+1) == '#' ) { char buf[10] = { 0 }; int len; p = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) ); for( int i=0; i<len; ++i ) { *q++ = buf[i]; } TIXMLASSERT( q <= p ); } else { int i=0; for(; i<NUM_ENTITIES; ++i ) { if ( strncmp( p+1, entities[i].pattern, entities[i].length ) == 0 && *(p+entities[i].length+1) == ';' ) { // Found an entity convert; *q = entities[i].value; ++q; p += entities[i].length + 2; break; } } if ( i == NUM_ENTITIES ) { // fixme: treat as error? ++p; ++q; } } } else { *q = *p; ++p; ++q; } } *q = 0; } // The loop below has plenty going on, and this // is a less useful mode. Break it out. if ( _flags & COLLAPSE_WHITESPACE ) { CollapseWhitespace(); } _flags = (_flags & NEEDS_DELETE); } return _start; }
const T& PeekTop() const { TIXMLASSERT( _size > 0 ); return _mem[ _size - 1]; }
const T& operator[](int i) const { TIXMLASSERT( i>= 0 && i < _size ); return _mem[i]; }
void PopArr( int count ) { TIXMLASSERT( _size >= count ); _size -= count; }
void XMLNode::DeleteChild(XMLNode* node) { TIXMLASSERT(node->_parent == this); DeleteNode(node); }
const char* XMLDocument::ErrorName() const { TIXMLASSERT(_errorID >= 0 && _errorID < XML_ERROR_COUNT); return _errorNames[_errorID]; }