diff options
author | Moriyoshi Koizumi <moriyoshi@php.net> | 2002-10-07 17:59:49 +0000 |
---|---|---|
committer | Moriyoshi Koizumi <moriyoshi@php.net> | 2002-10-07 17:59:49 +0000 |
commit | 2e1d931c66e7f518f8d2360b0d57b90e353f2763 (patch) | |
tree | 8ff11b23db39179a03487f75c2b11da08c83bb7c /ext/mbstring/php_mbregex.c | |
parent | 7076a9b9f3dcf5220faa8ff8c918de49bddb6b50 (diff) | |
download | php-git-2e1d931c66e7f518f8d2360b0d57b90e353f2763.tar.gz |
Lots of clean-up for upcoming mbstring merging event.
Added mb_regex_set_options().
The Options parameters of various mbregex functions are now deprecated.
@- Added mb_regex_set_options(). The Options parameters of
@ various mbregex functions are now deprecated. (Moriyoshi).
Diffstat (limited to 'ext/mbstring/php_mbregex.c')
-rw-r--r-- | ext/mbstring/php_mbregex.c | 370 |
1 files changed, 189 insertions, 181 deletions
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index 57d39c8db5..34e5980f5c 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -25,6 +25,7 @@ #include "php.h" #include "php_ini.h" +#include "php_mbregex.h" #include "mbregex.h" #include "mbstring.h" @@ -43,7 +44,7 @@ struct strbuf { }; static void -php_mbregex_strbuf_init(struct strbuf *pd) +_php_mb_regex_strbuf_init(struct strbuf *pd) { if (pd) { pd->buffer = (char*)0; @@ -54,7 +55,7 @@ php_mbregex_strbuf_init(struct strbuf *pd) } static int -php_mbregex_strbuf_ncat(struct strbuf *pd, const unsigned char *psrc, int len) +_php_mb_regex_strbuf_ncat(struct strbuf *pd, const unsigned char *psrc, int len) { if (pd == NULL || psrc == NULL) { return -1; @@ -83,8 +84,7 @@ php_mbregex_strbuf_ncat(struct strbuf *pd, const unsigned char *psrc, int len) /* * encoding name resolver */ -int -php_mbregex_name2mbctype(const char *pname) +static int _php_mb_regex_name2mbctype(const char *pname) { int mbctype; @@ -170,43 +170,43 @@ php_mbregex_compile_pattern(mb_regex_t *pre, const char *pattern, int patlen, in } static void -php_mbregex_init_option(const char *parg, int narg, int *option, int *eval) +_php_mb_regex_init_options(const char *parg, int narg, int *option, int *eval) { int n; char c; + int optm = 0; - if (parg) { + if (parg != NULL) { n = 0; while(n < narg) { c = parg[n++]; - if (option) { - switch (c) { + switch (c) { case 'i': - *option |= MBRE_OPTION_IGNORECASE; + optm |= MBRE_OPTION_IGNORECASE; break; case 'x': - *option |= MBRE_OPTION_EXTENDED; + optm |= MBRE_OPTION_EXTENDED; break; case 'm': - *option |= MBRE_OPTION_MULTILINE; + optm |= MBRE_OPTION_MULTILINE; break; case 's': - *option |= MBRE_OPTION_SINGLELINE; + optm |= MBRE_OPTION_SINGLELINE; break; case 'p': - *option |= MBRE_OPTION_POSIXLINE; + optm |= MBRE_OPTION_POSIXLINE; break; case 'l': - *option |= MBRE_OPTION_LONGEST; + optm |= MBRE_OPTION_LONGEST; + break; + case 'e': + if (eval != NULL) *eval = 1; break; default: break; - } - } - if (eval && (c == 'e')) { - *eval = 1; } } + if (option != NULL) *option|=optm; } } @@ -232,7 +232,7 @@ PHP_FUNCTION(mb_regex_encoding) } else if (ZEND_NUM_ARGS() == 1 && zend_get_parameters_ex(1, &arg1) != FAILURE) { convert_to_string_ex(arg1); - mbctype = php_mbregex_name2mbctype(Z_STRVAL_PP(arg1)); + mbctype = _php_mb_regex_name2mbctype(Z_STRVAL_PP(arg1)); if (mbctype < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown encoding \"%s\"", Z_STRVAL_PP(arg1)); RETVAL_FALSE; @@ -247,88 +247,72 @@ PHP_FUNCTION(mb_regex_encoding) /* }}} */ -/* regex match */ +/* {{{ _php_mb_regex_ereg_exec */ static void -php_mbereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase) +_php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase) { - zval **arg_pattern, **arg_string, **array = NULL; + zval *arg_pattern, *array; + char *string; + int string_len; mb_regex_t re; struct mbre_registers regs = {0, 0, 0, 0}; - int i, err, match_len, string_len, option, beg, end; + int i, err, match_len, option, beg, end; char *str; - switch(ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &arg_pattern, &arg_string) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - - case 3: - if (zend_get_parameters_ex(3, &arg_pattern, &arg_string, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; + array = NULL; - default: - WRONG_PARAM_COUNT; - break; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|z", &arg_pattern, &string, &string_len, &array) == FAILURE) { + RETURN_FALSE; } - option = 0; + option = MBSTRG(regex_default_options); if (icase) { option |= MBRE_OPTION_IGNORECASE; } /* compile the regular expression from the supplied regex */ - if (Z_TYPE_PP(arg_pattern) == IS_STRING) { - option |= MBRE_OPTION_EXTENDED; - } else { + if (Z_TYPE_P(arg_pattern) != IS_STRING) { /* we convert numbers to integers and treat them as a string */ - if (Z_TYPE_PP(arg_pattern) == IS_DOUBLE) { - convert_to_long_ex(arg_pattern); /* get rid of decimal places */ + if (Z_TYPE_P(arg_pattern) == IS_DOUBLE) { + convert_to_long_ex(&arg_pattern); /* get rid of decimal places */ } - convert_to_string_ex(arg_pattern); + convert_to_string_ex(&arg_pattern); /* don't bother doing an extended regex with just a number */ } err = php_mbregex_compile_pattern( &re, - Z_STRVAL_PP(arg_pattern), - Z_STRLEN_PP(arg_pattern), + Z_STRVAL_P(arg_pattern), + Z_STRLEN_P(arg_pattern), option, MBSTRG(current_mbctype) TSRMLS_CC); if (err) { RETURN_FALSE; } /* actually execute the regular expression */ - convert_to_string_ex(arg_string); err = mbre_search( &re, - Z_STRVAL_PP(arg_string), - Z_STRLEN_PP(arg_string), - 0, Z_STRLEN_PP(arg_string), + string, + string_len, + 0, string_len, ®s); if (err < 0) { mbre_free_registers(®s); RETURN_FALSE; } - if (regs.beg[0] == regs.end[0]) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty regular expression"); - } + match_len = 1; - str = Z_STRVAL_PP(arg_string); + str = string; if (array) { match_len = regs.end[0] - regs.beg[0]; - string_len = Z_STRLEN_PP(arg_string); - zval_dtor(*array); /* start with clean array */ - array_init(*array); + zval_dtor(array); /* start with clean array */ + array_init(array); for (i = 0; i < regs.num_regs; i++) { beg = regs.beg[i]; end = regs.end[i]; if (beg >= 0 && beg < end && end <= string_len) { - add_index_stringl(*array, i, &str[beg], end - beg, 1); + add_index_stringl(array, i, &str[beg], end - beg, 1); } else { - add_index_bool(*array, i, 0); + add_index_bool(array, i, 0); } } } @@ -344,7 +328,7 @@ php_mbereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase) Regular expression match for multibyte string */ PHP_FUNCTION(mb_ereg) { - php_mbereg_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ @@ -352,69 +336,79 @@ PHP_FUNCTION(mb_ereg) Case-insensitive regular expression match for multibyte string */ PHP_FUNCTION(mb_eregi) { - php_mbereg_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ -/* regex replacement */ +/* {{{ _php_mb_regex_ereg_replace_exec */ static void -php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int option) +_php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int option) { - zval **arg_pattern, **arg_replace, **arg_string, **arg_option; - char *p, *string, *replace; + zval *arg_pattern_zval; + + char *arg_pattern; + int arg_pattern_len; + + char *replace; + int replace_len; + + char *string; + int string_len; + + char *p; mb_regex_t re; struct mbre_registers regs = {0, 0, 0, 0}; struct strbuf outdev, evaldev, *pdevice; - int i, n, err, pos, replace_len, string_len, eval; + int i, n, err, pos, eval; char *description = NULL; - zval retval; + char pat_buf[2]; eval = 0; - switch(ZEND_NUM_ARGS()) { - case 3: - if (zend_get_parameters_ex(3, &arg_pattern, &arg_replace, &arg_string) == FAILURE) { - WRONG_PARAM_COUNT; + { + char *option_str = NULL; + int option_str_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zss|s", + &arg_pattern_zval, + &replace, &replace_len, + &string, &string_len, + &option_str, &option_str_len) == FAILURE) { + RETURN_FALSE; } - break; - case 4: - if (zend_get_parameters_ex(4, &arg_pattern, &arg_replace, &arg_string, &arg_option) == FAILURE) { - WRONG_PARAM_COUNT; + if (option_str != NULL) { + _php_mb_regex_init_options(option_str, option_str_len, &option, &eval); + } else { + option |= MBSTRG(regex_default_options); } - convert_to_string_ex(arg_option); - option = 0; - php_mbregex_init_option(Z_STRVAL_PP(arg_option), Z_STRLEN_PP(arg_option), &option, &eval); - break; - - default: - WRONG_PARAM_COUNT; - break; } + if (Z_TYPE_P(arg_pattern_zval) == IS_STRING) { + arg_pattern = Z_STRVAL_P(arg_pattern_zval); + arg_pattern_len = Z_STRLEN_P(arg_pattern_zval); + } else { + /* FIXME: this code is not multibyte aware! */ + convert_to_long_ex(&arg_pattern_zval); + pat_buf[0] = (char)Z_LVAL_P(arg_pattern_zval); + pat_buf[1] = '\0'; - convert_to_string_ex(arg_pattern); + arg_pattern = pat_buf; + arg_pattern_len = 1; + } /* create regex pattern buffer */ err = php_mbregex_compile_pattern( &re, - Z_STRVAL_PP(arg_pattern), - Z_STRLEN_PP(arg_pattern), + arg_pattern, + arg_pattern_len, option, MBSTRG(current_mbctype) TSRMLS_CC); if (err) { RETURN_FALSE; } - convert_to_string_ex(arg_replace); - replace = Z_STRVAL_PP(arg_replace); - replace_len = Z_STRLEN_PP(arg_replace); - - convert_to_string_ex(arg_string); - string = Z_STRVAL_PP(arg_string); - string_len = Z_STRLEN_PP(arg_string); - /* initialize string buffer (auto reallocate buffer) */ - php_mbregex_strbuf_init(&outdev); - php_mbregex_strbuf_init(&evaldev); + _php_mb_regex_strbuf_init(&outdev); + _php_mb_regex_strbuf_init(&evaldev); outdev.allocsz = (string_len >> 2) + 8; if (eval) { @@ -440,8 +434,9 @@ php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int option) break; } /* copy the part of the string before the match */ - php_mbregex_strbuf_ncat(&outdev, &string[pos], regs.beg[0] - pos); + _php_mb_regex_strbuf_ncat(&outdev, &string[pos], regs.beg[0] - pos); /* copy replacement and backrefs */ + /* FIXME: this code (\\digit replacement) is not mbyte aware! */ i = 0; p = replace; while (i < replace_len) { @@ -451,27 +446,28 @@ php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int option) } if (n >= 0 && n < regs.num_regs) { if (regs.beg[n] >= 0 && regs.beg[n] < regs.end[n] && regs.end[n] <= string_len) { - php_mbregex_strbuf_ncat(pdevice, &string[regs.beg[n]], regs.end[n] - regs.beg[n]); + _php_mb_regex_strbuf_ncat(pdevice, &string[regs.beg[n]], regs.end[n] - regs.beg[n]); } p += 2; i += 2; } else { - php_mbregex_strbuf_ncat(pdevice, p, 1); + _php_mb_regex_strbuf_ncat(pdevice, p, 1); p++; i++; } } if (eval) { + zval v; /* null terminate buffer */ - php_mbregex_strbuf_ncat(&evaldev, "\0", 1); + _php_mb_regex_strbuf_ncat(&evaldev, "\0", 1); /* do eval */ - zend_eval_string(evaldev.buffer, &retval, description TSRMLS_CC); + zend_eval_string(evaldev.buffer, &v, description TSRMLS_CC); /* result of eval */ - convert_to_string(&retval); - php_mbregex_strbuf_ncat(&outdev, retval.value.str.val, retval.value.str.len); + convert_to_string(&v); + _php_mb_regex_strbuf_ncat(&outdev, Z_STRVAL(v), Z_STRLEN(v)); /* Clean up */ evaldev.pos = 0; - zval_dtor(&retval); + zval_dtor(&v); } n = regs.end[0]; if (pos < n) { @@ -481,7 +477,7 @@ php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int option) } } else { /* nomatch */ /* stick that last bit of string on our output */ - php_mbregex_strbuf_ncat(&outdev, &string[pos], string_len - pos); + _php_mb_regex_strbuf_ncat(&outdev, &string[pos], string_len - pos); } } @@ -493,7 +489,7 @@ php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int option) efree((void*)evaldev.buffer); } n = outdev.pos; - php_mbregex_strbuf_ncat(&outdev, "\0", 1); + _php_mb_regex_strbuf_ncat(&outdev, "\0", 1); if (err <= -2) { if (outdev.buffer) { efree((void*)outdev.buffer); @@ -503,12 +499,12 @@ php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int option) RETVAL_STRINGL(outdev.buffer, n, 0); } } - +/* }}} */ /* {{{ proto string mb_ereg_replace(string pattern, string replacement, string string [, string option]) Replace regular expression for multibyte string */ PHP_FUNCTION(mb_ereg_replace) { - php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, MBRE_OPTION_EXTENDED); + _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ @@ -516,7 +512,7 @@ PHP_FUNCTION(mb_ereg_replace) Case insensitive replace regular expression for multibyte string */ PHP_FUNCTION(mb_eregi_replace) { - php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, MBRE_OPTION_EXTENDED | MBRE_OPTION_IGNORECASE); + _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, MBRE_OPTION_IGNORECASE); } /* }}} */ @@ -525,54 +521,35 @@ PHP_FUNCTION(mb_eregi_replace) split multibyte string into array by regular expression */ PHP_FUNCTION(mb_split) { - zval **arg_pat, **arg_str, **arg_count = NULL; + zval *arg_pat; mb_regex_t re; struct mbre_registers regs = {0, 0, 0, 0}; char *string; int n, err, count, string_len, pos; count = -1; - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &arg_pat, &arg_str) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 3: - if (zend_get_parameters_ex(3, &arg_pat, &arg_str, &arg_count) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg_count); - count = Z_LVAL_PP(arg_count); - break; - - default: - WRONG_PARAM_COUNT; - break; - } + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs|l", &arg_pat, + &string, &string_len, &count) == FAILURE) { + RETURN_FALSE; + } - if (count == 0) count = 1; + if (count == 0) count = 1; if (array_init(return_value) == FAILURE) { RETURN_FALSE; } - convert_to_string_ex(arg_pat); - convert_to_string_ex(arg_str); - /* create regex pattern buffer */ err = php_mbregex_compile_pattern( &re, - Z_STRVAL_PP(arg_pat), - Z_STRLEN_PP(arg_pat), - MBRE_OPTION_EXTENDED, MBSTRG(current_mbctype) TSRMLS_CC); + Z_STRVAL_P(arg_pat), + Z_STRLEN_P(arg_pat), + MBSTRG(regex_default_options), MBSTRG(current_mbctype) TSRMLS_CC); if (err) { RETURN_FALSE; } - string = Z_STRVAL_PP(arg_str); - string_len = Z_STRLEN_PP(arg_str); pos = 0; err = 0; /* churn through str, generating array entries as we go */ @@ -583,11 +560,10 @@ PHP_FUNCTION(mb_split) break; } - n = regs.beg[0]; + /* add it to the array */ - if (n < string_len && n >= pos) { - n -= pos; - add_next_index_stringl(return_value, &string[pos], n, 1); + if ( regs.beg[0] < string_len && regs.beg[0] >= pos) { + add_next_index_stringl(return_value, &string[pos], regs.beg[0]-pos, 1); } else { err = -2; break; @@ -596,8 +572,6 @@ PHP_FUNCTION(mb_split) n = regs.end[0]; if (pos < n) { pos = n; - } else { - pos++; } if (count < 0) { count = 0; @@ -628,44 +602,45 @@ PHP_FUNCTION(mb_split) Regular expression match for multibyte string */ PHP_FUNCTION(mb_ereg_match) { - zval **arg_pattern, **arg_str, **arg_option; + zval *arg_pattern; + + char *string; + int string_len; + mb_regex_t re; int option, err; - option = MBRE_OPTION_EXTENDED; - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &arg_pattern, &arg_str) == FAILURE) { - WRONG_PARAM_COUNT; + option = 0; + { + char *option_str = NULL; + int option_str_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|s", + &arg_pattern, &string, &string_len, + &option_str, &option_str_len)==FAILURE) { + RETURN_FALSE; } - break; - case 3: - if (zend_get_parameters_ex(3, &arg_pattern, &arg_str, &arg_option) == FAILURE) { - WRONG_PARAM_COUNT; + + if (option_str != NULL) { + _php_mb_regex_init_options(option_str, option_str_len, &option, NULL); + } else { + option |= MBSTRG(regex_default_options); } - convert_to_string_ex(arg_option); - option = 0; - php_mbregex_init_option(Z_STRVAL_PP(arg_option), Z_STRLEN_PP(arg_option), &option, NULL); - break; - default: - WRONG_PARAM_COUNT; - break; } + convert_to_string_ex(&arg_pattern); - /* create regex pattern buffer */ - convert_to_string_ex(arg_pattern); err = php_mbregex_compile_pattern( &re, - Z_STRVAL_PP(arg_pattern), - Z_STRLEN_PP(arg_pattern), + Z_STRVAL_P(arg_pattern), + Z_STRLEN_P(arg_pattern), option, MBSTRG(current_mbctype) TSRMLS_CC); + if (err) { RETURN_FALSE; } /* match */ - convert_to_string_ex(arg_str); - err = mbre_match(&re, Z_STRVAL_PP(arg_str), Z_STRLEN_PP(arg_str), 0, NULL); + err = mbre_match(&re, string, string_len, 0, NULL); if (err >= 0) { RETVAL_TRUE; } else { @@ -677,13 +652,13 @@ PHP_FUNCTION(mb_ereg_match) /* regex search */ static void -php_mbereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode) +_php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode) { - zval **arg_pattern, **arg_option; + zval **arg_pattern, **arg_options; int n, i, err, pos, len, beg, end, option; unsigned char *str; - option = MBRE_OPTION_EXTENDED; + option = MBSTRG(regex_default_options); switch (ZEND_NUM_ARGS()) { case 0: break; @@ -693,12 +668,12 @@ php_mbereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode) } break; case 2: - if (zend_get_parameters_ex(2, &arg_pattern, &arg_option) == FAILURE) { + if (zend_get_parameters_ex(2, &arg_pattern, &arg_options) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string_ex(arg_option); + convert_to_string_ex(arg_options); option = 0; - php_mbregex_init_option(Z_STRVAL_PP(arg_option), Z_STRLEN_PP(arg_option), &option, NULL); + _php_mb_regex_init_options(Z_STRVAL_PP(arg_options), Z_STRLEN_PP(arg_options), &option, NULL); break; default: WRONG_PARAM_COUNT; @@ -808,7 +783,7 @@ php_mbereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode) Regular expression search for multibyte string */ PHP_FUNCTION(mb_ereg_search) { - php_mbereg_search_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ @@ -817,7 +792,7 @@ PHP_FUNCTION(mb_ereg_search) Regular expression search for multibyte string */ PHP_FUNCTION(mb_ereg_search_pos) { - php_mbereg_search_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ @@ -826,7 +801,7 @@ PHP_FUNCTION(mb_ereg_search_pos) Regular expression search for multibyte string */ PHP_FUNCTION(mb_ereg_search_regs) { - php_mbereg_search_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); + _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); } /* }}} */ @@ -835,10 +810,10 @@ PHP_FUNCTION(mb_ereg_search_regs) Initialize string and regular expression for search. */ PHP_FUNCTION(mb_ereg_search_init) { - zval **arg_str, **arg_pattern, **arg_option; + zval **arg_str, **arg_pattern, **arg_options; int err, option; - option = MBRE_OPTION_EXTENDED; + option = MBSTRG(regex_default_options); switch (ZEND_NUM_ARGS()) { case 1: if (zend_get_parameters_ex(1, &arg_str) == FAILURE) { @@ -851,12 +826,12 @@ PHP_FUNCTION(mb_ereg_search_init) } break; case 3: - if (zend_get_parameters_ex(3, &arg_str, &arg_pattern, &arg_option) == FAILURE) { + if (zend_get_parameters_ex(3, &arg_str, &arg_pattern, &arg_options) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string_ex(arg_option); + convert_to_string_ex(arg_options); option = 0; - php_mbregex_init_option(Z_STRVAL_PP(arg_option), Z_STRLEN_PP(arg_option), &option, NULL); + _php_mb_regex_init_options(Z_STRVAL_PP(arg_options), Z_STRLEN_PP(arg_options), &option, NULL); break; default: WRONG_PARAM_COUNT; @@ -981,4 +956,37 @@ PHP_FUNCTION(mb_ereg_search_setpos) } /* }}} */ +/* {{{ php_mb_regex_set_options */ +PHPAPI int php_mb_regex_set_options( int options ) +{ + int prev_opt = MBSTRG(regex_default_options); + MBSTRG(regex_default_options) = options; + return prev_opt; +} +/* }}} */ + +/* {{{ php_mb_regex_set_options_by_string */ +PHPAPI int php_mb_regex_set_options_by_string( const char *opt_str, int len ) +{ + int new_opt; + _php_mb_regex_init_options( opt_str, len, &new_opt, NULL); + return php_mb_regex_set_options( new_opt ); +} +/* }}} */ + +/* {{{ proto bool mb_regex_set_options([string encoding]) + Set the default options for mbregex functions */ +PHP_FUNCTION(mb_regex_set_options) +{ + char *string; + int string_len; + if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", + &string, &string_len ) == FAILURE ) { + RETURN_FALSE; + } + php_mb_regex_set_options_by_string( (const char*)string, string_len ); + RETURN_TRUE; +} +/* }}} */ + #endif /* HAVE_MBREGEX */ |