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:transformations:devel [2009/10/21 16:32]
87.95.89.72
cookbooks:transformations:devel [2011/11/09 12:34] (current)
193.146.38.124 old revision restored
Line 66: Line 66:
  
 <code> <code>
-xlog("MD4 over From username: $(fU{s.md5})");+xlog("md5 over From username: $(fU{s.md5})");
 </code> </code>
 +
 ==== {s.substr,offset,length} ==== ==== {s.substr,offset,length} ====
  
Line 139: Line 140:
 Return string with upper case ASCII letters. Return string with upper case ASCII letters.
  
 +==== {s.strip,len} ====
 +
 +Return string after removing starting 'len' characters. Parameter 'len' can be positive integer or pseudo-variable holding a positive integer.
 +
 +Example:
 +
 +<code c>
 +$var(x) = "1234";
 +$var(y) = $(var(x){s.strip,2}); # resulted value is "34"
 +</code>
 +
 +==== {s.striptail,len} ====
 +
 +Return string after removing ending 'len' characters. Parameter 'len' can be positive integer or pseudo-variable holding a positive integer.
 +
 +==== {s.prefixes[,len]} ====
 +
 +Return series of comma separated prefixes of the pv. Parameter 'len' is optional and will limit the maximum prefix length.
 +
 +Example:
 +<code c>
 +$var(x) = "123456";
 +$(var(x){s.prefixes}) => 1,12,123,1234,12345,123456
 +$(var(x){s.prefixes,4} => 1,12,123,1234
 +</code>
 +
 +
 +==== {s.prefixes.quoted[,len]} ====
 +
 +Return series of comma separated quoted prefixes of the pv. Parameter 'len' is optional and will limit the maximum prefix length.
 +
 +Example: 
 +<code c>
 +$var(x) = "123456";
 +$(var(x){s.prefixes.quoted} => '1','12','123','1234','12345','123456'
 +$(var(x){s.prefixes.quoted,4} => '1','12','123','1234'
 +</code>
  
 ===== URI Transformations ===== ===== URI Transformations =====
Line 318: Line 356:
 <hi #c0c0c0>This transformation class is exported by **textops** module.</hi> <hi #c0c0c0>This transformation class is exported by **textops** module.</hi>
  
-Access parts of a ToBody-like structure. 
-  
  
 ==== {re.subst,expression} ==== ==== {re.subst,expression} ====
Line 325: Line 361:
 Perform Perl-like substitutions on string value pseudo-variables. Perform Perl-like substitutions on string value pseudo-variables.
  
-<code>+<code c>
 # Assign Request-URI user to PV # Assign Request-URI user to PV
 $var(user) = $(ru{re.subst,/^sip:(.*)@(.*)/\1/}); $var(user) = $(ru{re.subst,/^sip:(.*)@(.*)/\1/});
 </code> </code>
  
-<code> +<code c
-# Assign Request-URI user, where every 'A' has been replaced by 'a' +# Assign Request-URI user to PV, where every 'A' has been replaced by 'a' 
-$var(user) = $(rU{re.subst,/A/a/g/});+$var(user) = $(rU{re.subst,/A/a/g});
 </code> </code>
 +
 +The prototype is:
 +
 +<code c>
 +{re.subst,/match_expression/replacement_expression/flags}
 +</code>
 +
 +  * match_expression - Posix regular expression
 +  * replacement_expression - substitution expression with back references to matched tokes: \1, \2, ..., \9
 +  * flags:
 +    * i - match ignore case
 +    * s - match within multi-lines strings
 +    * g - replace all matches
 +
 +===== SQL Transformations =====
 +
 +<hi #c0c0c0>The transformations in this class are exported by the **sqlops** module.</hi>
 +
 +==== {sql.val} ====
 +
 +This transformation outputs valid SQL values for various PV values:
 +  * <null> values are output as NULL
 +  * integers are output as integers
 +  * everything else is output as quoted and escaped string
 +    
 +<code c>
 +    $var(null) = $null;
 +    $avp(null) = $null;
 +    $avp(str) = "String with \ illegal \\characters";
 +    $avp(nr) = 12345;
 +    $avp(strnr) = "12345";
 +    
 +    xlog("$$rm = $rm = $(rm{s.sql})");
 +    xlog("$$var(null) = $var(null) = $(var(null){s.sql})");
 +    xlog("$$avp(null) = $avp(null) = $(avp(null){s.sql})");
 +    xlog("$$avp(str) = $avp(str) = $(avp(str){s.sql})");
 +    xlog("$$avp(nr) = $avp(nr) = $(avp(nr){s.sql})");
 +    xlog("$$avp(strnr) = $avp(strnr) = $(avp(strnr){s.sql})");
 +
 +  Output:
 +    $rm = ACK = 'ACK'
 +    $var(null) = 0 = 0
 +    $avp(null) = <null> = NULL
 +    $avp(str) = String with \ illegal \characters = 'String with \\ illegal \\characters'
 +    $avp(nr) = 12345 = 12345
 +    $avp(strnr) = 12345 = '12345'
 +</code>
 +
 +==== {sql.val.int} ====
 +
 +Like sql.val, but output number 0 for null values.
 +
 +==== {sql.val.str} ====
 +
 +Like sql.val, but output string '' for null values.
  
 ===== Examples ===== ===== Examples =====

Navigation

Wiki

Other

QR Code
QR Code cookbooks:transformations:devel (generated for current page)