Dictionary Lookups
The following functions perform lookups based on dictionary names and numbers.
The functions are defined in the dict module. It must be listed in
the mods-enabled/
directory in order for the expansions to work.
%str.concat(<ref:[idx]>, <delim>)
Used to join two or more attributes, separated by an optional delimiter.
In most cases, %str.concat(…)
is only useful inside of a dynamically
expanded string. If you need to concatenate strings together in a policy, just use +
.
control += {
Tmp-String-0 = "aaa"
Tmp-String-0 = "bb"
Tmp-String-0 = "c"
}
reply += {
Reply-Message = "%str.concat(%{control.Tmp-String-0[*]}, ', ')"
Reply-Message = "%str.concat(%{control.Tmp-String-0[*]}, ',')"
}
aaa, bb, c
aaa,bb,c
string foo
foo += { "a", "c", "c", "d" } # abcd
foo += control.Tmp-String-0[*]
%str.split(<ref>, <delim>)
Split an string into multiple new strings based on a delimiter.
This expansion is the opposite of %str.concat( … )
.
control.Tmp-String-0 := "bob.toba@domain.com"
control.Tmp-String-1 := "%str.split(control.Tmp-String-0, '@')"
reply.Reply-Message := "Welcome %{control.Tmp-String-1[0]}"
Welcome bob.toba
%str.lpad(<string>, <val>, <char>)
Left-pad a string.
control.Tmp-String-0 := "123"
reply.Reply-Message := "Maximum should be %str.lpad(%{control.Tmp-String-0}, 11, '0')"
Maximum should be 00000000123
%str.rpad(<string>, <val>, <char>)
Right-pad a string.
control.Tmp-String-0 := "123"
reply.Reply-Message := "Maximum should be %str.rpad(%{control.Tmp-String-0}, 11, '0')"
Maximum should be 12300000000
%str.lower( … )
Dynamically expands the string and returns the lowercase version of it. This definition is only available in version 2.1.10 and later.
control.Tmp-String-0 := "CAIPIRINHA"
reply.Reply-Message := "tolower of %{control.Tmp-String-0} is %str.lower(%{control.Tmp-String-0})"
tolower of CAIPIRINHA is caipirinha
%str.upper( … )
Dynamically expands the string and returns the uppercase version of it. This definition is only available in version 2.1.10 and later.
control.Tmp-String-0 := "caipirinha"
reply.Reply-Message := "toupper of %{control.Tmp-String-0} is " + %str.upper(%{control.Tmp-String-0})
toupper of caipirinha is CAIPIRINHA