Click here to Skip to main content
11,790,366 members (62,626 online)
Click here to Skip to main content
Add your own
alternative version

Fast regular expressions

, 29 Oct 2000 293.3K 4.6K 102
Compiles a regular expression into a fast automaton.
// RexFileProcessor.cpp: implementation of the CRexFileProcessor class.

#include "stdafx.h"
#include "RexSearch.h"
#include "RexFileProcessor.h"
#include "RexAlgorithm.h"
#include "RexInterface.h"

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

// Construction/Destruction



REXI_DefErr   CRexFileProcessor::AddRegDefinition(const char* pcszName,const char* pcszRegExp)
    return m_rexSearch.AddRegDef(pcszName,pcszRegExp);
REXI_DefErr   CRexFileProcessor::SetRegExpression(const char* pcszExpr)
    return m_rexSearch.SetRegexp(pcszExpr);

void                CRexFileProcessor::ProcessFile(CSearchResult& rResult,
        const char* pcszPathName,const char* pcszFileName,
        bool bLinewise,bool bAtMostOneMatchPerLine)
    CFile oFile;
    if( oFile.Open(pcszPathName,CFile::modeRead) ){
        CString strFile;
        LPSTR pszBuf= strFile.GetBufferSetLength(oFile.GetLength()+3);
        pszBuf[0]= '\n';
        bool bEos;
        REXA_BegEnd matchRange;
        LPCSTR pszFindBuf= pszBuf;
        int nLenMatch;
        while( m_rexSearch.Find(pszFindBuf,nLenMatch,bEos) ){
            const char* psz= pszFindBuf-nLenMatch;
            const char* pLineBeg;
            for(pLineBeg= psz;*pLineBeg!='\n';pLineBeg--);
            const char* pLineEnd;
            nLenMatch= max(nLenMatch,1);
            for(pLineEnd= psz+nLenMatch;*pLineEnd && *pLineEnd!='\n' && *pLineEnd!='\r';pLineEnd++);
            CString strLine= CString(pLineBeg+1,pLineEnd-pLineBeg-1);
            strLine.Replace("\t","    ");
            SSearchInfo sSearchInfo(pcszPathName,pcszFileName,
            pszFindBuf= pLineEnd;

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.


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


About the Author

Martin Holzherr
Switzerland Switzerland
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1509028.1 | Last Updated 30 Oct 2000
Article Copyright 2000 by Martin Holzherr
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid