]> granicus.if.org Git - php/commitdiff
Fixed PCRE so that global matching with patterns with \b works.
authorAndrey Hristov <andrey@php.net>
Sat, 29 May 1999 19:38:50 +0000 (19:38 +0000)
committerAndrey Hristov <andrey@php.net>
Sat, 29 May 1999 19:38:50 +0000 (19:38 +0000)
ext/pcre/pcre.c
ext/pcre/pcrelib/internal.h
ext/pcre/pcrelib/pcre.c
ext/pcre/pcrelib/pcre.h

index 30721b09e639daf7fd3e7069c0d52b24afc2fe2a..a36a2dce2cb13b82d845d60d23efe23729302b92 100644 (file)
@@ -29,8 +29,6 @@
 
 /* $Id$ */
 
-/* Get PCRE library from ftp://ftp.cus.cam.ac.uk/pub/software/programs/pcre/ */
-
 #include "php.h"
 
 #if HAVE_PCRE
@@ -381,7 +379,7 @@ void _pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global)
        do {
                /* Execute the regular expression. */
                count = pcre_exec(re, extra, &subject->value.str.val[subject_offset],
-                                                 subject->value.str.len-subject_offset,
+                                                 subject->value.str.len-subject_offset, subject->value.str.val,
                                                  (subject_offset ? exoptions|PCRE_NOTBOL : exoptions),
                                                  offsets, size_offsets, 0);
 
@@ -548,7 +546,7 @@ char *_php_pcre_replace(char *regex, char *subject, char *replace)
        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));
                
@@ -796,7 +794,7 @@ PHP_FUNCTION(preg_split)
        /* 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,
+                                                 subject->value.str.len-last_offset, subject->value.str.val,
                                                  (last_offset ? exoptions|PCRE_NOTBOL : exoptions),
                                                  offsets, size_offsets, 0);
 
index 2b28ac1a543efecc5f861ec63ab5f21f0e2e7b67..b6680a0d5043d100c9b3bf2c9c4acd03f050ce58 100644 (file)
@@ -307,6 +307,7 @@ typedef struct match_data {
   const uschar *end_subject;    /* End of the subject string */
   const uschar *end_match_ptr;  /* Subject position at end match */
   int     end_offset_top;       /* Highwater mark at end of match */
+  char   regprev;              /* Character previous to subject string (Andrey Zmievski) */
 } match_data;
 
 /* Bit definitions for entries in the pcre_ctypes table. */
index caeeaa4971c8e0231e63d548a671c88b060ee9fc..51cb6b6c878ad8418f375f0deb4d3db3fb104926 100644 (file)
@@ -3321,8 +3321,12 @@ for (;;)
     case OP_NOT_WORD_BOUNDARY:
     case OP_WORD_BOUNDARY:
       {
-      BOOL prev_is_word = (eptr != md->start_subject) &&
-        ((md->ctypes[eptr[-1]] & ctype_word) != 0);
+      /* Modified the next line to check previous character
+        in case we're not at the beginning of the whole string
+        (Andrey Zmievski) */
+      BOOL prev_is_word = (eptr != md->start_subject) ?
+        ((md->ctypes[eptr[-1]] & ctype_word) != 0) :
+               ((md->ctypes[md->regprev] & ctype_word) != 0);
       BOOL cur_is_word = (eptr < md->end_subject) &&
         ((md->ctypes[*eptr] & ctype_word) != 0);
       if ((*ecode++ == OP_WORD_BOUNDARY)?
@@ -4125,7 +4129,8 @@ Returns:          > 0 => success; value is the number of elements filled in
 
 int
 pcre_exec(const pcre *external_re, const pcre_extra *external_extra,
-  const char *subject, int length, int options, int *offsets, int offsetcount, int minlen)
+  const char *subject, int length, const char *strbeg, int options,
+  int *offsets, int offsetcount, int minlen)
 {
 int resetcount, ocount;
 int first_char = -1;
@@ -4160,6 +4165,15 @@ match_block.errorcode = PCRE_ERROR_NOMATCH;     /* Default error */
 match_block.lcc = re->tables + lcc_offset;
 match_block.ctypes = re->tables + ctypes_offset;
 
+/* Setup previous character (Andrey Zmievski) */
+if (subject == strbeg)
+       match_block.regprev = '\n';
+else {
+       match_block.regprev = subject[-1];
+       if (!(re->options & PCRE_MULTILINE) && match_block.regprev == '\n')
+               match_block.regprev = '\0';
+}
+
 /* The ims options can vary during the matching as a result of the presence
 of (?ims) items in the pattern. They are kept in a local variable so that
 restoring at the exit of a group is easy. */
index 0efc0f650215aeedc88bebeba93347f01be12252..8fedb8189e1e927ce507309053feae2bc3a2b487 100644 (file)
@@ -59,7 +59,7 @@ extern pcre *pcre_compile(const char *, int, const char **, int *,
   const unsigned char *);
 extern int pcre_copy_substring(const char *, int *, int, int, char *, int);
 extern int pcre_exec(const pcre *, const pcre_extra *, const char *,
-  int, int, int *, int, int);
+  int, const char *, int, int *, int, int);
 extern int pcre_get_substring(const char *, int *, int, int, const char **);
 extern int pcre_get_substring_list(const char *, int *, int, const char ***);
 extern int pcre_info(const pcre *, int *, int *);