add opts to regex
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6254 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
d6d9890b8d
commit
c5e0348f63
|
@ -61,20 +61,40 @@ SWITCH_DECLARE(int) switch_regex_perform(const char *field, const char *expressi
|
||||||
int erroffset = 0;
|
int erroffset = 0;
|
||||||
pcre *re = NULL;
|
pcre *re = NULL;
|
||||||
int match_count = 0;
|
int match_count = 0;
|
||||||
|
char *tmp = NULL;
|
||||||
|
uint32_t flags = 0;
|
||||||
|
|
||||||
if (!(field && expression)) {
|
if (!(field && expression)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*expression == '/' && *(expression + (strlen(expression) - 1)) == '/') {
|
||||||
|
char *opts = NULL;
|
||||||
|
tmp = strdup(expression + 1);
|
||||||
|
assert(tmp);
|
||||||
|
if ((opts = strrchr(tmp, '/'))) {
|
||||||
|
*opts++ = '\0';
|
||||||
|
}
|
||||||
|
expression = tmp;
|
||||||
|
if (opts) {
|
||||||
|
if (strchr(opts, 'i')) {
|
||||||
|
flags |= PCRE_CASELESS;
|
||||||
|
}
|
||||||
|
if (strchr(opts, 's')) {
|
||||||
|
flags |= PCRE_DOTALL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
re = pcre_compile(expression, /* the pattern */
|
re = pcre_compile(expression, /* the pattern */
|
||||||
0, /* default options */
|
flags, /* default options */
|
||||||
&error, /* for error message */
|
&error, /* for error message */
|
||||||
&erroffset, /* for error offset */
|
&erroffset, /* for error offset */
|
||||||
NULL); /* use default character tables */
|
NULL); /* use default character tables */
|
||||||
if (error) {
|
if (error) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "COMPILE ERROR: %d [%s]\n", erroffset, error);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "COMPILE ERROR: %d [%s]\n", erroffset, error);
|
||||||
switch_regex_safe_free(re);
|
switch_regex_safe_free(re);
|
||||||
return 0;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
match_count = pcre_exec(re, /* result of pcre_compile() */
|
match_count = pcre_exec(re, /* result of pcre_compile() */
|
||||||
|
@ -93,6 +113,8 @@ SWITCH_DECLARE(int) switch_regex_perform(const char *field, const char *expressi
|
||||||
|
|
||||||
*new_re = (switch_regex_t *) re;
|
*new_re = (switch_regex_t *) re;
|
||||||
|
|
||||||
|
end:
|
||||||
|
switch_safe_free(tmp);
|
||||||
return match_count;
|
return match_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue