moriyoshi Sun Oct 20 11:11:05 2002 EDT Modified files: /php4/ext/mbstring php_mbregex.c Log: Changed mb_regex_set_options() more informative Index: php4/ext/mbstring/php_mbregex.c diff -u php4/ext/mbstring/php_mbregex.c:1.15 php4/ext/mbstring/php_mbregex.c:1.16 --- php4/ext/mbstring/php_mbregex.c:1.15 Thu Oct 10 13:00:36 2002 +++ php4/ext/mbstring/php_mbregex.c Sun Oct 20 11:11:04 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_mbregex.c,v 1.15 2002/10/10 17:00:36 moriyoshi Exp $ */ +/* $Id: php_mbregex.c,v 1.16 2002/10/20 15:11:04 moriyoshi Exp $ */ #ifdef HAVE_CONFIG_H @@ -169,6 +169,73 @@ return res; } +static size_t +_php_mb_regex_get_option_string(char *str, size_t len, int option) +{ + size_t len_left = len; + size_t len_req = 0; + char *p = str; + + + if ((option & MBRE_OPTION_IGNORECASE) != 0) { + if (len_left > 0) { + --len_left; + *(p++) = 'i'; + } + ++len_req; + } + + if ((option & MBRE_OPTION_EXTENDED) != 0) { + if (len_left > 0) { + --len_left; + *(p++) = 'x'; + } + ++len_req; + } + + if ((option & MBRE_OPTION_POSIXLINE) == MBRE_OPTION_POSIXLINE) { + if (len_left > 0) { + --len_left; + *(p++) = 'p'; + } + ++len_req; + } else { + if ((option & MBRE_OPTION_MULTILINE) != 0) { + if (len_left > 0) { + --len_left; + *(p++) = 'm'; + } + ++len_req; + } + + if ((option & MBRE_OPTION_SINGLELINE) != 0) { + if (len_left > 0) { + --len_left; + *(p++) = 's'; + } + ++len_req; + } + } + if ((option & MBRE_OPTION_LONGEST) != 0) { + if (len_left > 0) { + --len_left; + *(p++) = 'l'; + } + ++len_req; + } + if (len_left > 0) { + --len_left; + *(p++) = '\0'; + } + + ++len_req; + if (len < len_req) { + return len_req; + } + + return 0; +} + static void _php_mb_regex_init_options(const char *parg, int narg, int *option, int *eval) { @@ -974,18 +1041,28 @@ } /* }}} */ -/* {{{ proto bool mb_regex_set_options([string options]) - Set the default options for mbregex functions */ +/* {{{ proto string mb_regex_set_options([string options]) + Set or get the default options for mbregex functions */ PHP_FUNCTION(mb_regex_set_options) { - char *string; + int opt; + char *string = NULL; int string_len; - if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", + char buf[16]; + + 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 TSRMLS_CC); - RETURN_TRUE; + if (string != NULL) { + opt = php_mb_regex_set_options_by_string( (const char*)string, + string_len TSRMLS_CC ); + } else { + opt = MBSTRG(regex_default_options); + } + _php_mb_regex_get_option_string(buf, sizeof(buf), opt); + + RETVAL_STRING(buf, 1); } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php