aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-09-27 02:39:04 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-09-27 02:39:04 +0000
commit9f2fba7fb1d2d024ab4fb67c3adcb24031c1e88e (patch)
tree0fd4ed81c78a4a67c0727d70ea27c51d66ce0de5 /apps
parent0dcff0d3d27c3c3c5f7904bb47b27fcd3e9ce039 (diff)
Add relative substring (bug #229)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1569 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rwxr-xr-xapps/app_substring.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/apps/app_substring.c b/apps/app_substring.c
index aedd2e815..3217a5e13 100755
--- a/apps/app_substring.c
+++ b/apps/app_substring.c
@@ -33,13 +33,16 @@ static char *descrip =
"of string_of_digits to a given variable. Parameter count1 may be positive\n"
"or negative. If it's positive then we skip the first count1 digits from the\n"
"left. If it's negative, we move count1 digits counting from the end of\n"
-"the string to the left. Parameter count2 may be only positive and implies\n"
-"how many digits we're taking from the point that count1 placed us.\n"
+"the string to the left. Parameter count2 implies how many digits we are\n"
+"taking from the point that count1 placed us. If count2 is negative, then\n"
+"that many digits are omitted from the end.\n"
"For example:\n"
"exten => _NXXXXXX,1,SubString,test=2564286161|0|3\n"
"assigns the area code (3 first digits) to variable test.\n"
"exten => _NXXXXXX,1,SubString,test=2564286161|-7|7\n"
"assigns the last 7 digits to variable test.\n"
+"exten => _NXXXXXX,1,SubString,test=2564286161|0|-4\n"
+"assigns all but the last 4 digits to variable test.\n"
"If there are no parameters it'll return with -1.\n"
"If there wrong parameters it go on and return with 0\n";
@@ -71,9 +74,8 @@ static int substring_exec(struct ast_channel *chan, void *data)
}
icount1=atoi(count1);
icount2=atoi(count2);
- if (icount2<=0) {
- ast_log(LOG_DEBUG, "Exiting, wrong parameter count2\n");
- return -1;
+ if (icount2<0) {
+ icount2 = icount2 + strlen(second);
}
if (abs(icount1)>strlen(second)) {
ast_log(LOG_WARNING, "Limiting count1 parameter because it exceeds the length of the string\n");