Click here to Skip to main content
15,894,132 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 363.9K   5.2K   104  
Compiles a regular expression into a fast automaton.
// ErrListView.cpp: Implementierungsdatei
//

#include "stdafx.h"
#include "MainFrm.h"
#include "ErrListView.h"
#include "RexSearchDoc.h"
#include "RexSearchView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CErrListView

IMPLEMENT_DYNCREATE(CErrListView, CListView)

CErrListView::CErrListView():m_bIsInitialized(false)
{
}

CErrListView::~CErrListView()
{
}
void    CErrListView::Init()
{
    GetListCtrl().DeleteAllItems();
    GetListCtrl().Invalidate();
    GetListCtrl().UpdateWindow();
}
void  CErrListView::PresentSearch(const CSearchResult& rResult,int nPieceNo)
{
	if( nPieceNo==0){
		GetListCtrl().DeleteAllItems();
	}
	int nItems= GetListCtrl().GetItemCount();
    char buf[32];
    for(int i=0;i<rResult.vecSearchInfo.size();i++){
        GetListCtrl().InsertItem(nItems+i,rResult.vecSearchInfo[i].strPathname);
        GetListCtrl().SetItemText(nItems+i,1,rResult.vecSearchInfo[i].strFilename);
        GetListCtrl().SetItemText(nItems+i,2,itoa(rResult.vecSearchInfo[i].nFilePosTokenBeg,buf,10));
        GetListCtrl().SetItemText(nItems+i,3,itoa(rResult.vecSearchInfo[i].nLen,buf,10));
        GetListCtrl().SetItemText(nItems+i,4,rResult.vecSearchInfo[i].strLine);
    }
}



BEGIN_MESSAGE_MAP(CErrListView, CListView)
	//{{AFX_MSG_MAP(CErrListView)
	ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnItemchanged)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Zeichnung CErrListView 

void CErrListView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// ZU ERLEDIGEN: Code zum Zeichnen hier einf�gen
}

/////////////////////////////////////////////////////////////////////////////
// Diagnose CErrListView

#ifdef _DEBUG
void CErrListView::AssertValid() const
{
	CListView::AssertValid();
}

void CErrListView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen f�r Nachrichten CErrListView 

void CErrListView::OnInitialUpdate() 
{
	CListView::OnInitialUpdate();
    if(!m_bIsInitialized){
        m_bIsInitialized= true;
        GetListCtrl().ModifyStyle(0,LVS_REPORT|LVS_SINGLESEL|LVS_SHOWSELALWAYS);
		GetListCtrl().SetExtendedStyle(GetListCtrl().GetExtendedStyle()|LVS_EX_FULLROWSELECT );
        GetListCtrl().InsertColumn(0,"Path",LVCFMT_LEFT,50);
        GetListCtrl().InsertColumn(1,"File",LVCFMT_LEFT,100);
        GetListCtrl().InsertColumn(2,"Position",LVCFMT_LEFT,50);
        GetListCtrl().InsertColumn(3,"Length",LVCFMT_LEFT,30);
        GetListCtrl().InsertColumn(4,"Line",LVCFMT_LEFT,500);
        CMainFrame::RegisterSearchPresenter(this);
    }
}

void CErrListView::OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    if( pNMListView->uChanged&LVIF_STATE ){
        if( pNMListView->uNewState&LVIS_SELECTED ){
            CString strPath= GetListCtrl().GetItemText(pNMListView->iItem,0);
            long lPos= atol(GetListCtrl().GetItemText(pNMListView->iItem,2));
            int  nLen= atoi(GetListCtrl().GetItemText(pNMListView->iItem,3));
            CMainFrame::GetEditPane()->ShowFile(strPath,lPos,nLen);
        }
    }
	*pResult = 0;
}

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