svghmi/sprintf.js
author Edouard Tisserant
Thu, 04 Nov 2021 12:02:08 +0100
changeset 3382 589abe084e57
parent 3360 746e3e3f6537
child 3451 302efcf746e0
permissions -rw-r--r--
merged
3360
746e3e3f6537 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 */
746e3e3f6537 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 */
746e3e3f6537 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
746e3e3f6537 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() {
746e3e3f6537 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'
746e3e3f6537 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
746e3e3f6537 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 = {
746e3e3f6537 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]/,
746e3e3f6537 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]/,
746e3e3f6537 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]/,
746e3e3f6537 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]/,
746e3e3f6537 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]/,
746e3e3f6537 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]/,
746e3e3f6537 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]/,
746e3e3f6537 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]/,
746e3e3f6537 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]+/,
746e3e3f6537 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}/,
746e3e3f6537 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])/,
746e3e3f6537 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,
746e3e3f6537 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,
746e3e3f6537 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+)\]/,
746e3e3f6537 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: /^[+-]/
746e3e3f6537 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
    }
746e3e3f6537 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
746e3e3f6537 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) {
746e3e3f6537 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
746e3e3f6537 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)
746e3e3f6537 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
    }
746e3e3f6537 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
746e3e3f6537 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) {
746e3e3f6537 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 || []))
746e3e3f6537 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
    }
746e3e3f6537 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
746e3e3f6537 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) {
746e3e3f6537 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
746e3e3f6537 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++) {
746e3e3f6537 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') {
746e3e3f6537 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]
746e3e3f6537 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
            }
746e3e3f6537 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') {
746e3e3f6537 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
746e3e3f6537 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
746e3e3f6537 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]
746e3e3f6537 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++) {
746e3e3f6537 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) {
746e3e3f6537 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]))
746e3e3f6537 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
                        }
746e3e3f6537 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]]
746e3e3f6537 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
                    }
746e3e3f6537 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
                }
746e3e3f6537 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)
746e3e3f6537 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]
746e3e3f6537 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
                }
746e3e3f6537 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)
746e3e3f6537 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++]
746e3e3f6537 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
                }
746e3e3f6537 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
746e3e3f6537 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) {
746e3e3f6537 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()
746e3e3f6537 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
                }
746e3e3f6537 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
746e3e3f6537 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))) {
746e3e3f6537 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))
746e3e3f6537 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
                }
746e3e3f6537 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
746e3e3f6537 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)) {
746e3e3f6537 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
746e3e3f6537 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
                }
746e3e3f6537 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
746e3e3f6537 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) {
746e3e3f6537 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':
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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))
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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':
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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()
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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)
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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)
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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()
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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()
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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':
746e3e3f6537 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()
746e3e3f6537 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
746e3e3f6537 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
                }
746e3e3f6537 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)) {
746e3e3f6537 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
746e3e3f6537 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
                }
746e3e3f6537 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 {
746e3e3f6537 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)) {
746e3e3f6537 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 ? '+' : '-'
746e3e3f6537 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, '')
746e3e3f6537 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
                    }
746e3e3f6537 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 {
746e3e3f6537 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 = ''
746e3e3f6537 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
                    }
746e3e3f6537 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) : ' '
746e3e3f6537 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
746e3e3f6537 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) : '') : ''
746e3e3f6537 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)
746e3e3f6537 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
                }
746e3e3f6537 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
            }
746e3e3f6537 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
        }
746e3e3f6537 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
746e3e3f6537 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
    }
746e3e3f6537 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
746e3e3f6537 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)
746e3e3f6537 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
746e3e3f6537 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) {
746e3e3f6537 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]) {
746e3e3f6537 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]
746e3e3f6537 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
        }
746e3e3f6537 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
746e3e3f6537 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
746e3e3f6537 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) {
746e3e3f6537 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) {
746e3e3f6537 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])
746e3e3f6537 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
            }
746e3e3f6537 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) {
746e3e3f6537 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('%')
746e3e3f6537 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
            }
746e3e3f6537 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) {
746e3e3f6537 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]) {
746e3e3f6537 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
746e3e3f6537 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 = []
746e3e3f6537 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) {
746e3e3f6537 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])
746e3e3f6537 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)) !== '') {
746e3e3f6537 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) {
746e3e3f6537 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])
746e3e3f6537 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
                            }
746e3e3f6537 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) {
746e3e3f6537 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])
746e3e3f6537 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
                            }
746e3e3f6537 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 {
746e3e3f6537 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')
746e3e3f6537 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
                            }
746e3e3f6537 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
                        }
746e3e3f6537 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
                    }
746e3e3f6537 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 {
746e3e3f6537 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')
746e3e3f6537 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
                    }
746e3e3f6537 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
746e3e3f6537 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
                }
746e3e3f6537 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 {
746e3e3f6537 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
746e3e3f6537 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
                }
746e3e3f6537 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) {
746e3e3f6537 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')
746e3e3f6537 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
                }
746e3e3f6537 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
746e3e3f6537 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(
746e3e3f6537 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
                    {
746e3e3f6537 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],
746e3e3f6537 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],
746e3e3f6537 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],
746e3e3f6537 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],
746e3e3f6537 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],
746e3e3f6537 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],
746e3e3f6537 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],
746e3e3f6537 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],
746e3e3f6537 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]
746e3e3f6537 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
                    }
746e3e3f6537 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
                )
746e3e3f6537 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
            }
746e3e3f6537 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 {
746e3e3f6537 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')
746e3e3f6537 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
            }
746e3e3f6537 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)
746e3e3f6537 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
        }
746e3e3f6537 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
746e3e3f6537 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
    }
746e3e3f6537 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
746e3e3f6537 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
    /**
746e3e3f6537 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
746e3e3f6537 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
     */
746e3e3f6537 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 */
746e3e3f6537 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') {
746e3e3f6537 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
746e3e3f6537 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
746e3e3f6537 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
    }
746e3e3f6537 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') {
746e3e3f6537 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
746e3e3f6537 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
746e3e3f6537 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
746e3e3f6537 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']) {
746e3e3f6537 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() {
746e3e3f6537 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 {
746e3e3f6537 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,
746e3e3f6537 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
746e3e3f6537 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
                }
746e3e3f6537 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
            })
746e3e3f6537 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
        }
746e3e3f6537 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
    }
746e3e3f6537 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 */
746e3e3f6537 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