The existence of an error is signaled by error_string being nonempty.
This commit is contained in:
@@ -137,11 +137,8 @@ unsigned XNode::LoadAttributes( const RString &xml, PARSEINFO *pi, unsigned iOff
|
||||
if( iEnd == xml.npos )
|
||||
{
|
||||
// error
|
||||
if( !pi->error_occur )
|
||||
{
|
||||
pi->error_occur = true;
|
||||
if( pi->error_string.empty() )
|
||||
pi->error_string = ssprintf( "<%s> attribute has error ", m_sName.c_str() );
|
||||
}
|
||||
return string::npos;
|
||||
}
|
||||
|
||||
@@ -184,11 +181,8 @@ unsigned XNode::LoadAttributes( const RString &xml, PARSEINFO *pi, unsigned iOff
|
||||
if( iEnd == xml.npos )
|
||||
{
|
||||
// error
|
||||
if( !pi->error_occur )
|
||||
{
|
||||
pi->error_occur = true;
|
||||
if( pi->error_string.empty() )
|
||||
pi->error_string = ssprintf( "<%s> attribute text: couldn't find matching quote", sName.c_str() );
|
||||
}
|
||||
return string::npos;
|
||||
}
|
||||
|
||||
@@ -237,11 +231,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
|
||||
unsigned iEnd = xml.find( "-->", iOffset );
|
||||
if( iEnd == string::npos )
|
||||
{
|
||||
if( !pi->error_occur )
|
||||
{
|
||||
pi->error_occur = true;
|
||||
if( pi->error_string.empty() )
|
||||
pi->error_string = "Unterminated comment";
|
||||
}
|
||||
|
||||
return string::npos;
|
||||
}
|
||||
@@ -277,11 +268,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
|
||||
if( iOffset == xml.size() || xml[iOffset] != chXMLTagClose )
|
||||
{
|
||||
// error: <TAG ... / >
|
||||
if( !pi->error_occur )
|
||||
{
|
||||
pi->error_occur = true;
|
||||
if( pi->error_string.empty() )
|
||||
pi->error_string = "Element must be closed.";
|
||||
}
|
||||
|
||||
// ill-formed tag
|
||||
return string::npos;
|
||||
@@ -308,11 +296,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
|
||||
unsigned iEnd = xml.find( chXMLTagOpen, iOffset );
|
||||
if( iEnd == string::npos )
|
||||
{
|
||||
if( !pi->error_occur )
|
||||
{
|
||||
pi->error_occur = true;
|
||||
if( pi->error_string.empty() )
|
||||
pi->error_string = ssprintf( "%s must be closed with </%s>", m_sName.c_str(), m_sName.c_str() );
|
||||
}
|
||||
// error cos not exist CloseTag </TAG>
|
||||
return string::npos;
|
||||
}
|
||||
@@ -355,11 +340,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
|
||||
unsigned iEnd = xml.find_first_of( " >", iOffset );
|
||||
if( iEnd == string::npos )
|
||||
{
|
||||
if( !pi->error_occur )
|
||||
{
|
||||
pi->error_occur = true;
|
||||
if( pi->error_string.empty() )
|
||||
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
|
||||
}
|
||||
// error
|
||||
return string::npos;
|
||||
}
|
||||
@@ -376,11 +358,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
|
||||
else
|
||||
{
|
||||
// not welformed open/close
|
||||
if( !pi->error_occur )
|
||||
{
|
||||
pi->error_occur = true;
|
||||
if( pi->error_string.empty() )
|
||||
pi->error_string = ssprintf( "'<%s> ... </%s>' is not well-formed.", m_sName.c_str(), closename.c_str() );
|
||||
}
|
||||
return string::npos;
|
||||
}
|
||||
}
|
||||
@@ -393,11 +372,8 @@ unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset )
|
||||
if( iEnd == string::npos )
|
||||
{
|
||||
// error cos not exist CloseTag </TAG>
|
||||
if( !pi->error_occur )
|
||||
{
|
||||
pi->error_occur = true;
|
||||
if( pi->error_string.empty() )
|
||||
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
|
||||
}
|
||||
return string::npos;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,7 @@ typedef multimap<RString,XNode*> XNodes;
|
||||
// Parse info.
|
||||
struct PARSEINFO
|
||||
{
|
||||
bool error_occur; // [get] is occurance of error?
|
||||
RString error_string; // [get] error string
|
||||
|
||||
PARSEINFO() { error_occur = false; }
|
||||
};
|
||||
|
||||
// display optional environment
|
||||
|
||||
@@ -11,19 +11,12 @@ bool XmlFileUtil::LoadFromFileShowErrors( XNode &xml, RageFileBasic &f )
|
||||
PARSEINFO pi;
|
||||
RString s;
|
||||
if( f.Read( s ) == -1 )
|
||||
{
|
||||
pi.error_occur = true;
|
||||
pi.error_string = f.GetError();
|
||||
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
xml.Load( s, &pi );
|
||||
if( pi.error_string.empty() )
|
||||
return true;
|
||||
|
||||
xml.Load( s, &pi );
|
||||
if( pi.error_occur )
|
||||
goto error;
|
||||
return true;
|
||||
|
||||
error:
|
||||
RString sWarning = ssprintf( "XML: LoadFromFile failed: %s", pi.error_string.c_str() );
|
||||
LOG->Warn( sWarning );
|
||||
Dialog::OK( sWarning, "XML_PARSE_ERROR" );
|
||||
|
||||
Reference in New Issue
Block a user