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 )
|
if( iEnd == xml.npos )
|
||||||
{
|
{
|
||||||
// error
|
// error
|
||||||
if( !pi->error_occur )
|
if( pi->error_string.empty() )
|
||||||
{
|
|
||||||
pi->error_occur = true;
|
|
||||||
pi->error_string = ssprintf( "<%s> attribute has error ", m_sName.c_str() );
|
pi->error_string = ssprintf( "<%s> attribute has error ", m_sName.c_str() );
|
||||||
}
|
|
||||||
return string::npos;
|
return string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,11 +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_occur )
|
if( pi->error_string.empty() )
|
||||||
{
|
|
||||||
pi->error_occur = true;
|
|
||||||
pi->error_string = ssprintf( "<%s> attribute text: couldn't find matching quote", sName.c_str() );
|
pi->error_string = ssprintf( "<%s> attribute text: couldn't find matching quote", sName.c_str() );
|
||||||
}
|
|
||||||
return string::npos;
|
return string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,11 +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_occur )
|
if( pi->error_string.empty() )
|
||||||
{
|
|
||||||
pi->error_occur = true;
|
|
||||||
pi->error_string = "Unterminated comment";
|
pi->error_string = "Unterminated comment";
|
||||||
}
|
|
||||||
|
|
||||||
return string::npos;
|
return string::npos;
|
||||||
}
|
}
|
||||||
@@ -277,11 +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_occur )
|
if( pi->error_string.empty() )
|
||||||
{
|
|
||||||
pi->error_occur = true;
|
|
||||||
pi->error_string = "Element must be closed.";
|
pi->error_string = "Element must be closed.";
|
||||||
}
|
|
||||||
|
|
||||||
// ill-formed tag
|
// ill-formed tag
|
||||||
return string::npos;
|
return string::npos;
|
||||||
@@ -308,11 +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_occur )
|
if( pi->error_string.empty() )
|
||||||
{
|
|
||||||
pi->error_occur = true;
|
|
||||||
pi->error_string = ssprintf( "%s must be closed with </%s>", m_sName.c_str(), m_sName.c_str() );
|
pi->error_string = 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;
|
||||||
}
|
}
|
||||||
@@ -355,11 +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_occur )
|
if( pi->error_string.empty() )
|
||||||
{
|
|
||||||
pi->error_occur = true;
|
|
||||||
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
|
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
|
||||||
}
|
|
||||||
// error
|
// error
|
||||||
return string::npos;
|
return string::npos;
|
||||||
}
|
}
|
||||||
@@ -376,11 +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_occur )
|
if( pi->error_string.empty() )
|
||||||
{
|
|
||||||
pi->error_occur = true;
|
|
||||||
pi->error_string = ssprintf( "'<%s> ... </%s>' is not well-formed.", m_sName.c_str(), closename.c_str() );
|
pi->error_string = ssprintf( "'<%s> ... </%s>' is not well-formed.", m_sName.c_str(), closename.c_str() );
|
||||||
}
|
|
||||||
return string::npos;
|
return string::npos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,11 +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_occur )
|
if( pi->error_string.empty() )
|
||||||
{
|
|
||||||
pi->error_occur = true;
|
|
||||||
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
|
pi->error_string = ssprintf( "it must be closed with </%s>", m_sName.c_str() );
|
||||||
}
|
|
||||||
return string::npos;
|
return string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,10 +38,7 @@ typedef multimap<RString,XNode*> XNodes;
|
|||||||
// Parse info.
|
// Parse info.
|
||||||
struct PARSEINFO
|
struct PARSEINFO
|
||||||
{
|
{
|
||||||
bool error_occur; // [get] is occurance of error?
|
|
||||||
RString error_string; // [get] error string
|
RString error_string; // [get] error string
|
||||||
|
|
||||||
PARSEINFO() { error_occur = false; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// display optional environment
|
// display optional environment
|
||||||
|
|||||||
@@ -11,19 +11,12 @@ bool XmlFileUtil::LoadFromFileShowErrors( XNode &xml, RageFileBasic &f )
|
|||||||
PARSEINFO pi;
|
PARSEINFO pi;
|
||||||
RString s;
|
RString s;
|
||||||
if( f.Read( s ) == -1 )
|
if( f.Read( s ) == -1 )
|
||||||
{
|
|
||||||
pi.error_occur = true;
|
|
||||||
pi.error_string = f.GetError();
|
pi.error_string = f.GetError();
|
||||||
|
else
|
||||||
|
xml.Load( s, &pi );
|
||||||
|
if( pi.error_string.empty() )
|
||||||
|
return true;
|
||||||
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
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() );
|
RString sWarning = ssprintf( "XML: LoadFromFile failed: %s", pi.error_string.c_str() );
|
||||||
LOG->Warn( sWarning );
|
LOG->Warn( sWarning );
|
||||||
Dialog::OK( sWarning, "XML_PARSE_ERROR" );
|
Dialog::OK( sWarning, "XML_PARSE_ERROR" );
|
||||||
|
|||||||
Reference in New Issue
Block a user