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