Date: 05/28/99
- Next message: andrey: "[PHP-DEV] CVS update: php3/pcrelib"
- Previous message: andrey: "[PHP-DEV] CVS update: php3"
- Next in thread: thies: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Friday May 28, 1999 @ 17:12
Author: andrey
Update of /repository/php3/functions
In directory php:/tmp/cvs-serv20456/functions
Modified Files:
pcre.c php3_pcre.h
Log Message:
Updated PCRE library and PCRE module.
Index: php3/functions/pcre.c
diff -u php3/functions/pcre.c:1.3 php3/functions/pcre.c:1.4
--- php3/functions/pcre.c:1.3 Thu May 27 16:19:38 1999
+++ php3/functions/pcre.c Fri May 28 17:12:43 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pcre.c,v 1.3 1999/05/27 20:19:38 andrey Exp $ */
+/* $Id: pcre.c,v 1.4 1999/05/28 21:12:43 andrey Exp $ */
#include "php.h"
@@ -347,7 +347,7 @@
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);
+ offsets, size_offsets, 0);
/* Check for too many substrings condition. */
if (count == 0) {
@@ -472,12 +472,14 @@
int alloc_len; /* Actual allocated length */
int subject_len; /* Length of the subject string */
int result_len; /* Current length of the result */
- int subject_offset; /* Current position in the subject string */
int backref; /* Backreference number */
char *result, /* Result of replacement */
*new_buf, /* Temporary buffer for re-allocation */
*walkbuf, /* Location of current replacement in the result */
- *walk; /* Used to walk the replacement string */
+ *walk, /* Used to walk the replacement string */
+ *match, /* The current match */
+ *piece, /* The current piece of subject */
+ *subject_end; /* Points to the end of the subject */
/* Compile regex or get it from cache. */
if ((re = _pcre_get_compiled_regex(regex, extra)) == NULL) {
@@ -499,23 +501,29 @@
return NULL;
}
- subject_offset = 0;
+ /* Initialize */
result[0] = '\0';
+ piece = subject;
+ subject_end = subject + subject_len;
+ match = NULL;
while (count >= 0) {
/* Execute the regular expression. */
- count = pcre_exec(re, extra, &subject[subject_offset],
- subject_len-subject_offset,
- (subject_offset ? exoptions|PCRE_NOTBOL : exoptions),
- offsets, size_offsets);
-
- /* Check for too many substrings condition. */
+ count = pcre_exec(re, extra, piece,
+ subject_end-piece,
+ (piece==subject ? exoptions : exoptions|PCRE_NOTBOL),
+ offsets, size_offsets, (piece == match));
+
+ /* Check for too many substrings condition. */
if (count == 0) {
php3_error(E_NOTICE, "Matched, but too many substrings\n");
count = size_offsets/3;
}
if (count > 0) {
+ /* Set the match location in piece */
+ match = piece + offsets[0];
+
new_len = strlen(result) + offsets[0]; /* part before the match */
walk = replace;
while (*walk)
@@ -538,7 +546,7 @@
}
result_len = strlen(result);
/* copy the part of the string before the match */
- strncat(result, &subject[subject_offset], offsets[0]);
+ strncat(result, piece, match-piece);
/* copy replacement and backrefs */
walkbuf = &result[result_len + offsets[0]];
@@ -549,7 +557,7 @@
backref < count) {
result_len = offsets[(backref<<1)+1] - offsets[backref<<1];
memcpy (walkbuf,
- &subject[subject_offset + offsets[backref<<1]],
+ piece + offsets[backref<<1],
result_len);
walkbuf += result_len;
walk += (backref > 9) ? 3 : 2;
@@ -557,26 +565,10 @@
*walkbuf++ = *walk++;
*walkbuf = '\0';
- /* and get ready to keep looking for replacements */
- if (offsets[0] == offsets[1]) {
- if (offsets[0] + subject_offset >= subject_len)
- break;
- new_len = strlen (result) + 1;
- if (new_len + 1 > alloc_len) {
- alloc_len = 1 + alloc_len + 2 * new_len;
- new_buf = emalloc(alloc_len * sizeof(char));
- strcpy(new_buf, result);
- efree(result);
- result = new_buf;
- }
- subject_offset += offsets[1] + 1;
- result [new_len-1] = subject[subject_offset-1];
- result [new_len] = '\0';
- } else {
- subject_offset += offsets[1];
- }
+ /* Advance to the next piece */
+ piece += offsets[1];
} else {
- new_len = strlen(result) + strlen(&subject[subject_offset]);
+ new_len = strlen(result) + subject_end-piece;
if (new_len + 1 > alloc_len) {
alloc_len = new_len + 1; /* now we know exactly how long it is */
new_buf = emalloc(alloc_len * sizeof(char));
@@ -585,7 +577,7 @@
result = new_buf;
}
/* stick that last bit of string on our output */
- strcat(result, &subject[subject_offset]);
+ strcat(result, piece);
}
}
@@ -761,7 +753,7 @@
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);
+ offsets, size_offsets, 0);
/* Check for too many substrings condition. */
if (count == 0) {
Index: php3/functions/php3_pcre.h
diff -u php3/functions/php3_pcre.h:1.2 php3/functions/php3_pcre.h:1.3
--- php3/functions/php3_pcre.h:1.2 Thu May 27 16:19:38 1999
+++ php3/functions/php3_pcre.h Fri May 28 17:12:43 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php3_pcre.h,v 1.2 1999/05/27 20:19:38 andrey Exp $ */
+/* $Id: php3_pcre.h,v 1.3 1999/05/28 21:12:43 andrey Exp $ */
#ifndef _PHP_PCRE_H
#define _PHP_PCRE_H
@@ -37,11 +37,7 @@
#include "modules.h"
#include "internal_functions.h"
-#if HAVE_BUNDLED_PCRE
#include "pcrelib/pcre.h"
-#else
-#include "pcre.h"
-#endif
extern void php_info_pcre(void);
extern int php_minit_pcre(INIT_FUNC_ARGS);
-- 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>
- Next message: andrey: "[PHP-DEV] CVS update: php3/pcrelib"
- Previous message: andrey: "[PHP-DEV] CVS update: php3"
- Next in thread: thies: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

