andrei Fri Feb 2 20:53:50 2001 EDT
Modified files:
/php4 NEWS
/php4/ext/pcre php_pcre.c
Log:
Adding delimiter capturing functionality.
As far as NEWS, compilation fixed don't belong here.
Index: php4/NEWS
diff -u php4/NEWS:1.578 php4/NEWS:1.579
--- php4/NEWS:1.578 Fri Feb 2 18:09:20 2001
+++ php4/NEWS Fri Feb 2 20:53:49 2001
@@ -2,8 +2,9 @@
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 200?, Version 4.0.5
-- pspell .12 fix (Hugh Jones)
-- Fix strip_tags to not strip a lone > character (Rasmus)
+- Added PREG_SPLIT_DELIM_CAPTURE flag to preg_split() that allows for Perl-like
+ functionality of capturing parenthesized delimiter expression. (Andrei)
+- Fixed strip_tags() to not strip a lone > character. (Rasmus)
- Added new UDM_PARAM_STOPTABLE and UDM_PARAM_STOPFILE parameters
for Udm_Set_Agent_Params mnoGoSearch module. Now it can use stopwords
stored either in database or in the plain text files. Added php warnings.
Index: php4/ext/pcre/php_pcre.c
diff -u php4/ext/pcre/php_pcre.c:1.84 php4/ext/pcre/php_pcre.c:1.85
--- php4/ext/pcre/php_pcre.c:1.84 Thu Feb 1 07:25:53 2001
+++ php4/ext/pcre/php_pcre.c Fri Feb 2 20:53:49 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pcre.c,v 1.84 2001/02/01 15:25:53 andrei Exp $ */
+/* $Id: php_pcre.c,v 1.85 2001/02/03 04:53:49 andrei Exp $ */
/*
TODO:
@@ -33,13 +33,14 @@
#include "ext/standard/php_string.h"
-#define PREG_PATTERN_ORDER 0
-#define PREG_SET_ORDER 1
+#define PREG_PATTERN_ORDER 0
+#define PREG_SET_ORDER 1
-#define PREG_SPLIT_NO_EMPTY (1<<0)
+#define PREG_SPLIT_NO_EMPTY (1<<0)
+#define PREG_SPLIT_DELIM_CAPTURE (1<<1)
-#define PREG_REPLACE_EVAL (1<<0)
-#define PREG_REPLACE_FUNC (1<<1)
+#define PREG_REPLACE_EVAL (1<<0)
+#define PREG_REPLACE_FUNC (1<<1)
#ifdef ZTS
int pcre_globals_id;
@@ -110,6 +111,7 @@
REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS |
CONST_PERSISTENT);
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);
return SUCCESS;
}
/* }}} */
@@ -1064,8 +1066,9 @@
int exoptions = 0; /* Execution options */
int preg_options = 0; /* Custom preg options
*/
int argc; /* Argument
count */
- int limit_val; /* Integer
value of limit */
+ int limit_val = -1; /* Integer value of
+limit */
int no_empty = 0; /* If NO_EMPTY flag is
set */
+ int delim_capture = 0; /* If delimiters should be
+captured */
int count = 0; /* Count of
matched subpatterns */
int start_offset; /* Where the new
search starts */
int g_notempty = 0; /* If the match should
not be empty */
@@ -1078,16 +1081,15 @@
WRONG_PARAM_COUNT;
}
- if (argc == 3) {
+ if (argc > 2) {
convert_to_long_ex(limit);
limit_val = Z_LVAL_PP(limit);
- }
- else
- limit_val = -1;
-
- if (argc == 4) {
- convert_to_long_ex(flags);
- no_empty = Z_LVAL_PP(flags) & PREG_SPLIT_NO_EMPTY;
+
+ if (argc > 3) {
+ convert_to_long_ex(flags);
+ no_empty = Z_LVAL_PP(flags) & PREG_SPLIT_NO_EMPTY;
+ delim_capture = Z_LVAL_PP(flags) & PREG_SPLIT_DELIM_CAPTURE;
+ }
}
/* Make sure we're dealing with strings */
@@ -1133,6 +1135,17 @@
&Z_STRVAL_PP(subject)[offsets[0]]-last_match, 1);
last_match = &Z_STRVAL_PP(subject)[offsets[1]];
+
+ if (delim_capture) {
+ int i, match_len;
+ for (i = 1; i < count; i++) {
+ match_len = offsets[(i<<1)+1] - offsets[i<<1];
+ if (!no_empty || match_len > 0)
+ add_next_index_stringl(return_value,
+
+ &Z_STRVAL_PP(subject)[offsets[i<<1]],
+
+ match_len, 1);
+ }
+ }
/* One less left to do */
if (limit_val != -1)
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]