cleanups
This commit is contained in:
+80
-102
@@ -1,8 +1,5 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "XmlFile.h"
|
#include "XmlFile.h"
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
#include "RageFile.h"
|
#include "RageFile.h"
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
@@ -11,6 +8,10 @@
|
|||||||
#include "arch/Dialog/Dialog.h"
|
#include "arch/Dialog/Dialog.h"
|
||||||
#include "RageFileDriverMemory.h"
|
#include "RageFileDriverMemory.h"
|
||||||
|
|
||||||
|
static inline long XStr2Int( const char* str, long default_value = 0 )
|
||||||
|
{
|
||||||
|
return str ? atol(str) : default_value;
|
||||||
|
}
|
||||||
|
|
||||||
static const char chXMLTagOpen = '<';
|
static const char chXMLTagOpen = '<';
|
||||||
static const char chXMLTagClose = '>';
|
static const char chXMLTagClose = '>';
|
||||||
@@ -42,18 +43,18 @@ static char* tcsskip( const char* psz )
|
|||||||
// Name : tcsechr
|
// Name : tcsechr
|
||||||
// Desc : similar with strchr with escape process
|
// Desc : similar with strchr with escape process
|
||||||
// Param : escape - will be escape character
|
// Param : escape - will be escape character
|
||||||
static char* tcsechr( const char* psz, int ch, int escape )
|
static const char* tcsechr( const char* pch, int ch, char escape )
|
||||||
{
|
{
|
||||||
char* pch = (char*)psz;
|
bool bInEscape = false;
|
||||||
char* prev_escape = NULL;
|
|
||||||
while( pch && *pch )
|
while( pch && *pch )
|
||||||
{
|
{
|
||||||
if( *pch == escape && prev_escape == NULL )
|
if( *pch == escape && !bInEscape )
|
||||||
prev_escape = pch;
|
bInEscape = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
prev_escape = NULL;
|
bInEscape = false;
|
||||||
if( *pch == ch ) return (char*)pch;
|
if( *pch == ch )
|
||||||
|
return pch;
|
||||||
}
|
}
|
||||||
pch++;
|
pch++;
|
||||||
}
|
}
|
||||||
@@ -62,19 +63,17 @@ static char* tcsechr( const char* psz, int ch, int escape )
|
|||||||
|
|
||||||
// Desc : similar with strlen with escape process
|
// Desc : similar with strlen with escape process
|
||||||
// Param : escape - will be escape character
|
// Param : escape - will be escape character
|
||||||
static int tcselen( int escape, const char *start, const char *end )
|
static int tcselen( char escape, const char *start, const char *end )
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
if( end == NULL )
|
bool bInEscape = false;
|
||||||
end = (char*) sizeof(long);
|
|
||||||
const char *prev_escape = NULL;
|
|
||||||
while( start && *start && start<end )
|
while( start && *start && start<end )
|
||||||
{
|
{
|
||||||
if( *start == escape && prev_escape == NULL )
|
if( *start == escape && !bInEscape )
|
||||||
prev_escape = start;
|
bInEscape = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
prev_escape = NULL;
|
bInEscape = false;
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
++start;
|
++start;
|
||||||
@@ -84,7 +83,7 @@ static int tcselen( int escape, const char *start, const char *end )
|
|||||||
|
|
||||||
// Desc : similar with _tcscpy with escape process
|
// Desc : similar with _tcscpy with escape process
|
||||||
// Param : escape - will be escape character
|
// Param : escape - will be escape character
|
||||||
static void unescape( char *psz, int escape, char* srt, char* end = NULL )
|
static void unescape( char *psz, int escape, const char* srt, const char* end = NULL )
|
||||||
{
|
{
|
||||||
const char* pch = srt;
|
const char* pch = srt;
|
||||||
if( end==NULL ) end = (char*)sizeof(long);
|
if( end==NULL ) end = (char*)sizeof(long);
|
||||||
@@ -131,16 +130,21 @@ static bool XIsEmptyString( const CString &s )
|
|||||||
return s.find_first_not_of( "\r\n\t " ) == s.npos;
|
return s.find_first_not_of( "\r\n\t " ) == s.npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Desc : put string of (psz~end) on ps string
|
// put string of (psz~end) on ps string
|
||||||
static void SetString( char* psz, char* end, CString* ps, bool trim = false, int escape = 0 )
|
static void SetString( const char* psz, const char* end, CString* ps, bool trim = false, char escape = 0 )
|
||||||
{
|
{
|
||||||
if( trim )
|
if( trim )
|
||||||
{
|
{
|
||||||
while( psz && psz < end && isspace(*psz) ) psz++;
|
while( psz < end && isspace(*psz) )
|
||||||
while( (end-1) && psz < (end-1) && isspace(*(end-1)) ) end--;
|
psz++;
|
||||||
|
while( end-1 >= psz && isspace(end[-1]) )
|
||||||
|
end--;
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = end - psz;
|
int len = end - psz;
|
||||||
if( len <= 0 ) return;
|
if( len <= 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
if( escape )
|
if( escape )
|
||||||
{
|
{
|
||||||
len = tcselen( escape, psz, end );
|
len = tcselen( escape, psz, end );
|
||||||
@@ -179,14 +183,8 @@ 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 NULL)
|
// Return : advanced string pointer. (error return NULL)
|
||||||
//--------------------------------------------------------
|
const char* XNode::LoadAttributes( const char* xml, PARSEINFO *pi /*= &piDefault*/)
|
||||||
// Coder Date Desc
|
|
||||||
// bro 2002-10-29
|
|
||||||
//========================================================
|
|
||||||
char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault*/)
|
|
||||||
{
|
{
|
||||||
char* xml = (char*)pszAttrs;
|
|
||||||
|
|
||||||
while( xml && *xml )
|
while( xml && *xml )
|
||||||
{
|
{
|
||||||
xml = tcsskip( xml );
|
xml = tcsskip( xml );
|
||||||
@@ -199,7 +197,7 @@ char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault*
|
|||||||
return xml;
|
return xml;
|
||||||
|
|
||||||
// XML Attr Name
|
// XML Attr Name
|
||||||
char* pEnd = strpbrk( xml, " =" );
|
const char* pEnd = strpbrk( xml, " =" );
|
||||||
if( pEnd == NULL )
|
if( pEnd == NULL )
|
||||||
{
|
{
|
||||||
// error
|
// error
|
||||||
@@ -278,16 +276,10 @@ char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault*
|
|||||||
// Param : pszXml - plain xml text
|
// Param : pszXml - plain xml text
|
||||||
// pi = parser information
|
// pi = parser information
|
||||||
// Return : advanced string pointer (error return NULL)
|
// Return : advanced string pointer (error return NULL)
|
||||||
//--------------------------------------------------------
|
const char* XNode::Load( const char* xml, PARSEINFO *pi /*= &piDefault*/ )
|
||||||
// Coder Date Desc
|
|
||||||
// bro 2002-10-29
|
|
||||||
//========================================================
|
|
||||||
char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
|
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
char* xml = (char*)pszXml;
|
|
||||||
|
|
||||||
// <
|
// <
|
||||||
xml = strchr( xml, chXMLTagOpen );
|
xml = strchr( xml, chXMLTagOpen );
|
||||||
if( xml == NULL )
|
if( xml == NULL )
|
||||||
@@ -325,7 +317,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
|
|||||||
|
|
||||||
// XML Node Tag Name Open
|
// XML Node Tag Name Open
|
||||||
xml++;
|
xml++;
|
||||||
char* pTagEnd = strpbrk( xml, " \t\r\n/>" );
|
const char* pTagEnd = strpbrk( xml, " \t\r\n/>" );
|
||||||
SetString( xml, pTagEnd, &m_sName );
|
SetString( xml, pTagEnd, &m_sName );
|
||||||
|
|
||||||
xml = pTagEnd;
|
xml = pTagEnd;
|
||||||
@@ -345,8 +337,21 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
|
|||||||
if( *xml == chXMLDash )
|
if( *xml == chXMLDash )
|
||||||
xml++;
|
xml++;
|
||||||
|
|
||||||
if( *xml == chXMLTagClose )
|
if( *xml != chXMLTagClose )
|
||||||
{
|
{
|
||||||
|
// error: <TAG ... / >
|
||||||
|
if( !pi->error_occur )
|
||||||
|
{
|
||||||
|
pi->error_occur = true;
|
||||||
|
pi->error_pointer = xml;
|
||||||
|
pi->error_code = PIE_ALONE_NOT_CLOSED;
|
||||||
|
pi->error_string = "Element must be closed.";
|
||||||
|
}
|
||||||
|
|
||||||
|
// ill-formed tag
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// well-formed tag
|
// well-formed tag
|
||||||
++xml;
|
++xml;
|
||||||
|
|
||||||
@@ -358,30 +363,13 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
|
|||||||
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// error: <TAG ... / >
|
|
||||||
if( !pi->error_occur )
|
|
||||||
{
|
|
||||||
pi->error_occur = true;
|
|
||||||
pi->error_pointer = xml;
|
|
||||||
pi->error_code = PIE_ALONE_NOT_CLOSED;
|
|
||||||
pi->error_string = ("Element must be closed.");
|
|
||||||
}
|
|
||||||
// not wel-formed tag
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
// open/close tag <TAG ..> ... </TAG>
|
// open/close tag <TAG ..> ... </TAG>
|
||||||
// ^- current pointer
|
// ^- current pointer
|
||||||
{
|
|
||||||
// text value°¡ ¾øÀ¸¸�E³Öµµ·ÏÇÑ´Ù.
|
|
||||||
//if( this->m_sValue.empty() || this->m_sValue == ("") )
|
|
||||||
if( XIsEmptyString( m_sValue ) )
|
if( XIsEmptyString( m_sValue ) )
|
||||||
{
|
{
|
||||||
// Text Value
|
// Text Value
|
||||||
char* pEnd = tcsechr( ++xml, chXMLTagOpen, chXMLEscape );
|
const char* pEnd = tcsechr( ++xml, chXMLTagOpen, chXMLEscape );
|
||||||
if( pEnd == NULL )
|
if( pEnd == NULL )
|
||||||
{
|
{
|
||||||
if( !pi->error_occur )
|
if( !pi->error_occur )
|
||||||
@@ -397,7 +385,6 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
|
|||||||
|
|
||||||
bool trim = pi->trim_value;
|
bool trim = pi->trim_value;
|
||||||
char escape = pi->escape_value;
|
char escape = pi->escape_value;
|
||||||
//SetString( xml, pEnd, &m_sValue, trim, chXMLEscape );
|
|
||||||
SetString( xml, pEnd, &m_sValue, trim, escape );
|
SetString( xml, pEnd, &m_sValue, trim, escape );
|
||||||
|
|
||||||
xml = pEnd;
|
xml = pEnd;
|
||||||
@@ -435,7 +422,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
CString closename;
|
CString closename;
|
||||||
char* pEnd = strpbrk( xml, " >" );
|
const char* pEnd = strpbrk( xml, " >" );
|
||||||
if( pEnd == NULL )
|
if( pEnd == NULL )
|
||||||
{
|
{
|
||||||
if( !pi->error_occur )
|
if( !pi->error_occur )
|
||||||
@@ -472,14 +459,11 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Alone child Tag Loaded
|
else // Alone child Tag Loaded
|
||||||
// else ÇØ¾ßÇÏ´ÂÁ�E¸»¾Æ¾ßÇÏ´ÂÁ�EÀǽɰ£´Ù.
|
|
||||||
{
|
{
|
||||||
|
|
||||||
//if( xml && this->m_sValue.empty() && *xml !=chXMLTagOpen )
|
|
||||||
if( xml && XIsEmptyString( m_sValue ) && *xml !=chXMLTagOpen )
|
if( xml && XIsEmptyString( m_sValue ) && *xml !=chXMLTagOpen )
|
||||||
{
|
{
|
||||||
// Text Value
|
// Text Value
|
||||||
char* pEnd = tcsechr( xml, chXMLTagOpen, chXMLEscape );
|
const char* pEnd = tcsechr( xml, chXMLTagOpen, chXMLEscape );
|
||||||
if( pEnd == NULL )
|
if( pEnd == NULL )
|
||||||
{
|
{
|
||||||
// error cos not exist CloseTag </TAG>
|
// error cos not exist CloseTag </TAG>
|
||||||
@@ -495,7 +479,6 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
|
|||||||
|
|
||||||
bool trim = pi->trim_value;
|
bool trim = pi->trim_value;
|
||||||
char escape = pi->escape_value;
|
char escape = pi->escape_value;
|
||||||
//SetString( xml, pEnd, &m_sValue, trim, chXMLEscape );
|
|
||||||
SetString( xml, pEnd, &m_sValue, trim, escape );
|
SetString( xml, pEnd, &m_sValue, trim, escape );
|
||||||
|
|
||||||
xml = pEnd;
|
xml = pEnd;
|
||||||
@@ -505,7 +488,6 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
@@ -524,7 +506,6 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt ) const
|
|||||||
// tab
|
// tab
|
||||||
if( opt && opt->newline )
|
if( opt && opt->newline )
|
||||||
{
|
{
|
||||||
if( opt && opt->newline )
|
|
||||||
if( f.Write("\r\n") == -1 )
|
if( f.Write("\r\n") == -1 )
|
||||||
return false;
|
return false;
|
||||||
if( opt->write_tabs )
|
if( opt->write_tabs )
|
||||||
@@ -614,27 +595,27 @@ CString XNode::GetXML() const
|
|||||||
return f.GetString();
|
return f.GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XNode::GetValue(CString &out) const { out = m_sValue; }
|
void XNode::GetValue( CString &out ) const { out = m_sValue; }
|
||||||
void XNode::GetValue(int &out) const { out = atoi(m_sValue); }
|
void XNode::GetValue( int &out ) const { out = atoi(m_sValue); }
|
||||||
void XNode::GetValue(float &out) const { out = strtof(m_sValue, NULL); }
|
void XNode::GetValue( float &out ) const { out = strtof(m_sValue, NULL); }
|
||||||
void XNode::GetValue(bool &out) const { out = atoi(m_sValue) != 0; }
|
void XNode::GetValue( bool &out ) const { out = atoi(m_sValue) != 0; }
|
||||||
void XNode::GetValue(unsigned &out) const { out = 0; sscanf(m_sValue,"%u",&out); }
|
void XNode::GetValue( unsigned &out ) const { out = 0; sscanf(m_sValue,"%u",&out); }
|
||||||
void XNode::GetValue(DateTime &out) const { out.FromString( m_sValue ); }
|
void XNode::GetValue( DateTime &out ) const { out.FromString( m_sValue ); }
|
||||||
|
|
||||||
void XAttr::GetValue(CString &out) const { out = m_sValue; }
|
void XAttr::GetValue( CString &out ) const { out = m_sValue; }
|
||||||
void XAttr::GetValue(int &out) const { out = atoi(m_sValue); }
|
void XAttr::GetValue( int &out ) const { out = atoi(m_sValue); }
|
||||||
void XAttr::GetValue(float &out) const { out = strtof(m_sValue, NULL); }
|
void XAttr::GetValue( float &out ) const { out = strtof(m_sValue, NULL); }
|
||||||
void XAttr::GetValue(bool &out) const { out = atoi(m_sValue) != 0; }
|
void XAttr::GetValue( bool &out ) const { out = atoi(m_sValue) != 0; }
|
||||||
void XAttr::GetValue(unsigned &out) const { out = 0; sscanf(m_sValue,"%u",&out); }
|
void XAttr::GetValue( unsigned &out ) const { out = 0; sscanf(m_sValue,"%u",&out); }
|
||||||
void XAttr::GetValue(DateTime &out) const { out.FromString( m_sValue ); }
|
void XAttr::GetValue( DateTime &out ) const { out.FromString( m_sValue ); }
|
||||||
|
|
||||||
void XNode::SetValue(int v) { m_sValue = ssprintf("%d",v); }
|
void XNode::SetValue( int v ) { m_sValue = ssprintf("%d",v); }
|
||||||
void XNode::SetValue(float v) { m_sValue = ssprintf("%f",v); }
|
void XNode::SetValue( float v ) { m_sValue = ssprintf("%f",v); }
|
||||||
void XNode::SetValue(bool v) { m_sValue = ssprintf("%d",v); }
|
void XNode::SetValue( bool v ) { m_sValue = ssprintf("%d",v); }
|
||||||
void XNode::SetValue(unsigned v) { m_sValue = ssprintf("%u",v); }
|
void XNode::SetValue( unsigned v ) { m_sValue = ssprintf("%u",v); }
|
||||||
void XNode::SetValue(const DateTime &v) { m_sValue = v.GetString(); }
|
void XNode::SetValue( const DateTime &v ) { m_sValue = v.GetString(); }
|
||||||
|
|
||||||
const XAttr *XNode::GetAttr( const char* attrname ) const
|
const XAttr *XNode::GetAttr( const CString &attrname ) const
|
||||||
{
|
{
|
||||||
multimap<CString, XAttr*>::const_iterator it = m_attrs.find( attrname );
|
multimap<CString, XAttr*>::const_iterator it = m_attrs.find( attrname );
|
||||||
if( it != m_attrs.end() )
|
if( it != m_attrs.end() )
|
||||||
@@ -645,7 +626,7 @@ const XAttr *XNode::GetAttr( const char* attrname ) const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
XAttr *XNode::GetAttr( const char* attrname )
|
XAttr *XNode::GetAttr( const CString &attrname )
|
||||||
{
|
{
|
||||||
multimap<CString, XAttr*>::iterator it = m_attrs.find( attrname );
|
multimap<CString, XAttr*>::iterator it = m_attrs.find( attrname );
|
||||||
if( it != m_attrs.end() )
|
if( it != m_attrs.end() )
|
||||||
@@ -657,7 +638,7 @@ XAttr *XNode::GetAttr( const char* attrname )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Desc : get attribute with attribute name, return its value
|
// Desc : get attribute with attribute name, return its value
|
||||||
const char* XNode::GetAttrValue( const char* attrname )
|
const char* XNode::GetAttrValue( const CString &attrname )
|
||||||
{
|
{
|
||||||
XAttr *attr = GetAttr( attrname );
|
XAttr *attr = GetAttr( attrname );
|
||||||
return attr ? (const char*)attr->m_sValue : NULL;
|
return attr ? (const char*)attr->m_sValue : NULL;
|
||||||
@@ -665,7 +646,7 @@ const char* XNode::GetAttrValue( const char* attrname )
|
|||||||
|
|
||||||
|
|
||||||
// get child node count
|
// get child node count
|
||||||
int XNode::GetChildCount()
|
int XNode::GetChildCount() const
|
||||||
{
|
{
|
||||||
return m_childs.size();
|
return m_childs.size();
|
||||||
}
|
}
|
||||||
@@ -807,12 +788,12 @@ XENTITY *XENTITYS::GetEntity( int entity )
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
XENTITY *XENTITYS::GetEntity( char* entity )
|
XENTITY *XENTITYS::GetEntity( const char* entity )
|
||||||
{
|
{
|
||||||
for( unsigned i = 0 ; i < size(); i ++ )
|
for( unsigned i = 0 ; i < size(); i ++ )
|
||||||
{
|
{
|
||||||
char* ref = (char*)at(i).ref;
|
const char* ref = at(i).ref;
|
||||||
char* ps = entity;
|
const char* ps = entity;
|
||||||
while( ref && *ref )
|
while( ref && *ref )
|
||||||
if( *ref++ != *ps++ )
|
if( *ref++ != *ps++ )
|
||||||
break;
|
break;
|
||||||
@@ -825,17 +806,16 @@ XENTITY *XENTITYS::GetEntity( char* entity )
|
|||||||
int XENTITYS::GetEntityCount( const char* str )
|
int XENTITYS::GetEntityCount( const char* str )
|
||||||
{
|
{
|
||||||
int nCount = 0;
|
int nCount = 0;
|
||||||
char* ps = (char*)str;
|
while( str && *str )
|
||||||
while( ps && *ps )
|
if( GetEntity(*str++) )
|
||||||
if( GetEntity( *ps++ ) ) nCount ++;
|
++nCount;
|
||||||
return nCount;
|
return nCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int XENTITYS::Ref2Entity( const char* estr, char* str, int strlen )
|
int XENTITYS::Ref2Entity( const char* pes, char* str, int len )
|
||||||
{
|
{
|
||||||
char* pes = (char*)estr;
|
|
||||||
char* ps = str;
|
char* ps = str;
|
||||||
char* ps_end = ps+strlen;
|
char* ps_end = ps+len;
|
||||||
while( pes && *pes && ps < ps_end )
|
while( pes && *pes && ps < ps_end )
|
||||||
{
|
{
|
||||||
XENTITY *ent = GetEntity( pes );
|
XENTITY *ent = GetEntity( pes );
|
||||||
@@ -855,9 +835,8 @@ int XENTITYS::Ref2Entity( const char* estr, char* str, int strlen )
|
|||||||
return ps-str;
|
return ps-str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int XENTITYS::Entity2Ref( const char* str, char* estr, int estrlen )
|
int XENTITYS::Entity2Ref( const char* ps, char* estr, int estrlen )
|
||||||
{
|
{
|
||||||
char* ps = (char*)str;
|
|
||||||
char* pes = (char*)estr;
|
char* pes = (char*)estr;
|
||||||
char* pes_end = pes+estrlen;
|
char* pes_end = pes+estrlen;
|
||||||
while( ps && *ps && pes < pes_end )
|
while( ps && *ps && pes < pes_end )
|
||||||
@@ -866,7 +845,7 @@ int XENTITYS::Entity2Ref( const char* str, char* estr, int estrlen )
|
|||||||
if( ent )
|
if( ent )
|
||||||
{
|
{
|
||||||
// copy entity string
|
// copy entity string
|
||||||
char* ref = (char*)ent->ref;
|
const char* ref = ent->ref;
|
||||||
while( ref && *ref )
|
while( ref && *ref )
|
||||||
*pes++ = *ref++;
|
*pes++ = *ref++;
|
||||||
}
|
}
|
||||||
@@ -907,7 +886,6 @@ CString XENTITYS::Entity2Ref( const char* str )
|
|||||||
int len = strlen(str) + nEntityCount*10 ;
|
int len = strlen(str) + nEntityCount*10 ;
|
||||||
//char* sbuf = s.GetBufferSetLength( len+1 );
|
//char* sbuf = s.GetBufferSetLength( len+1 );
|
||||||
char* szTemp = new char[len+1];
|
char* szTemp = new char[len+1];
|
||||||
if( szTemp )
|
|
||||||
Entity2Ref( str, szTemp, len );
|
Entity2Ref( str, szTemp, len );
|
||||||
s = szTemp;
|
s = szTemp;
|
||||||
delete [] szTemp;
|
delete [] szTemp;
|
||||||
|
|||||||
+38
-45
@@ -68,7 +68,7 @@ struct XENTITY
|
|||||||
struct XENTITYS : public vector<XENTITY>
|
struct XENTITYS : public vector<XENTITY>
|
||||||
{
|
{
|
||||||
XENTITY *GetEntity( int entity );
|
XENTITY *GetEntity( int entity );
|
||||||
XENTITY *GetEntity( char* entity );
|
XENTITY *GetEntity( const char* entity );
|
||||||
int GetEntityCount( const char* str );
|
int GetEntityCount( const char* str );
|
||||||
int Ref2Entity( const char* estr, char* str, int strlen );
|
int Ref2Entity( const char* estr, char* str, int strlen );
|
||||||
int Entity2Ref( const char* str, char* estr, int estrlen );
|
int Entity2Ref( const char* str, char* estr, int estrlen );
|
||||||
@@ -102,7 +102,7 @@ struct PARSEINFO
|
|||||||
|
|
||||||
char* xml; // [get] xml source
|
char* xml; // [get] xml source
|
||||||
bool error_occur; // [get] is occurance of error?
|
bool error_occur; // [get] is occurance of error?
|
||||||
char* error_pointer; // [get] error position of xml source
|
const char* error_pointer; // [get] error position of xml source
|
||||||
PCODE error_code; // [get] error code
|
PCODE error_code; // [get] error code
|
||||||
CString error_string; // [get] error string
|
CString error_string; // [get] error string
|
||||||
|
|
||||||
@@ -135,12 +135,12 @@ struct XAttr
|
|||||||
{
|
{
|
||||||
CString m_sName; // a duplicate of the m_sName in the parent's map
|
CString m_sName; // a duplicate of the m_sName in the parent's map
|
||||||
CString m_sValue;
|
CString m_sValue;
|
||||||
void GetValue(CString &out) const;
|
void GetValue( CString &out ) const;
|
||||||
void GetValue(int &out) const;
|
void GetValue( int &out ) const;
|
||||||
void GetValue(float &out) const;
|
void GetValue( float &out ) const;
|
||||||
void GetValue(bool &out) const;
|
void GetValue( bool &out ) const;
|
||||||
void GetValue(unsigned &out) const;
|
void GetValue( unsigned &out ) const;
|
||||||
void GetValue(DateTime &out) const;
|
void GetValue( DateTime &out ) const;
|
||||||
|
|
||||||
bool GetXML( RageFileBasic &f, DISP_OPT *opt ) const;
|
bool GetXML( RageFileBasic &f, DISP_OPT *opt ) const;
|
||||||
};
|
};
|
||||||
@@ -150,25 +150,24 @@ struct XNode
|
|||||||
{
|
{
|
||||||
CString m_sName; // a duplicate of the m_sName in the parent's map
|
CString m_sName; // a duplicate of the m_sName in the parent's map
|
||||||
CString m_sValue;
|
CString m_sValue;
|
||||||
void GetValue(CString &out) const;
|
|
||||||
void GetValue(int &out) const;
|
|
||||||
void GetValue(float &out) const;
|
|
||||||
void GetValue(bool &out) const;
|
|
||||||
void GetValue(unsigned &out) const;
|
|
||||||
void GetValue(DateTime &out) const;
|
|
||||||
void SetValue(int v);
|
|
||||||
void SetValue(float v);
|
|
||||||
void SetValue(bool v);
|
|
||||||
void SetValue(unsigned v);
|
|
||||||
void SetValue(const DateTime &v);
|
|
||||||
|
|
||||||
// internal variables
|
|
||||||
XNodes m_childs; // child node
|
XNodes m_childs; // child node
|
||||||
XAttrs m_attrs; // attributes
|
XAttrs m_attrs; // attributes
|
||||||
|
|
||||||
|
void GetValue( CString &out ) const;
|
||||||
|
void GetValue( int &out ) const;
|
||||||
|
void GetValue( float &out ) const;
|
||||||
|
void GetValue( bool &out ) const;
|
||||||
|
void GetValue( unsigned &out ) const;
|
||||||
|
void GetValue( DateTime &out ) const;
|
||||||
|
void SetValue( int v );
|
||||||
|
void SetValue( float v );
|
||||||
|
void SetValue( bool v );
|
||||||
|
void SetValue( unsigned v );
|
||||||
|
void SetValue( const DateTime &v );
|
||||||
|
|
||||||
// Load/Save XML
|
// Load/Save XML
|
||||||
char* Load( const char* pszXml, PARSEINFO *pi );
|
const char *Load( const char* pszXml, PARSEINFO *pi );
|
||||||
char* LoadAttributes( const char* pszAttrs, PARSEINFO *pi );
|
const char *LoadAttributes( const char* pszAttrs, PARSEINFO *pi );
|
||||||
bool GetXML( RageFileBasic &f, DISP_OPT *opt ) const;
|
bool GetXML( RageFileBasic &f, DISP_OPT *opt ) const;
|
||||||
CString GetXML() const;
|
CString GetXML() const;
|
||||||
|
|
||||||
@@ -178,32 +177,32 @@ struct XNode
|
|||||||
bool SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const;
|
bool SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const;
|
||||||
|
|
||||||
// in own attribute list
|
// in own attribute list
|
||||||
const XAttr *GetAttr( const char* attrname ) const;
|
const XAttr *GetAttr( const CString &attrname ) const;
|
||||||
XAttr *GetAttr( const char* attrname );
|
XAttr *GetAttr( const CString &attrname );
|
||||||
const char* GetAttrValue( const char* attrname );
|
const char* GetAttrValue( const CString &attrname );
|
||||||
bool GetAttrValue(const char* name,CString &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
bool GetAttrValue( const char* name, CString &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
||||||
bool GetAttrValue(const char* name,int &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
bool GetAttrValue( const char* name, int &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
||||||
bool GetAttrValue(const char* name,float &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
bool GetAttrValue( const char* name, float &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
||||||
bool GetAttrValue(const char* name,bool &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
bool GetAttrValue( const char* name, bool &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
||||||
bool GetAttrValue(const char* name,unsigned &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
bool GetAttrValue( const char* name, unsigned &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
||||||
bool GetAttrValue(const char* name,DateTime &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
bool GetAttrValue( const char* name, DateTime &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
|
||||||
|
|
||||||
// in one level child nodes
|
// in one level child nodes
|
||||||
const XNode *GetChild( const char* m_sName ) const;
|
const XNode *GetChild( const char* m_sName ) const;
|
||||||
XNode *GetChild( const char* m_sName );
|
XNode *GetChild( const char* m_sName );
|
||||||
const char* GetChildValue( const char* m_sName );
|
const char* GetChildValue( const char* m_sName );
|
||||||
bool GetChildValue(const char* name,CString &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
bool GetChildValue( const char* name, CString &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
||||||
bool GetChildValue(const char* name,int &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
bool GetChildValue( const char* name, int &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
||||||
bool GetChildValue(const char* name,float &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
bool GetChildValue( const char* name, float &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
||||||
bool GetChildValue(const char* name,bool &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
bool GetChildValue( const char* name, bool &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
||||||
bool GetChildValue(const char* name,unsigned &out) const{ const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
bool GetChildValue( const char* name, unsigned &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
||||||
bool GetChildValue(const char* name,DateTime &out) const{ const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
bool GetChildValue( const char* name, DateTime &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
|
||||||
|
|
||||||
XAttr *GetChildAttr( const char* name, const char* attrname );
|
XAttr *GetChildAttr( const char* name, const char* attrname );
|
||||||
const char* GetChildAttrValue( const char* name, const char* attrname );
|
const char* GetChildAttrValue( const char* name, const char* attrname );
|
||||||
|
|
||||||
// modify DOM
|
// modify DOM
|
||||||
int GetChildCount();
|
int GetChildCount() const;
|
||||||
XNode *AppendChild( const char* m_sName = NULL, const char* value = NULL );
|
XNode *AppendChild( const char* m_sName = NULL, const char* value = NULL );
|
||||||
XNode *AppendChild( const char* m_sName, float value );
|
XNode *AppendChild( const char* m_sName, float value );
|
||||||
XNode *AppendChild( const char* m_sName, int value );
|
XNode *AppendChild( const char* m_sName, int value );
|
||||||
@@ -229,10 +228,4 @@ struct XNode
|
|||||||
void Clear();
|
void Clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper Funtion
|
|
||||||
inline long XStr2Int( const char* str, long default_value = 0 )
|
|
||||||
{
|
|
||||||
return str ? atol(str) : default_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user