|
1 function "yml:hex2dec" { |
|
2 param "hex"; |
|
3 param "_result", 0; |
|
4 |
|
5 const "hd", "substring($hex, 1, 1)"; |
|
6 const "a", """translate($hd, 'ABCDEFabcdef123456789', |
|
7 '123456123456000000000')"""; |
|
8 |
|
9 const "d" choose { |
|
10 when "$a>0" value "$a + 9"; |
|
11 otherwise value "$hd"; |
|
12 } |
|
13 |
|
14 choose { |
|
15 when "string-length($hex) = 1" |
|
16 value "$_result * 16 + $d"; |
|
17 otherwise call "yml:hex2dec" |
|
18 with "hex", "substring($hex, 2, 8)", |
|
19 with "_result", "$_result * 16 + $d"; |
|
20 } |
|
21 } |
|
22 |
|
23 function "yml:dec2hex" { |
|
24 param "dec"; |
|
25 param "bits", !16**7!; |
|
26 |
|
27 const "v", "floor($dec div $bits)"; |
|
28 value "substring('0123456789abcdef', $v + 1, 1)"; |
|
29 |
|
30 if "$bits > 1" call "yml:dec2hex" |
|
31 with "dec", "$dec - $bits * $v", |
|
32 with "bits", "$bits div 16"; |
|
33 } |
|
34 |
|
35 def "yml:dec2hex" { |
|
36 param "dec"; |
|
37 param "digits", 8; |
|
38 |
|
39 result call "yml:dec2hex" with "dec", "$dec", with "bits", "math:power(16, $digits - 1)"; |
|
40 } |
|
41 |
|
42 def "yml:hex2dec" { |
|
43 param "hex"; |
|
44 result call "yml:hex2dec" with "hex", "$hex"; |
|
45 } |
|
46 |
|
47 def "yml:lcase" { |
|
48 param "text", "''"; |
|
49 result "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"; |
|
50 } |
|
51 |
|
52 def "yml:ucase" { |
|
53 param "text", "''"; |
|
54 result "translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"; |
|
55 } |