text stringlengths 0 152 |
|---|
expr1 & expr2 |
This operator (called “and”) returns the evaluation of expr1 if both expres‐ |
sions are true (i.e., neither expression evaluates to an empty string or zero). |
Otherwise, it returns zero. |
expr1 {=, >, >=, <, <=, !=} expr2 |
These operators return the results of an integer comparison if both argu‐ |
ments are integers; otherwise, they return the results of a string comparison. |
The result of each comparison is 1 if the specified relation is true, or 0 if the |
relation is false. (If you are doing string comparisons, they will be done in a |
manner that’s consistent with the current local settings of your operating |
system.) |
Mathematical operators |
Want to perform a calculation? You’ll want one of these: |
expr1 {+, -} expr2 |
These operators return the results of the addition or subtraction of integer- |
valued arguments. |
expr1 {*, /, %} expr2 |
These return, respectively, the results of the multiplication, integer division, |
or remainder of integer-valued arguments. |
Regular expression operator |
You can also use the regular expression operator in Asterisk: |
Expressions and Variable Manipulation |
| |
165 |
Some additional information about the peculiarities of the reg‐ |
ular expression operator in Asterisk can be found at Walter |
Doekes’s website. |
expr1 : expr2 |
This operator matches expr1 against expr2, where expr2 must be a regular |
expression.2 The regular expression is anchored to the beginning of the |
string with an implicit ^.3 |
If the pattern contains no subexpression, the number of matched characters |
is returned. This will be 0 if the match failed. If the pattern contains a subex‐ |
pression -- \(...\) -- the string corresponding to \1 is returned. If the |
match fails, the empty string is returned. |
expr1 =~ expr2 |
This operator works the same as the : operator, except that it is not anchored |
to the beginning. |
Dialplan Functions |
Dialplan functions allow you to add more power to your expressions; you can think |
of them as intelligent variables. Dialplan functions allow you to calculate string |
lengths, dates and times, MD5 checksums, and so on, all from within a dialplan |
expression. |
You’ll see usage of Playback(silence/1) throughout the examples |
in this chapter. We are doing this as it will answer the line if it |
hasn’t already been answered for us, and plays back some silence on |
the line. This allows other applications such as SayNumber() to play |
back audio without gaps. |
Syntax |
Dialplan functions have the following basic syntax: |
FUNCTION_NAME(argument) |
2 For more on regular expressions, grab a copy of the ultimate reference, Jeffrey E. F. Friedl’s Mastering Regular |
Expressions (O’Reilly, 2006), or visit http://www.regular-expressions.info. |
3 If you don’t know what a ^ has to do with regular expressions, you simply must read Mastering Regular |
Expressions. It will change your life! |
166 |
| |
Chapter 10: Deeper into the Dialplan |
You reference a function’s name the same way as a variable’s name, but you reference |
a function’s value with the addition of a dollar sign, an opening curly brace, and a |
closing curly brace: |
${FUNCTION_NAME(argument)} |
Functions can also encapsulate other functions, like so: |
${FUNCTION_NAME(${FUNCTION_NAME(argument)})} |
^ ^ ^ ^ ^^^^ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.