diff options
author | Moriyoshi Koizumi <moriyoshi@php.net> | 2002-10-20 15:11:04 +0000 |
---|---|---|
committer | Moriyoshi Koizumi <moriyoshi@php.net> | 2002-10-20 15:11:04 +0000 |
commit | 852117694a4b749bed90bee27080caa65d65acfc (patch) | |
tree | 9b3b9c8ec93aacbd27a41b7b8a002ed395c6f035 /ext/mbstring/php_mbregex.c | |
parent | 8d9963b0d880467e0ff841f25cac402221199f1a (diff) | |
download | php-git-852117694a4b749bed90bee27080caa65d65acfc.tar.gz |
Changed mb_regex_set_options() more informative
Diffstat (limited to 'ext/mbstring/php_mbregex.c')
-rw-r--r-- | ext/mbstring/php_mbregex.c | 89 |
1 files changed, 83 insertions, 6 deletions
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index 8485824592..46aafd0c41 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -169,6 +169,73 @@ php_mbregex_compile_pattern(mb_regex_t *pre, const char *pattern, int patlen, in 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 @@ PHPAPI int php_mb_regex_set_options_by_string( const char *opt_str, int len TSRM } /* }}} */ -/* {{{ 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); } /* }}} */ |