Date: 06/04/99
- Next message: andrey: "[PHP-DEV] CVS update: php3"
- Previous message: Andrey Zmievski: "Re: [PHP-DEV] more chars for quotemeta()"
- Next in thread: andrey: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Friday June 4, 1999 @ 10:03
Author: andrey
Update of /repository/php3/functions
In directory php:/tmp/cvs-serv27534
Modified Files:
pcre.c php3_pcre.h
Log Message:
Added preg_quote() function.
Index: php3/functions/pcre.c
diff -u php3/functions/pcre.c:1.7 php3/functions/pcre.c:1.8
--- php3/functions/pcre.c:1.7 Thu Jun 3 10:15:28 1999
+++ php3/functions/pcre.c Fri Jun 4 10:03:33 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pcre.c,v 1.7 1999/06/03 14:15:28 sas Exp $ */
+/* $Id: pcre.c,v 1.8 1999/06/04 14:03:33 andrey Exp $ */
#include "php.h"
@@ -47,6 +47,7 @@
PHP_FE(preg_match_all, third_arg_force_ref)
PHP_FE(preg_replace, NULL)
PHP_FE(preg_split, NULL)
+ PHP_FE(preg_quote, NULL)
{NULL, NULL, NULL}
};
@@ -253,7 +254,7 @@
array for global match */
*result_set, /* Holds a set of subpatterns after
a global match */
- **match_sets = NULL; /* An array of sets of matches for each
+ **match_sets = NULL; /* An array of sets of matches for each
subpattern after a global match */
pcre *re = NULL; /* Compiled regular expression */
pcre_extra *extra = NULL; /* Holds results of studying */
@@ -652,6 +653,7 @@
}
else {
/* Make sure we're dealing with strings and do the replacement */
+ convert_to_string(regex);
convert_to_string(replace);
result = _php_pcre_replace(regex->value.str.val,
subject->value.str.val,
@@ -793,6 +795,70 @@
/* Clean up */
efree(offsets);
+}
+/* }}} */
+
+
+/* {{{ proto string preg_quote(string str) */
+PHP_FUNCTION(preg_quote)
+{
+ pval *in_str_arg; /* Input string argument */
+ char *in_str, /* Input string */
+ *out_str, /* Output string with quoted characters */
+ *p, /* Iterator for input string */
+ *q, /* Iterator for output string */
+ c; /* Current character */
+
+ /* Get the arguments and check for errors */
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &in_str_arg) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ /* Make sure we're working with strings */
+ convert_to_string(in_str_arg);
+ in_str = in_str_arg->value.str.val;
+
+ /* Nothing to do if we got an empty string */
+ if (!*in_str) {
+ RETVAL_STRING(empty_string, 0);
+ }
+
+ /* Allocate enough memory so that even if each character
+ is quoted, we won't run out of room */
+ out_str = emalloc(2 * in_str_arg->value.str.len + 1);
+
+ /* Go through the string and quote necessary characters */
+ for(p = in_str, q = out_str; (c = *p); p++) {
+ switch(c) {
+ case '.':
+ case '\\':
+ case '+':
+ case '*':
+ case '?':
+ case '[':
+ case '^':
+ case ']':
+ case '$':
+ case '(':
+ case ')':
+ case '{':
+ case '}':
+ case '=':
+ case '!':
+ case '>':
+ case '<':
+ case '|':
+ case ':':
+ *q++ = '\\';
+ /* break is missing _intentionally_ */
+ default:
+ *q++ = c;
+ }
+ }
+ *q = '\0';
+
+ /* Reallocate string and return it */
+ RETVAL_STRING(erealloc(out_str, q - out_str + 1), 0);
}
/* }}} */
Index: php3/functions/php3_pcre.h
diff -u php3/functions/php3_pcre.h:1.3 php3/functions/php3_pcre.h:1.4
--- php3/functions/php3_pcre.h:1.3 Fri May 28 17:12:43 1999
+++ php3/functions/php3_pcre.h Fri Jun 4 10:03:33 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php3_pcre.h,v 1.3 1999/05/28 21:12:43 andrey Exp $ */
+/* $Id: php3_pcre.h,v 1.4 1999/06/04 14:03:33 andrey Exp $ */
#ifndef _PHP_PCRE_H
#define _PHP_PCRE_H
@@ -48,6 +48,7 @@
PHP_FUNCTION(preg_match_all);
PHP_FUNCTION(preg_replace);
PHP_FUNCTION(preg_split);
+PHP_FUNCTION(preg_quote);
extern php3_module_entry pcre_module_entry;
#define pcre_module_ptr &pcre_module_entry
-- PHP Development Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: andrey: "[PHP-DEV] CVS update: php3"
- Previous message: Andrey Zmievski: "Re: [PHP-DEV] more chars for quotemeta()"
- Next in thread: andrey: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

