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