home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2000 February
/
PCWorld_2000-02_cd.bin
/
Software
/
TemaCD
/
tcvpa
/
data1.cab
/
MyFileGroup
/
INCLUDE
/
RegExp.hpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-06-03
|
5KB
|
127 lines
#ifdef BUILD_TCCORE
#define TCCORELIB __declspec(dllexport)
#else
#ifdef BUILD_LOCAL
#define TCCORELIB
#else
#define TCCORELIB __declspec(dllimport)
#endif
#endif
// **********************************************************************
class TCCORELIB TC_CRegExp
{
public:
enum { MAX_PAIRS = 10 };
/*
REGULAR EXPRESSION SYNTAX:
A regular expression is zero or more branches, separated by `|`.
It matches anything that matches one of the branches.
A branch is zero or more pieces, concatenated.
It matches a match for the first, followed by a match for the second, etc.
A piece is an atom possibly followed by `*`, `+`, or `?`.
An atom followed by `*` matches a sequence of 0 or more matches of the atom.
An atom followed by `+` matches a sequence of 1 or more matches of the atom.
An atom followed by `?` matches a match of the atom, or the null string.
An atom is:
- a regular expression in parentheses (matching a match for the regular expression)
- range (see below)
- `.` (matching any single character)
- `^` (matching the null string at the beginning of the input string)
- `$` (matching the null string at the end of the input string)
- `\e` followed by a single character (matching that character)
- a single character with no other significance (matching that character).
A range is a sequence of characters enclosed in `[]`.
It normally matches any single character from the sequence.
If the sequence begins with `^`, it matches any single character not from the rest of the sequence.
If two characters in the sequence are separated by `-`, this is shorthand
for the full list of ASCII characters between them (e.g. `[0-9]` matches any decimal digit).
To include a literal `]` in the sequence, make it the first character
(following a possible `^`).
To include a literal `-`, make it the first or last character.
*/
// **********************************************************************
public:
struct IntPair
{
public: long position ;
public: long length ;
}; // end of class IntPair
// **********************************************************************
// **********************************************************************
public:
struct RegExpStruct
{
public: char * startp [MAX_PAIRS];
public: char * endp [MAX_PAIRS];
public: char regstart ;
public: char reganch ;
public: char * regmust ;
public: int regmlen ;
public: char program [1];
}; // end of class RegExpStruct
// **********************************************************************
protected: RegExpStruct* m_RegExp ;
protected: TC_CString m_RegExpString ;
protected: TC_CString m_LastError ;
protected: char* m_RegParse ;
protected: int m_RegNPar ;
protected: char m_RegDummy ;
protected: char* m_RegCode ;
protected: long m_RegSize ;
protected: char * m_RegInput ;
protected: char * m_RegBOL ;
protected: char ** m_RegStartP ;
protected: char ** m_RegEndP ;
protected: void regerror (char* s) ;
protected: char* reg (int paren, int* flagp) ;
protected: char* regbranch (int* flagp) ;
protected: char* regpiece (int* flagp) ;
protected: char* regatom (int* flagp) ;
protected: char* regnode (char op) ;
protected: void regc (char b) ;
protected: void reginsert (char op, char* opnd) ;
protected: void regtail (char *p, char *val) ;
protected: void regoptail (char *p, char *val) ;
protected: int regtry (RegExpStruct *prog, char *string) ;
protected: int regmatch (char *prog) ;
protected: int regrepeat (char *p) ;
protected: char * regnext (register char *p) ;
protected: TC_CRegExp::RegExpStruct* _regcomp (char* exp) ;
protected: int _regexec (register RegExpStruct *prog, register char *string) ;
protected: void _regsub (RegExpStruct *prog, char *source, char *dest) ;
public: TC_CRegExp () ;
public: TC_CRegExp (const char* regExp) ;
public: TC_CRegExp (TC_CRegExp& r) ;
public: ~TC_CRegExp () ;
public: BOOL SetRegExp (const char* regExp) ;
public: BOOL SetRegExp (TC_CRegExp& regExp) ;
public: TC_CRegExp& operator= (const char* regExp) ;
public: TC_CRegExp& operator= (TC_CRegExp& regExp) ;
public: long IndexIn (const char* string, long beginFrom = 0) ;
public: long Match (const char* string, long& length, long beginFrom = 0) ;
public: long Match (const char* string, IntPair segs [MAX_PAIRS], long beginFrom = 0) ;
public: TC_CString & LastError () ;
}; // end of class TC_CRegExp
// **********************************************************************