User Tools

Site Tools


cookbooks:devel:transformations

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cookbooks:devel:transformations [2021/06/01 10:40]
miconda [{param.value,name[, delimiter]}]
cookbooks:devel:transformations [2022/04/08 18:08] (current)
miconda [URI Alias Transformations]
Line 381: Line 381:
 ==== {s.after,x} ==== ==== {s.after,x} ====
  
-Return the part of the string after the character **x**. If the character **x** is not found, it returns empty string.+Return the part of the string after the character **x** searched from the start of the value. If the character **x** is not found, it returns empty string.
  
 <code c> <code c>
Line 388: Line 388:
 </code> </code>
  
 +==== {s.rafter,x} ====
 +
 +Return the part of the string after the character **x** searched from the end of the value. If the character **x** is not found, it returns empty string.
 +
 +<code c>
 +"abcdefcgh"{s.rafter,c}
 +# will return "gh"
 +</code>
 ==== {s.before,x} ==== ==== {s.before,x} ====
  
-Return the part of the string before the character **x**. If the character **x** is not found, it returns the entire input string.+Return the part of the string before the character **x** searched from the start of the value. If the character **x** is not found, it returns the entire input string.
  
 <code c> <code c>
 "abcdef"{s.before,c} "abcdef"{s.before,c}
 # will return "ab" # will return "ab"
 +</code>
 +
 +==== {s.rbefore,x} ====
 +
 +Return the part of the string before the character **x** searched from the end of the value. If the character **x** is not found, it returns the entire input string.
 +
 +<code c>
 +"abcdefcgh"{s.rbefore,c}
 +# will return "abcdef"
 +</code>
 +
 +==== {s.fmtlines,n,m} ====
 +
 +Format the value in lines of n characters, adding m spaces to the start of each new line (not to first line). Each line is ended with "\r\n" apart of last line.
 +
 +<code c>
 +"abcdefgh"{s.fmtlines,4,2}
 +</code>
 +
 +==== {s.fmtlinet,n,m} ====
 +
 +Format the value in lines of n characters, adding m tabs to the start of each new line (not to first line). Each line is ended with "\r\n" apart of last line.
 +
 +<code c>
 +"abcdefgh"{s.fmtlinet,4,2}
 </code> </code>
 ==== {s.urlencode.param} ==== ==== {s.urlencode.param} ====
Line 661: Line 694:
 ==== {line.at,pos} ==== ==== {line.at,pos} ====
  
-Return the line at position 'pos'. The index start from 0. Negative position can be used to count from last line (which is -1).+Return the line at position 'pos'. The index start from 0. Negative position can be used to count from last line (which is -1). The pos can be also a variable holding the index value.
  
 Example: Example:
Line 844: Line 877:
  
 </code> </code>
 +
 +===== Socket Address Transformations =====
 +
 +Transformations related to socket address values (**proto:host:port**).
 +
 +==== {sock.host} ====
 +
 +Return the host part.
 +
 +==== {sock.port} ====
 +
 +Return the port part.
 +
 +==== {sock.proto} ====
 +
 +Return the proto part.
 +
 +==== {sock.touri} ====
 +
 +Return the socket address converted to SIP URI: **sip:host:port;transport=proto**.
  
 ===== URI Alias Transformations ===== ===== URI Alias Transformations =====
Line 865: Line 918:
 </code> </code>
  
 +===== Value Transformations  =====
 +
 +Exported by **pv** module.
 +
 +==== {val.json} ====
 +
 +If value is $null, return empty string; if value is string, then it is escaped for use as json value (without surrounding quotes.
 +
 +<code c>
 +$var(x) = '"name" <sip:name@a.com>';
 +$(var(x){val.json}) => \"name\" <sip:name@a.com>
 +</code>
 +
 +==== {val.n0} ====
 +
 +Return integer 0 for values that are $null.
 +
 +<code c>
 +$sht(a=>x) = $null;
 +$(sht(a=>x){val.n0}) => 0
 +</code>
 +
 +==== {val.ne} ====
 +
 +Return empty string for values that are $null.
 +
 +<code c>
 +$sht(a=>x) = $null;
 +# $(sht(a=>x){val.ne});
 +</code>
 +
 +==== {val.jsonqe} ====
 +
 +If value is $null, return quoted empty string; if value is string, then it is escaped for use as json value already with surrounding quotes; if the value is int, then it is preserved as it is.
 +
 +<code c>
 +$var(x) = '"name" <sip:name@a.com>';
 +$(var(x){val.jsonqe}) => "\"name\" <sip:name@a.com>"
 +</code>
cookbooks/devel/transformations.1622536844.txt.gz ยท Last modified: 2021/06/01 10:40 by miconda