CVS update: php4/ext/pcre

From: Date: Fri, 04 Jun 1999 13:56:23 +0000
Subject: CVS update: php4/ext/pcre
Groups: php.version4 
Request: Send a blank email to php-version4+get-1285@lists.php.net to get a copy of this message
Date: Friday June 4, 1999 @ 9:56 Author: andrey Update of /repository/php4/ext/pcre In directory php:/tmp/cvs-serv22547/ext/pcre Modified Files: pcre.c php_pcre.h Log Message: Added preg_quote() function. Index: php4/ext/pcre/pcre.c diff -u php4/ext/pcre/pcre.c:1.14 php4/ext/pcre/pcre.c:1.15 --- php4/ext/pcre/pcre.c:1.14 Fri Jun 4 09:37:44 1999 +++ php4/ext/pcre/pcre.c Fri Jun 4 09:56:22 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pcre.c,v 1.14 1999/06/04 13:37:44 andrey Exp $ */ +/* $Id: pcre.c,v 1.15 1999/06/04 13:56:22 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} }; @@ -839,6 +840,70 @@ /* Clean up */ efree(offsets); +} +/* }}} */ + + +/* {{{ proto string preg_quote(string str) */ +PHP_FUNCTION(preg_quote) +{ + zval *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: php4/ext/pcre/php_pcre.h diff -u php4/ext/pcre/php_pcre.h:1.7 php4/ext/pcre/php_pcre.h:1.8 --- php4/ext/pcre/php_pcre.h:1.7 Fri May 28 16:54:51 1999 +++ php4/ext/pcre/php_pcre.h Fri Jun 4 09:56:23 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_pcre.h,v 1.7 1999/05/28 20:54:51 andrey Exp $ */ +/* $Id: php_pcre.h,v 1.8 1999/06/04 13:56:23 andrey Exp $ */ #ifndef _PHP_PCRE_H #define _PHP_PCRE_H @@ -45,6 +45,7 @@ PHP_FUNCTION(preg_match_all); PHP_FUNCTION(preg_replace); PHP_FUNCTION(preg_split); +PHP_FUNCTION(preg_quote); extern zend_module_entry pcre_module_entry; #define pcre_module_ptr &pcre_module_entry

« previous php.version4 (#1285) next »