@@ -487,29 +487,33 @@ _php_mb_regex_init_options(const char *parg, int narg, OnigOptionType *option, O
487
487
Returns the current encoding for regex as a string. */
488
488
PHP_FUNCTION (mb_regex_encoding )
489
489
{
490
- zval * * arg1 ;
490
+ size_t argc = ZEND_NUM_ARGS ();
491
+ char * encoding ;
492
+ long encoding_len ;
491
493
OnigEncoding mbctype ;
492
494
493
- if (ZEND_NUM_ARGS () == 0 ) {
495
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "|s" , & encoding , & encoding_len ) == FAILURE ) {
496
+ return ;
497
+ }
498
+
499
+ if (argc == 0 ) {
494
500
const char * retval = php_mb_regex_mbctype2name (MBSTRG (current_mbctype ));
495
- if ( retval != NULL ) {
496
- RETVAL_STRING ((char * )retval , 1 );
497
- } else {
498
- RETVAL_FALSE ;
501
+
502
+ if (retval == NULL ) {
503
+ RETURN_FALSE ;
499
504
}
500
- } else if (ZEND_NUM_ARGS () == 1 &&
501
- zend_get_parameters_ex (1 , & arg1 ) != FAILURE ) {
502
- convert_to_string_ex (arg1 );
503
- mbctype = php_mb_regex_name2mbctype (Z_STRVAL_PP (arg1 ));
505
+
506
+ RETURN_STRING ((char * )retval , 1 );
507
+ } else if (argc == 1 ) {
508
+ mbctype = php_mb_regex_name2mbctype (encoding );
509
+
504
510
if (mbctype == ONIG_ENCODING_UNDEF ) {
505
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unknown encoding \"%s\"" , Z_STRVAL_PP (arg1 ));
506
- RETVAL_FALSE ;
507
- } else {
508
- MBSTRG (current_mbctype ) = mbctype ;
509
- RETVAL_TRUE ;
511
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unknown encoding \"%s\"" , encoding );
512
+ RETURN_FALSE ;
510
513
}
511
- } else {
512
- WRONG_PARAM_COUNT ;
514
+
515
+ MBSTRG (current_mbctype ) = mbctype ;
516
+ RETURN_TRUE ;
513
517
}
514
518
}
515
519
/* }}} */
@@ -940,37 +944,27 @@ PHP_FUNCTION(mb_ereg_match)
940
944
static void
941
945
_php_mb_regex_ereg_search_exec (INTERNAL_FUNCTION_PARAMETERS , int mode )
942
946
{
943
- zval * * arg_pattern , * * arg_options ;
947
+ size_t argc = ZEND_NUM_ARGS ();
948
+ char * arg_pattern , * arg_options ;
949
+ long arg_pattern_len , arg_options_len ;
944
950
int n , i , err , pos , len , beg , end , option ;
945
951
OnigUChar * str ;
946
952
OnigSyntaxType * syntax ;
947
953
954
+ if (zend_parse_parameters (argc TSRMLS_CC , "|ss" , & arg_pattern , & arg_pattern_len , & arg_options , & arg_options_len ) == FAILURE ) {
955
+ return ;
956
+ }
957
+
948
958
option = MBSTRG (regex_default_options );
949
- switch (ZEND_NUM_ARGS ()) {
950
- case 0 :
951
- break ;
952
- case 1 :
953
- if (zend_get_parameters_ex (1 , & arg_pattern ) == FAILURE ) {
954
- WRONG_PARAM_COUNT ;
955
- }
956
- break ;
957
- case 2 :
958
- if (zend_get_parameters_ex (2 , & arg_pattern , & arg_options ) == FAILURE ) {
959
- WRONG_PARAM_COUNT ;
960
- }
961
- convert_to_string_ex (arg_options );
959
+
960
+ if (argc == 2 ) {
962
961
option = 0 ;
963
- _php_mb_regex_init_options (Z_STRVAL_PP (arg_options ), Z_STRLEN_PP (arg_options ), & option , & syntax , NULL );
964
- break ;
965
- default :
966
- WRONG_PARAM_COUNT ;
967
- break ;
962
+ _php_mb_regex_init_options (arg_options , arg_options_len , & option , & syntax , NULL );
968
963
}
969
- if (ZEND_NUM_ARGS () > 0 ) {
970
- /* create regex pattern buffer */
971
- convert_to_string_ex (arg_pattern );
972
964
973
- if ((MBSTRG (search_re ) = php_mbregex_compile_pattern (Z_STRVAL_PP (arg_pattern ), Z_STRLEN_PP (arg_pattern ), option , MBSTRG (current_mbctype ), MBSTRG (regex_default_syntax ) TSRMLS_CC )) == NULL ) {
965
+ if (argc > 0 ) {
966
+ /* create regex pattern buffer */
967
+ if ((MBSTRG (search_re ) = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , option , MBSTRG (current_mbctype ), MBSTRG (regex_default_syntax ) TSRMLS_CC )) == NULL ) {
974
968
RETURN_FALSE ;
975
969
}
976
970
}
@@ -1079,41 +1073,28 @@ PHP_FUNCTION(mb_ereg_search_regs)
1079
1073
Initialize string and regular expression for search. */
1080
1074
PHP_FUNCTION (mb_ereg_search_init )
1081
1075
{
1082
- zval * * arg_str , * * arg_pattern , * * arg_options ;
1076
+ size_t argc = ZEND_NUM_ARGS ();
1077
+ zval * arg_str ;
1078
+ char * arg_pattern , * arg_options ;
1079
+ long arg_pattern_len , arg_options_len ;
1083
1080
OnigSyntaxType * syntax = NULL ;
1084
1081
int option ;
1085
1082
1083
+ if (zend_parse_parameters (argc TSRMLS_CC , "z|ss" , & arg_str , & arg_pattern , & arg_pattern_len , & arg_options , & arg_options_len ) == FAILURE ) {
1084
+ return ;
1085
+ }
1086
+
1086
1087
option = MBSTRG (regex_default_options );
1087
1088
syntax = MBSTRG (regex_default_syntax );
1088
- switch (ZEND_NUM_ARGS ()) {
1089
- case 1 :
1090
- if (zend_get_parameters_ex (1 , & arg_str ) == FAILURE ) {
1091
- WRONG_PARAM_COUNT ;
1092
- }
1093
- break ;
1094
- case 2 :
1095
- if (zend_get_parameters_ex (2 , & arg_str , & arg_pattern ) == FAILURE ) {
1096
- WRONG_PARAM_COUNT ;
1097
- }
1098
- break ;
1099
- case 3 :
1100
- if (zend_get_parameters_ex (3 , & arg_str , & arg_pattern , & arg_options ) == FAILURE ) {
1101
- WRONG_PARAM_COUNT ;
1102
- }
1103
- convert_to_string_ex (arg_options );
1089
+
1090
+ if (argc == 3 ) {
1104
1091
option = 0 ;
1105
- _php_mb_regex_init_options (Z_STRVAL_PP (arg_options ), Z_STRLEN_PP (arg_options ), & option , & syntax , NULL );
1106
- break ;
1107
- default :
1108
- WRONG_PARAM_COUNT ;
1109
- break ;
1110
- }
1111
- convert_to_string_ex (arg_str );
1112
- if (ZEND_NUM_ARGS () > 1 ) {
1113
- /* create regex pattern buffer */
1114
- convert_to_string_ex (arg_pattern );
1092
+ _php_mb_regex_init_options (arg_options , arg_options_len , & option , & syntax , NULL );
1093
+ }
1115
1094
1116
- if ((MBSTRG (search_re ) = php_mbregex_compile_pattern (Z_STRVAL_PP (arg_pattern ), Z_STRLEN_PP (arg_pattern ), option , MBSTRG (current_mbctype ), syntax TSRMLS_CC )) == NULL ) {
1095
+ if (argc > 1 ) {
1096
+ /* create regex pattern buffer */
1097
+ if ((MBSTRG (search_re ) = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , option , MBSTRG (current_mbctype ), syntax TSRMLS_CC )) == NULL ) {
1117
1098
RETURN_FALSE ;
1118
1099
}
1119
1100
}
@@ -1123,7 +1104,7 @@ PHP_FUNCTION(mb_ereg_search_init)
1123
1104
MBSTRG (search_str ) = (zval * )NULL ;
1124
1105
}
1125
1106
1126
- MBSTRG (search_str ) = * arg_str ;
1107
+ MBSTRG (search_str ) = arg_str ;
1127
1108
Z_ADDREF_P (MBSTRG (search_str ));
1128
1109
SEPARATE_ZVAL_IF_NOT_REF (& MBSTRG (search_str ));
1129
1110
@@ -1178,22 +1159,21 @@ PHP_FUNCTION(mb_ereg_search_getpos)
1178
1159
Set search start position */
1179
1160
PHP_FUNCTION (mb_ereg_search_setpos )
1180
1161
{
1181
- zval * * arg_pos ;
1162
+ long position ;
1182
1163
int n ;
1183
1164
1184
- if (ZEND_NUM_ARGS () != 1 || zend_get_parameters_ex ( 1 , & arg_pos ) == FAILURE ) {
1185
- WRONG_PARAM_COUNT ;
1165
+ if (zend_parse_parameters ( ZEND_NUM_ARGS () TSRMLS_CC , "l" , & position ) == FAILURE ) {
1166
+ return ;
1186
1167
}
1187
- convert_to_long_ex (arg_pos );
1188
- n = Z_LVAL_PP (arg_pos );
1189
- if (n < 0 || (MBSTRG (search_str ) != NULL && Z_TYPE_P (MBSTRG (search_str )) == IS_STRING && n >= Z_STRLEN_P (MBSTRG (search_str )))) {
1168
+
1169
+ if (position < 0 || (MBSTRG (search_str ) != NULL && Z_TYPE_P (MBSTRG (search_str )) == IS_STRING && position >= Z_STRLEN_P (MBSTRG (search_str )))) {
1190
1170
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Position is out of range" );
1191
1171
MBSTRG (search_pos ) = 0 ;
1192
- RETVAL_FALSE ;
1193
- } else {
1194
- MBSTRG (search_pos ) = n ;
1195
- RETVAL_TRUE ;
1172
+ RETURN_FALSE ;
1196
1173
}
1174
+
1175
+ MBSTRG (search_pos ) = position ;
1176
+ RETURN_TRUE ;
1197
1177
}
1198
1178
/* }}} */
1199
1179
0 commit comments