Simplify.

This commit is contained in:
Steve Checkoway
2006-10-01 12:52:00 +00:00
parent d778966fc6
commit 08155c351a
3 changed files with 29 additions and 35 deletions
+22 -22
View File
@@ -119,7 +119,7 @@ void XNode::Clear()
// Param : pszAttrs - xml of attributes // Param : pszAttrs - xml of attributes
// pi = parser information // pi = parser information
// Return : advanced string pointer. (error return npos) // Return : advanced string pointer. (error return npos)
unsigned XNode::LoadAttributes( const RString &xml, PARSEINFO *pi, unsigned iOffset ) unsigned XNode::LoadAttributes( const RString &xml, RString &sErrorOut, unsigned iOffset )
{ {
while( iOffset < xml.size() ) while( iOffset < xml.size() )
{ {
@@ -137,8 +137,8 @@ unsigned XNode::LoadAttributes( const RString &xml, PARSEINFO *pi, unsigned iOff
if( iEnd == xml.npos ) if( iEnd == xml.npos )
{ {
// error // error
if( pi->error_string.empty() ) if( sErrorOut.empty() )
pi->error_string = ssprintf( "<%s> attribute has error ", m_sName.c_str() ); sErrorOut = ssprintf( "<%s> attribute has error ", m_sName.c_str() );
return string::npos; return string::npos;
} }
@@ -181,8 +181,8 @@ unsigned XNode::LoadAttributes( const RString &xml, PARSEINFO *pi, unsigned iOff
if( iEnd == xml.npos ) if( iEnd == xml.npos )
{ {
// error // error
if( pi->error_string.empty() ) if( sErrorOut.empty() )
pi->error_string = ssprintf( "<%s> attribute text: couldn't find matching quote", sName.c_str() ); sErrorOut = ssprintf( "<%s> attribute text: couldn't find matching quote", sName.c_str() );
return string::npos; return string::npos;
} }
@@ -209,7 +209,7 @@ unsigned XNode::LoadAttributes( const RString &xml, PARSEINFO *pi, unsigned iOff
// Param : pszXml - plain xml text // Param : pszXml - plain xml text
// pi = parser information // pi = parser information
// Return : advanced string pointer (error return npos) // Return : advanced string pointer (error return npos)
unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset ) unsigned XNode::Load( const RString &xml, RString &sErrorOut, unsigned iOffset )
{ {
Clear(); Clear();
@@ -231,8 +231,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
unsigned iEnd = xml.find( "-->", iOffset ); unsigned iEnd = xml.find( "-->", iOffset );
if( iEnd == string::npos ) if( iEnd == string::npos )
{ {
if( pi->error_string.empty() ) if( sErrorOut.empty() )
pi->error_string = "Unterminated comment"; sErrorOut = "Unterminated comment";
return string::npos; return string::npos;
} }
@@ -240,7 +240,7 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
// Skip -->. // Skip -->.
iOffset = iEnd + 3; iOffset = iEnd + 3;
return Load( xml, pi, iOffset ); return Load( xml, sErrorOut, iOffset );
} }
// XML Node Tag Name Open // XML Node Tag Name Open
@@ -250,7 +250,7 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
iOffset = iTagEnd; iOffset = iTagEnd;
// Generate XML Attributte List // Generate XML Attributte List
iOffset = LoadAttributes( xml, pi, iOffset ); iOffset = LoadAttributes( xml, sErrorOut, iOffset );
if( iOffset == string::npos ) if( iOffset == string::npos )
return string::npos; return string::npos;
@@ -268,8 +268,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
if( iOffset == xml.size() || xml[iOffset] != chXMLTagClose ) if( iOffset == xml.size() || xml[iOffset] != chXMLTagClose )
{ {
// error: <TAG ... / > // error: <TAG ... / >
if( pi->error_string.empty() ) if( sErrorOut.empty() )
pi->error_string = "Element must be closed."; sErrorOut = "Element must be closed.";
// ill-formed tag // ill-formed tag
return string::npos; return string::npos;
@@ -282,7 +282,7 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
// just loaded is a meta tag, then Load ourself again using the rest // just loaded is a meta tag, then Load ourself again using the rest
// of the file until we reach a non-meta tag. // of the file until we reach a non-meta tag.
if( !m_sName.empty() && (m_sName[0] == chXMLQuestion || m_sName[0] == chXMLExclamation) ) if( !m_sName.empty() && (m_sName[0] == chXMLQuestion || m_sName[0] == chXMLExclamation) )
iOffset = Load( xml, pi, iOffset ); iOffset = Load( xml, sErrorOut, iOffset );
return iOffset; return iOffset;
} }
@@ -296,8 +296,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
unsigned iEnd = xml.find( chXMLTagOpen, iOffset ); unsigned iEnd = xml.find( chXMLTagOpen, iOffset );
if( iEnd == string::npos ) if( iEnd == string::npos )
{ {
if( pi->error_string.empty() ) if( sErrorOut.empty() )
pi->error_string = ssprintf( "%s must be closed with </%s>", m_sName.c_str(), m_sName.c_str() ); sErrorOut = ssprintf( "%s must be closed with </%s>", m_sName.c_str(), m_sName.c_str() );
// error cos not exist CloseTag </TAG> // error cos not exist CloseTag </TAG>
return string::npos; return string::npos;
} }
@@ -314,7 +314,7 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
{ {
XNode *node = new XNode; XNode *node = new XNode;
iOffset = node->Load( xml, pi, iOffset ); iOffset = node->Load( xml, sErrorOut, iOffset );
if( !node->m_sName.empty() ) if( !node->m_sName.empty() )
{ {
DEBUG_ASSERT( node->m_sName.size() ); DEBUG_ASSERT( node->m_sName.size() );
@@ -340,8 +340,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
unsigned iEnd = xml.find_first_of( " >", iOffset ); unsigned iEnd = xml.find_first_of( " >", iOffset );
if( iEnd == string::npos ) if( iEnd == string::npos )
{ {
if( pi->error_string.empty() ) if( sErrorOut.empty() )
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() ); sErrorOut = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
// error // error
return string::npos; return string::npos;
} }
@@ -358,8 +358,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
else else
{ {
// not welformed open/close // not welformed open/close
if( pi->error_string.empty() ) if( sErrorOut.empty() )
pi->error_string = ssprintf( "'<%s> ... </%s>' is not well-formed.", m_sName.c_str(), closename.c_str() ); sErrorOut = ssprintf( "'<%s> ... </%s>' is not well-formed.", m_sName.c_str(), closename.c_str() );
return string::npos; return string::npos;
} }
} }
@@ -372,8 +372,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
if( iEnd == string::npos ) if( iEnd == string::npos )
{ {
// error cos not exist CloseTag </TAG> // error cos not exist CloseTag </TAG>
if( pi->error_string.empty() ) if( sErrorOut.empty() )
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() ); sErrorOut = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
return string::npos; return string::npos;
} }
+2 -8
View File
@@ -35,12 +35,6 @@ typedef multimap<RString,XNode*> XNodes;
Var##Iter != (pNode)->m_childs.end(); \ Var##Iter != (pNode)->m_childs.end(); \
++Var##Iter ) ++Var##Iter )
// Parse info.
struct PARSEINFO
{
RString error_string; // [get] error string
};
// display optional environment // display optional environment
struct DISP_OPT struct DISP_OPT
{ {
@@ -82,8 +76,8 @@ public:
void SetValue( const DateTime &v ); void SetValue( const DateTime &v );
// Load/Save XML // Load/Save XML
unsigned Load( const RString &sXml, PARSEINFO *pi, unsigned iOffset = 0 ); unsigned Load( const RString &sXml, RString &sErrorOut, unsigned iOffset = 0 );
unsigned LoadAttributes( const RString &sAttrs, PARSEINFO *pi, unsigned iOffset ); unsigned LoadAttributes( const RString &sAttrs, RString &sErrorOut, unsigned iOffset );
bool GetXML( RageFileBasic &f, DISP_OPT &opt ) const; bool GetXML( RageFileBasic &f, DISP_OPT &opt ) const;
bool GetAttrXML( RageFileBasic &f, DISP_OPT &opt, const RString &sName, const RString &sValue ) const; bool GetAttrXML( RageFileBasic &f, DISP_OPT &opt, const RString &sName, const RString &sValue ) const;
RString GetXML() const; RString GetXML() const;
+5 -5
View File
@@ -8,16 +8,16 @@
bool XmlFileUtil::LoadFromFileShowErrors( XNode &xml, RageFileBasic &f ) bool XmlFileUtil::LoadFromFileShowErrors( XNode &xml, RageFileBasic &f )
{ {
PARSEINFO pi; RString sError;
RString s; RString s;
if( f.Read( s ) == -1 ) if( f.Read( s ) == -1 )
pi.error_string = f.GetError(); sError = f.GetError();
else else
xml.Load( s, &pi ); xml.Load( s, sError );
if( pi.error_string.empty() ) if( sError.empty() )
return true; return true;
RString sWarning = ssprintf( "XML: LoadFromFile failed: %s", pi.error_string.c_str() ); RString sWarning = ssprintf( "XML: LoadFromFile failed: %s", sError.c_str() );
LOG->Warn( sWarning ); LOG->Warn( sWarning );
Dialog::OK( sWarning, "XML_PARSE_ERROR" ); Dialog::OK( sWarning, "XML_PARSE_ERROR" );
return false; return false;