[PHP-DEV] CVS update: php3/functions From: andrey (php-dev <email protected>)
Date: 05/29/99

Date: Saturday May 29, 1999 @ 17:05
Author: andrey

Update of /repository/php3/functions
In directory php:/tmp/cvs-serv16290/functions

Modified Files:
        pcre.c
Log Message:
Updated PCRE to properly handle \b assertions.

Index: php3/functions/pcre.c
diff -u php3/functions/pcre.c:1.4 php3/functions/pcre.c:1.5
--- php3/functions/pcre.c:1.4 Fri May 28 17:12:43 1999
+++ php3/functions/pcre.c Sat May 29 17:05:26 1999
@@ -27,7 +27,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: pcre.c,v 1.4 1999/05/28 21:12:43 andrey Exp $ */
+/* $Id: pcre.c,v 1.5 1999/05/29 21:05:26 andrey Exp $ */
 
 #include "php.h"
 
@@ -148,7 +148,7 @@
         
         /* Parse through the leading whitespace, and display a warning if we
            get to the end without encountering a delimiter. */
- while (isspace(*p)) p++;
+ while (isspace((int)*p)) p++;
         if (*p == 0) {
                 php3_error(E_WARNING, "Empty regular expression");
                 return NULL;
@@ -157,7 +157,7 @@
         /* Get the delimiter and display a warning if it is alphanumeric
            or a backslash. */
         delimiter = *p++;
- if (isalnum(delimiter) || delimiter == '\\') {
+ if (isalnum((int)delimiter) || delimiter == '\\') {
                 php3_error(E_WARNING, "Delimiter must not be alphanumeric or backslash");
                 return NULL;
         }
@@ -266,7 +266,9 @@
         int i;
         int subpats_order_val; /* Integer value of subpats_order */
         const char **stringlist; /* Used to hold list of subpatterns */
- int subject_offset; /* Current position in the subject string */
+ char *match, /* The current match */
+ *piece, /* The current piece of subject */
+ *subject_end; /* Points to the end of the subject */
         
         /* Get function parameters and do error-checking. */
         switch(ARG_COUNT(ht)) {
@@ -340,14 +342,16 @@
         }
 
         /* Start from the beginning of the string */
- subject_offset = 0;
+ piece = subject->value.str.val;
+ subject_end = piece + subject->value.str.len;
+ match = NULL;
         
         do {
                 /* Execute the regular expression. */
- count = pcre_exec(re, extra, &subject->value.str.val[subject_offset],
- subject->value.str.len-subject_offset,
- (subject_offset ? exoptions|PCRE_NOTBOL : exoptions),
- offsets, size_offsets, 0);
+ count = pcre_exec(re, extra, piece,
+ subject_end-piece, subject->value.str.val,
+ (piece==subject->value.str.val ? exoptions : exoptions|PCRE_NOTBOL),
+ offsets, size_offsets, (piece == match));
 
                 /* Check for too many substrings condition. */
                 if (count == 0) {
@@ -358,14 +362,13 @@
                 /* If something has matched */
                 if (count >= 0) {
                         matched = 1;
+ match = piece + offsets[0];
 
                         /* If subpatters array has been passed, fill it in with values. */
                         if (subpats != NULL) {
                                 /* Try to get the list of substrings and display a warning if failed. */
- if (pcre_get_substring_list(&subject->value.str.val[subject_offset],
- offsets, count, &stringlist) < 0) {
+ if (pcre_get_substring_list(piece, offsets, count, &stringlist) < 0) {
                                         efree(offsets);
- efree(re);
                                         php3_error(E_WARNING, "Get subpatterns list failed");
                                         return;
                                 }
@@ -401,7 +404,7 @@
                                 php_pcre_free(stringlist);
                                 
                                 /* Advance to the position right after the last full match */
- subject_offset += offsets[1];
+ piece += offsets[1];
                         }
                 }
                 /* If nothing matched */
@@ -414,6 +417,7 @@
         if (global && subpats_order_val == PREG_PATTERN_ORDER) {
                 for (i=0; i<num_subpats; i++) {
                         _php3_hash_next_index_insert(subpats->value.ht, match_sets[i], sizeof(pval), NULL);
+ efree(match_sets[i]);
                 }
                 efree(match_sets);
         }
@@ -496,7 +500,6 @@
         result = emalloc(alloc_len * sizeof(char));
         if (!result) {
                 php3_error(E_WARNING, "Unable to allocate memory in pcre_replace");
- efree(re);
                 efree(offsets);
                 return NULL;
         }
@@ -510,7 +513,7 @@
         while (count >= 0) {
                 /* Execute the regular expression. */
                 count = pcre_exec(re, extra, piece,
- subject_end-piece,
+ subject_end-piece, subject,
                                                           (piece==subject ? exoptions : exoptions|PCRE_NOTBOL),
                                                         offsets, size_offsets, (piece == match));
                 
@@ -592,7 +595,7 @@
 {
         pval *regex_entry,
                                 *replace_entry;
- char *replace_value,
+ char *replace_value = NULL,
                                 *subject_value,
                                 *result;
 
@@ -714,7 +717,9 @@
         int argc; /* Argument count */
         int limit_val; /* Integer value of limit */
         int count = 0; /* Count of matched subpatterns */
- int last_offset; /* Holds the offset of the last match */
+ char *match, /* The current match */
+ *piece, /* The current piece of subject */
+ *subject_end; /* Points to the end of subject string */
 
         /* Get function parameters and do error checking */
         argc = ARG_COUNT(ht);
@@ -746,14 +751,16 @@
         offsets = (int *)emalloc(size_offsets * sizeof(int));
         
         /* Start at the beginning of the string */
- last_offset = 0;
+ piece = subject->value.str.val;
+ subject_end = piece + subject->value.str.len;
+ match = NULL;
         
         /* Get next piece if no limit or limit not yet reached and something matched*/
         while ((limit_val == -1 || limit_val > 0) && count >= 0) {
- count = pcre_exec(re, extra, &subject->value.str.val[last_offset],
- subject->value.str.len-last_offset,
- (last_offset ? exoptions|PCRE_NOTBOL : exoptions),
- offsets, size_offsets, 0);
+ count = pcre_exec(re, extra, piece,
+ subject_end-piece, subject->value.str.val,
+ (piece==subject->value.str.val ? exoptions : exoptions|PCRE_NOTBOL),
+ offsets, size_offsets, (piece==match));
 
                 /* Check for too many substrings condition. */
                 if (count == 0) {
@@ -763,13 +770,15 @@
 
                 /* If something matched */
                 if (count > 0) {
+ match = piece + offsets[0];
+
                         /* Add the piece to the return value */
                         add_next_index_stringl(return_value,
- &subject->value.str.val[last_offset],
- offsets[0], 1);
+ piece,
+ offsets[0], 1);
                         
                         /* Advance to next position */
- last_offset += offsets[1];
+ piece += offsets[1];
                         
                         /* One less left to do */
                         if (limit_val != -1)
@@ -778,10 +787,10 @@
                 else { /* if no match */
                         /* Add the last piece to the return value, if there
                            were matches before */
- if (last_offset > 0)
+ if (piece > subject->value.str.val)
                                 add_next_index_stringl(return_value,
- &subject->value.str.val[last_offset],
- subject->value.str.len - last_offset, 1);
+ piece ,
+ subject_end-piece, 1);
                 }
         }
         

--
PHP Development Mailing List   http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
For help: php-dev-help <email protected>