Using a Function Call

When a variable name contains commas, it is split into a sequence of fragments at their boundaries, and then interpreted as a sequence of function names and their parameters. In the following example:

%{substr,0,4,myvar}

the substr function extracts the first four characters from the value of %myvar. The table below describes the available functions.

Functions can be nested by specifying additional commas in the last argument of the preceding function. In the following example:

%{int,substr,0,4,map}
switch-var='trim,substr,4,,map'

the first line takes the first four characters of the variable and converts them to a canonical integer, the second line takes the remainder, removes leading and trailing spaces, and uses the result in a switch, and so forth.

Function Description
substr,<start>,<size>,<variable> Extracts a substring from the value of the variable. The substring begins at position <start> (counted from 0), and is <size> characters long. If <size> is an empty string, the substring extends up to the end of the value string.
int,<variable> Interprets the value of the variable as an integer and formats it in canonical form, without preceding zeroes or explicit plus (+) sign. If the value is not an integer, the function fails.
trim,<variable> Removes leading and trailing spaces from a string value of the variable.
const,<string> or =,<string> Returns the string as the function result.
warning,<id-num>[,<variable>] Produces the warning specified by <id-num>, a numeric code that identifies the warning in the backend.msg file, and returns the value of the variable. If the variable is not specified, the function fails. So %{warning,12345} is equivalent to %{warning,12345,_fail}.
lookup, <file>, <keyCol>, <valueCol>, <variable> Looks up a value from a comma-separated value (CSV) file. The CSV file is located on disk at <file>. For each line in that file, <keyCol> specifies the column (counted from 0) containing the key to match against <variable> and <valueCol> specifies the column containing the value to return. If <keyCol> is an empty string, column 0 is assumed. If <valueCol> is an empty string, column 1 is assumed. If no matching row is found in the file, an empty string is returned.
upper, <variable> Returns the value of the variable converted to all upper-case characters.
lower, <variable> Returns the value of the variable converted to all lower-case characters.