summaryrefslogtreecommitdiff
path: root/ext/mbstring/php_mbregex.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mbstring/php_mbregex.c')
-rw-r--r--ext/mbstring/php_mbregex.c75
1 files changed, 37 insertions, 38 deletions
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c
index baf0a2d44a..8be88c3fee 100644
--- a/ext/mbstring/php_mbregex.c
+++ b/ext/mbstring/php_mbregex.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
@@ -28,7 +28,7 @@
#if HAVE_MBREGEX
-#include "ext/standard/php_smart_str.h"
+#include "zend_smart_str.h"
#include "ext/standard/info.h"
#include "php_mbregex.h"
#include "mbstring.h"
@@ -655,7 +655,7 @@ PHP_FUNCTION(mb_regex_encoding)
{
size_t argc = ZEND_NUM_ARGS();
char *encoding;
- int encoding_len;
+ size_t encoding_len;
OnigEncoding mbctype;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &encoding, &encoding_len) == FAILURE) {
@@ -689,7 +689,7 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
{
zval *arg_pattern, *array;
char *string;
- int string_len;
+ size_t string_len;
php_mb_regex_t *re;
OnigRegion *regs = NULL;
int i, match_len, beg, end;
@@ -711,19 +711,19 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
if (Z_TYPE_P(arg_pattern) != IS_STRING) {
/* we convert numbers to integers and treat them as a string */
if (Z_TYPE_P(arg_pattern) == IS_DOUBLE) {
- convert_to_int_ex(arg_pattern); /* get rid of decimal places */
+ convert_to_long_ex(arg_pattern); /* get rid of decimal places */
}
convert_to_string_ex(arg_pattern);
/* don't bother doing an extended regex with just a number */
}
- if (!Z_STRVAL_P(arg_pattern) || Z_STRSIZE_P(arg_pattern) == 0) {
+ if (Z_STRLEN_P(arg_pattern) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "empty pattern");
RETVAL_FALSE;
goto out;
}
- re = php_mbregex_compile_pattern(Z_STRVAL_P(arg_pattern), Z_STRSIZE_P(arg_pattern), options, MBREX(current_mbctype), MBREX(regex_default_syntax) TSRMLS_CC);
+ re = php_mbregex_compile_pattern(Z_STRVAL_P(arg_pattern), Z_STRLEN_P(arg_pattern), options, MBREX(current_mbctype), MBREX(regex_default_syntax) TSRMLS_CC);
if (re == NULL) {
RETVAL_FALSE;
goto out;
@@ -758,7 +758,7 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
if (match_len == 0) {
match_len = 1;
}
- RETVAL_INT(match_len);
+ RETVAL_LONG(match_len);
out:
if (regs != NULL) {
onig_region_free(regs, 1);
@@ -788,16 +788,16 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
zval *arg_pattern_zval;
char *arg_pattern;
- int arg_pattern_len;
+ size_t arg_pattern_len;
char *replace;
- int replace_len;
+ size_t replace_len;
zend_fcall_info arg_replace_fci;
zend_fcall_info_cache arg_replace_fci_cache;
char *string;
- int string_len;
+ size_t string_len;
char *p;
php_mb_regex_t *re;
@@ -826,7 +826,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
eval = 0;
{
char *option_str = NULL;
- int option_str_len = 0;
+ size_t option_str_len = 0;
if (!is_callable) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zss|s",
@@ -855,11 +855,11 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
}
if (Z_TYPE_P(arg_pattern_zval) == IS_STRING) {
arg_pattern = Z_STRVAL_P(arg_pattern_zval);
- arg_pattern_len = Z_STRSIZE_P(arg_pattern_zval);
+ arg_pattern_len = Z_STRLEN_P(arg_pattern_zval);
} else {
/* FIXME: this code is not multibyte aware! */
- convert_to_int_ex(arg_pattern_zval);
- pat_buf[0] = (char)Z_IVAL_P(arg_pattern_zval);
+ convert_to_long_ex(arg_pattern_zval);
+ pat_buf[0] = (char)Z_LVAL_P(arg_pattern_zval);
pat_buf[1] = '\0';
arg_pattern = pat_buf;
@@ -947,7 +947,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
/* result of eval */
convert_to_string(&v);
- smart_str_appendl(&out_buf, Z_STRVAL(v), Z_STRSIZE(v));
+ smart_str_appendl(&out_buf, Z_STRVAL(v), Z_STRLEN(v));
/* Clean up */
eval_buf.s->len = 0;
zval_dtor(&v);
@@ -971,7 +971,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
if (zend_call_function(&arg_replace_fci, &arg_replace_fci_cache TSRMLS_CC) == SUCCESS &&
!Z_ISUNDEF(retval)) {
convert_to_string_ex(&retval);
- smart_str_appendl(&out_buf, Z_STRVAL(retval), Z_STRSIZE(retval));
+ smart_str_appendl(&out_buf, Z_STRVAL(retval), Z_STRLEN(retval));
if (eval_buf.s) {
eval_buf.s->len = 0;
}
@@ -1052,17 +1052,17 @@ PHP_FUNCTION(mb_ereg_replace_callback)
PHP_FUNCTION(mb_split)
{
char *arg_pattern;
- int arg_pattern_len;
+ size_t arg_pattern_len;
php_mb_regex_t *re;
OnigRegion *regs = NULL;
char *string;
OnigUChar *pos, *chunk_pos;
- int string_len;
+ size_t string_len;
int n, err;
- php_int_t count = -1;
+ zend_long count = -1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|i", &arg_pattern, &arg_pattern_len, &string, &string_len, &count) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &arg_pattern, &arg_pattern_len, &string, &string_len, &count) == FAILURE) {
RETURN_FALSE;
}
@@ -1081,7 +1081,7 @@ PHP_FUNCTION(mb_split)
err = 0;
regs = onig_region_new();
/* churn through str, generating array entries as we go */
- while (count != 0 && (pos - (OnigUChar *)string) < string_len) {
+ while (count != 0 && (pos - (OnigUChar *)string) < (ptrdiff_t)string_len) {
int beg, end;
err = onig_search(re, (OnigUChar *)string, (OnigUChar *)(string + string_len), pos, (OnigUChar *)(string + string_len), regs, 0);
if (err < 0) {
@@ -1131,10 +1131,10 @@ PHP_FUNCTION(mb_split)
PHP_FUNCTION(mb_ereg_match)
{
char *arg_pattern;
- int arg_pattern_len;
+ size_t arg_pattern_len;
char *string;
- int string_len;
+ size_t string_len;
php_mb_regex_t *re;
OnigSyntaxType *syntax;
@@ -1143,7 +1143,7 @@ PHP_FUNCTION(mb_ereg_match)
{
char *option_str = NULL;
- int option_str_len = 0;
+ size_t option_str_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s",
&arg_pattern, &arg_pattern_len, &string, &string_len,
@@ -1180,7 +1180,7 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
{
size_t argc = ZEND_NUM_ARGS();
char *arg_pattern, *arg_options;
- int arg_pattern_len, arg_options_len;
+ size_t arg_pattern_len, arg_options_len;
int n, i, err, pos, len, beg, end;
OnigOptionType option;
OnigUChar *str;
@@ -1209,7 +1209,7 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
len = 0;
if (!Z_ISUNDEF(MBREX(search_str)) && Z_TYPE(MBREX(search_str)) == IS_STRING){
str = (OnigUChar *)Z_STRVAL(MBREX(search_str));
- len = Z_STRSIZE(MBREX(search_str));
+ len = Z_STRLEN(MBREX(search_str));
}
if (MBREX(search_re) == NULL) {
@@ -1245,8 +1245,8 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
array_init(return_value);
beg = MBREX(search_regs)->beg[0];
end = MBREX(search_regs)->end[0];
- add_next_index_int(return_value, beg);
- add_next_index_int(return_value, end - beg);
+ add_next_index_long(return_value, beg);
+ add_next_index_long(return_value, end - beg);
break;
case 2:
array_init(return_value);
@@ -1311,7 +1311,7 @@ PHP_FUNCTION(mb_ereg_search_init)
size_t argc = ZEND_NUM_ARGS();
zval *arg_str;
char *arg_pattern = NULL, *arg_options = NULL;
- int arg_pattern_len = 0, arg_options_len = 0;
+ size_t arg_pattern_len = 0, arg_options_len = 0;
OnigSyntaxType *syntax = NULL;
OnigOptionType option;
@@ -1343,8 +1343,7 @@ PHP_FUNCTION(mb_ereg_search_init)
zval_ptr_dtor(&MBREX(search_str));
}
- ZVAL_COPY(&MBREX(search_str), arg_str);
- SEPARATE_ZVAL_IF_NOT_REF(&MBREX(search_str));
+ ZVAL_DUP(&MBREX(search_str), arg_str);
MBREX(search_pos) = 0;
@@ -1368,7 +1367,7 @@ PHP_FUNCTION(mb_ereg_search_getregs)
array_init(return_value);
str = (OnigUChar *)Z_STRVAL(MBREX(search_str));
- len = Z_STRSIZE(MBREX(search_str));
+ len = Z_STRLEN(MBREX(search_str));
n = MBREX(search_regs)->num_regs;
for (i = 0; i < n; i++) {
beg = MBREX(search_regs)->beg[i];
@@ -1389,7 +1388,7 @@ PHP_FUNCTION(mb_ereg_search_getregs)
Get search start position */
PHP_FUNCTION(mb_ereg_search_getpos)
{
- RETVAL_INT(MBREX(search_pos));
+ RETVAL_LONG(MBREX(search_pos));
}
/* }}} */
@@ -1397,13 +1396,13 @@ PHP_FUNCTION(mb_ereg_search_getpos)
Set search start position */
PHP_FUNCTION(mb_ereg_search_setpos)
{
- php_int_t position;
+ zend_long position;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i", &position) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &position) == FAILURE) {
return;
}
- if (position < 0 || (!Z_ISUNDEF(MBREX(search_str)) && Z_TYPE(MBREX(search_str)) == IS_STRING && position >= Z_STRSIZE(MBREX(search_str)))) {
+ if (position < 0 || (!Z_ISUNDEF(MBREX(search_str)) && Z_TYPE(MBREX(search_str)) == IS_STRING && (size_t)position >= Z_STRLEN(MBREX(search_str)))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Position is out of range");
MBREX(search_pos) = 0;
RETURN_FALSE;
@@ -1435,7 +1434,7 @@ PHP_FUNCTION(mb_regex_set_options)
OnigOptionType opt;
OnigSyntaxType *syntax;
char *string = NULL;
- int string_len;
+ size_t string_len;
char buf[16];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s",