[asterisk-dev] [Code Review] Add stack-like functions for manipulating comma-separated lists in the dialplan
Tilghman Lesher
tlesher at digium.com
Wed Apr 22 01:16:09 CDT 2009
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviewboard.digium.com/r/230/#review732
-----------------------------------------------------------
/trunk/funcs/func_strings.c
<http://reviewboard.digium.com/r/230/#comment1881>
You have POP() in this example, while I think you meant to have SHIFT().
/trunk/funcs/func_strings.c
<http://reviewboard.digium.com/r/230/#comment1882>
I think a much more logical syntax would be:
Set(PUSH(array)=one,two,three)
- Tilghman
On 2009-04-22 00:18:58, Terry Wilson wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://reviewboard.digium.com/r/230/
> -----------------------------------------------------------
>
> (Updated 2009-04-22 00:18:58)
>
>
> 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