update for HEAD-2003091401
[reactos.git] / subsys / system / explorer / Seashell / SeaShellExt / Include / TextParse.h
1 //*******************************************************************************
2 // COPYRIGHT NOTES
3 // ---------------
4 // You may use this source code, compile or redistribute it as part of your application 
5 // for free. You cannot redistribute it as a part of a software development 
6 // library without the agreement of the author. If the sources are 
7 // distributed along with the application, you should leave the original 
8 // copyright notes in the source code without any changes.
9 // This code can be used WITHOUT ANY WARRANTIES at your own risk.
10 // 
11 // For the latest updates to this code, check this site:
12 // http://www.masmex.com 
13 // after Sept 2000
14 // 
15 // Copyright(C) 2000 Philip Oldaker <email: philip@masmex.com>
16 //*******************************************************************************
17
18 #ifndef __LINEPARSE_H__
19 #define __LINEPARSE_H__
20
21 #define CPP_SPACE ' '
22 #define CPP_TAB '\t'
23 #define CPP_NEWLINE '\n'
24 #define CPP_CRLF _T("\r\n")
25 #define CPP_WHITE_SPACE _T(" \t")
26
27 class CTRL_EXT_CLASS CTextParse 
28 {
29         enum { MAX_BUF = 4096 };
30 public:
31         CTextParse();
32         CTextParse(const CTextParse &tp);
33         CTextParse(LPCTSTR pszLine);
34         ~CTextParse();
35 public:
36         operator LPCTSTR() const;
37         operator LPTSTR();
38         const CTextParse& operator=(LPCTSTR lpsz);
39         const CTextParse& operator=(const CTextParse &tp);
40         LPCTSTR operator++(int);
41         LPTSTR &operator++();
42         LPCTSTR operator--(int);
43         LPCTSTR &operator--();
44         int GetMax();
45         void Set(LPCTSTR p);
46         void Reset();
47         void SaveCurPos();
48         void RestorePos();
49         void SetAtCurrent(int c);
50         void MoveForward();
51         void MoveBack();
52         void MoveForward(int nCount);
53         void MoveBack(int nCount);
54         BOOL IsVirtualFunc();
55         BOOL IsPrivate();
56         BOOL IsPublic();
57         BOOL IsProtected();
58         BOOL IsEnd();
59         BOOL IsClass();
60         BOOL IsStartBrace();
61         BOOL IsEndBrace();
62         BOOL IsAccessSpecifier();
63         BOOL IsMsgMap();
64         BOOL IsDeclareMacro();
65         BOOL IsStartCommentBlock();
66         BOOL IsEndCommentBlock();
67         BOOL IsConstructor(LPCTSTR pszClassName);
68         BOOL IsValidCPP(LPCTSTR pszText);
69         BOOL CharAtStart(int c);
70         BOOL CharAtStart(LPCTSTR strTok);
71         BOOL CharAtCurrent(int c);
72         BOOL CharAtCurrent(LPCTSTR strTok);
73         BOOL StringAtStart(LPCTSTR str);
74         BOOL StringAtCurrent(LPCTSTR str);
75         BOOL CharExist(int c,BOOL bForward = TRUE);
76         BOOL StringExist(LPCTSTR str);
77         BOOL StringExistInString(LPCTSTR str);
78         BOOL SkipWord(BOOL bForward = TRUE);
79         BOOL SkipWhiteSpace(BOOL bForward = TRUE);
80
81         BOOL CharExistFromCurPos(int c,BOOL bForward = TRUE);
82         BOOL ValidCppCharExist(int c,BOOL bForward = TRUE);
83         BOOL CharExist(LPCTSTR str);
84         BOOL FindString(LPCTSTR str);
85         BOOL FindChar(int c);
86         BOOL MoveWhileWhiteSpace(BOOL bForward = TRUE);
87         BOOL MoveUntilWhiteSpace(BOOL bForward = TRUE);
88         BOOL MoveUntilChar(int c,BOOL bForward = TRUE);
89         BOOL MoveUntilChar(LPCTSTR strTok,BOOL bForward = TRUE);
90         BOOL MoveUntilString(LPCTSTR str,BOOL bForward = TRUE);
91         BOOL MoveWhileChar(int c,BOOL bForward = TRUE);
92         BOOL MoveWhileChar(LPCTSTR strTok,BOOL bForward = TRUE);
93         void MoveToLastChar();
94         LPCTSTR CopyUntilWhiteSpace();
95         LPCTSTR CopyUntilChar(int c);
96         LPCTSTR CopyUntilString(LPCTSTR pszText);
97         LPCTSTR CopyUntilChar(LPCTSTR strTok);
98         LPCTSTR CopyWhileChar(int c);
99         LPCTSTR CopyWhileChar(LPCTSTR strTok);
100         LPCTSTR CopyFuncUntilChar(LPCTSTR strTok);
101         LPCTSTR CopyUntilEnd();
102         LPCTSTR CopyWhileWhiteSpace();
103         BOOL IsCommentBlock(LPCTSTR strStart,LPCTSTR strEnd);
104         BOOL ExtractArgs(CString &sRet,CStringArray &asArgs);
105         LPCTSTR ExtractDeclareMacro();
106         LPCTSTR ExtractConstructor();
107         LPCTSTR ExtractFuncName();
108         LPCTSTR ExtractClassName();
109         LPCTSTR ExtractBaseClassName();
110         LPCTSTR ExtractHTMLText(bool bRemoveCRLF=false);
111         LPCTSTR ExtractHTMLText(LPCTSTR pszUntil,bool bRemoveCRLF=false);
112         LPCTSTR ExtractHTMLLink();
113         LPCTSTR ExtractDefaultArgs();
114         LPCTSTR CopyWholeWord();
115         bool FindWholeWord(LPCTSTR pszText);
116         int GetWordLen();
117         int GetCurrentChar();
118         bool SkipHTMLCommand(bool bSkipCRLF=true);
119         void SkipHTMLCommands(bool bSkipCRLF=true);
120 protected:
121         BOOL IsToken(LPCTSTR strTok,LPCTSTR p);
122         BOOL IsString(LPCTSTR str);
123 private:
124         LPCTSTR m_pLine;
125         LPCTSTR m_pStartLine;
126         LPCTSTR m_pSavePos;
127         TCHAR m_szCopyBuf[MAX_BUF+1];
128         TCHAR m_szBuffer[MAX_BUF+1];
129 };
130
131 inline void CTextParse::MoveForward()
132 {
133         m_pLine = _tcsinc(m_pLine);
134 }
135
136 inline void CTextParse::MoveBack()
137 {
138         m_pLine = _tcsdec(m_pStartLine,m_pLine);
139 }
140
141 inline void CTextParse::MoveForward(int nCount)
142 {
143         m_pLine = _tcsninc(m_pLine,nCount);
144 }
145
146 inline void CTextParse::MoveBack(int nCount)
147 {
148         int i=nCount;
149         LPCTSTR p = m_pLine;
150         while (p > m_pStartLine && i > 0)
151         {
152                    p = _tcsdec(m_pLine,p);
153                    i--;
154         }
155         m_pLine = p;
156 }
157
158 inline CTextParse::operator LPCTSTR() const
159 {
160         return m_pStartLine;
161 }
162
163 inline CTextParse::operator LPTSTR() 
164 {
165         Reset();
166         return m_szBuffer;
167 }
168
169 // prefix
170 inline LPCTSTR CTextParse::operator++(int)
171 {
172         MoveForward();
173         return (LPCTSTR&)*m_pLine;
174 }
175
176 // postfix
177 inline LPTSTR &CTextParse::operator++()
178 {
179         LPCTSTR p = m_pLine;
180         MoveForward();
181         return (LPTSTR&)*p;
182 }
183
184 inline LPCTSTR CTextParse::operator--(int)
185 {
186         MoveBack();
187         return m_pLine;
188 }
189
190 inline LPCTSTR &CTextParse::operator--()
191 {
192         LPCTSTR p = m_pLine;
193         MoveBack();
194         return (LPCTSTR&)*p;
195 }
196
197 inline BOOL CTextParse::IsEnd()
198 {
199         return *m_pLine == '\0';
200 }
201
202 inline int CTextParse::GetMax()
203 {
204         return MAX_BUF;
205 }
206
207 inline int CTextParse::GetCurrentChar()
208 {
209         return *m_pLine;
210 }
211
212 inline void CTextParse::SetAtCurrent(int c)
213 {
214         int i = m_pLine-m_szBuffer;
215         m_szBuffer[i] = c;
216 }
217
218 inline void CTextParse::Set(LPCTSTR p)
219 {
220         m_pStartLine = p;
221         m_pLine = p;
222         m_pSavePos = p;
223 }
224
225 inline void CTextParse::Reset()
226 {
227         m_pLine = m_pStartLine;
228 }
229
230 inline void CTextParse::SaveCurPos()
231 {
232         m_pSavePos = m_pLine;
233 }
234
235 inline void CTextParse::RestorePos()
236 {
237         m_pLine = m_pSavePos;
238 }
239
240 inline BOOL CTextParse::CharAtStart(int c)
241 {
242         return *m_pStartLine == c;
243 }
244
245 inline BOOL CTextParse::CharAtStart(LPCTSTR strTok)
246 {
247         return IsToken(strTok,m_pStartLine);
248 }
249
250 inline BOOL CTextParse::CharAtCurrent(int c)
251 {
252         return *m_pLine == c;
253 }
254
255 inline BOOL CTextParse::CharAtCurrent(LPCTSTR strTok)
256 {
257         return IsToken(strTok,m_pLine);
258 }
259
260 inline BOOL CTextParse::StringAtStart(LPCTSTR str)
261 {
262         return(_tcsncmp(m_pStartLine,str,_tcslen(str)) == 0);
263 }
264
265 inline BOOL CTextParse::StringAtCurrent(LPCTSTR str)
266 {
267         return(_tcsncmp(m_pLine,str,_tcslen(str)) == 0);
268 }
269
270 inline BOOL CTextParse::CharExist(int c,BOOL bForward)
271 {
272         return _tcschr(m_pStartLine,c) != NULL;
273 }
274
275 inline BOOL CTextParse::StringExist(LPCTSTR str)
276 {
277         return _tcsstr(m_pLine,str) != NULL;
278 }
279
280 inline BOOL CTextParse::StringExistInString(LPCTSTR str)
281 {
282         return _tcsstr(m_pStartLine,str) != NULL;
283 }
284
285 inline BOOL CTextParse::SkipWord(BOOL bForward)
286 {
287         return MoveUntilChar(CPP_WHITE_SPACE,bForward);
288 }
289
290 inline BOOL CTextParse::SkipWhiteSpace(BOOL bForward)
291 {
292         return MoveWhileChar(CPP_WHITE_SPACE,bForward);
293 }
294
295 inline BOOL CTextParse::IsString(LPCTSTR str)
296 {
297         return(_tcsncmp(m_pLine,str,_tcslen(str)) == 0);
298 }
299
300 inline LPCTSTR CTextParse::CopyUntilWhiteSpace()
301 {
302         return CopyUntilChar(CPP_WHITE_SPACE);
303 }
304
305 inline LPCTSTR CTextParse::CopyWhileWhiteSpace()
306 {
307         return CopyWhileChar(CPP_WHITE_SPACE);
308 }
309
310 inline BOOL CTextParse::MoveWhileWhiteSpace(BOOL bForward)
311 {
312         return MoveWhileChar(CPP_WHITE_SPACE,bForward);
313 }
314
315 inline BOOL CTextParse::MoveUntilWhiteSpace(BOOL bForward)
316 {
317         return MoveUntilChar(CPP_WHITE_SPACE,bForward);
318 }
319
320 // move to last char
321 inline void CTextParse::MoveToLastChar()
322 {
323         LPCTSTR p = m_pLine;
324         while (*p != '\0')
325                    p = _tcsinc(p);
326         if (p != m_pLine)
327                 p = _tcsdec(m_pStartLine,p);
328         m_pLine = p;
329 }
330
331 #endif