author | Volker Birk <vb@pep.foundation> |
Wed, 29 Aug 2018 23:57:58 +0200 | |
changeset 22 | 3a2bd70c01df |
parent 20 | c936066cff62 |
permissions | -rw-r--r-- |
20
c936066cff62
keywords as values in decl parameters
Volker Birk <vb@pep.foundation>
parents:
17
diff
changeset
|
1 |
// YML2 standardlib version 2.5.8 |
c936066cff62
keywords as values in decl parameters
Volker Birk <vb@pep.foundation>
parents:
17
diff
changeset
|
2 |
|
0 | 3 |
function "yml:hex2dec" { |
4 |
param "hex"; |
|
5 |
param "_result", 0; |
|
6 |
||
7 |
const "hd", "substring($hex, 1, 1)"; |
|
8 |
const "a", """translate($hd, 'ABCDEFabcdef123456789', |
|
9 |
'123456123456000000000')"""; |
|
10 |
||
11 |
const "d" choose { |
|
12 |
when "$a>0" value "$a + 9"; |
|
13 |
otherwise value "$hd"; |
|
14 |
} |
|
15 |
||
16 |
choose { |
|
17 |
when "string-length($hex) = 1" |
|
18 |
value "$_result * 16 + $d"; |
|
19 |
otherwise call "yml:hex2dec" |
|
20 |
with "hex", "substring($hex, 2, 8)", |
|
21 |
with "_result", "$_result * 16 + $d"; |
|
22 |
} |
|
23 |
} |
|
24 |
||
25 |
function "yml:dec2hex" { |
|
26 |
param "dec"; |
|
27 |
param "bits", !16**7!; |
|
28 |
||
29 |
const "v", "floor($dec div $bits)"; |
|
30 |
value "substring('0123456789abcdef', $v + 1, 1)"; |
|
31 |
||
32 |
if "$bits > 1" call "yml:dec2hex" |
|
33 |
with "dec", "$dec - $bits * $v", |
|
34 |
with "bits", "$bits div 16"; |
|
35 |
} |
|
36 |
||
37 |
def "yml:dec2hex" { |
|
38 |
param "dec"; |
|
39 |
param "digits", 8; |
|
40 |
||
41 |
result call "yml:dec2hex" with "dec", "$dec", with "bits", "math:power(16, $digits - 1)"; |
|
42 |
} |
|
43 |
||
44 |
def "yml:hex2dec" { |
|
45 |
param "hex"; |
|
46 |
result call "yml:hex2dec" with "hex", "$hex"; |
|
47 |
} |
|
48 |
||
49 |
def "yml:lcase" { |
|
50 |
param "text", "''"; |
|
51 |
result "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"; |
|
52 |
} |
|
53 |
||
54 |
def "yml:ucase" { |
|
55 |
param "text", "''"; |
|
56 |
result "translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"; |
|
57 |
} |
|
10 | 58 |
|
59 |
def "yml:mixedCase" { |
|
60 |
param "text", "''"; |
|
61 |
result "concat(yml:lcase(substring($text,1,1)),substring($text,2))"; |
|
62 |
} |
|
63 |
||
17 | 64 |
def "yml:capit" { |
65 |
param "text", "''"; |
|
66 |
result "concat(yml:ucase(substring($text,1,1)),substring($text,2))"; |
|
67 |
} |
|
68 |