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