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.c | |
| parent | dece0e45b7f66cc51bcbe590240eab3f82da900c (diff) | |
introduced sp_regexp / store original regex
Diffstat (limited to 'src/sp_pcre_compat.c')
| -rw-r--r-- | src/sp_pcre_compat.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/sp_pcre_compat.c b/src/sp_pcre_compat.c index 375a708..81c51fd 100644 --- a/src/sp_pcre_compat.c +++ b/src/sp_pcre_compat.c | |||
| @@ -1,10 +1,5 @@ | |||
| 1 | #include "php_snuffleupagus.h" | 1 | #include "php_snuffleupagus.h" |
| 2 | 2 | ||
| 3 | inline void sp_pcre_free(sp_pcre* regexp) { | ||
| 4 | #ifdef SP_HAS_PCRE2 | ||
| 5 | pcre2_code_free(regexp); | ||
| 6 | #endif | ||
| 7 | } | ||
| 8 | 3 | ||
| 9 | sp_pcre* sp_pcre_compile(const char* const pattern) { | 4 | sp_pcre* sp_pcre_compile(const char* const pattern) { |
| 10 | assert(NULL != pattern); | 5 | assert(NULL != pattern); |
| @@ -14,8 +9,7 @@ sp_pcre* sp_pcre_compile(const char* const pattern) { | |||
| 14 | unsigned char pcre_error[128] = {0}; | 9 | unsigned char pcre_error[128] = {0}; |
| 15 | int errornumber; | 10 | int errornumber; |
| 16 | PCRE2_SIZE erroroffset; | 11 | PCRE2_SIZE erroroffset; |
| 17 | ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, | 12 | ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errornumber, &erroroffset, NULL); |
| 18 | PCRE2_CASELESS, &errornumber, &erroroffset, NULL); | ||
| 19 | pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error)-1); | 13 | pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error)-1); |
| 20 | #else | 14 | #else |
| 21 | const char* pcre_error = NULL; | 15 | const char* pcre_error = NULL; |
| @@ -29,16 +23,14 @@ sp_pcre* sp_pcre_compile(const char* const pattern) { | |||
| 29 | return ret; | 23 | return ret; |
| 30 | } | 24 | } |
| 31 | 25 | ||
| 32 | bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, | 26 | bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, size_t len) { |
| 33 | size_t len) { | ||
| 34 | int ret = 0; | 27 | int ret = 0; |
| 35 | 28 | ||
| 36 | assert(NULL != regexp); | 29 | assert(NULL != regexp); |
| 37 | assert(NULL != str); | 30 | assert(NULL != str); |
| 38 | 31 | ||
| 39 | #ifdef SP_HAS_PCRE2 | 32 | #ifdef SP_HAS_PCRE2 |
| 40 | pcre2_match_data* match_data = | 33 | pcre2_match_data* match_data = pcre2_match_data_create_from_pattern(regexp, NULL); |
| 41 | pcre2_match_data_create_from_pattern(regexp, NULL); | ||
| 42 | if (NULL == match_data) { | 34 | if (NULL == match_data) { |
| 43 | sp_log_err("regexp", "Unable to get memory for a regxp."); | 35 | sp_log_err("regexp", "Unable to get memory for a regxp."); |
| 44 | } | 36 | } |
