svghmi/sprintf.js
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 22 Mar 2022 14:50:46 +0100
branchwxPython4
changeset 3442 29dbdb09da2e
parent 3329 d44b6346d4c2
child 3451 302efcf746e0
permissions -rw-r--r--
Tests: fix project edit test sikuli IDE test.

Background click based on bitmap matching doesn't work.
Grid dots are not good match candidates.
Rendering probably affected by virtual display's bpp or rasterizer approximations.
3329
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     1
/* https://github.com/alexei/sprintf.js/blob/master/src/sprintf.js */
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     2
/* global window, exports, define */
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     3
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     4
!function() {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     5
    'use strict'
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     6
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     7
    var re = {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     8
        not_string: /[^s]/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     9
        not_bool: /[^t]/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    10
        not_type: /[^T]/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    11
        not_primitive: /[^v]/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    12
        number: /[diefg]/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    13
        numeric_arg: /[bcdiefguxX]/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    14
        json: /[j]/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    15
        not_json: /[^j]/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    16
        text: /^[^\x25]+/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    17
        modulo: /^\x25{2}/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    18
        placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    19
        key: /^([a-z_][a-z_\d]*)/i,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    20
        key_access: /^\.([a-z_][a-z_\d]*)/i,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    21
        index_access: /^\[(\d+)\]/,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    22
        sign: /^[+-]/
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    23
    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    24
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    25
    function sprintf(key) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    26
        // arguments is not an array, but should be fine for this call
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    27
        return sprintf_format(sprintf_parse(key), arguments)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    28
    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    29
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    30
    function vsprintf(fmt, argv) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    31
        return sprintf.apply(null, [fmt].concat(argv || []))
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    32
    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    33
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    34
    function sprintf_format(parse_tree, argv) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    35
        var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    36
        for (i = 0; i < tree_length; i++) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    37
            if (typeof parse_tree[i] === 'string') {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    38
                output += parse_tree[i]
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    39
            }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    40
            else if (typeof parse_tree[i] === 'object') {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    41
                ph = parse_tree[i] // convenience purposes only
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    42
                if (ph.keys) { // keyword argument
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    43
                    arg = argv[cursor]
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    44
                    for (k = 0; k < ph.keys.length; k++) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    45
                        if (arg == undefined) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    46
                            throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1]))
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    47
                        }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    48
                        arg = arg[ph.keys[k]]
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    49
                    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    50
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    51
                else if (ph.param_no) { // positional argument (explicit)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    52
                    arg = argv[ph.param_no]
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    53
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    54
                else { // positional argument (implicit)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    55
                    arg = argv[cursor++]
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    56
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    57
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    58
                if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    59
                    arg = arg()
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    60
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    61
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    62
                if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    63
                    throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg))
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    64
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    65
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    66
                if (re.number.test(ph.type)) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    67
                    is_positive = arg >= 0
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    68
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    69
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    70
                switch (ph.type) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    71
                    case 'b':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    72
                        arg = parseInt(arg, 10).toString(2)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    73
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    74
                    case 'c':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    75
                        arg = String.fromCharCode(parseInt(arg, 10))
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    76
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    77
                    case 'd':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    78
                    case 'i':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    79
                        arg = parseInt(arg, 10)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    80
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    81
                    case 'j':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    82
                        arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    83
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    84
                    case 'e':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    85
                        arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential()
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    86
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    87
                    case 'f':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    88
                        arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    89
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    90
                    case 'g':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    91
                        arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    92
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    93
                    case 'o':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    94
                        arg = (parseInt(arg, 10) >>> 0).toString(8)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    95
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    96
                    case 's':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    97
                        arg = String(arg)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    98
                        arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    99
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   100
                    case 't':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   101
                        arg = String(!!arg)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   102
                        arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   103
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   104
                    case 'T':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   105
                        arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase()
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   106
                        arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   107
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   108
                    case 'u':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   109
                        arg = parseInt(arg, 10) >>> 0
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   110
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   111
                    case 'v':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   112
                        arg = arg.valueOf()
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   113
                        arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   114
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   115
                    case 'x':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   116
                        arg = (parseInt(arg, 10) >>> 0).toString(16)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   117
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   118
                    case 'X':
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   119
                        arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase()
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   120
                        break
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   121
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   122
                if (re.json.test(ph.type)) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   123
                    output += arg
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   124
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   125
                else {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   126
                    if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   127
                        sign = is_positive ? '+' : '-'
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   128
                        arg = arg.toString().replace(re.sign, '')
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   129
                    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   130
                    else {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   131
                        sign = ''
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   132
                    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   133
                    pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' '
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   134
                    pad_length = ph.width - (sign + arg).length
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   135
                    pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : ''
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   136
                    output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   137
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   138
            }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   139
        }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   140
        return output
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   141
    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   142
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   143
    var sprintf_cache = Object.create(null)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   144
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   145
    function sprintf_parse(fmt) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   146
        if (sprintf_cache[fmt]) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   147
            return sprintf_cache[fmt]
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   148
        }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   149
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   150
        var _fmt = fmt, match, parse_tree = [], arg_names = 0
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   151
        while (_fmt) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   152
            if ((match = re.text.exec(_fmt)) !== null) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   153
                parse_tree.push(match[0])
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   154
            }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   155
            else if ((match = re.modulo.exec(_fmt)) !== null) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   156
                parse_tree.push('%')
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   157
            }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   158
            else if ((match = re.placeholder.exec(_fmt)) !== null) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   159
                if (match[2]) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   160
                    arg_names |= 1
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   161
                    var field_list = [], replacement_field = match[2], field_match = []
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   162
                    if ((field_match = re.key.exec(replacement_field)) !== null) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   163
                        field_list.push(field_match[1])
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   164
                        while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   165
                            if ((field_match = re.key_access.exec(replacement_field)) !== null) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   166
                                field_list.push(field_match[1])
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   167
                            }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   168
                            else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   169
                                field_list.push(field_match[1])
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   170
                            }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   171
                            else {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   172
                                throw new SyntaxError('[sprintf] failed to parse named argument key')
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   173
                            }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   174
                        }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   175
                    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   176
                    else {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   177
                        throw new SyntaxError('[sprintf] failed to parse named argument key')
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   178
                    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   179
                    match[2] = field_list
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   180
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   181
                else {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   182
                    arg_names |= 2
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   183
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   184
                if (arg_names === 3) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   185
                    throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported')
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   186
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   187
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   188
                parse_tree.push(
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   189
                    {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   190
                        placeholder: match[0],
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   191
                        param_no:    match[1],
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   192
                        keys:        match[2],
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   193
                        sign:        match[3],
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   194
                        pad_char:    match[4],
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   195
                        align:       match[5],
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   196
                        width:       match[6],
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   197
                        precision:   match[7],
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   198
                        type:        match[8]
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   199
                    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   200
                )
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   201
            }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   202
            else {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   203
                throw new SyntaxError('[sprintf] unexpected placeholder')
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   204
            }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   205
            _fmt = _fmt.substring(match[0].length)
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   206
        }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   207
        return sprintf_cache[fmt] = parse_tree
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   208
    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   209
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   210
    /**
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   211
     * export to either browser or node.js
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   212
     */
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   213
    /* eslint-disable quote-props */
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   214
    if (typeof exports !== 'undefined') {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   215
        exports['sprintf'] = sprintf
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   216
        exports['vsprintf'] = vsprintf
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   217
    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   218
    if (typeof window !== 'undefined') {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   219
        window['sprintf'] = sprintf
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   220
        window['vsprintf'] = vsprintf
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   221
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   222
        if (typeof define === 'function' && define['amd']) {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   223
            define(function() {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   224
                return {
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   225
                    'sprintf': sprintf,
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   226
                    'vsprintf': vsprintf
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   227
                }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   228
            })
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   229
        }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   230
    }
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   231
    /* eslint-enable quote-props */
d44b6346d4c2 SVGHMI: Move sprintf.js out of widget_display.ysl2 since it is used in other widgets as well
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
   232
}(); // eslint-disable-line