From: Andrey Hristov Date: Sat, 29 May 1999 19:38:50 +0000 (+0000) Subject: Fixed PCRE so that global matching with patterns with \b works. X-Git-Tag: BEFORE_REMOVING_GC_STEP1~235 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c970e1910a9e7863eb92f0a8b2286a5aeb11b46;p=php Fixed PCRE so that global matching with patterns with \b works. --- diff --git a/ext/pcre/pcre.c b/ext/pcre/pcre.c index 30721b09e6..a36a2dce2c 100644 --- a/ext/pcre/pcre.c +++ b/ext/pcre/pcre.c @@ -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); diff --git a/ext/pcre/pcrelib/internal.h b/ext/pcre/pcrelib/internal.h index 2b28ac1a54..b6680a0d50 100644 --- a/ext/pcre/pcrelib/internal.h +++ b/ext/pcre/pcrelib/internal.h @@ -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. */ diff --git a/ext/pcre/pcrelib/pcre.c b/ext/pcre/pcrelib/pcre.c index caeeaa4971..51cb6b6c87 100644 --- a/ext/pcre/pcrelib/pcre.c +++ b/ext/pcre/pcrelib/pcre.c @@ -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. */ diff --git a/ext/pcre/pcrelib/pcre.h b/ext/pcre/pcrelib/pcre.h index 0efc0f6502..8fedb8189e 100644 --- a/ext/pcre/pcrelib/pcre.h +++ b/ext/pcre/pcrelib/pcre.h @@ -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 *);