diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index 02f9ca5ae2..350010ac91 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -27,8 +27,8 @@ static const char chXMLExclamation = '!'; static const char chXMLDash = '-'; -static map g_mapEntitiesToChars; -static map g_mapCharsToEntities; +static map g_mapEntitiesToChars; +static map g_mapCharsToEntities; static void InitEntities() { @@ -52,7 +52,7 @@ static void InitEntities() for( unsigned i = 0; i < ARRAYSIZE(EntityTable); ++i ) { const Entity &ent = EntityTable[i]; - g_mapEntitiesToChars[ent.pEntity] = CString(1, ent.c); + g_mapEntitiesToChars[ent.pEntity] = RString(1, ent.c); g_mapCharsToEntities[ent.c] = ent.pEntity; } } @@ -63,18 +63,18 @@ static struct RunInitEntities } g_RunInitEntities; // skip spaces -static void tcsskip( const CString &s, unsigned &i ) +static void tcsskip( const RString &s, unsigned &i ) { i = s.find_first_not_of( " \t\r\n", i ); } -static bool XIsEmptyString( const CString &s ) +static bool XIsEmptyString( const RString &s ) { return s.find_first_not_of( "\r\n\t " ) == s.npos; } // put string of (psz~end) on ps string -static void SetString( const CString &s, int iStart, int iEnd, CString* ps, bool trim = false ) +static void SetString( const RString &s, int iStart, int iEnd, RString* ps, bool trim = false ) { if( trim ) { @@ -119,7 +119,7 @@ void XNode::Clear() // Param : pszAttrs - xml of attributes // pi = parser information // Return : advanced string pointer. (error return npos) -unsigned XNode::LoadAttributes( const CString &xml, PARSEINFO *pi, unsigned iOffset ) +unsigned XNode::LoadAttributes( const RString &xml, PARSEINFO *pi, unsigned iOffset ) { while( iOffset < xml.size() ) { @@ -148,13 +148,13 @@ unsigned XNode::LoadAttributes( const CString &xml, PARSEINFO *pi, unsigned iOff } // XML Attr Name - CString sName; + RString sName; SetString( xml, iOffset, iEnd, &sName ); // add new attribute DEBUG_ASSERT( sName.size() ); - pair it = m_attrs.insert( make_pair(sName, CString()) ); - CString &sValue = it.first->second; + pair it = m_attrs.insert( make_pair(sName, RString()) ); + RString &sValue = it.first->second; iOffset = iEnd; // XML Attr Value @@ -221,7 +221,7 @@ unsigned XNode::LoadAttributes( const CString &xml, PARSEINFO *pi, unsigned iOff // Param : pszXml - plain xml text // pi = parser information // Return : advanced string pointer (error return npos) -unsigned XNode::Load( const CString &xml, PARSEINFO *pi, unsigned iOffset ) +unsigned XNode::Load( const RString &xml, PARSEINFO *pi, unsigned iOffset ) { Clear(); @@ -380,7 +380,7 @@ unsigned XNode::Load( const CString &xml, PARSEINFO *pi, unsigned iOffset ) return string::npos; } - CString closename; + RString closename; SetString( xml, iOffset, iEnd, &closename ); iOffset = iEnd+1; if( closename == this->m_sName ) @@ -437,9 +437,9 @@ unsigned XNode::Load( const CString &xml, PARSEINFO *pi, unsigned iOffset ) // Desc : convert plain xml text from parsed xml attirbute // Return : converted plain string -bool XNode::GetAttrXML( RageFileBasic &f, DISP_OPT &opt, const CString &sName, const CString &sValue ) const +bool XNode::GetAttrXML( RageFileBasic &f, DISP_OPT &opt, const RString &sName, const RString &sValue ) const { - CString s(sValue); + RString s(sValue); if( opt.reference_value ) ReplaceEntityText( s, g_mapCharsToEntities ); return f.Write(sName + "='" + s + "' ") != -1; @@ -506,7 +506,7 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT &opt ) const if( f.Write("\t") == -1 ) return false; } - CString s( m_sValue ); + RString s( m_sValue ); if( opt.reference_value ) ReplaceEntityText( s, g_mapCharsToEntities ); if( f.Write(s) == -1 ) @@ -537,7 +537,7 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT &opt ) const // Desc : convert plain xml text from parsed xml node // Return : converted plain string -CString XNode::GetXML() const +RString XNode::GetXML() const { RageFileObjMem f; DISP_OPT opt; @@ -545,19 +545,19 @@ CString XNode::GetXML() const return f.GetString(); } -void XNode::GetValue( CString &out ) const { out = m_sValue; } +void XNode::GetValue( RString &out ) const { out = 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( bool &out ) const { out = atoi(m_sValue) != 0; } void XNode::GetValue( unsigned &out ) const { out = 0; sscanf(m_sValue,"%u",&out); } void XNode::GetValue( DateTime &out ) const { out.FromString( m_sValue ); } -bool XNode::GetAttrValue( const CString &sName, CString &out ) const { const CString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = *pAttr; return true; } -bool XNode::GetAttrValue( const CString &sName, int &out ) const { const CString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = atoi(*pAttr); return true; } -bool XNode::GetAttrValue( const CString &sName, float &out ) const { const CString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = strtof(*pAttr, NULL); return true; } -bool XNode::GetAttrValue( const CString &sName, bool &out ) const { const CString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = atoi(*pAttr) != 0; return true; } -bool XNode::GetAttrValue( const CString &sName, unsigned &out ) const { const CString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = 0; sscanf(*pAttr,"%u",&out); return true; } -bool XNode::GetAttrValue( const CString &sName, DateTime &out ) const { const CString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out.FromString( *pAttr ); return true; } +bool XNode::GetAttrValue( const RString &sName, RString &out ) const { const RString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = *pAttr; return true; } +bool XNode::GetAttrValue( const RString &sName, int &out ) const { const RString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = atoi(*pAttr); return true; } +bool XNode::GetAttrValue( const RString &sName, float &out ) const { const RString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = strtof(*pAttr, NULL); return true; } +bool XNode::GetAttrValue( const RString &sName, bool &out ) const { const RString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = atoi(*pAttr) != 0; return true; } +bool XNode::GetAttrValue( const RString &sName, unsigned &out ) const { const RString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out = 0; sscanf(*pAttr,"%u",&out); return true; } +bool XNode::GetAttrValue( const RString &sName, DateTime &out ) const { const RString* pAttr=GetAttr(sName); if(pAttr==NULL) return false; out.FromString( *pAttr ); return true; } void XNode::SetValue( int v ) { m_sValue = ssprintf("%d",v); } void XNode::SetValue( float v ) { m_sValue = ssprintf("%f",v); } @@ -565,17 +565,17 @@ void XNode::SetValue( bool v ) { m_sValue = ssprintf("%d",v); } void XNode::SetValue( unsigned v ) { m_sValue = ssprintf("%u",v); } void XNode::SetValue( const DateTime &v ) { m_sValue = v.GetString(); } -const CString *XNode::GetAttr( const CString &attrname ) const +const RString *XNode::GetAttr( const RString &attrname ) const { - map::const_iterator it = m_attrs.find( attrname ); + map::const_iterator it = m_attrs.find( attrname ); if( it != m_attrs.end() ) return &it->second; return NULL; } -CString *XNode::GetAttr( const CString &attrname ) +RString *XNode::GetAttr( const RString &attrname ) { - map::iterator it = m_attrs.find( attrname ); + map::iterator it = m_attrs.find( attrname ); if( it != m_attrs.end() ) return &it->second; return NULL; @@ -583,9 +583,9 @@ CString *XNode::GetAttr( const CString &attrname ) // Desc : Find child with name and return child // Return : NULL return if no child. -XNode *XNode::GetChild( const CString &sName ) +XNode *XNode::GetChild( const RString &sName ) { - multimap::iterator it = m_childs.find( sName ); + multimap::iterator it = m_childs.find( sName ); if( it != m_childs.end() ) { DEBUG_ASSERT( sName == it->second->m_sName ); @@ -594,9 +594,9 @@ XNode *XNode::GetChild( const CString &sName ) return NULL; } -const XNode *XNode::GetChild( const CString &sName ) const +const XNode *XNode::GetChild( const RString &sName ) const { - multimap::const_iterator it = m_childs.find( sName ); + multimap::const_iterator it = m_childs.find( sName ); if( it != m_childs.end() ) { DEBUG_ASSERT( sName == it->second->m_sName ); @@ -605,25 +605,25 @@ const XNode *XNode::GetChild( const CString &sName ) const return NULL; } -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 *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, unsigned value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); } -XNode *XNode::AppendChild( const CString &sName, const DateTime &value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); } +XNode *XNode::AppendChild( const RString &sName, const RString &value ) { XNode *p = new XNode; p->m_sName = sName; p->m_sValue = value; return AppendChild( p ); } +XNode *XNode::AppendChild( const RString &sName, float value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); } +XNode *XNode::AppendChild( const RString &sName, int value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); } +XNode *XNode::AppendChild( const RString &sName, unsigned value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); } +XNode *XNode::AppendChild( const RString &sName, const DateTime &value ) { XNode *p = new XNode; p->m_sName = sName; p->SetValue( value ); return AppendChild( p ); } XNode *XNode::AppendChild( XNode *node ) { DEBUG_ASSERT( node->m_sName.size() ); /* Hinted insert: optimize for alphabetical inserts, for the copy ctor. */ - m_childs.insert( m_childs.end(), pair(node->m_sName,node) ); + m_childs.insert( m_childs.end(), pair(node->m_sName,node) ); return node; } // detach node and delete object bool XNode::RemoveChild( XNode *node ) { - FOREACHMM( CString, XNode*, m_childs, p ) + FOREACHMM( RString, XNode*, m_childs, p ) { if( p->second == node ) { @@ -637,21 +637,21 @@ bool XNode::RemoveChild( XNode *node ) // detach attribute -bool XNode::RemoveAttr( const CString &sName ) +bool XNode::RemoveAttr( const RString &sName ) { return m_attrs.erase(sName) > 0; } -void XNode::AppendAttr( const CString &sName, const CString &sValue ) +void XNode::AppendAttr( const RString &sName, const RString &sValue ) { pair ret = m_attrs.insert( make_pair(sName,sValue) ); if( !ret.second ) ret.first->second = sValue; // already existed } -void XNode::AppendAttr( const CString &sName, float value ){ AppendAttr(sName,ssprintf("%f",value)); } -void XNode::AppendAttr( const CString &sName, int value ) { AppendAttr(sName,ssprintf("%d",value)); } -void XNode::AppendAttr( const CString &sName, unsigned value ) { AppendAttr(sName,ssprintf("%u",value)); } +void XNode::AppendAttr( const RString &sName, float value ){ AppendAttr(sName,ssprintf("%f",value)); } +void XNode::AppendAttr( const RString &sName, int value ) { AppendAttr(sName,ssprintf("%d",value)); } +void XNode::AppendAttr( const RString &sName, unsigned value ) { AppendAttr(sName,ssprintf("%u",value)); } bool XNode::SaveToFile( RageFileBasic &f, DISP_OPT &opt ) const { @@ -665,7 +665,7 @@ bool XNode::SaveToFile( RageFileBasic &f, DISP_OPT &opt ) const return true; } -bool XNode::SaveToFile( const CString &sFile, DISP_OPT &opt ) const +bool XNode::SaveToFile( const RString &sFile, DISP_OPT &opt ) const { RageFile f; if( !f.Open(sFile, RageFile::WRITE) ) diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index 06f96cb32d..5601d7b2a1 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -7,9 +7,9 @@ struct DateTime; class RageFileBasic; -typedef map XAttrs; +typedef map XAttrs; class XNode; -typedef multimap XNodes; +typedef multimap XNodes; #define FOREACH_Attr( pNode, Var ) \ for( XAttrs::iterator Var = (pNode)->m_attrs.begin(); \ @@ -55,7 +55,7 @@ struct PARSEINFO bool error_occur; // [get] is occurance of error? const char* error_pointer; // [get] error position of xml source PCODE error_code; // [get] error code - CString error_string; // [get] error string + RString error_string; // [get] error string PARSEINFO() { trim_value = true; entity_value = true; xml = NULL; error_occur = false; error_pointer = NULL; error_code = PIE_PARSE_WELL_FORMED; } }; @@ -65,7 +65,7 @@ struct DISP_OPT { bool newline; // newline when new tag bool reference_value; // do convert from entity to reference ( < -> < ) - CString stylesheet; // empty string = no stylesheet + RString stylesheet; // empty string = no stylesheet bool write_tabs; // if false, don't write tab indent characters int tab_base; // internal usage @@ -83,12 +83,12 @@ struct DISP_OPT class XNode { public: - CString m_sName; // a duplicate of the m_sName in the parent's map - CString m_sValue; + RString m_sName; // a duplicate of the m_sName in the parent's map + RString m_sValue; XNodes m_childs; // child node XAttrs m_attrs; // attributes - void GetValue( CString &out ) const; + void GetValue( RString &out ) const; void GetValue( int &out ) const; void GetValue( float &out ) const; void GetValue( bool &out ) const; @@ -101,50 +101,50 @@ public: void SetValue( const DateTime &v ); // Load/Save XML - unsigned Load( const CString &sXml, PARSEINFO *pi, unsigned iOffset = 0 ); - unsigned LoadAttributes( const CString &sAttrs, PARSEINFO *pi, unsigned iOffset ); + unsigned Load( const RString &sXml, PARSEINFO *pi, unsigned iOffset = 0 ); + unsigned LoadAttributes( const RString &sAttrs, PARSEINFO *pi, unsigned iOffset ); bool GetXML( RageFileBasic &f, DISP_OPT &opt ) const; - bool GetAttrXML( RageFileBasic &f, DISP_OPT &opt, const CString &sName, const CString &sValue ) const; - CString GetXML() const; + bool GetAttrXML( RageFileBasic &f, DISP_OPT &opt, const RString &sName, const RString &sValue ) const; + RString GetXML() const; - bool SaveToFile( const CString &sFile, DISP_OPT &opt ) const; + bool SaveToFile( const RString &sFile, DISP_OPT &opt ) const; bool SaveToFile( RageFileBasic &f, DISP_OPT &opt ) const; // in own attribute list - const CString *GetAttr( const CString &sAttrName ) const; - CString *GetAttr( const CString &sAttrName ); - bool GetAttrValue( const CString &sName, CString &out ) const; - bool GetAttrValue( const CString &sName, int &out ) const; - bool GetAttrValue( const CString &sName, float &out ) const; - bool GetAttrValue( const CString &sName, bool &out ) const; - bool GetAttrValue( const CString &sName, unsigned &out ) const; - bool GetAttrValue( const CString &sName, DateTime &out ) const; + const RString *GetAttr( const RString &sAttrName ) const; + RString *GetAttr( const RString &sAttrName ); + bool GetAttrValue( const RString &sName, RString &out ) const; + bool GetAttrValue( const RString &sName, int &out ) const; + bool GetAttrValue( const RString &sName, float &out ) const; + bool GetAttrValue( const RString &sName, bool &out ) const; + bool GetAttrValue( const RString &sName, unsigned &out ) const; + bool GetAttrValue( const RString &sName, DateTime &out ) const; // in one level child nodes - const XNode *GetChild( const CString &sName ) const; - XNode *GetChild( const CString &sName ); - bool GetChildValue( const CString &sName, CString &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue( const CString &sName, int &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue( const CString &sName, float &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue( const CString &sName, bool &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; } + const XNode *GetChild( const RString &sName ) const; + XNode *GetChild( const RString &sName ); + bool GetChildValue( const RString &sName, RString &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const RString &sName, int &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const RString &sName, float &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const RString &sName, bool &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const RString &sName, unsigned &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const RString &sName, DateTime &out ) const { const XNode* pChild=GetChild(sName); if(pChild==NULL) return false; pChild->GetValue(out); return true; } // modify DOM - XNode *AppendChild( const CString &sName = CString(), const CString &value = CString() ); - XNode *AppendChild( const CString &sName, float value ); - XNode *AppendChild( const CString &sName, int value ); - XNode *AppendChild( const CString &sName, unsigned value ); - XNode *AppendChild( const CString &sName, const DateTime &value ); + XNode *AppendChild( const RString &sName = RString(), const RString &value = RString() ); + XNode *AppendChild( const RString &sName, float value ); + XNode *AppendChild( const RString &sName, int value ); + XNode *AppendChild( const RString &sName, unsigned value ); + XNode *AppendChild( const RString &sName, const DateTime &value ); XNode *AppendChild( XNode *node ); bool RemoveChild( XNode *node ); - void AppendAttr( const CString &sName = CString(), const CString &sValue = CString() ); - void AppendAttr( const CString &sName, float value ); - void AppendAttr( const CString &sName, int value ); - void AppendAttr( const CString &sName, unsigned value ); - void AppendAttr( const CString &sName, const DateTime &value ); - bool RemoveAttr( const CString &sName ); + void AppendAttr( const RString &sName = RString(), const RString &sValue = RString() ); + void AppendAttr( const RString &sName, float value ); + void AppendAttr( const RString &sName, int value ); + void AppendAttr( const RString &sName, unsigned value ); + void AppendAttr( const RString &sName, const DateTime &value ); + bool RemoveAttr( const RString &sName ); XNode() { } XNode( const XNode &cpy );