cvs: php4 /ext/pcre/ php_pcre.c

From: Date: Thu, 25 May 2000 21:04:10 +0000
Subject: cvs: php4 /ext/pcre/ php_pcre.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-15765@lists.php.net to get a copy of this message
andrei Thu May 25 14:04:10 2000 EDT Modified files: /php4/ext/pcre php_pcre.c Log: @- Added second argument to preg_quote() which allows quoting of @ one additional character, usually the regex delimiter. (Andrei) Index: php4/ext/pcre/php_pcre.c diff -u php4/ext/pcre/php_pcre.c:1.53 php4/ext/pcre/php_pcre.c:1.54 --- php4/ext/pcre/php_pcre.c:1.53 Tue May 23 02:33:44 2000 +++ php4/ext/pcre/php_pcre.c Thu May 25 14:04:09 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_pcre.c,v 1.53 2000/05/23 09:33:44 sas Exp $ */ +/* $Id: php_pcre.c,v 1.54 2000/05/25 21:04:09 andrei Exp $ */ /* TODO: @@ -1036,15 +1036,19 @@ PHP_FUNCTION(preg_quote) { zval **in_str_arg; /* Input string argument */ + zval **delim; /* Additional delimiter argument */ char *in_str, /* Input string */ *in_str_end, /* End of the input string */ *out_str, /* Output string with quoted characters */ *p, /* Iterator for input string */ *q, /* Iterator for output string */ + delim_char, /* Delimiter character to be quoted */ c; /* Current character */ + zend_bool quote_delim = 0; /* Whether to quote additional delim char */ /* Get the arguments and check for errors */ - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &in_str_arg) == FAILURE) { + if (ARG_COUNT(ht) < 1 || ARG_COUNT(ht) > 2 || + zend_get_parameters_ex(ARG_COUNT(ht), &in_str_arg, &delim) == FAILURE) { WRONG_PARAM_COUNT; } @@ -1057,6 +1061,14 @@ if (in_str == in_str_end) { RETVAL_STRINGL(empty_string, 0, 0); } + + if (ARG_COUNT(ht) == 2) { + convert_to_string_ex(delim); + if (Z_STRLEN_PP(delim) > 0) { + delim_char = Z_STRVAL_PP(delim)[0]; + quote_delim = 1; + } + } /* Allocate enough memory so that even if each character is quoted, we won't run out of room */ @@ -1086,9 +1098,14 @@ case '|': case ':': *q++ = '\\'; - /* break is missing _intentionally_ */ + *q++ = c; + break; + default: + if (c == delim_char && quote_delim) + *q++ = '\\'; *q++ = c; + break; } } *q = '\0';

« previous php.version4 (#15765) next »