summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAndrei Zmievski <andrei@php.net>2000-05-25 21:04:09 +0000
committerAndrei Zmievski <andrei@php.net>2000-05-25 21:04:09 +0000
commit0a142bb94e0c1ca346d55ce44a0ad58f1d2cbbd5 (patch)
tree6db4954ad74ed8c05cda2b72cb6c2fef51787366 /ext
parent80db5483696427126ee45cfc771eecad43b6427c (diff)
downloadphp-git-0a142bb94e0c1ca346d55ce44a0ad58f1d2cbbd5.tar.gz
@- Added second argument to preg_quote() which allows quoting of
@ one additional character, usually the regex delimiter. (Andrei)
Diffstat (limited to 'ext')
-rw-r--r--ext/pcre/php_pcre.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index d84c5ff744..3467503cff 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -1036,15 +1036,19 @@ PHP_FUNCTION(preg_split)
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 @@ PHP_FUNCTION(preg_quote)
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 @@ PHP_FUNCTION(preg_quote)
case '|':
case ':':
*q++ = '\\';
- /* break is missing _intentionally_ */
+ *q++ = c;
+ break;
+
default:
+ if (c == delim_char && quote_delim)
+ *q++ = '\\';
*q++ = c;
+ break;
}
}
*q = '\0';