Merge pull request #488 from Dmitry-Me/reuseElementWithNameCheck

Reuse "is element with name" check
This commit is contained in:
Lee Thomason 2016-10-12 15:23:39 -07:00 committed by GitHub
commit f6106bec9a
2 changed files with 24 additions and 14 deletions

View File

@ -897,11 +897,9 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
const XMLElement* XMLNode::FirstChildElement( const char* name ) const
{
for( const XMLNode* node = _firstChild; node; node = node->_next ) {
const XMLElement* element = node->ToElement();
const XMLElement* element = node->ToElementWithName( name );
if ( element ) {
if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {
return element;
}
return element;
}
}
return 0;
@ -911,11 +909,9 @@ const XMLElement* XMLNode::FirstChildElement( const char* name ) const
const XMLElement* XMLNode::LastChildElement( const char* name ) const
{
for( const XMLNode* node = _lastChild; node; node = node->_prev ) {
const XMLElement* element = node->ToElement();
const XMLElement* element = node->ToElementWithName( name );
if ( element ) {
if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {
return element;
}
return element;
}
}
return 0;
@ -925,9 +921,8 @@ const XMLElement* XMLNode::LastChildElement( const char* name ) const
const XMLElement* XMLNode::NextSiblingElement( const char* name ) const
{
for( const XMLNode* node = _next; node; node = node->_next ) {
const XMLElement* element = node->ToElement();
if ( element
&& (!name || XMLUtil::StringEqual( name, element->Name() ))) {
const XMLElement* element = node->ToElementWithName( name );
if ( element ) {
return element;
}
}
@ -938,9 +933,8 @@ const XMLElement* XMLNode::NextSiblingElement( const char* name ) const
const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const
{
for( const XMLNode* node = _prev; node; node = node->_prev ) {
const XMLElement* element = node->ToElement();
if ( element
&& (!name || XMLUtil::StringEqual( name, element->Name() ))) {
const XMLElement* element = node->ToElementWithName( name );
if ( element ) {
return element;
}
}
@ -1056,6 +1050,21 @@ void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const
insertThis->_memPool->SetTracked();
}
const XMLElement* XMLNode::ToElementWithName( const char* name ) const
{
const XMLElement* element = this->ToElement();
if ( element == 0 ) {
return 0;
}
if ( name == 0 ) {
return element;
}
if ( XMLUtil::StringEqual( element->Name(), name ) ) {
return element;
}
return 0;
}
// --------- XMLText ---------- //
char* XMLText::ParseDeep( char* p, StrPair* )
{

View File

@ -908,6 +908,7 @@ private:
void Unlink( XMLNode* child );
static void DeleteNode( XMLNode* node );
void InsertChildPreamble( XMLNode* insertThis ) const;
const XMLElement* ToElementWithName( const char* name ) const;
XMLNode( const XMLNode& ); // not supported
XMLNode& operator=( const XMLNode& ); // not supported