diff options
| author | Ben Fuhrmannek | 2022-02-05 12:22:13 +0100 |
|---|---|---|
| committer | Ben Fuhrmannek | 2022-02-05 12:22:13 +0100 |
| commit | 323f818a6ce33d021bc0a6d34064598917e68c91 (patch) | |
| tree | 474200051e6e908489ea8d23a58fc60464ea9492 /src/sp_pcre_compat.h | |
| parent | dece0e45b7f66cc51bcbe590240eab3f82da900c (diff) | |
introduced sp_regexp / store original regex
Diffstat (limited to '')
| -rw-r--r-- | src/sp_pcre_compat.h | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/sp_pcre_compat.h b/src/sp_pcre_compat.h index 725004d..6e9d91a 100644 --- a/src/sp_pcre_compat.h +++ b/src/sp_pcre_compat.h | |||
| @@ -17,12 +17,36 @@ | |||
| 17 | #endif | 17 | #endif |
| 18 | 18 | ||
| 19 | sp_pcre* sp_pcre_compile(const char* str); | 19 | sp_pcre* sp_pcre_compile(const char* str); |
| 20 | void sp_pcre_free(sp_pcre* regexp); | 20 | static inline void sp_pcre_free(sp_pcre* regexp) { |
| 21 | #define sp_is_regexp_matching_zend(regexp, zstr) \ | 21 | #ifdef SP_HAS_PCRE2 |
| 22 | sp_is_regexp_matching_len(regexp, ZSTR_VAL(zstr), ZSTR_LEN(zstr)) | 22 | pcre2_code_free(regexp); |
| 23 | #define sp_is_regexp_matching(regexp, str) \ | 23 | #endif |
| 24 | sp_is_regexp_matching_len(regexp, str, strlen(str)) | 24 | } |
| 25 | bool sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, | 25 | bool sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, size_t len); |
| 26 | size_t len); | 26 | |
| 27 | |||
| 28 | typedef struct { | ||
| 29 | sp_pcre *re; | ||
| 30 | zend_string *pattern; | ||
| 31 | } sp_regexp; | ||
| 32 | |||
| 33 | #define sp_is_regexp_matching_zstr(regexp, zstr) sp_is_regexp_matching_len(regexp->re, ZSTR_VAL(zstr), ZSTR_LEN(zstr)) | ||
| 34 | #define sp_is_regexp_matching(regexp, str) sp_is_regexp_matching_len(regexp->re, str, strlen(str)) | ||
| 35 | static inline sp_regexp* sp_regexp_compile(zend_string *zstr) { | ||
| 36 | sp_pcre *re = sp_pcre_compile(ZSTR_VAL(zstr)); | ||
| 37 | if (!re) { return NULL; } | ||
| 38 | sp_regexp *ret = pecalloc(sizeof(sp_regexp), 1, 1); | ||
| 39 | ret->re = re; | ||
| 40 | ret->pattern = zstr; | ||
| 41 | return ret; | ||
| 42 | } | ||
| 43 | static inline void sp_regexp_free(sp_regexp *regexp) { | ||
| 44 | if (regexp) { | ||
| 45 | if (regexp->re) { sp_pcre_free(regexp->re); } | ||
| 46 | if (regexp->pattern) { zend_string_release(regexp->pattern); } | ||
| 47 | pefree(regexp, 1); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 27 | 51 | ||
| 28 | #endif // SP_PCRE_COMPAT_H | 52 | #endif // SP_PCRE_COMPAT_H |
