1 //*******************************************************************************
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.
11 // For the latest updates to this code, check this site:
12 // http://www.masmex.com
15 // Copyright(C) 2000 Philip Oldaker <email: philip@masmex.com>
16 //*******************************************************************************
18 #ifndef __LINEPARSE_H__
19 #define __LINEPARSE_H__
23 #define CPP_NEWLINE '\n'
24 #define CPP_CRLF _T("\r\n")
25 #define CPP_WHITE_SPACE _T(" \t")
27 class CTRL_EXT_CLASS CTextParse
29 enum { MAX_BUF = 4096 };
32 CTextParse(const CTextParse &tp);
33 CTextParse(LPCTSTR pszLine);
36 operator LPCTSTR() const;
38 const CTextParse& operator=(LPCTSTR lpsz);
39 const CTextParse& operator=(const CTextParse &tp);
40 LPCTSTR operator++(int);
42 LPCTSTR operator--(int);
43 LPCTSTR &operator--();
49 void SetAtCurrent(int c);
52 void MoveForward(int nCount);
53 void MoveBack(int nCount);
62 BOOL IsAccessSpecifier();
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);
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);
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);
117 int GetCurrentChar();
118 bool SkipHTMLCommand(bool bSkipCRLF=true);
119 void SkipHTMLCommands(bool bSkipCRLF=true);
121 BOOL IsToken(LPCTSTR strTok,LPCTSTR p);
122 BOOL IsString(LPCTSTR str);
125 LPCTSTR m_pStartLine;
127 TCHAR m_szCopyBuf[MAX_BUF+1];
128 TCHAR m_szBuffer[MAX_BUF+1];
131 inline void CTextParse::MoveForward()
133 m_pLine = _tcsinc(m_pLine);
136 inline void CTextParse::MoveBack()
138 m_pLine = _tcsdec(m_pStartLine,m_pLine);
141 inline void CTextParse::MoveForward(int nCount)
143 m_pLine = _tcsninc(m_pLine,nCount);
146 inline void CTextParse::MoveBack(int nCount)
150 while (p > m_pStartLine && i > 0)
152 p = _tcsdec(m_pLine,p);
158 inline CTextParse::operator LPCTSTR() const
163 inline CTextParse::operator LPTSTR()
170 inline LPCTSTR CTextParse::operator++(int)
173 return (LPCTSTR&)*m_pLine;
177 inline LPTSTR &CTextParse::operator++()
184 inline LPCTSTR CTextParse::operator--(int)
190 inline LPCTSTR &CTextParse::operator--()
197 inline BOOL CTextParse::IsEnd()
199 return *m_pLine == '\0';
202 inline int CTextParse::GetMax()
207 inline int CTextParse::GetCurrentChar()
212 inline void CTextParse::SetAtCurrent(int c)
214 int i = m_pLine-m_szBuffer;
218 inline void CTextParse::Set(LPCTSTR p)
225 inline void CTextParse::Reset()
227 m_pLine = m_pStartLine;
230 inline void CTextParse::SaveCurPos()
232 m_pSavePos = m_pLine;
235 inline void CTextParse::RestorePos()
237 m_pLine = m_pSavePos;
240 inline BOOL CTextParse::CharAtStart(int c)
242 return *m_pStartLine == c;
245 inline BOOL CTextParse::CharAtStart(LPCTSTR strTok)
247 return IsToken(strTok,m_pStartLine);
250 inline BOOL CTextParse::CharAtCurrent(int c)
252 return *m_pLine == c;
255 inline BOOL CTextParse::CharAtCurrent(LPCTSTR strTok)
257 return IsToken(strTok,m_pLine);
260 inline BOOL CTextParse::StringAtStart(LPCTSTR str)
262 return(_tcsncmp(m_pStartLine,str,_tcslen(str)) == 0);
265 inline BOOL CTextParse::StringAtCurrent(LPCTSTR str)
267 return(_tcsncmp(m_pLine,str,_tcslen(str)) == 0);
270 inline BOOL CTextParse::CharExist(int c,BOOL bForward)
272 return _tcschr(m_pStartLine,c) != NULL;
275 inline BOOL CTextParse::StringExist(LPCTSTR str)
277 return _tcsstr(m_pLine,str) != NULL;
280 inline BOOL CTextParse::StringExistInString(LPCTSTR str)
282 return _tcsstr(m_pStartLine,str) != NULL;
285 inline BOOL CTextParse::SkipWord(BOOL bForward)
287 return MoveUntilChar(CPP_WHITE_SPACE,bForward);
290 inline BOOL CTextParse::SkipWhiteSpace(BOOL bForward)
292 return MoveWhileChar(CPP_WHITE_SPACE,bForward);
295 inline BOOL CTextParse::IsString(LPCTSTR str)
297 return(_tcsncmp(m_pLine,str,_tcslen(str)) == 0);
300 inline LPCTSTR CTextParse::CopyUntilWhiteSpace()
302 return CopyUntilChar(CPP_WHITE_SPACE);
305 inline LPCTSTR CTextParse::CopyWhileWhiteSpace()
307 return CopyWhileChar(CPP_WHITE_SPACE);
310 inline BOOL CTextParse::MoveWhileWhiteSpace(BOOL bForward)
312 return MoveWhileChar(CPP_WHITE_SPACE,bForward);
315 inline BOOL CTextParse::MoveUntilWhiteSpace(BOOL bForward)
317 return MoveUntilChar(CPP_WHITE_SPACE,bForward);
321 inline void CTextParse::MoveToLastChar()
327 p = _tcsdec(m_pStartLine,p);