summaryrefslogtreecommitdiff
path: root/pcreposix.c
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2008-04-05 16:11:05 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2008-04-05 16:11:05 +0000
commit049881b7af634cd0c59d5053c169642c0a06b1de (patch)
tree5e030660d38359780964e84736008c3b66f95e8a /pcreposix.c
parenta38caa81033fe61f01fc1c2d98b9af92a514f9e6 (diff)
downloadpcre-049881b7af634cd0c59d5053c169642c0a06b1de.tar.gz
Alan Lehotsky's patch for REG_STARTEND.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@332 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcreposix.c')
-rw-r--r--pcreposix.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/pcreposix.c b/pcreposix.c
index 6c7198b..d129c02 100644
--- a/pcreposix.c
+++ b/pcreposix.c
@@ -263,7 +263,7 @@ PCREPOSIX_EXP_DEFN int
regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags)
{
-int rc;
+int rc, so, eo;
int options = 0;
int *ovector = NULL;
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
@@ -296,7 +296,23 @@ else if (nmatch > 0)
}
}
-rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string),
+/* REG_STARTEND is a BSD extension, to allow for non-NUL-terminated strings.
+The man page from OS X says "REG_STARTEND affects only the location of the
+string, not how it is matched". That is why the "so" value is used to bump the
+start location rather than being passed as a PCRE "starting offset". */
+
+if ((eflags & REG_STARTEND) != 0)
+ {
+ so = pmatch[0].rm_so;
+ eo = pmatch[0].rm_eo;
+ }
+else
+ {
+ so = 0;
+ eo = strlen(string);
+ }
+
+rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string + so, (eo - so),
0, options, ovector, nmatch * 3);
if (rc == 0) rc = nmatch; /* All captured slots were filled in */