Simplify.

This commit is contained in:
Steve Checkoway
2007-02-04 10:57:09 +00:00
parent 69b4f62a7a
commit eebc1e9f3c
+21 -26
View File
@@ -402,41 +402,39 @@ unsigned LoadInternal( XNode *pNode, const RString &xml, RString &sErrorOut, uns
bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int &iTabBase ) bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int &iTabBase )
{ {
#define WRITE(x) if( f.Write(x) == -1 ) return false
// tab // tab
if( f.Write("\r\n") == -1 ) WRITE( "\r\n" );
return false;
if( bWriteTabs ) if( bWriteTabs )
for( int i = 0 ; i < iTabBase ; i++) for( int i = 0 ; i < iTabBase ; i++)
if( f.Write("\t") == -1 ) WRITE( "\t" );
return false;
// <TAG // <TAG
if( f.Write("<") == -1 || f.Write(pNode->GetName()) == -1 ) WRITE( "<" );
return false; WRITE( pNode->GetName() );
// <TAG Attr1="Val1" // <TAG Attr1="Val1"
if( !pNode->m_attrs.empty() ) if( !pNode->m_attrs.empty() )
if( f.Write(" ") == -1 ) WRITE( " " );
return false;
FOREACH_CONST_Attr( pNode, p ) FOREACH_CONST_Attr( pNode, p )
{ {
RString attr( p->second->GetValue<RString>() ); RString attr( p->second->GetValue<RString>() );
ReplaceEntityText( attr, g_mapCharsToEntities ); ReplaceEntityText( attr, g_mapCharsToEntities );
if( f.Write( p->first ) == -1 || f.Write( "='" ) == -1 || f.Write( attr ) || f.Write( "' " ) == -1 ) WRITE( p->first );
return false; WRITE( "='" );
WRITE( attr );
WRITE( "' " );
} }
if( pNode->m_childs.empty() && pNode->m_pValue->GetValue<RString>().empty() ) if( pNode->m_childs.empty() && pNode->m_pValue->GetValue<RString>().empty() )
{ {
// <TAG Attr1="Val1"/> alone tag // <TAG Attr1="Val1"/> alone tag
if( f.Write("/>") == -1 ) WRITE( "/>" );
return false;
} }
else else
{ {
// <TAG Attr1="Val1"> and get child // <TAG Attr1="Val1"> and get child
if( f.Write(">") == -1 ) WRITE( ">" );
return false;
if( !pNode->m_childs.empty() ) if( !pNode->m_childs.empty() )
iTabBase++; iTabBase++;
@@ -450,37 +448,34 @@ bool GetXMLInternal( const XNode *pNode, RageFileBasic &f, bool bWriteTabs, int
{ {
if( !pNode->m_childs.empty() ) if( !pNode->m_childs.empty() )
{ {
if( f.Write("\r\n") == -1 ) WRITE( "\r\n" );
return false;
if( bWriteTabs ) if( bWriteTabs )
for( int i = 0 ; i < iTabBase ; i++) for( int i = 0 ; i < iTabBase ; i++)
if( f.Write("\t") == -1 ) WRITE( "\t" );
return false;
} }
RString s; RString s;
pNode->m_pValue->GetValue( s ); pNode->m_pValue->GetValue( s );
ReplaceEntityText( s, g_mapCharsToEntities ); ReplaceEntityText( s, g_mapCharsToEntities );
if( f.Write(s) == -1 ) WRITE( s );
return false;
} }
// </TAG> CloseTag // </TAG> CloseTag
if( !pNode->m_childs.empty() ) if( !pNode->m_childs.empty() )
{ {
if( f.Write("\r\n") == -1 ) WRITE( "\r\n" );
return false;
if( bWriteTabs ) if( bWriteTabs )
for( int i = 0 ; i < iTabBase-1 ; i++) for( int i = 0 ; i < iTabBase-1 ; i++)
if( f.Write("\t") == -1 ) WRITE( "\t" );
return false;
} }
if( f.Write("</") == -1 || f.Write(pNode->GetName()) == -1 || f.Write(">") == -1 ) WRITE( "</" );
return false; WRITE( pNode->GetName() );
WRITE( ">" );
if( !pNode->m_childs.empty() ) if( !pNode->m_childs.empty() )
iTabBase--; iTabBase--;
} }
return true; return true;
#undef WRITE
} }
} }