/* {{{ _php_mb_compile_regex */
static void *_php_mb_compile_regex(const char *pattern)
{
- pcre *retval;
- const char *err_str;
- int err_offset;
+ pcre2_code *retval;
+ PCRE2_SIZE err_offset;
+ int errnum;
- if (!(retval = pcre_compile(pattern,
- PCRE_CASELESS, &err_str, &err_offset, NULL))) {
- php_error_docref(NULL, E_WARNING, "%s (offset=%d): %s", pattern, err_offset, err_str);
+ if (!(retval = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
+ PCRE2_CASELESS, &errnum, &err_offset, php_pcre_cctx()))) {
+ PCRE2_UCHAR err_str[256];
+ pcre2_get_error_message(errnum, err_str, sizeof(err_str));
+ php_error_docref(NULL, E_WARNING, "%s (offset=%zu): %s", pattern, err_offset, err_str);
}
return retval;
}
/* {{{ _php_mb_match_regex */
static int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
{
- return pcre_exec((pcre *)opaque, NULL, str, (int)str_len, 0,
- 0, NULL, 0) >= 0;
+ int res;
+
+ pcre2_match_data *match_data = php_pcre_create_match_data(0, opaque);
+ if (NULL == match_data) {
+ pcre2_code_free(opaque);
+ php_error_docref(NULL, E_WARNING, "Cannot allocate match data");
+ return FAILURE;
+ }
+ res = pcre2_match(opaque, (PCRE2_SPTR)str, str_len, 0, 0, match_data, php_pcre_mctx());
+ php_pcre_free_match_data(match_data);
+
+ return res;
}
/* }}} */
/* {{{ _php_mb_free_regex */
static void _php_mb_free_regex(void *opaque)
{
- pcre_free(opaque);
+ pcre2_code_free(opaque);
}
/* }}} */
#endif