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

atis at iq-labs.net atis at iq-labs.net
Wed Apr 22 11:42:29 CDT 2009



> On 2009-04-22 01:16:09, Tilghman Lesher wrote:
> >

Don't forget the UNSHIFT function - to add element in beginning of array :)


- atis


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


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