mirror of https://github.com/AxioDL/tinyxml2.git
Reuse "is element with name" check
This commit is contained in:
parent
e8157ff9ae
commit
ecb9b07476
33
tinyxml2.cpp
33
tinyxml2.cpp
|
@ -897,13 +897,11 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
|
||||||
const XMLElement* XMLNode::FirstChildElement( const char* name ) const
|
const XMLElement* XMLNode::FirstChildElement( const char* name ) const
|
||||||
{
|
{
|
||||||
for( const XMLNode* node = _firstChild; node; node = node->_next ) {
|
for( const XMLNode* node = _firstChild; node; node = node->_next ) {
|
||||||
const XMLElement* element = node->ToElement();
|
const XMLElement* element = node->ToElementWithName( name );
|
||||||
if ( element ) {
|
if ( element ) {
|
||||||
if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,13 +909,11 @@ const XMLElement* XMLNode::FirstChildElement( const char* name ) const
|
||||||
const XMLElement* XMLNode::LastChildElement( const char* name ) const
|
const XMLElement* XMLNode::LastChildElement( const char* name ) const
|
||||||
{
|
{
|
||||||
for( const XMLNode* node = _lastChild; node; node = node->_prev ) {
|
for( const XMLNode* node = _lastChild; node; node = node->_prev ) {
|
||||||
const XMLElement* element = node->ToElement();
|
const XMLElement* element = node->ToElementWithName( name );
|
||||||
if ( element ) {
|
if ( element ) {
|
||||||
if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -925,9 +921,8 @@ const XMLElement* XMLNode::LastChildElement( const char* name ) const
|
||||||
const XMLElement* XMLNode::NextSiblingElement( const char* name ) const
|
const XMLElement* XMLNode::NextSiblingElement( const char* name ) const
|
||||||
{
|
{
|
||||||
for( const XMLNode* node = _next; node; node = node->_next ) {
|
for( const XMLNode* node = _next; node; node = node->_next ) {
|
||||||
const XMLElement* element = node->ToElement();
|
const XMLElement* element = node->ToElementWithName( name );
|
||||||
if ( element
|
if ( element ) {
|
||||||
&& (!name || XMLUtil::StringEqual( name, element->Name() ))) {
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -938,9 +933,8 @@ const XMLElement* XMLNode::NextSiblingElement( const char* name ) const
|
||||||
const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const
|
const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const
|
||||||
{
|
{
|
||||||
for( const XMLNode* node = _prev; node; node = node->_prev ) {
|
for( const XMLNode* node = _prev; node; node = node->_prev ) {
|
||||||
const XMLElement* element = node->ToElement();
|
const XMLElement* element = node->ToElementWithName( name );
|
||||||
if ( element
|
if ( element ) {
|
||||||
&& (!name || XMLUtil::StringEqual( name, element->Name() ))) {
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1056,6 +1050,21 @@ void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const
|
||||||
insertThis->_memPool->SetTracked();
|
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 ---------- //
|
// --------- XMLText ---------- //
|
||||||
char* XMLText::ParseDeep( char* p, StrPair* )
|
char* XMLText::ParseDeep( char* p, StrPair* )
|
||||||
{
|
{
|
||||||
|
|
|
@ -908,6 +908,7 @@ private:
|
||||||
void Unlink( XMLNode* child );
|
void Unlink( XMLNode* child );
|
||||||
static void DeleteNode( XMLNode* node );
|
static void DeleteNode( XMLNode* node );
|
||||||
void InsertChildPreamble( XMLNode* insertThis ) const;
|
void InsertChildPreamble( XMLNode* insertThis ) const;
|
||||||
|
const XMLElement* ToElementWithName( const char* name ) const;
|
||||||
|
|
||||||
XMLNode( const XMLNode& ); // not supported
|
XMLNode( const XMLNode& ); // not supported
|
||||||
XMLNode& operator=( const XMLNode& ); // not supported
|
XMLNode& operator=( const XMLNode& ); // not supported
|
||||||
|
|
Loading…
Reference in New Issue