diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-08-31 04:07:35 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-08-31 04:07:35 +0000 |
commit | 7ab2e8a729b59e58ede5525e6f1d6c1ebf0794da (patch) | |
tree | 7e3e46acfd895a8612937ce2e9d3433135ef0b49 /funcs | |
parent | 6a1a080f671ca54318e8193c0e0a469818e3dd81 (diff) |
The behavior of REGEX when it did not match was not defined by the docs, so
define it to provide a result of "0" and change the code appropriately.
(issue #7805)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@41544 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs')
-rw-r--r-- | funcs/func_strings.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/funcs/func_strings.c b/funcs/func_strings.c index 86063185a..8c3b4628a 100644 --- a/funcs/func_strings.c +++ b/funcs/func_strings.c @@ -115,7 +115,7 @@ static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf, int errcode; regex_t regexbuf; - buf[0] = '\0'; + buf[0] = '0'; AST_NONSTANDARD_APP_ARGS(args, parse, '"'); @@ -130,10 +130,10 @@ static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf, regerror(errcode, ®exbuf, buf, len); ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf); return -1; - } else { - if (!regexec(®exbuf, args.str, 0, NULL, 0)) - strcpy(buf, "1"); } + + strcpy(buf, regexec(®exbuf, args.str, 0, NULL, 0) ? "0" : "1"); + regfree(®exbuf); return 0; @@ -141,8 +141,8 @@ static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf, static struct ast_custom_function regex_function = { .name = "REGEX", - .synopsis = - "Regular Expression: Returns 1 if data matches regular expression.", + .synopsis = "Regular Expression", + .desc = "Returns 1 if data matches regular expression, or 0 otherwise.", .syntax = "REGEX(\"<regular expression>\" <data>)", .read = regex, }; |