On 09/21/2010 08:42 PM, [email protected] wrote: > Author: niq > Date: Tue Sep 21 18:42:20 2010 > New Revision: 999533 > > URL: http://svn.apache.org/viewvc?rev=999533&view=rev > Log: > Introduce ap_rxplus class: higher-level regexps supporting perl-style > regexp operations. > > Added: > httpd/httpd/trunk/server/util_regex.c > Modified: > httpd/httpd/trunk/CHANGES > httpd/httpd/trunk/include/ap_regex.h > httpd/httpd/trunk/server/Makefile.in > httpd/httpd/trunk/server/util_pcre.c >
> Added: httpd/httpd/trunk/server/util_regex.c > URL: > http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_regex.c?rev=999533&view=auto > ============================================================================== > --- httpd/httpd/trunk/server/util_regex.c (added) > +++ httpd/httpd/trunk/server/util_regex.c Tue Sep 21 18:42:20 2010 > + > +AP_DECLARE(int) ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx, > + const char *pattern, char **newpattern) > + //int max_iterations) This looks like a C++ style comment. > +{ > +#if 1 > + int ret = 1; > + int startl, oldl, newl, diffsz; > + const char *remainder; > + char *subs; > +/* snrf process_regexp from mod_headers */ > + if (ap_regexec(&rx->rx, pattern, rx->nmatch, rx->pmatch, rx->flags) != > 0) { > + rx->match = NULL; > + return 0; /* no match, nothing to do */ > + } > + rx->match = pattern; > + if (rx->subs) { > + *newpattern = ap_pregsub(pool, rx->subs, pattern, > + rx->nmatch, rx->pmatch); > + if (!*newpattern) { > + return 0; /* FIXME - should we do more to handle error? */ > + } > + startl = rx->pmatch[0].rm_so; > + oldl = rx->pmatch[0].rm_eo - startl; > + newl = strlen(*newpattern); > + diffsz = newl - oldl; > + remainder = pattern + startl + oldl; > + if (rx->flags & AP_REG_MULTI) { > + /* recurse to do any further matches */ > + char *subs; > + ret += ap_rxplus_exec(pool, rx, remainder, &subs); > + if (ret > 1) { > + /* a further substitution happened */ > + diffsz += strlen(subs) - strlen(remainder); > + remainder = subs; > + } > + } > + subs = apr_palloc(pool, strlen(pattern) + 1 + diffsz); > + memcpy(subs, pattern, startl); > + memcpy(subs+startl, *newpattern, newl); > + strcpy(subs+startl+newl, remainder); > + *newpattern = subs; > + } > + return ret; > + > + > + > + > +#else > + > + > + > + > + > + > + > + > + > + > + > + > + if (!(rx->flags & AP_REG_MULTI) || (rx->subs == NULL)) { > + max_iterations = 1; > + } > + /* FIXME: multi-matching is incorrect */ > + while (max_iterations-- > 0) { > + if (ap_regexec(&rx->rx, pattern, rx->nmatch, rx->pmatch, rx->flags) > + == 0) { > + ret++; > + if (rx->subs) { > + rx->match = pattern; > + *newpattern = ap_pregsub(pool, rx->subs, pattern, > + rx->nmatch, rx->pmatch); > + pattern = *newpattern; > + if (pattern == NULL) { > + max_iterations = 0; > + } > + } > + } > + else { > + max_iterations = 0; > + } > + } > + > + if (ret == 0 || rx->flags&AP_REG_NOMEM) { > + rx->match = NULL; /* no match, so don't pretend to remember a match > */ > + } > + else { > +#if 0 > + /* FIXME - should we be 'safe' and take the performance hit, > + * or just document thou-shalt-keep-pattern-in-scope? > + */ > + if (rx->match == inpattern) { > + rx->match = apr_pstrdup(pool, inpattern); > + } > +#endif > + } > + return ret; > +#endif Why do you commit dead code that is never used? Regards RĂ¼diger
