diff options
author | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2008-04-05 16:11:05 +0000 |
---|---|---|
committer | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2008-04-05 16:11:05 +0000 |
commit | 049881b7af634cd0c59d5053c169642c0a06b1de (patch) | |
tree | 5e030660d38359780964e84736008c3b66f95e8a | |
parent | a38caa81033fe61f01fc1c2d98b9af92a514f9e6 (diff) | |
download | pcre-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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | doc/pcreposix.3 | 20 | ||||
-rw-r--r-- | pcreposix.c | 20 | ||||
-rw-r--r-- | pcreposix.h | 1 |
4 files changed, 39 insertions, 7 deletions
@@ -10,7 +10,7 @@ Version 7.7 05-Mar-08 2. Applied Craig's patch to pcrecpp.cc to restore ABI compatibility with pre-7.6 versions, which defined a global no_arg variable instead of putting - it in the RE class. + it in the RE class. (See also #8 below.) 3. Remove a line of dead code, identified by coverity and reported by Nuno Lopes. @@ -43,6 +43,9 @@ Version 7.7 05-Mar-08 9. Applied Craig's patch to remove the use of push_back(). +10. Applied Alan Lehotsky's patch to add REG_STARTEND support to the POSIX + matching function regexec(). + Version 7.6 28-Jan-08 --------------------- diff --git a/doc/pcreposix.3 b/doc/pcreposix.3 index 2f75c9b..e01068e 100644 --- a/doc/pcreposix.3 +++ b/doc/pcreposix.3 @@ -157,8 +157,9 @@ REG_NEWLINE action. .rs .sp The function \fBregexec()\fP is called to match a compiled pattern \fIpreg\fP -against a given \fIstring\fP, which is terminated by a zero byte, subject to -the options in \fIeflags\fP. These can be: +against a given \fIstring\fP, which is by default terminated by a zero byte +(but see REG_STARTEND below), subject to the options in \fIeflags\fP. These can +be: .sp REG_NOTBOL .sp @@ -169,6 +170,17 @@ function. .sp The PCRE_NOTEOL option is set when calling the underlying PCRE matching function. +.sp + REG_STARTEND +.sp +The string is considered to start at \fIstring\fP + \fIpmatch[0].rm_so\fP and +to have a terminating NUL located at \fIstring\fP + \fIpmatch[0].rm_eo\fP +(there need not actually be a NUL at that location), regardless of the value of +\fInmatch\fP. This is a BSD extension, compatible with but not specified by +IEEE Standard 1003.2 (POSIX.2), and should be used with caution in software +intended to be portable to other systems. Note that a non-zero \fIrm_so\fP does +not imply REG_NOTBOL; REG_STARTEND affects only the location of the string, not +how it is matched. .P If the pattern was compiled with the REG_NOSUB flag, no data about any matched strings is returned. The \fInmatch\fP and \fIpmatch\fP arguments of @@ -221,6 +233,6 @@ Cambridge CB2 3QH, England. .rs .sp .nf -Last updated: 06 March 2007 -Copyright (c) 1997-2007 University of Cambridge. +Last updated: 05 April 2008 +Copyright (c) 1997-2008 University of Cambridge. .fi 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 */ diff --git a/pcreposix.h b/pcreposix.h index 109376d..a73ad26 100644 --- a/pcreposix.h +++ b/pcreposix.h @@ -59,6 +59,7 @@ extern "C" { #define REG_DOTALL 0x0010 /* NOT defined by POSIX. */ #define REG_NOSUB 0x0020 #define REG_UTF8 0x0040 /* NOT defined by POSIX. */ +#define REG_STARTEND 0x0080 /* BSD feature: pass subject string by so,eo */ /* This is not used by PCRE, but by defining it we make it easier to slot PCRE into existing programs that make POSIX calls. */ |