This commit is contained in:
Glenn Maynard
2005-09-04 21:59:00 +00:00
parent a23620b72f
commit 7c88d5ed88
2 changed files with 33 additions and 61 deletions
+21 -44
View File
@@ -23,14 +23,14 @@ static const char chXMLDash = '-';
static const XENTITY x_EntityTable[] = { static const XENTITY x_EntityTable[] = {
{ '&', ("&"), 5 } , { '&', "&", 5 } ,
{ '\"', ("""), 6 } , { '\"', """, 6 } ,
{ '\'', ("'"), 6 } , { '\'', "'", 6 } ,
{ '<', ("&lt;"), 4 } , { '<', "&lt;", 4 } ,
{ '>', ("&gt;"), 4 } { '>', "&gt;", 4 }
}; };
XENTITYS entityDefault((XENTITY*)x_EntityTable, sizeof(x_EntityTable)/sizeof(x_EntityTable[0]) ); XENTITYS entityDefault(x_EntityTable, sizeof(x_EntityTable)/sizeof(x_EntityTable[0]) );
// skip spaces // skip spaces
static char* tcsskip( const char* psz ) static char* tcsskip( const char* psz )
@@ -190,8 +190,7 @@ const char* XNode::LoadAttributes( const char* xml, PARSEINFO *pi /*= &piDefault
// close tag // close tag
if( *xml == chXMLTagClose || *xml == chXMLTagPre || *xml == chXMLQuestion || *xml == chXMLDash ) if( *xml == chXMLTagClose || *xml == chXMLTagPre || *xml == chXMLQuestion || *xml == chXMLDash )
// wel-formed tag return xml; // well-formed tag
return xml;
// XML Attr Name // XML Attr Name
const char* pEnd = strpbrk( xml, " =" ); const char* pEnd = strpbrk( xml, " =" );
@@ -632,12 +631,6 @@ XAttr *XNode::GetAttr( const CString &attrname )
return NULL; return NULL;
} }
// get child node count
int XNode::GetChildCount() const
{
return m_childs.size();
}
// Desc : Find child with name and return child // Desc : Find child with name and return child
// Return : NULL return if no child. // Return : NULL return if no child.
XNode *XNode::GetChild( const CString &sName ) XNode *XNode::GetChild( const CString &sName )
@@ -662,13 +655,7 @@ const XNode *XNode::GetChild( const CString &sName ) const
return NULL; return NULL;
} }
XAttr *XNode::GetChildAttr( const char* name, const char* attrname ) XNode *XNode::AppendChild( const CString &sName, const CString &value ) { XNode *p = new XNode; p->m_sName = sName; p->m_sValue = value; return AppendChild( p ); }
{
XNode *node = GetChild(name);
return node ? node->GetAttr(attrname) : NULL;
}
XNode *XNode::AppendChild( const CString &sName, const char* value ) { XNode *p = new XNode; p->m_sName = sName; p->m_sValue = value; return AppendChild( p ); }
XNode *XNode::AppendChild( const CString &sName, float value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); } XNode *XNode::AppendChild( const CString &sName, float value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const CString &sName, int value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); } XNode *XNode::AppendChild( const CString &sName, int value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); }
XNode *XNode::AppendChild( const CString &sName, unsigned value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); } XNode *XNode::AppendChild( const CString &sName, unsigned value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); }
@@ -742,23 +729,23 @@ void XNode::SetAttrValue( const CString &sName, const CString &sValue )
} }
XENTITYS::XENTITYS( XENTITY *entities, int count ) XENTITYS::XENTITYS( const XENTITY *entities, int count )
{ {
for( int i = 0; i < count; i++) for( int i = 0; i < count; i++)
push_back( entities[i] ); push_back( entities[i] );
} }
XENTITY *XENTITYS::GetEntity( int entity ) const XENTITY *XENTITYS::GetEntity( char entity ) const
{ {
for( unsigned i = 0 ; i < size(); i ++ ) for( unsigned i = 0 ; i < size(); i ++ )
{ {
if( at(i).entity == entity ) if( at(i).entity == entity )
return (XENTITY *) (&at(i)); return &at(i);
} }
return NULL; return NULL;
} }
XENTITY *XENTITYS::GetEntity( const char* entity ) const XENTITY *XENTITYS::GetEntity( const char* entity ) const
{ {
for( unsigned i = 0 ; i < size(); i ++ ) for( unsigned i = 0 ; i < size(); i ++ )
{ {
@@ -768,12 +755,12 @@ XENTITY *XENTITYS::GetEntity( const char* entity )
if( *ref++ != *ps++ ) if( *ref++ != *ps++ )
break; break;
if( ref && !*ref ) // found! if( ref && !*ref ) // found!
return (XENTITY *) (&at(i)); return &at(i);
} }
return NULL; return NULL;
} }
int XENTITYS::GetEntityCount( const char* str ) int XENTITYS::GetEntityCount( const char* str ) const
{ {
int nCount = 0; int nCount = 0;
while( str && *str ) while( str && *str )
@@ -782,13 +769,13 @@ int XENTITYS::GetEntityCount( const char* str )
return nCount; return nCount;
} }
int XENTITYS::Ref2Entity( const char* pes, char* str, int len ) int XENTITYS::Ref2Entity( const char* pes, char* str, int len ) const
{ {
char* ps = str; char* ps = str;
char* ps_end = ps+len; char* ps_end = ps+len;
while( pes && *pes && ps < ps_end ) while( pes && *pes && ps < ps_end )
{ {
XENTITY *ent = GetEntity( pes ); const XENTITY *ent = GetEntity( pes );
if( ent ) if( ent )
{ {
// copy entity meanning char // copy entity meanning char
@@ -805,13 +792,13 @@ int XENTITYS::Ref2Entity( const char* pes, char* str, int len )
return ps-str; return ps-str;
} }
int XENTITYS::Entity2Ref( const char* ps, char* estr, int estrlen ) int XENTITYS::Entity2Ref( const char* ps, char* estr, int estrlen ) const
{ {
char* pes = (char*)estr; char* pes = estr;
char* pes_end = pes+estrlen; char* pes_end = pes+estrlen;
while( ps && *ps && pes < pes_end ) while( ps && *ps && pes < pes_end )
{ {
XENTITY *ent = GetEntity( *ps ); const XENTITY *ent = GetEntity( *ps );
if( ent ) if( ent )
{ {
// copy entity string // copy entity string
@@ -829,7 +816,7 @@ int XENTITYS::Entity2Ref( const char* ps, char* estr, int estrlen )
return pes-estr; return pes-estr;
} }
CString XENTITYS::Ref2Entity( const char* estr ) CString XENTITYS::Ref2Entity( const char* estr ) const
{ {
CString es; CString es;
if( estr ) if( estr )
@@ -843,7 +830,7 @@ CString XENTITYS::Ref2Entity( const char* estr )
return es; return es;
} }
CString XENTITYS::Entity2Ref( const char* str ) CString XENTITYS::Entity2Ref( const char* str ) const
{ {
CString s; CString s;
if( str ) if( str )
@@ -860,16 +847,6 @@ CString XENTITYS::Entity2Ref( const char* str )
return s; return s;
} }
CString XRef2Entity( const char* estr )
{
return entityDefault.Ref2Entity( estr );
}
CString XEntity2Ref( const char* str )
{
return entityDefault.Entity2Ref( str );
}
bool XNode::LoadFromFile( const CString &sFile ) bool XNode::LoadFromFile( const CString &sFile )
{ {
RageFile f; RageFile f;
+12 -17
View File
@@ -67,24 +67,22 @@ struct XENTITY
struct XENTITYS : public vector<XENTITY> struct XENTITYS : public vector<XENTITY>
{ {
XENTITY *GetEntity( int entity ); const XENTITY *GetEntity( char entity ) const;
XENTITY *GetEntity( const char* entity ); const XENTITY *GetEntity( const char* entity ) const;
int GetEntityCount( const char* str ); int GetEntityCount( const char* str ) const;
int Ref2Entity( const char* estr, char* str, int strlen ); int Ref2Entity( const char* estr, char* str, int strlen ) const;
int Entity2Ref( const char* str, char* estr, int estrlen ); int Entity2Ref( const char* str, char* estr, int estrlen ) const;
CString Ref2Entity( const char* estr ); CString Ref2Entity( const char* estr ) const;
CString Entity2Ref( const char* str ); CString Entity2Ref( const char* str ) const;
XENTITYS(){}; XENTITYS(){};
XENTITYS( XENTITY *entities, int count ); XENTITYS( const XENTITY *entities, int count );
}; };
extern XENTITYS entityDefault; extern XENTITYS entityDefault;
CString XRef2Entity( const char* estr );
CString XEntity2Ref( const char* str );
enum PCODE enum PCODE
{ {
PIE_PARSE_WELFORMED = 0, PIE_PARSE_WELL_FORMED = 0,
PIE_ALONE_NOT_CLOSED, PIE_ALONE_NOT_CLOSED,
PIE_NOT_CLOSED, PIE_NOT_CLOSED,
PIE_NOT_NESTED, PIE_NOT_NESTED,
@@ -106,7 +104,7 @@ struct PARSEINFO
PCODE error_code; // [get] error code PCODE error_code; // [get] error code
CString error_string; // [get] error string CString error_string; // [get] error string
PARSEINFO() { trim_value = true; entity_value = true; entitys = &entityDefault; xml = NULL; error_occur = false; error_pointer = NULL; error_code = PIE_PARSE_WELFORMED; escape_value = 0; } PARSEINFO() { trim_value = true; entity_value = true; entitys = &entityDefault; xml = NULL; error_occur = false; error_pointer = NULL; error_code = PIE_PARSE_WELL_FORMED; escape_value = 0; }
}; };
// display optional environment // display optional environment
@@ -196,11 +194,8 @@ struct XNode
bool GetChildValue( const CString &sName, unsigned &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } bool GetChildValue( const CString &sName, unsigned &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
bool GetChildValue( const CString &sName, DateTime &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } bool GetChildValue( const CString &sName, DateTime &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; }
XAttr *GetChildAttr( const char* name, const char* attrname );
// modify DOM // modify DOM
int GetChildCount() const; XNode *AppendChild( const CString &sName = CString(), const CString &value = CString() );
XNode *AppendChild( const CString &sName = "", const char* value = "" );
XNode *AppendChild( const CString &sName, float value ); XNode *AppendChild( const CString &sName, float value );
XNode *AppendChild( const CString &sName, int value ); XNode *AppendChild( const CString &sName, int value );
XNode *AppendChild( const CString &sName, unsigned value ); XNode *AppendChild( const CString &sName, unsigned value );
@@ -208,7 +203,7 @@ struct XNode
XNode *AppendChild( XNode *node ); XNode *AppendChild( XNode *node );
bool RemoveChild( XNode *node ); bool RemoveChild( XNode *node );
XAttr *AppendAttr( const CString &sName = "", const CString &sValue = "" ); XAttr *AppendAttr( const CString &sName = CString(), const CString &sValue = CString() );
XAttr *AppendAttr( const CString &sName, float value ); XAttr *AppendAttr( const CString &sName, float value );
XAttr *AppendAttr( const CString &sName, int value ); XAttr *AppendAttr( const CString &sName, int value );
XAttr *AppendAttr( const CString &sName, unsigned value ); XAttr *AppendAttr( const CString &sName, unsigned value );