@@ -465,6 +465,7 @@ static php_mb_regex_t *php_mbregex_compile_pattern(const char *pattern, size_t p
465
465
OnigEncoding enc = MBREX (current_mbctype );
466
466
467
467
if (!php_mb_check_encoding (pattern , patlen , php_mb_regex_get_mbctype_encoding ())) {
468
+ // TODO convert to ValueError after adding pattern_arg_num pass through argument
468
469
php_error_docref (NULL , E_WARNING ,
469
470
"Pattern is not valid under %s encoding" , _php_mb_regex_mbctype2name (enc ));
470
471
return NULL ;
@@ -474,6 +475,7 @@ static php_mb_regex_t *php_mbregex_compile_pattern(const char *pattern, size_t p
474
475
if (!rc || onig_get_options (rc ) != options || onig_get_encoding (rc ) != enc || onig_get_syntax (rc ) != syntax ) {
475
476
if ((err_code = onig_new (& retval , (OnigUChar * )pattern , (OnigUChar * )(pattern + patlen ), options , enc , syntax , & err_info )) != ONIG_NORMAL ) {
476
477
onig_error_code_to_str (err_str , err_code , & err_info );
478
+ // Convert to error?
477
479
php_error_docref (NULL , E_WARNING , "mbregex compile err: %s" , err_str );
478
480
return NULL ;
479
481
}
@@ -897,15 +899,21 @@ static int _php_mb_onig_search(regex_t* reg, const OnigUChar* str, const OnigUCh
897
899
static void _php_mb_regex_ereg_exec (INTERNAL_FUNCTION_PARAMETERS , int icase )
898
900
{
899
901
zval * array = NULL ;
900
- char * arg_pattern , * string ;
901
- size_t arg_pattern_len , string_len ;
902
+ char * string ;
903
+ size_t string_len ;
904
+ zend_string * pattern ;
902
905
php_mb_regex_t * re ;
903
906
OnigRegion * regs = NULL ;
904
907
int i , match_len , beg , end ;
905
908
OnigOptionType options ;
906
909
char * str ;
907
910
908
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "ss|z" , & arg_pattern , & arg_pattern_len , & string , & string_len , & array ) == FAILURE ) {
911
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Ss|z" , & pattern , & string , & string_len , & array ) == FAILURE ) {
912
+ RETURN_THROWS ();
913
+ }
914
+
915
+ if (ZSTR_LEN (pattern ) == 0 ) {
916
+ zend_argument_value_error (1 , "must not be empty" );
909
917
RETURN_THROWS ();
910
918
}
911
919
@@ -929,13 +937,7 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
929
937
options |= ONIG_OPTION_IGNORECASE ;
930
938
}
931
939
932
- if (arg_pattern_len == 0 ) {
933
- php_error_docref (NULL , E_WARNING , "Empty pattern" );
934
- RETVAL_FALSE ;
935
- goto out ;
936
- }
937
-
938
- re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , options , MBREX (regex_default_syntax ));
940
+ re = php_mbregex_compile_pattern (ZSTR_VAL (pattern ), ZSTR_LEN (pattern ), options , MBREX (regex_default_syntax ));
939
941
if (re == NULL ) {
940
942
RETVAL_FALSE ;
941
943
goto out ;
@@ -1025,15 +1027,9 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1025
1027
1026
1028
const mbfl_encoding * enc ;
1027
1029
1028
- {
1029
- const char * current_enc_name ;
1030
- current_enc_name = php_mb_regex_get_mbctype ();
1031
- if (current_enc_name == NULL ||
1032
- (enc = mbfl_name2encoding (current_enc_name )) == NULL ) {
1033
- php_error_docref (NULL , E_WARNING , "Unknown error" );
1034
- RETURN_FALSE ;
1035
- }
1036
- }
1030
+ enc = mbfl_name2encoding (php_mb_regex_get_mbctype ());
1031
+ ZEND_ASSERT (enc != NULL );
1032
+
1037
1033
eval = 0 ;
1038
1034
{
1039
1035
char * option_str = NULL ;
@@ -1073,8 +1069,12 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1073
1069
}
1074
1070
}
1075
1071
if (eval && !is_callable ) {
1076
- php_error_docref (NULL , E_WARNING , "The 'e' option is no longer supported, use mb_ereg_replace_callback instead" );
1077
- RETURN_FALSE ;
1072
+ zend_argument_value_error (4 , "option 'e' is not supported, use mb_ereg_replace_callback() instead" );
1073
+ RETURN_THROWS ();
1074
+ }
1075
+ if (eval && is_callable ) {
1076
+ zend_argument_value_error (4 , "option 'e' cannot be used with replacement callback" );
1077
+ RETURN_THROWS ();
1078
1078
}
1079
1079
1080
1080
/* create regex pattern buffer */
@@ -1091,13 +1091,6 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1091
1091
description = NULL ;
1092
1092
}
1093
1093
1094
- if (is_callable ) {
1095
- if (eval ) {
1096
- php_error_docref (NULL , E_WARNING , "Option 'e' cannot be used with replacement callback" );
1097
- RETURN_FALSE ;
1098
- }
1099
- }
1100
-
1101
1094
/* do the actual work */
1102
1095
err = 0 ;
1103
1096
pos = (OnigUChar * )string ;
@@ -1176,6 +1169,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1176
1169
zval_ptr_dtor (& retval );
1177
1170
} else {
1178
1171
if (!EG (exception )) {
1172
+ // TODO Is this a return throw?
1179
1173
php_error_docref (NULL , E_WARNING , "Unable to call custom replacement function" );
1180
1174
}
1181
1175
}
@@ -1435,11 +1429,13 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
1435
1429
}
1436
1430
1437
1431
if (MBREX (search_re ) == NULL ) {
1432
+ // TODO which Error/Exception to use, as this seems to be a logical error in function call ordering
1438
1433
php_error_docref (NULL , E_WARNING , "No regex given" );
1439
1434
RETURN_FALSE ;
1440
1435
}
1441
1436
1442
1437
if (str == NULL ) {
1438
+ // TODO which Error/Exception to use, as this seems to be a logical error in function call ordering
1443
1439
php_error_docref (NULL , E_WARNING , "No string given" );
1444
1440
RETURN_FALSE ;
1445
1441
}
@@ -1534,19 +1530,19 @@ PHP_FUNCTION(mb_ereg_search_regs)
1534
1530
PHP_FUNCTION (mb_ereg_search_init )
1535
1531
{
1536
1532
int argc = ZEND_NUM_ARGS ();
1537
- zend_string * arg_str ;
1538
- char * arg_pattern = NULL , * arg_options = NULL ;
1539
- size_t arg_pattern_len = 0 , arg_options_len = 0 ;
1533
+ zend_string * arg_str , * pattern = NULL ;
1534
+ char * arg_options = NULL ;
1535
+ size_t arg_options_len = 0 ;
1540
1536
OnigSyntaxType * syntax = NULL ;
1541
1537
OnigOptionType option ;
1542
1538
1543
- if (zend_parse_parameters (argc , "S|ss " , & arg_str , & arg_pattern , & arg_pattern_len , & arg_options , & arg_options_len ) == FAILURE ) {
1539
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "S|Ss " , & arg_str , & pattern , & arg_options , & arg_options_len ) == FAILURE ) {
1544
1540
RETURN_THROWS ();
1545
1541
}
1546
1542
1547
- if (argc > 1 && arg_pattern_len == 0 ) {
1548
- php_error_docref ( NULL , E_WARNING , "Empty pattern " );
1549
- RETURN_FALSE ;
1543
+ if (argc > 1 && ZSTR_LEN ( pattern ) == 0 ) {
1544
+ zend_argument_value_error ( 2 , "must not be empty " );
1545
+ RETURN_THROWS () ;
1550
1546
}
1551
1547
1552
1548
option = MBREX (regex_default_options );
@@ -1559,7 +1555,7 @@ PHP_FUNCTION(mb_ereg_search_init)
1559
1555
1560
1556
if (argc > 1 ) {
1561
1557
/* create regex pattern buffer */
1562
- if ((MBREX (search_re ) = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , option , syntax )) == NULL ) {
1558
+ if ((MBREX (search_re ) = php_mbregex_compile_pattern (ZSTR_VAL ( pattern ), ZSTR_LEN ( pattern ) , option , syntax )) == NULL ) {
1563
1559
RETURN_FALSE ;
1564
1560
}
1565
1561
}
@@ -1660,12 +1656,12 @@ PHP_FUNCTION(mb_ereg_search_setpos)
1660
1656
}
1661
1657
1662
1658
if (position < 0 || (!Z_ISUNDEF (MBREX (search_str )) && Z_TYPE (MBREX (search_str )) == IS_STRING && (size_t )position > Z_STRLEN (MBREX (search_str )))) {
1663
- php_error_docref (NULL , E_WARNING , "Position is out of range" );
1664
- MBREX (search_pos ) = 0 ;
1665
- RETURN_FALSE ;
1659
+ zend_argument_value_error (1 , "is out of range" );
1660
+ RETURN_THROWS ();
1666
1661
}
1667
1662
1668
1663
MBREX (search_pos ) = position ;
1664
+ // TODO Return void
1669
1665
RETURN_TRUE ;
1670
1666
}
1671
1667
/* }}} */
0 commit comments