| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef REGENGINE_H |
| 22 |
#define REGENGINE_H |
| 23 |
|
| 24 |
#include "config.h" |
| 25 |
|
| 26 |
#include <stdlib.h> |
| 27 |
#include <sys/types.h> |
| 28 |
#include <regex.h> |
| 29 |
#ifdef HAVE_LIBPCRE |
| 30 |
#define PCRE2_CODE_UNIT_WIDTH 8 |
| 31 |
#include <pcre2.h> |
| 32 |
#endif |
| 33 |
#include <vector> |
| 34 |
#include <string> |
| 35 |
#include <memory> |
| 36 |
|
| 37 |
|
| 38 |
struct match; |
| 39 |
|
| 40 |
class Regengine |
| 41 |
{ |
| 42 |
public: |
| 43 |
|
| 44 |
virtual bool exec(const std::string &str, size_t offset, struct match &m) const = 0; |
| 45 |
virtual ~Regengine() {} |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
class PatternList : public Regengine |
| 54 |
{ |
| 55 |
public: |
| 56 |
PatternList() {} |
| 57 |
~PatternList() {} |
| 58 |
bool exec(const std::string &str, size_t offset, struct match &m) const override; |
| 59 |
void add_pattern(std::unique_ptr<Regengine> pattern); |
| 60 |
private: |
| 61 |
std::vector<std::unique_ptr<Regengine>> patterns; |
| 62 |
}; |
| 63 |
|
| 64 |
class PosixRegex : public Regengine |
| 65 |
{ |
| 66 |
public: |
| 67 |
PosixRegex(const std::string &pattern, bool case_insensitive); |
| 68 |
~PosixRegex(); |
| 69 |
bool exec(const std::string &str, size_t offset, struct match &m) const override; |
| 70 |
private: |
| 71 |
regex_t regex; |
| 72 |
}; |
| 73 |
|
| 74 |
#ifdef HAVE_LIBPCRE |
| 75 |
class PCRERegex : public Regengine |
| 76 |
{ |
| 77 |
public: |
| 78 |
PCRERegex(const std::string &pattern, bool case_insensitive); |
| 79 |
~PCRERegex(); |
| 80 |
bool exec(const std::string &str, size_t offset, struct match &m) const override; |
| 81 |
private: |
| 82 |
pcre2_code *regex; |
| 83 |
}; |
| 84 |
#endif |
| 85 |
|
| 86 |
class FixedString : public Regengine |
| 87 |
{ |
| 88 |
public: |
| 89 |
FixedString(const std::string &pattern, bool case_insensitive); |
| 90 |
bool exec(const std::string &str, size_t offset, struct match &m) const override; |
| 91 |
private: |
| 92 |
std::vector<std::string> patterns; |
| 93 |
bool case_insensitive; |
| 94 |
}; |
| 95 |
|
| 96 |
#endif |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|