mirror of https://github.com/AxioDL/tinyxml2.git
Reuse "is element with name" check
This commit is contained in:
parent
e8157ff9ae
commit
ecb9b07476
37
tinyxml2.cpp
37
tinyxml2.cpp
|
@ -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* )
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue