Click here to Skip to main content
15,881,027 members
Articles / Programming Languages / C++

Fast regular expressions

Rate me:
Please Sign up or sign in to vote.
4.85/5 (19 votes)
29 Oct 2000 360.6K   5.2K   104  
Compiles a regular expression into a fast automaton.
#pragma once
#include "RexInterface.h"


struct SSearchInfo{
	SSearchInfo(CString strPathname,CString strFilename,
                        int nFilePosTokenBeg=0,int nLen=0,CString strLine="")
		:strPathname(strPathname),strFilename(strFilename),
		nFilePosTokenBeg(nFilePosTokenBeg),
		nLen(nLen),strLine(strLine)
	{}
    CString  strFilename;
    CString  strPathname;
    CString  strLine;
    int nFilePosTokenBeg;
    int nLen;
};

class CSearchResult{
public: 
    vector< SSearchInfo > vecSearchInfo;
};

class CSearchPresenter{
public:
    virtual void  Init()=0;
    virtual void  PresentSearch(const CSearchResult& rResult,int nPieceNo)=0;
};
class CFileProcessor{
public:
    virtual REXI_DefErr   AddRegDefinition(const char* pcszName,const char* pcszRegExp)=0;
    virtual REXI_DefErr   SetRegExpression(const char* pcszExpr)=0;
    virtual void    ProcessFile(CSearchResult& pResult,
        const char* pcszPathName,const char* pcszFileName,
        bool bLinewise,bool bAtMostOneMatchPerLine)=0;
};
class CSearchBar: public CDialogBar{
public:
    CSearchBar();
       
    ~CSearchBar()
    {
    }
    void RegisterSearchPresenter(CSearchPresenter* pSearchPresenter)
    {
        m_vecSearchPresenters.push_back(pSearchPresenter);
    }
    void RegisterFileProcessor(CFileProcessor* pFileProcessor);
    DECLARE_DYNCREATE(CSearchBar)
    void DoDataExchange(CDataExchange* pDX);
    void ShowDialog();
    void Serialize(CArchive& ar);
    static bool FindInThisFile(const char* pcszPathName,const char* pcszFileName,void* pThis);
    bool SetRegexp(CString strRegexp);
    void Resize(int cx,int cy);
    CComboBox   m_cmbSearch;
    CComboBox   m_cmbDir;
    CComboBox   m_cmbWildCards;
    CString     m_strBrowseDir;
    CButton     m_btnReghelp;
	CButton		m_btnSearch;
    CButton     m_btnDirBrowse;
    CProgressCtrl   m_progress;
    CStatic     m_static;
private:
    void NotifyPresenters(const CSearchResult& result);
    void NotifyProcessors(const char* pcszPathName,
                                  const char* pcszFileName,CSearchResult& result);
    void        DoMessageLoop();
    BOOL        PumpMessage();
    bool        m_bQuit;
    vector<CSearchPresenter*>   m_vecSearchPresenters;
    vector<CFileProcessor*>     m_vecFileProcessors;
    CSearchPresenter*   m_pSearchPresenter;
    CSearchResult       m_searchResult;
    DWORD               m_dwCmbSelection;
    int                 m_nPieceNo;
    bool                m_bEnableSearch;
    bool                m_bCanceled;
    int                 m_nOccurences;
    bool CheckSearchEnableThis  (CWnd& rWnd);
    void InsertAtCaretPos       (const char* pcszToInsert,int nPos);
    void CmbContentSerialize    (CComboBox& rCmb,CArchive& ar);
    void InsertIntoCmbList      (CComboBox& rCmb,CString strToInsert);
    vector< pair<CString,CString> > m_vecDefs;
public:
    void OnCancelSearch();
protected:
    //{{AFX_MSG(CSearchBar)
    afx_msg void OnUpdateSearch(CCmdUI* pCmdUI);
    afx_msg void OnUpdateButtonDirBrowse(CCmdUI* pCmdUI);
    afx_msg void OnUpdateButtonDef(CCmdUI* pCmdUI);
    afx_msg void OnUpdateCancel(CCmdUI* pCmdUI);
	afx_msg void OnButtonDirBrowse();
	afx_msg void OnButtonReghelp();
    afx_msg void OnUpdateButtonReghelp(CCmdUI* pCmdUI);
	afx_msg void OnSearch();
	afx_msg void OnContextmenuCharacterinrange();
	afx_msg void OnContextmenuCharacternotinrange();
	afx_msg void OnContextmenuGroup();
	afx_msg void OnContextmenuOr();
	afx_msg void OnButtonDef();
	//}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions