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 #ifdef SCI_NAMESPACE
13 namespace Scintilla {
14 #endif
15 
16 /*
17  * The following defines are not meant to be changeable.
18  * They are for readability only.
19  */
20 #define MAXCHR	256
21 #define CHRBIT	8
22 #define BITBLK	MAXCHR/CHRBIT
23 
24 class CharacterIndexer {
25 public:
26 	virtual char CharAt(int index)=0;
~CharacterIndexer()27 	virtual ~CharacterIndexer() {
28 	}
29 };
30 
31 class RESearch {
32 
33 public:
34 	explicit RESearch(CharClassify *charClassTable);
35 	~RESearch();
36 	void GrabMatches(CharacterIndexer &ci);
37 	const char *Compile(const char *pattern, int length, bool caseSensitive, bool posix);
38 	int Execute(CharacterIndexer &ci, int lp, int endp);
39 
40 	enum { MAXTAG=10 };
41 	enum { MAXNFA=2048 };
42 	enum { NOTFOUND=-1 };
43 
44 	int bopat[MAXTAG];
45 	int eopat[MAXTAG];
46 	std::string pat[MAXTAG];
47 
48 private:
49 	void Clear();
50 	void ChSet(unsigned char c);
51 	void ChSetWithCase(unsigned char c, bool caseSensitive);
52 	int GetBackslashExpression(const char *pattern, int &incr);
53 
54 	int PMatch(CharacterIndexer &ci, int lp, int endp, char *ap);
55 
56 	int bol;
57 	int tagstk[MAXTAG];  /* subpat tag stack */
58 	char nfa[MAXNFA];    /* automaton */
59 	int sta;
60 	unsigned char bittab[BITBLK]; /* bit table for CCL pre-set bits */
61 	int failure;
62 	CharClassify *charClass;
iswordc(unsigned char x)63 	bool iswordc(unsigned char x) const {
64 		return charClass->IsWord(x);
65 	}
66 };
67 
68 #ifdef SCI_NAMESPACE
69 }
70 #endif
71 
72 #endif
73 
74