vb@20: // YML2 standardlib version 2.5.8 vb@20: vb@0: function "yml:hex2dec" { vb@0: param "hex"; vb@0: param "_result", 0; vb@0: vb@0: const "hd", "substring($hex, 1, 1)"; vb@0: const "a", """translate($hd, 'ABCDEFabcdef123456789', vb@0: '123456123456000000000')"""; vb@0: vb@0: const "d" choose { vb@0: when "$a>0" value "$a + 9"; vb@0: otherwise value "$hd"; vb@0: } vb@0: vb@0: choose { vb@0: when "string-length($hex) = 1" vb@0: value "$_result * 16 + $d"; vb@0: otherwise call "yml:hex2dec" vb@0: with "hex", "substring($hex, 2, 8)", vb@0: with "_result", "$_result * 16 + $d"; vb@0: } vb@0: } vb@0: vb@0: function "yml:dec2hex" { vb@0: param "dec"; vb@0: param "bits", !16**7!; vb@0: vb@0: const "v", "floor($dec div $bits)"; vb@0: value "substring('0123456789abcdef', $v + 1, 1)"; vb@0: vb@0: if "$bits > 1" call "yml:dec2hex" vb@0: with "dec", "$dec - $bits * $v", vb@0: with "bits", "$bits div 16"; vb@0: } vb@0: vb@0: def "yml:dec2hex" { vb@0: param "dec"; vb@0: param "digits", 8; vb@0: vb@0: result call "yml:dec2hex" with "dec", "$dec", with "bits", "math:power(16, $digits - 1)"; vb@0: } vb@0: vb@0: def "yml:hex2dec" { vb@0: param "hex"; vb@0: result call "yml:hex2dec" with "hex", "$hex"; vb@0: } vb@0: vb@0: def "yml:lcase" { vb@0: param "text", "''"; vb@0: result "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"; vb@0: } vb@0: vb@0: def "yml:ucase" { vb@0: param "text", "''"; vb@0: result "translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"; vb@0: } vb@10: vb@10: def "yml:mixedCase" { vb@10: param "text", "''"; vb@10: result "concat(yml:lcase(substring($text,1,1)),substring($text,2))"; vb@10: } vb@10: vb@17: def "yml:capit" { vb@17: param "text", "''"; vb@17: result "concat(yml:ucase(substring($text,1,1)),substring($text,2))"; vb@17: } vb@17: