[Home]

Summary:ASTERISK-04220: [patch] Make IF func handle whitespace
Reporter:Anthony Minessale (anthm)Labels:
Date Opened:2005-05-18 16:18:02Date Closed:2008-01-15 15:35:49.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) iffix_rev1.diff
( 1) iffix.diff
Description:This patch fixes if so whitespace around ? and : is ignored unless it has " in it.

It also implements/uses a new api call in app.c called ast_trim_spaces

example

${IF($[ (${X}) = 1] ?  yes  :  no)}

${IF($[ (${X}) = 1] ?  "yes sir"  :  "no sir")}


****** ADDITIONAL INFORMATION ******

Disclaimer on file
anthmct@yahoo.com
Comments:By: Mark Spencer (markster) 2005-05-18 22:00:55

The function should probably operate "in place" and simply return a char * to the start.  Like this:

char *ast_trim_spaces(char *s)
{
 e = s + strlen(s) - 1;
 while(*s && *s < 33) s++;
 while(e > s && (*e < 33)) *(e--) = '\0';
 return s;
}

By: Kevin P. Fleming (kpfleming) 2005-05-19 00:06:37

That looks nearly identical to ast_strip().

By: Anthony Minessale (anthm) 2005-05-19 09:12:26

I was back and forth on the fence about that and had it that way at 1 point then I decided for the good of the API that it would be more flexible to be able to work with read-only as well as read-write strings since you may not always be allowed to modify the string.
maybe there should be 2 funcs? *shrug*

By: Mark Spencer (markster) 2005-05-19 09:41:48

You could always strncpy or ast_strdupa if necessary.  I would think only the one would be necessary at the moment.

By: Anthony Minessale (anthm) 2005-05-19 10:21:27

Am i supposed to recode it? this is a bug I was trying to fix so I'm not sure what to do now?  

For the record, this kind of thing upsets me because I worked on this for a longer amount of time to make sure it worked perfectly as described and went to the trouble of making an api call and made 3 variations of the API call till I thought it was the best choice since in general C prefers the passing of a buffer thing over modifying pointers unless you are passing a pointer to a pointer so that was why I picked the way I picked. This is not a problem that was afflicting me in any way I was just doing to to improve things because someone told me about it and it seemed problematic.

So let me know, am I supposed to recode the API call to take a pointer to a string, modify it and return a pointer to the new beginning? If so... the example func still needs to remove the (quote) " character too. if there is one on both sides of the string

By: Mark Spencer (markster) 2005-05-19 13:59:43

Okay using ast_strip i think this can go in.

By: Anthony Minessale (anthm) 2005-05-19 15:06:41

new patch replaces the real ast_strip with the one markster pasted in the bugnote since it's nicer and adds ast_strip_quoted to strip and remove quotes in 1 step and it also still fixes the whitespace issue.

ast_strip_quoted(string, '"', '"');

By: Kevin P. Fleming (kpfleming) 2005-05-20 12:25:38

Committed to CVS HEAD with API mods as discussed on IRC. Thanks!

By: Digium Subversion (svnbot) 2008-01-15 15:35:49.000-0600

Repository: asterisk
Revision: 5750

U   trunk/funcs/func_logic.c
U   trunk/include/asterisk/utils.h
U   trunk/utils.c

------------------------------------------------------------------------
r5750 | kpfleming | 2008-01-15 15:35:49 -0600 (Tue, 15 Jan 2008) | 2 lines

make IF dialplan function handle quoted strings properly (bug ASTERISK-4220, with API mods)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=5750