9 #if !defined(AFX_MARKUPSTL_H__948A2705_9E68_11D2_A0BF_00105A27C570__INCLUDED_)
10 #define AFX_MARKUPSTL_H__948A2705_9E68_11D2_A0BF_00105A27C570__INCLUDED_
12 #pragma warning(disable:4786)
22 #define _DS(i) (i?&(m_strDoc.c_str())[m_aPos[i].nStartL]:0)
23 #define MARKUP_SETDEBUGSTATE m_pMainDS=_DS(m_iPos); m_pChildDS=_DS(m_iPosChild)
25 #define MARKUP_SETDEBUGSTATE
32 CMarkupSTL(
const char* szDoc ) { SetDoc( szDoc ); };
38 bool Load(
const char* szFileName );
39 bool SetDoc(
const char* szDoc );
41 bool FindElem(
const char* szName=NULL );
42 bool FindChildElem(
const char* szName=NULL );
43 virtual bool IntoElem();
44 virtual bool OutOfElem();
45 void ResetChildPos() { x_SetPos(m_iPosParent,m_iPos,0); };
46 void ResetMainPos() { x_SetPos(m_iPosParent,0,0); };
47 void ResetPos() { x_SetPos(0,0,0); };
48 std::string GetTagName()
const;
49 std::string GetChildTagName()
const {
return x_GetTagName(m_iPosChild); };
50 std::string GetData()
const {
return x_GetData(m_iPos); };
51 std::string GetChildData()
const {
return x_GetData(m_iPosChild); };
52 std::string GetAttrib(
const char* szAttrib )
const {
return x_GetAttrib(m_iPos,szAttrib); };
53 std::string GetChildAttrib(
const char* szAttrib )
const {
return x_GetAttrib(m_iPosChild,szAttrib); };
54 std::string GetAttribName(
int n )
const;
55 bool SavePos(
const char* szPosName=
"" );
56 bool RestorePos(
const char* szPosName=
"" );
57 bool GetOffsets(
int& nStart,
int& nEnd )
const;
58 std::string GetError()
const {
return m_strError; };
65 MNT_CDATA_SECTION = 8,
66 MNT_PROCESSING_INSTRUCTION = 16,
68 MNT_DOCUMENT_TYPE = 64,
69 MNT_EXCLUDE_WHITESPACE = 123,
73 bool Save(
const char* szFileName );
74 std::string GetDoc()
const {
return m_strDoc; };
75 bool AddElem(
const char* szName,
const char* szData=NULL ) {
return x_AddElem(szName,szData,
false,
false); };
76 bool InsertElem(
const char* szName,
const char* szData=NULL ) {
return x_AddElem(szName,szData,
true,
false); };
77 bool AddChildElem(
const char* szName,
const char* szData=NULL ) {
return x_AddElem(szName,szData,
false,
true); };
78 bool InsertChildElem(
const char* szName,
const char* szData=NULL ) {
return x_AddElem(szName,szData,
true,
true); };
79 bool AddAttrib(
const char* szAttrib,
const char* szValue ) {
return x_SetAttrib(m_iPos,szAttrib,szValue); };
80 bool AddChildAttrib(
const char* szAttrib,
const char* szValue ) {
return x_SetAttrib(m_iPosChild,szAttrib,szValue); };
81 bool AddAttrib(
const char* szAttrib,
int nValue ) {
return x_SetAttrib(m_iPos,szAttrib,nValue); };
82 bool AddChildAttrib(
const char* szAttrib,
int nValue ) {
return x_SetAttrib(m_iPosChild,szAttrib,nValue); };
83 bool AddChildSubDoc(
const char* szSubDoc ) {
return x_AddSubDoc(szSubDoc,
false,
true); };
84 bool InsertChildSubDoc(
const char* szSubDoc ) {
return x_AddSubDoc(szSubDoc,
true,
true); };
85 std::string GetChildSubDoc()
const;
89 bool RemoveChildElem();
90 bool SetAttrib(
const char* szAttrib,
const char* szValue ) {
return x_SetAttrib(m_iPos,szAttrib,szValue); };
91 bool SetChildAttrib(
const char* szAttrib,
const char* szValue ) {
return x_SetAttrib(m_iPosChild,szAttrib,szValue); };
92 bool SetAttrib(
const char* szAttrib,
int nValue ) {
return x_SetAttrib(m_iPos,szAttrib,nValue); };
93 bool SetChildAttrib(
const char* szAttrib,
int nValue ) {
return x_SetAttrib(m_iPosChild,szAttrib,nValue); };
94 bool SetData(
const char* szData,
int nCDATA=0 ) {
return x_SetData(m_iPos,szData,nCDATA); };
95 bool SetChildData(
const char* szData,
int nCDATA=0 ) {
return x_SetData(m_iPosChild,szData,nCDATA); };
100 const char* m_pMainDS;
101 const char* m_pChildDS;
104 std::string m_strDoc;
105 std::string m_strError;
111 bool IsEmptyElement()
const {
return (nStartR == nEndL + 1); };
114 nStartL=0; nStartR=0; nEndL=0; nEndR=0; nReserved=0;
115 iElemParent=0; iElemChild=0; iElemNext=0;
117 void AdjustStart(
int n ) { nStartL+=n; nStartR+=n; };
118 void AdjustEnd(
int n ) { nEndL+=n; nEndR+=n; };
129 typedef std::vector<ElemPos> vectorElemPosT;
130 vectorElemPosT m_aPos;
139 TokenPos(
const char* sz ) { Clear(); szDoc = sz; };
140 void Clear() { nL=0; nR=-1; nNext=0; bIsString=
false; };
141 bool Match(
const char* szName )
143 int nLen = nR - nL + 1;
145 #ifdef MARKUP_IGNORECASE
146 return ( (strnicmp( &szDoc[nL], szName, nLen ) == 0)
148 return ( (strncmp( &szDoc[nL], szName, nLen ) == 0)
150 && ( szName[nLen] ==
'\0' || strchr(
" =/[",szName[nLen]) ) );
165 typedef std::map<std::string,SavedPos> mapSavedPosT;
166 mapSavedPosT m_mapSavedPos;
168 void x_SetPos(
int iPosParent,
int iPos,
int iPosChild )
170 m_iPosParent = iPosParent;
172 m_iPosChild = iPosChild;
173 m_nNodeType = iPos?MNT_ELEMENT:0;
174 MARKUP_SETDEBUGSTATE;
180 int x_ParseElem(
int iPos );
181 int x_ParseError(
const char* szError,
const char* szName = NULL );
182 static bool x_FindChar(
const char* szDoc,
int& nChar,
char c );
183 static bool x_FindToken( TokenPos& token );
184 std::string x_GetToken(
const TokenPos& token )
const;
185 int x_FindElem(
int iPosParent,
int iPos,
const char* szPath );
186 std::string x_GetTagName(
int iPos )
const;
187 std::string x_GetData(
int iPos )
const;
188 std::string x_GetAttrib(
int iPos,
const char* szAttrib )
const;
189 bool x_AddElem(
const char* szName,
const char* szValue,
bool bInsert,
bool bAddChild );
190 bool x_AddSubDoc(
const char* szSubDoc,
bool bInsert,
bool bAddChild );
191 bool x_FindAttrib( TokenPos& token,
const char* szAttrib=NULL )
const;
192 bool x_SetAttrib(
int iPos,
const char* szAttrib,
const char* szValue );
193 bool x_SetAttrib(
int iPos,
const char* szAttrib,
int nValue );
194 bool x_CreateNode( std::string& strNode,
int nNodeType,
const char* szText );
195 void x_LocateNew(
int iPosParent,
int& iPosRel,
int& nOffset,
int nLength,
int nFlags );
196 int x_ParseNode( TokenPos& token );
197 bool x_SetData(
int iPos,
const char* szData,
int nCDATA );
198 int x_RemoveElem(
int iPos );
199 void x_DocChange(
int nLeft,
int nReplace,
const std::string& strInsert );
200 void x_PosInsert(
int iPos,
int nInsertLength );
201 void x_Adjust(
int iPos,
int nShift,
bool bAfterPos =
false );
202 std::string x_TextToDoc(
const char* szText,
bool bAttrib =
false )
const;
203 std::string x_TextFromDoc(
int nLeft,
int nRight )
const;
208 #endif // !defined(AFX_MARKUPSTL_H__948A2705_9E68_11D2_A0BF_00105A27C570__INCLUDED_)
Namespace for the standard utility objects.