version 1.1.1.1, 2012/02/21 23:47:57
|
version 1.1.1.2, 2012/05/29 12:34:40
|
Line 372 static OnigEncoding _php_mb_regex_name2mbctype(const c
|
Line 372 static OnigEncoding _php_mb_regex_name2mbctype(const c
|
const char *p; |
const char *p; |
php_mb_regex_enc_name_map_t *mapping; |
php_mb_regex_enc_name_map_t *mapping; |
|
|
if (pname == NULL) { | if (pname == NULL || !*pname) { |
return ONIG_ENCODING_UNDEF; |
return ONIG_ENCODING_UNDEF; |
} |
} |
|
|
Line 784 PHP_FUNCTION(mb_eregi)
|
Line 784 PHP_FUNCTION(mb_eregi)
|
/* }}} */ |
/* }}} */ |
|
|
/* {{{ _php_mb_regex_ereg_replace_exec */ |
/* {{{ _php_mb_regex_ereg_replace_exec */ |
static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOptionType options) | static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOptionType options, int is_callable) |
{ |
{ |
zval **arg_pattern_zval; |
zval **arg_pattern_zval; |
|
|
Line 794 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
Line 794 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
char *replace; |
char *replace; |
int replace_len; |
int replace_len; |
|
|
|
zend_fcall_info arg_replace_fci; |
|
zend_fcall_info_cache arg_replace_fci_cache; |
|
|
char *string; |
char *string; |
int string_len; |
int string_len; |
|
|
Line 826 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
Line 829 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
char *option_str = NULL; |
char *option_str = NULL; |
int option_str_len = 0; |
int option_str_len = 0; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zss|s", | if (!is_callable) { |
&arg_pattern_zval, | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zss|s", |
&replace, &replace_len, | &arg_pattern_zval, |
&string, &string_len, | &replace, &replace_len, |
&option_str, &option_str_len) == FAILURE) { | &string, &string_len, |
RETURN_FALSE; | &option_str, &option_str_len) == FAILURE) { |
| RETURN_FALSE; |
| } |
| } else { |
| if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zfs|s", |
| &arg_pattern_zval, |
| &arg_replace_fci, &arg_replace_fci_cache, |
| &string, &string_len, |
| &option_str, &option_str_len) == FAILURE) { |
| RETURN_FALSE; |
| } |
} |
} |
|
|
if (option_str != NULL) { |
if (option_str != NULL) { |
Line 859 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
Line 872 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (eval) { | if (eval || is_callable) { |
pbuf = &eval_buf; |
pbuf = &eval_buf; |
description = zend_make_compiled_string_description("mbregex replace" TSRMLS_CC); |
description = zend_make_compiled_string_description("mbregex replace" TSRMLS_CC); |
} else { |
} else { |
Line 867 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
Line 880 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
description = NULL; |
description = NULL; |
} |
} |
|
|
|
if (is_callable) { |
|
if (eval) { |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option 'e' cannot be used with replacement callback"); |
|
RETURN_FALSE; |
|
} |
|
} |
|
|
/* do the actual work */ |
/* do the actual work */ |
err = 0; |
err = 0; |
pos = (OnigUChar *)string; |
pos = (OnigUChar *)string; |
Line 889 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
Line 909 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
#endif |
#endif |
/* copy the part of the string before the match */ |
/* copy the part of the string before the match */ |
smart_str_appendl(&out_buf, pos, (size_t)((OnigUChar *)(string + regs->beg[0]) - pos)); |
smart_str_appendl(&out_buf, pos, (size_t)((OnigUChar *)(string + regs->beg[0]) - pos)); |
/* copy replacement and backrefs */ | |
i = 0; | if (!is_callable) { |
p = replace; | /* copy replacement and backrefs */ |
while (i < replace_len) { | i = 0; |
int fwd = (int) php_mb_mbchar_bytes_ex(p, enc); | p = replace; |
n = -1; | while (i < replace_len) { |
if ((replace_len - i) >= 2 && fwd == 1 && | int fwd = (int) php_mb_mbchar_bytes_ex(p, enc); |
| n = -1; |
| if ((replace_len - i) >= 2 && fwd == 1 && |
p[0] == '\\' && p[1] >= '0' && p[1] <= '9') { |
p[0] == '\\' && p[1] >= '0' && p[1] <= '9') { |
n = p[1] - '0'; | n = p[1] - '0'; |
} | |
if (n >= 0 && n < regs->num_regs) { | |
if (regs->beg[n] >= 0 && regs->beg[n] < regs->end[n] && regs->end[n] <= string_len) { | |
smart_str_appendl(pbuf, string + regs->beg[n], regs->end[n] - regs->beg[n]); | |
} |
} |
p += 2; | if (n >= 0 && n < regs->num_regs) { |
i += 2; | if (regs->beg[n] >= 0 && regs->beg[n] < regs->end[n] && regs->end[n] <= string_len) { |
} else { | smart_str_appendl(pbuf, string + regs->beg[n], regs->end[n] - regs->beg[n]); |
smart_str_appendl(pbuf, p, fwd); | } |
p += fwd; | p += 2; |
i += fwd; | i += 2; |
| } else { |
| smart_str_appendl(pbuf, p, fwd); |
| p += fwd; |
| i += fwd; |
| } |
} |
} |
} |
} |
|
|
if (eval) { |
if (eval) { |
zval v; |
zval v; |
/* null terminate buffer */ |
/* null terminate buffer */ |
Line 928 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
Line 952 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
/* Clean up */ |
/* Clean up */ |
eval_buf.len = 0; |
eval_buf.len = 0; |
zval_dtor(&v); |
zval_dtor(&v); |
|
} else if (is_callable) { |
|
zval *retval_ptr; |
|
zval **args[1]; |
|
zval *subpats; |
|
int i; |
|
|
|
MAKE_STD_ZVAL(subpats); |
|
array_init(subpats); |
|
|
|
for (i = 0; i < regs->num_regs; i++) { |
|
add_next_index_stringl(subpats, string + regs->beg[i], regs->end[i] - regs->beg[i], 1); |
|
} |
|
|
|
args[0] = &subpats; |
|
/* null terminate buffer */ |
|
smart_str_0(&eval_buf); |
|
|
|
arg_replace_fci.param_count = 1; |
|
arg_replace_fci.params = args; |
|
arg_replace_fci.retval_ptr_ptr = &retval_ptr; |
|
if (zend_call_function(&arg_replace_fci, &arg_replace_fci_cache TSRMLS_CC) == SUCCESS && arg_replace_fci.retval_ptr_ptr) { |
|
convert_to_string_ex(&retval_ptr); |
|
smart_str_appendl(&out_buf, Z_STRVAL_P(retval_ptr), Z_STRLEN_P(retval_ptr)); |
|
eval_buf.len = 0; |
|
zval_ptr_dtor(&retval_ptr); |
|
} else { |
|
efree(description); |
|
if (!EG(exception)) { |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call custom replacement function"); |
|
} |
|
} |
|
zval_ptr_dtor(&subpats); |
} |
} |
|
|
n = regs->end[0]; |
n = regs->end[0]; |
if ((pos - (OnigUChar *)string) < n) { |
if ((pos - (OnigUChar *)string) < n) { |
pos = (OnigUChar *)string + n; |
pos = (OnigUChar *)string + n; |
Line 969 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
Line 1026 static void _php_mb_regex_ereg_replace_exec(INTERNAL_F
|
Replace regular expression for multibyte string */ |
Replace regular expression for multibyte string */ |
PHP_FUNCTION(mb_ereg_replace) |
PHP_FUNCTION(mb_ereg_replace) |
{ |
{ |
_php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); | _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0); |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 977 PHP_FUNCTION(mb_ereg_replace)
|
Line 1034 PHP_FUNCTION(mb_ereg_replace)
|
Case insensitive replace regular expression for multibyte string */ |
Case insensitive replace regular expression for multibyte string */ |
PHP_FUNCTION(mb_eregi_replace) |
PHP_FUNCTION(mb_eregi_replace) |
{ |
{ |
_php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, ONIG_OPTION_IGNORECASE); | _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, ONIG_OPTION_IGNORECASE, 0); |
| } |
| /* }}} */ |
| |
| /* {{{ proto string mb_ereg_replace_callback(string pattern, string callback, string string [, string option]) |
| regular expression for multibyte string using replacement callback */ |
| PHP_FUNCTION(mb_ereg_replace_callback) |
| { |
| _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1); |
} |
} |
/* }}} */ |
/* }}} */ |
|
|