Click here to Skip to main content
13,145,774 members (57,762 online)
Click here to Skip to main content


103 bookmarked
Posted 29 Oct 2000

Fast regular expressions

, 29 Oct 2000
Compiles a regular expression into a fast automaton.

#include "RexAlgorithm.h"

struct REXI_DefErr{
        enum{eNoErr,eErrInName,eErrInRegExp} eErrCode;
        string  strErrMsg;
        int     nErrOffset;

class REXI_Base{

	REXI_Base(char cEos='\0');
    virtual ~REXI_Base()=0;

    inline void			SetSource			(const char* pszSource);
    inline const char*  GetSource    ()const;

    REXI_DefErr          AddRegDefinition    (string strName,string strRegExp,
                                            int nIdAnswer);
    void            GetRegDefinitions   (vector<string>& vecDefinitions);
    void            RemoveRegDefinition (string strName);

	REXI_DefErr			SetRegexp			(string strRegExp);


    inline void FreeMemory    ();          

//source,source position and end of string character
	char				m_cEos;
	const char*			m_pszSource;
    const char*         m_pszTokenBeg;
    const char*         m_pszTokenEnd;

//algorithmic objects
	REXA_Parser		    m_regexpParser;

	REXA_DFAState*      m_pStartState;


class REXI_Search : public REXI_Base
    REXI_Search(char cEos='\0');

            AddRegDef   (string strName,string strRegExp);
    inline  REXI_DefErr  
            SetRegexp	(string strRegExp);
    bool    MatchHere   (const char*& rpcszSrc, int& nMatchLen,bool& bEos);
    bool    Find        (const char*& rpcszSrc, int& nMatchLen,bool& bEos);
    bool    MatchHereImpl();
    int     m_nIdAnswer;

inline const char*     REXI_Base::GetSource()const  {return m_pszSource;}
inline void			   REXI_Base::SetSource(const char* pszSource)
    m_pszSource= pszSource;m_pszTokenBeg= m_pszTokenEnd=pszSource;
inline REXI_DefErr	        REXI_Search::SetRegexp	(string strRegExp)
    return REXI_Base::SetRegexp(strRegExp);
inline void             REXI_Base::FreeMemory()     {m_pStartState->DeleteAll();}

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...

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