Advertisement
Guest User

MFC problem

a guest
May 13th, 2011
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.57 KB | None | 0 0
  1. // Markup.h: interface for the CMarkup class.
  2. //
  3. // Markup Release 11.5
  4. // Copyright (C) 2011 First Objective Software, Inc. All rights reserved
  5. // Go to www.firstobject.com for the latest CMarkup and EDOM documentation
  6. // Use in commercial applications requires written permission
  7. // This software is provided "as is", with no warranty.
  8.  
  9. #if !defined(_MARKUP_H_INCLUDED_)
  10. #define _MARKUP_H_INCLUDED_
  11.  
  12. #include <stdlib.h>
  13. #include <string.h> // memcpy, memset, strcmp...
  14.  
  15. // Major build options
  16. // MARKUP_WCHAR wide char (2-byte UTF-16 on Windows, 4-byte UTF-32 on Linux and OS X)
  17. // MARKUP_MBCS ANSI/double-byte strings on Windows
  18. // MARKUP_STL (default except VC++) use STL strings instead of MFC strings
  19. // MARKUP_SAFESTR to use string _s functions in VC++ 2005 (_MSC_VER >= 1400)
  20. // MARKUP_WINCONV (default for VC++) for Windows API character conversion
  21. // MARKUP_ICONV (default for GNU) for character conversion on Linux and OS X and other platforms
  22. // MARKUP_STDCONV to use neither WINCONV or ICONV, falls back to setlocale based conversion for ANSI
  23. //
  24. #if ! defined(MARKUP_WINDOWS)
  25. #if defined(_WIN32) || defined(WIN32)
  26. #define MARKUP_WINDOWS
  27. #endif // WIN32 or _WIN32
  28. #endif // not MARKUP_WINDOWS
  29. #if _MSC_VER > 1000 // VC++
  30. #pragma once
  31. #if ! defined(MARKUP_SAFESTR) // not VC++ safe strings
  32. #pragma warning(disable:4996) // VC++ 2005 deprecated function warnings
  33. #endif // not VC++ safe strings
  34. #if defined(MARKUP_STL) && _MSC_VER < 1400 // STL pre VC++ 2005
  35. #pragma warning(disable:4786) // std::string long names
  36. #endif // VC++ 2005 STL
  37. #else // not VC++
  38. #if ! defined(MARKUP_STL)
  39. #define MARKUP_STL
  40. #endif // not STL
  41. #if defined(__GNUC__) && ! defined(MARKUP_ICONV) && ! defined(MARKUP_STDCONV) && ! defined(MARKUP_WINCONV)
  42. #if ! defined(MARKUP_WINDOWS)
  43. #define MARKUP_ICONV
  44. #endif // not Windows
  45. #endif // GNUC and not ICONV not STDCONV not WINCONV
  46. #endif // not VC++
  47. #if (defined(_UNICODE) || defined(UNICODE)) && ! defined(MARKUP_WCHAR)
  48. #define MARKUP_WCHAR
  49. #endif // _UNICODE or UNICODE
  50. #if (defined(_MBCS) || defined(MBCS)) && ! defined(MARKUP_MBCS)
  51. #define MARKUP_MBCS
  52. #endif // _MBCS and not MBCS
  53. #if ! defined(MARKUP_SIZEOFWCHAR)
  54. #if __SIZEOF_WCHAR_T__ == 4 || __WCHAR_MAX__ > 0x10000
  55. #define MARKUP_SIZEOFWCHAR 4
  56. #else // sizeof(wchar_t) != 4
  57. #define MARKUP_SIZEOFWCHAR 2
  58. #endif // sizeof(wchar_t) != 4
  59. #endif // not MARKUP_SIZEOFWCHAR
  60. #if ! defined(MARKUP_WINCONV) && ! defined(MARKUP_STDCONV) && ! defined(MARKUP_ICONV)
  61. #define MARKUP_WINCONV
  62. #endif // not WINCONV not STDCONV not ICONV
  63. #if ! defined(MARKUP_FILEBLOCKSIZE)
  64. #define MARKUP_FILEBLOCKSIZE 16384
  65. #endif
  66.  
  67. // Text type and function defines (compiler and build-option dependent)
  68. //
  69. #define MCD_ACP 0
  70. #define MCD_UTF8 65001
  71. #define MCD_UTF16 1200
  72. #define MCD_UTF32 65005
  73. #if defined(MARKUP_WCHAR)
  74. #define MCD_CHAR wchar_t
  75. #define MCD_PCSZ const wchar_t*
  76. #define MCD_PSZLEN (int)wcslen
  77. #define MCD_PSZCHR wcschr
  78. #define MCD_PSZSTR wcsstr
  79. #define MCD_PSZTOL wcstol
  80. #if defined(MARKUP_SAFESTR) // VC++ safe strings
  81. #define MCD_SSZ(sz) sz,(sizeof(sz)/sizeof(MCD_CHAR))
  82. #define MCD_PSZCPY(sz,p) wcscpy_s(MCD_SSZ(sz),p)
  83. #define MCD_PSZNCPY(sz,p,n) wcsncpy_s(MCD_SSZ(sz),p,n)
  84. #define MCD_SPRINTF swprintf_s
  85. #define MCD_FOPEN(f,n,m) {if(_wfopen_s(&f,n,m)!=0)f=NULL;}
  86. #else // not VC++ safe strings
  87. #if defined(__GNUC__) && ! defined(MARKUP_WINDOWS) // non-Windows GNUC
  88. #define MCD_SSZ(sz) sz,(sizeof(sz)/sizeof(MCD_CHAR))
  89. #else // not non-Windows GNUC
  90. #define MCD_SSZ(sz) sz
  91. #endif // not non-Windows GNUC
  92. #define MCD_PSZCPY wcscpy
  93. #define MCD_PSZNCPY wcsncpy
  94. #define MCD_SPRINTF swprintf
  95. #define MCD_FOPEN(f,n,m) f=_wfopen(n,m)
  96. #endif // not VC++ safe strings
  97. #define MCD_T(s) L ## s
  98. #if MARKUP_SIZEOFWCHAR == 4 // sizeof(wchar_t) == 4
  99. #define MCD_ENC MCD_T("UTF-32")
  100. #else // sizeof(wchar_t) == 2
  101. #define MCD_ENC MCD_T("UTF-16")
  102. #endif
  103. #define MCD_CLEN(p) 1
  104. #else // not MARKUP_WCHAR
  105. #define MCD_CHAR char
  106. #define MCD_PCSZ const char*
  107. #define MCD_PSZLEN (int)strlen
  108. #define MCD_PSZCHR strchr
  109. #define MCD_PSZSTR strstr
  110. #define MCD_PSZTOL strtol
  111. #if defined(MARKUP_SAFESTR) // VC++ safe strings
  112. #define MCD_SSZ(sz) sz,(sizeof(sz)/sizeof(MCD_CHAR))
  113. #define MCD_PSZCPY(sz,p) strcpy_s(MCD_SSZ(sz),p)
  114. #define MCD_PSZNCPY(sz,p,n) strncpy_s(MCD_SSZ(sz),p,n)
  115. #define MCD_SPRINTF sprintf_s
  116. #define MCD_FOPEN(f,n,m) {if(fopen_s(&f,n,m)!=0)f=NULL;}
  117. #else // not VC++ safe strings
  118. #define MCD_SSZ(sz) sz
  119. #define MCD_PSZCPY strcpy
  120. #define MCD_PSZNCPY strncpy
  121. #define MCD_SPRINTF sprintf
  122. #define MCD_FOPEN(f,n,m) f=fopen(n,m)
  123. #endif // not VC++ safe strings
  124. #define MCD_T(s) s
  125. #if defined(MARKUP_MBCS) // MBCS/double byte
  126. #define MCD_ENC MCD_T("")
  127. #if defined(MARKUP_WINCONV)
  128. #define MCD_CLEN(p) (int)_mbclen((const unsigned char*)p)
  129. #else // not WINCONV
  130. #define MCD_CLEN(p) (int)mblen(p,MB_CUR_MAX)
  131. #endif // not WINCONV
  132. #else // not MBCS/double byte
  133. #define MCD_ENC MCD_T("UTF-8")
  134. #define MCD_CLEN(p) 1
  135. #endif // not MBCS/double byte
  136. #endif // not MARKUP_WCHAR
  137. #if _MSC_VER < 1000 // not VC++
  138. #define MCD_STRERROR strerror(errno)
  139. #endif // not VC++
  140.  
  141. // String type and function defines (compiler and build-option dependent)
  142. // Define MARKUP_STL to use STL strings
  143. //
  144. #if defined(MARKUP_STL) // STL
  145. #include <string>
  146. #if defined(MARKUP_WCHAR)
  147. #define MCD_STR std::wstring
  148. #else // not MARKUP_WCHAR
  149. #define MCD_STR std::string
  150. #endif // not MARKUP_WCHAR
  151. #define MCD_2PCSZ(s) s.c_str()
  152. #define MCD_STRLENGTH(s) (int)s.size()
  153. #define MCD_STRCLEAR(s) s.erase()
  154. #define MCD_STRCLEARSIZE(s) MCD_STR t; s.swap(t)
  155. #define MCD_STRISEMPTY(s) s.empty()
  156. #define MCD_STRMID(s,n,l) s.substr(n,l)
  157. #define MCD_STRASSIGN(s,p,n) s.assign(p,n)
  158. #define MCD_STRCAPACITY(s) (int)s.capacity()
  159. #define MCD_STRINSERTREPLACE(d,i,r,s) d.replace(i,r,s)
  160. #define MCD_GETBUFFER(s,n) new MCD_CHAR[n+1]; if ((int)s.capacity()<(int)n) s.reserve(n)
  161. #define MCD_RELEASEBUFFER(s,p,n) s.replace(0,s.size(),p,n); delete[]p
  162. #define MCD_BLDRESERVE(s,n) s.reserve(n)
  163. #define MCD_BLDCHECK(s,n,d) ;
  164. #define MCD_BLDRELEASE(s) ;
  165. #define MCD_BLDAPPENDN(s,p,n) s.append(p,n)
  166. #define MCD_BLDAPPEND(s,p) s.append(p)
  167. #define MCD_BLDAPPEND1(s,c) s+=(MCD_CHAR)(c)
  168. #define MCD_BLDLEN(s) (int)s.size()
  169. #define MCD_BLDTRUNC(s,n) s.resize(n)
  170. #else // not STL, i.e. MFC
  171. // afx.h provides CString, to avoid "WINVER not defined" #include stdafh.x in Markup.cpp
  172. #include <afx.h>
  173. #define MCD_STR CString
  174. #define MCD_2PCSZ(s) ((MCD_PCSZ)s)
  175. #define MCD_STRLENGTH(s) s.GetLength()
  176. #define MCD_STRCLEAR(s) s.Empty()
  177. #define MCD_STRCLEARSIZE(s) s=MCD_STR()
  178. #define MCD_STRISEMPTY(s) s.IsEmpty()
  179. #define MCD_STRMID(s,n,l) s.Mid(n,l)
  180. #define MCD_STRASSIGN(s,p,n) memcpy(s.GetBuffer(n),p,(n)*sizeof(MCD_CHAR));s.ReleaseBuffer(n);
  181. #define MCD_STRCAPACITY(s) (((CStringData*)((MCD_PCSZ)s)-1)->nAllocLength)
  182. #define MCD_GETBUFFER(s,n) s.GetBuffer(n)
  183. #define MCD_RELEASEBUFFER(s,p,n) s.ReleaseBuffer(n)
  184. #define MCD_BLDRESERVE(s,n) MCD_CHAR*pD=s.GetBuffer(n); int nL=0
  185. #define MCD_BLDCHECK(s,n,d) if(nL+(int)(d)>n){s.ReleaseBuffer(nL);n<<=2;pD=s.GetBuffer(n);}
  186. #define MCD_BLDRELEASE(s) s.ReleaseBuffer(nL)
  187. #define MCD_BLDAPPENDN(s,p,n) MCD_PSZNCPY(&pD[nL],p,n);nL+=n
  188. #define MCD_BLDAPPEND(s,p) MCD_PSZCPY(&pD[nL],p);nL+=MCD_PSZLEN(p)
  189. #define MCD_BLDAPPEND1(s,c) pD[nL++]=(MCD_CHAR)(c)
  190. #define MCD_BLDLEN(s) nL
  191. #define MCD_BLDTRUNC(s,n) nL=n
  192. #endif // not STL
  193. #define MCD_STRTOINT(s) MCD_PSZTOL(MCD_2PCSZ(s),NULL,10)
  194.  
  195. // Allow function args to accept string objects as constant string pointers
  196. struct MCD_CSTR
  197. {
  198.     MCD_CSTR() { pcsz=NULL; };
  199.     MCD_CSTR( MCD_PCSZ p ) { pcsz=p; };
  200.     MCD_CSTR( const MCD_STR& s ) { pcsz = MCD_2PCSZ(s); };
  201.     operator MCD_PCSZ() const { return pcsz; };
  202.     MCD_PCSZ pcsz;
  203. };
  204.  
  205. // On Linux and OS X, filenames are not specified in wchar_t
  206. #if defined(MARKUP_WCHAR) && defined(__GNUC__)
  207. #undef MCD_FOPEN
  208. #define MCD_FOPEN(f,n,m) f=fopen(n,m)
  209. #define MCD_T_FILENAME(s) s
  210. #define MCD_PCSZ_FILENAME const char*
  211. struct MCD_CSTR_FILENAME
  212. {
  213.     MCD_CSTR_FILENAME() { pcsz=NULL; };
  214.     MCD_CSTR_FILENAME( MCD_PCSZ_FILENAME p ) { pcsz=p; };
  215.     MCD_CSTR_FILENAME( const std::string& s ) { pcsz = s.c_str(); };
  216.     operator MCD_PCSZ_FILENAME() const { return pcsz; };
  217.     MCD_PCSZ_FILENAME pcsz;
  218. };
  219. #else // not WCHAR GNUC
  220. #define MCD_CSTR_FILENAME MCD_CSTR
  221. #define MCD_T_FILENAME MCD_T
  222. #define MCD_PCSZ_FILENAME MCD_PCSZ
  223. #endif // not WCHAR GNUC
  224.  
  225. // File fseek, ftell and offset type
  226. #if defined(__GNUC__) && ! defined(MARKUP_WINDOWS) // non-Windows GNUC
  227. #define MCD_FSEEK fseeko
  228. #define MCD_FTELL ftello
  229. #define MCD_INTFILEOFFSET off_t
  230. #elif _MSC_VER >= 1000 && defined(MARKUP_HUGEFILE) // VC++ HUGEFILE
  231. #if _MSC_VER < 1400 // before VC++ 2005
  232. extern "C" int __cdecl _fseeki64(FILE *, __int64, int);
  233. extern "C" __int64 __cdecl _ftelli64(FILE *);
  234. #endif // before VC++ 2005
  235. #define MCD_FSEEK _fseeki64
  236. #define MCD_FTELL _ftelli64
  237. #define MCD_INTFILEOFFSET __int64
  238. #else // not non-Windows GNUC or VC++ HUGEFILE
  239. #define MCD_FSEEK fseek
  240. #define MCD_FTELL ftell
  241. #define MCD_INTFILEOFFSET long
  242. #endif // not non-Windows GNUC or VC++ HUGEFILE
  243.  
  244. // End of line choices: none, return, newline, or CRLF
  245. #if defined(MARKUP_EOL_NONE)
  246. #define MCD_EOL MCD_T("")
  247. #elif defined(MARKUP_EOL_RETURN) // rare; only used on some old operating systems
  248. #define MCD_EOL MCD_T("\r")
  249. #elif defined(MARKUP_EOL_NEWLINE) // Unix standard
  250. #define MCD_EOL MCD_T("\n")
  251. #elif defined(MARKUP_EOL_CRLF) || defined(MARKUP_WINDOWS) // Windows standard
  252. #define MCD_EOL MCD_T("\r\n")
  253. #else // not Windows and not otherwise specified
  254. #define MCD_EOL MCD_T("\n")
  255. #endif // not Windows and not otherwise specified
  256. #define MCD_EOLLEN (sizeof(MCD_EOL)/sizeof(MCD_CHAR)-1) // string length of MCD_EOL
  257.  
  258. struct FilePos;
  259. struct TokenPos;
  260. struct NodePos;
  261. struct PathPos;
  262. struct SavedPosMapArray;
  263. struct ElemPosTree;
  264.  
  265. class CMarkup
  266. {
  267. public:
  268.     CMarkup() { x_InitMarkup(); SetDoc( NULL ); };
  269.     CMarkup( MCD_CSTR szDoc ) { x_InitMarkup(); SetDoc( szDoc ); };
  270.     CMarkup( int nFlags ) { x_InitMarkup(); SetDoc( NULL ); m_nDocFlags = nFlags; };
  271.     CMarkup( const CMarkup& markup ) { x_InitMarkup(); *this = markup; };
  272.     void operator=( const CMarkup& markup );
  273.     ~CMarkup();
  274.  
  275.     // Navigate
  276.     bool Load( MCD_CSTR_FILENAME szFileName );
  277.     bool SetDoc( MCD_PCSZ pDoc );
  278.     bool SetDoc( const MCD_STR& strDoc );
  279.     bool IsWellFormed();
  280.     bool FindElem( MCD_CSTR szName=NULL );
  281.     bool FindChildElem( MCD_CSTR szName=NULL );
  282.     bool IntoElem();
  283.     bool OutOfElem();
  284.     void ResetChildPos() { x_SetPos(m_iPosParent,m_iPos,0); };
  285.     void ResetMainPos() { x_SetPos(m_iPosParent,0,0); };
  286.     void ResetPos() { x_SetPos(0,0,0); };
  287.     MCD_STR GetTagName() const;
  288.     MCD_STR GetChildTagName() const { return x_GetTagName(m_iPosChild); };
  289.     MCD_STR GetData() { return x_GetData(m_iPos); };
  290.     MCD_STR GetChildData() { return x_GetData(m_iPosChild); };
  291.     MCD_STR GetElemContent() const { return x_GetElemContent(m_iPos); };
  292.     MCD_STR GetAttrib( MCD_CSTR szAttrib ) const { return x_GetAttrib(m_iPos,szAttrib); };
  293.     MCD_STR GetChildAttrib( MCD_CSTR szAttrib ) const { return x_GetAttrib(m_iPosChild,szAttrib); };
  294.     bool GetNthAttrib( int n, MCD_STR& strAttrib, MCD_STR& strValue ) const;
  295.     MCD_STR GetAttribName( int n ) const;
  296.     int FindNode( int nType=0 );
  297.     int GetNodeType() { return m_nNodeType; };
  298.     bool SavePos( MCD_CSTR szPosName=MCD_T(""), int nMap = 0 );
  299.     bool RestorePos( MCD_CSTR szPosName=MCD_T(""), int nMap = 0 );
  300.     bool SetMapSize( int nSize, int nMap = 0 );
  301.     MCD_STR GetError() const;
  302.     const MCD_STR& GetResult() const { return m_strResult; };
  303.     int GetDocFlags() const { return m_nDocFlags; };
  304.     void SetDocFlags( int nFlags ) { m_nDocFlags = (nFlags & ~(MDF_READFILE|MDF_WRITEFILE|MDF_APPENDFILE)); };
  305.     enum MarkupDocFlags
  306.     {
  307.         MDF_UTF16LEFILE = 1,
  308.         MDF_UTF8PREAMBLE = 4,
  309.         MDF_IGNORECASE = 8,
  310.         MDF_READFILE = 16,
  311.         MDF_WRITEFILE = 32,
  312.         MDF_APPENDFILE = 64,
  313.         MDF_UTF16BEFILE = 128,
  314.         MDF_TRIMWHITESPACE = 256,
  315.         MDF_COLLAPSEWHITESPACE = 512
  316.     };
  317.     enum MarkupNodeFlags
  318.     {
  319.         MNF_WITHCDATA      = 0x01,
  320.         MNF_WITHNOLINES    = 0x02,
  321.         MNF_WITHXHTMLSPACE = 0x04,
  322.         MNF_WITHREFS       = 0x08,
  323.         MNF_WITHNOEND      = 0x10,
  324.         MNF_ESCAPEQUOTES  = 0x100,
  325.         MNF_NONENDED   = 0x100000,
  326.         MNF_ILLDATA    = 0x200000
  327.     };
  328.     enum MarkupNodeType
  329.     {
  330.         MNT_ELEMENT                 = 1,    // 0x0001
  331.         MNT_TEXT                    = 2,    // 0x0002
  332.         MNT_WHITESPACE              = 4,    // 0x0004
  333.         MNT_TEXT_AND_WHITESPACE     = 6,    // 0x0006
  334.         MNT_CDATA_SECTION           = 8,    // 0x0008
  335.         MNT_PROCESSING_INSTRUCTION  = 16,   // 0x0010
  336.         MNT_COMMENT                 = 32,   // 0x0020
  337.         MNT_DOCUMENT_TYPE           = 64,   // 0x0040
  338.         MNT_EXCLUDE_WHITESPACE      = 123,  // 0x007b
  339.         MNT_LONE_END_TAG            = 128,  // 0x0080
  340.         MNT_NODE_ERROR              = 32768 // 0x8000
  341.     };
  342.  
  343.     // Create
  344.     bool Save( MCD_CSTR_FILENAME szFileName );
  345.     const MCD_STR& GetDoc() const { return m_strDoc; };
  346.     bool AddElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags); };
  347.     bool InsertElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags|MNF_INSERT); };
  348.     bool AddChildElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags|MNF_CHILD); };
  349.     bool InsertChildElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags|MNF_INSERT|MNF_CHILD); };
  350.     bool AddElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags); };
  351.     bool InsertElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags|MNF_INSERT); };
  352.     bool AddChildElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags|MNF_CHILD); };
  353.     bool InsertChildElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags|MNF_INSERT|MNF_CHILD); };
  354.     bool AddAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue ) { return x_SetAttrib(m_iPos,szAttrib,szValue); };
  355.     bool AddChildAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue ) { return x_SetAttrib(m_iPosChild,szAttrib,szValue); };
  356.     bool AddAttrib( MCD_CSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPos,szAttrib,nValue); };
  357.     bool AddChildAttrib( MCD_CSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPosChild,szAttrib,nValue); };
  358.     bool AddSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,0); };
  359.     bool InsertSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,MNF_INSERT); };
  360.     MCD_STR GetSubDoc() { return x_GetSubDoc(m_iPos); };
  361.     bool AddChildSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,MNF_CHILD); };
  362.     bool InsertChildSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,MNF_CHILD|MNF_INSERT); };
  363.     MCD_STR GetChildSubDoc() { return x_GetSubDoc(m_iPosChild); };
  364.     bool AddNode( int nType, MCD_CSTR szText ) { return x_AddNode(nType,szText,0); };
  365.     bool InsertNode( int nType, MCD_CSTR szText ) { return x_AddNode(nType,szText,MNF_INSERT); };
  366.  
  367.     // Modify
  368.     bool RemoveElem();
  369.     bool RemoveChildElem();
  370.     bool RemoveNode();
  371.     bool SetAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue, int nFlags=0 ) { return x_SetAttrib(m_iPos,szAttrib,szValue,nFlags); };
  372.     bool SetChildAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue, int nFlags=0 ) { return x_SetAttrib(m_iPosChild,szAttrib,szValue,nFlags); };
  373.     bool SetAttrib( MCD_CSTR szAttrib, int nValue, int nFlags=0 ) { return x_SetAttrib(m_iPos,szAttrib,nValue,nFlags); };
  374.     bool SetChildAttrib( MCD_CSTR szAttrib, int nValue, int nFlags=0 ) { return x_SetAttrib(m_iPosChild,szAttrib,nValue,nFlags); };
  375.     bool SetData( MCD_CSTR szData, int nFlags=0 ) { return x_SetData(m_iPos,szData,nFlags); };
  376.     bool SetChildData( MCD_CSTR szData, int nFlags=0 ) { return x_SetData(m_iPosChild,szData,nFlags); };
  377.     bool SetData( int nValue ) { return x_SetData(m_iPos,nValue); };
  378.     bool SetChildData( int nValue ) { return x_SetData(m_iPosChild,nValue); };
  379.     bool SetElemContent( MCD_CSTR szContent ) { return x_SetElemContent(szContent); };
  380.  
  381.  
  382.     // Utility
  383.     static bool ReadTextFile( MCD_CSTR_FILENAME szFileName, MCD_STR& strDoc, MCD_STR* pstrResult=NULL, int* pnDocFlags=NULL, MCD_STR* pstrEncoding=NULL );
  384.     static bool WriteTextFile( MCD_CSTR_FILENAME szFileName, const MCD_STR& strDoc, MCD_STR* pstrResult=NULL, int* pnDocFlags=NULL, MCD_STR* pstrEncoding=NULL );
  385.     static MCD_STR EscapeText( MCD_CSTR szText, int nFlags = 0 );
  386.     static MCD_STR UnescapeText( MCD_CSTR szText, int nTextLength = -1, int nFlags = 0 );
  387.     static int UTF16To8( char *pszUTF8, const unsigned short* pwszUTF16, int nUTF8Count );
  388.     static int UTF8To16( unsigned short* pwszUTF16, const char* pszUTF8, int nUTF8Count );
  389.     static MCD_STR UTF8ToA( MCD_CSTR pszUTF8, int* pnFailed = NULL );
  390.     static MCD_STR AToUTF8( MCD_CSTR pszANSI );
  391.     static void EncodeCharUTF8( int nUChar, char* pszUTF8, int& nUTF8Len );
  392.     static int DecodeCharUTF8( const char*& pszUTF8, const char* pszUTF8End = NULL );
  393.     static void EncodeCharUTF16( int nUChar, unsigned short* pwszUTF16, int& nUTF16Len );
  394.     static int DecodeCharUTF16( const unsigned short*& pwszUTF16, const unsigned short* pszUTF16End = NULL );
  395.     static bool DetectUTF8( const char* pText, int nTextLen, int* pnNonASCII = NULL, bool* bErrorAtEnd = NULL );
  396.     static MCD_STR GetDeclaredEncoding( MCD_CSTR szDoc );
  397.     static int GetEncodingCodePage( MCD_CSTR pszEncoding );
  398.  
  399. protected:
  400.  
  401. #if defined(_DEBUG)
  402.     MCD_PCSZ m_pDebugCur;
  403.     MCD_PCSZ m_pDebugPos;
  404. #endif // DEBUG
  405.  
  406.     MCD_STR m_strDoc;
  407.     MCD_STR m_strResult;
  408.  
  409.     int m_iPosParent;
  410.     int m_iPos;
  411.     int m_iPosChild;
  412.     int m_iPosFree;
  413.     int m_iPosDeleted;
  414.     int m_nNodeType;
  415.     int m_nNodeOffset;
  416.     int m_nNodeLength;
  417.     int m_nDocFlags;
  418.  
  419.     FilePos* m_pFilePos;
  420.     SavedPosMapArray* m_pSavedPosMaps;
  421.     ElemPosTree* m_pElemPosTree;
  422.  
  423.     enum MarkupNodeFlagsInternal
  424.     {
  425.         MNF_INSERT     = 0x002000,
  426.         MNF_CHILD      = 0x004000
  427.     };
  428.  
  429. #if defined(_DEBUG) // DEBUG
  430.     void x_SetDebugState();
  431. #define MARKUP_SETDEBUGSTATE x_SetDebugState()
  432. #else // not DEBUG
  433. #define MARKUP_SETDEBUGSTATE
  434. #endif // not DEBUG
  435.  
  436.     void x_InitMarkup();
  437.     void x_SetPos( int iPosParent, int iPos, int iPosChild );
  438.     int x_GetFreePos();
  439.     bool x_AllocElemPos( int nNewSize = 0 );
  440.     int x_GetParent( int i );
  441.     bool x_ParseDoc();
  442.     int x_ParseElem( int iPos, TokenPos& token );
  443.     int x_FindElem( int iPosParent, int iPos, PathPos& path ) const;
  444.     MCD_STR x_GetPath( int iPos ) const;
  445.     MCD_STR x_GetTagName( int iPos ) const;
  446.     MCD_STR x_GetData( int iPos );
  447.     MCD_STR x_GetAttrib( int iPos, MCD_PCSZ pAttrib ) const;
  448.     static MCD_STR x_EncodeCDATASection( MCD_PCSZ szData );
  449.     bool x_AddElem( MCD_PCSZ pName, MCD_PCSZ pValue, int nFlags );
  450.     bool x_AddElem( MCD_PCSZ pName, int nValue, int nFlags );
  451.     MCD_STR x_GetSubDoc( int iPos );
  452.     bool x_AddSubDoc( MCD_PCSZ pSubDoc, int nFlags );
  453.     bool x_SetAttrib( int iPos, MCD_PCSZ pAttrib, MCD_PCSZ pValue, int nFlags=0 );
  454.     bool x_SetAttrib( int iPos, MCD_PCSZ pAttrib, int nValue, int nFlags=0 );
  455.     bool x_AddNode( int nNodeType, MCD_PCSZ pText, int nNodeFlags );
  456.     void x_RemoveNode( int iPosParent, int& iPos, int& nNodeType, int& nNodeOffset, int& nNodeLength );
  457.     static bool x_CreateNode( MCD_STR& strNode, int nNodeType, MCD_PCSZ pText );
  458.     int x_InsertNew( int iPosParent, int& iPosRel, NodePos& node );
  459.     void x_AdjustForNode( int iPosParent, int iPos, int nShift );
  460.     void x_Adjust( int iPos, int nShift, bool bAfterPos = false );
  461.     void x_LinkElem( int iPosParent, int iPosBefore, int iPos );
  462.     int x_UnlinkElem( int iPos );
  463.     int x_UnlinkPrevElem( int iPosParent, int iPosBefore, int iPos );
  464.     int x_ReleaseSubDoc( int iPos );
  465.     int x_ReleasePos( int iPos );
  466.     void x_CheckSavedPos();
  467.     bool x_SetData( int iPos, MCD_PCSZ szData, int nFlags );
  468.     bool x_SetData( int iPos, int nValue );
  469.     int x_RemoveElem( int iPos );
  470.     MCD_STR x_GetElemContent( int iPos ) const;
  471.     bool x_SetElemContent( MCD_PCSZ szContent );
  472.     void x_DocChange( int nLeft, int nReplace, const MCD_STR& strInsert );
  473. };
  474.  
  475. #endif // !defined(_MARKUP_H_INCLUDED_)
  476. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement