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