MCPcopy Create free account
hub / github.com/apache/httpd / ap_rxplus_compile

Function ap_rxplus_compile

server/util_regex.c:31–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool,
32 const char *pattern)
33{
34 /* perl style patterns
35 * add support for more as and when wanted
36 * substitute: s/rx/subs/
37 * match: m/rx/ or just /rx/
38 */
39
40 /* allow any nonalnum delimiter as first or second char.
41 * If we ever use this with non-string pattern we'll need an extra check
42 */
43 const char *endp = 0;
44 const char *str = pattern;
45 const char *rxstr;
46 ap_rxplus_t *ret = apr_pcalloc(pool, sizeof(ap_rxplus_t));
47 char delim = 0;
48 enum { SUBSTITUTE = 's', MATCH = 'm'} action = MATCH;
49
50 if (!apr_isalnum(pattern[0])) {
51 delim = *str++;
52 }
53 else if (pattern[0] == 's' && !apr_isalnum(pattern[1])) {
54 action = SUBSTITUTE;
55 delim = pattern[1];
56 str += 2;
57 }
58 else if (pattern[0] == 'm' && !apr_isalnum(pattern[1])) {
59 delim = pattern[1];
60 str += 2;
61 }
62 /* TODO: support perl's after/before */
63 /* FIXME: fix these simplminded delims */
64
65 /* we think there's a delimiter. Allow for it not to be if unmatched */
66 if (delim) {
67 endp = ap_strchr_c(str, delim);
68 }
69 if (!endp) { /* there's no delim or flags */
70 if (ap_regcomp(&ret->rx, pattern, 0) == 0) {
71 apr_pool_cleanup_register(pool, &ret->rx, rxplus_cleanup,
72 apr_pool_cleanup_null);
73 return ret;
74 }
75 else {
76 return NULL;
77 }
78 }
79
80 /* We have a delimiter. Use it to extract the regexp */
81 rxstr = apr_pstrmemdup(pool, str, endp-str);
82
83 /* If it's a substitution, we need the replacement string
84 * TODO: possible future enhancement - support other parsing
85 * in the replacement string.
86 */
87 if (action == SUBSTITUTE) {
88 str = endp+1;

Callers 2

fcgi_define_providerFunction · 0.85
mod_proxy_htmlFunction · 0.85

Calls 3

ap_strchr_cFunction · 0.85
ap_regcompFunction · 0.85

Tested by

no test coverage detected