[asterisk-dev] [Code Review] Add stack-like functions for manipulating comma-separated lists in the dialplan

Terry Wilson twilson at digium.com
Wed Apr 22 11:32:45 CDT 2009



> On 2009-04-22 02:07:07, Mark Michelson wrote:
> > Once Tilghman's two concerns are addressed, I give a "ship it!" to the code's execution.
> > 
> > Looking at the code, though, I realized that it would not be very difficult to enhance these functions to be able to use a different separator character than the comma. Would it be worth it to add the ability to override the default use of the comma as the separator character for these functions?

fixed


- Terry


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviewboard.digium.com/r/230/#review733
-----------------------------------------------------------


On 2009-04-22 11:31:52, Terry Wilson wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://reviewboard.digium.com/r/230/
> -----------------------------------------------------------
> 
> (Updated 2009-04-22 11:31:52)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> Currently there exists the ARRAY() dialplan function for setting multiple variables to the values in a comma-separated list.  This is only useful if the size of the list is known beforehand.  This patch adds the functions SHIFT(), POP(), and PUSH() for dealing with comma-separated lists of unknown length.  PUSH() and POP() add and remove a value to the end of the list (top of the stack), while SHIFT() removes a value from the front of a list.
> 
> I originally found a need for this when working on my calendaring branch.  I needed to be able to return a list of attendees to the dialplan and to be able to iterate over them.  As an example, I can now do something like:
> exten => s,1,Set(attendees=${EVENT_ATTENDEES()})
> exten => s,n,While($[${SET(attendee=${SHIFT(attendees)})}])
> exten => s,n,NoOp(Attendee is ${attendee})
> exten => s,n,EndWhile
> 
> instead of having to mess with using CUT(), maintaining a count for the offset, etc.  From what I can tell perl, python, and php all consider push and pop to operate on the "right-hand" side of a list.
> 
> 
> Diffs
> -----
> 
>   /trunk/funcs/func_strings.c 189273 
> 
> Diff: http://reviewboard.digium.com/r/230/diff
> 
> 
> Testing
> -------
> 
> I've tested most of the cases I can think of, like pushing to non-existent variables, pushing multiple values, shift and pop with a variable with a single or multiple entries, etc.
> 
> 
> Thanks,
> 
> Terry
> 
>




More information about the asterisk-dev mailing list