]> granicus.if.org Git - php/commitdiff
Adding delimiter capturing functionality.
authorAndrei Zmievski <andrei@php.net>
Sat, 3 Feb 2001 04:53:49 +0000 (04:53 +0000)
committerAndrei Zmievski <andrei@php.net>
Sat, 3 Feb 2001 04:53:49 +0000 (04:53 +0000)
As far as NEWS, compilation fixed don't belong here.

NEWS
ext/pcre/php_pcre.c

diff --git a/NEWS b/NEWS
index e5459cca36e3a84e07e3dcee2c16219e3d4b9783..afe36d0ad657d79a45d206a26878860f8223b441 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,8 +2,9 @@ PHP 4.0                                                                    NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
 ?? ??? 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 74ad26026e6355700b9489adc011d96def9ba7de..70597f3fb8bf575fc6c53d596f99d69f4b90478f 100644 (file)
 
 #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 @@ static PHP_MINIT_FUNCTION(pcre)
        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 @@ PHP_FUNCTION(preg_split)
        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 @@ PHP_FUNCTION(preg_split)
                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 @@ PHP_FUNCTION(preg_split)
                                                                           &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)