1 // Scintilla source code edit control
2 /** @file RESearch.h
3  ** Interface to the regular expression search library.
4  **/
5 // Written by Neil Hodgson <neilh@scintilla.org>
6 // Based on the work of Ozan S. Yigit.
7 // This file is in the public domain.
8 
9 #ifndef RESEARCH_H
10 #define RESEARCH_H
11 
12 /*
13  * The following defines are not meant to be changeable.
14  * They are for readability only.
15  */
16 #define MAXCHR	256
17 #define CHRBIT	8
18 #define BITBLK	MAXCHR/CHRBIT
19 
20 class CharacterIndexer {
21 public:
22 	virtual char CharAt(int index)=0;
~CharacterIndexer()23 	virtual ~CharacterIndexer() {
24 	}
25 };
26 
27 class RESearch {
28 
29 public:
30 	RESearch(CharClassify *charClassTable);
31 	~RESearch();
32 	bool GrabMatches(CharacterIndexer &ci);
33 	const char *Compile(const char *pat, int length, bool caseSensitive, bool posix);
34 	int Execute(CharacterIndexer &ci, int lp, int endp);
35 	int Substitute(CharacterIndexer &ci, char *src, char *dst);
36 
37 	enum {MAXTAG=10};
38 	enum {MAXNFA=2048};
39 	enum {NOTFOUND=-1};
40 
41 	int bopat[MAXTAG];
42 	int eopat[MAXTAG];
43 	char *pat[MAXTAG];
44 
45 private:
46 	void Init();
47 	void Clear();
48 	void ChSet(char c);
49 	void ChSetWithCase(char c, bool caseSensitive);
50 
51 	int PMatch(CharacterIndexer &ci, int lp, int endp, char *ap);
52 
53 	int bol;
54 	int  tagstk[MAXTAG]; /* subpat tag stack */
55 	char nfa[MAXNFA];    /* automaton */
56 	int sta;
57 	char bittab[BITBLK]; /* bit table for CCL pre-set bits */
58 	int failure;
59 	CharClassify *charClass;
iswordc(unsigned char x)60 	bool iswordc(unsigned char x) {
61 		return charClass->IsWord(x);
62 	}
63 };
64 
65 #endif
66