cvs: php4 /ext/pcre php_pcre.c
| From: | Andrei Zmievski | Date: | Tue, 18 Dec 2001 19:17:57 +0000 |
| Subject: | cvs: php4 /ext/pcre php_pcre.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-8716@lists.php.net to get a copy of this message | ||
andrei Tue Dec 18 14:17:57 2001 EDT
Modified files:
/php4/ext/pcre php_pcre.c
Log:
@- Added flags parameter to preg_grep(). The only flag currently is
@ PREG_GREP_INVERT that will make the function return entries that
@ did not match. (Andrei)
Index: php4/ext/pcre/php_pcre.c
diff -u php4/ext/pcre/php_pcre.c:1.113 php4/ext/pcre/php_pcre.c:1.114
--- php4/ext/pcre/php_pcre.c:1.113 Tue Dec 11 10:30:06 2001
+++ php4/ext/pcre/php_pcre.c Tue Dec 18 14:17:57 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pcre.c,v 1.113 2001/12/11 15:30:06 sebastian Exp $ */
+/* $Id: php_pcre.c,v 1.114 2001/12/18 19:17:57 andrei Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -40,6 +40,8 @@
#define PREG_REPLACE_EVAL (1<<0)
+#define PREG_GREP_INVERT (1<<0)
+
ZEND_DECLARE_MODULE_GLOBALS(pcre)
@@ -98,6 +100,7 @@
REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS |
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS |
CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS |
CONST_PERSISTENT);
return SUCCESS;
}
/* }}} */
@@ -1280,6 +1283,7 @@
{
zval **regex, /* Regular expression */
**input, /* Input array */
+ **flags,
**entry; /* An entry in the input array */
pcre *re = NULL; /* Compiled regular expression */
pcre_extra *extra = NULL; /* Holds results of studying */
@@ -1289,10 +1293,13 @@
int count = 0; /* Count of matched subpatterns */
char *string_key;
ulong num_key;
+ zend_bool invert = 0; /* Whether to return non-matching
+ entries */
/* Get arguments and do error checking */
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(ZEND_NUM_ARGS(), ®ex, &input) ==
FAILURE) {
+ if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 ||
+ zend_get_parameters_ex(ZEND_NUM_ARGS(), ®ex, &input, &flags) == FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -1305,6 +1312,12 @@
/* Make sure regex is a string */
convert_to_string_ex(regex);
+
+ if (ZEND_NUM_ARGS() > 2) {
+ convert_to_long_ex(flags);
+ invert = Z_LVAL_PP(flags) & PREG_GREP_INVERT;
+ }
+ printf("invert: %d\n", invert);
/* Compile regex or get it from cache. */
if ((re = pcre_get_compiled_regex(Z_STRVAL_PP(regex), extra, &preg_options)) == NULL) {
@@ -1335,8 +1348,9 @@
count = size_offsets/3;
}
- /* If something matched */
- if (count > 0) {
+ /* If the entry fits our requirements */
+ if ((count > 0 && !invert) ||
+ (count < 0 && invert)) {
(*entry)->refcount++;
/* Add to return array */