~ubuntu-branches/ubuntu/saucy/phpmyadmin/saucy-proposed

« back to all changes in this revision

Viewing changes to js/jquery/jquery.sprintf.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-08-04 13:24:37 UTC
  • mfrom: (1.2.44)
  • Revision ID: package-import@ubuntu.com-20130804132437-jznw8efwy4hr1nms
Tags: 4:4.0.5-1
* New upstream release.
  - Fixes security issue PMASA-2013-10.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(function(d){var a={b:function(e){return parseInt(e,10).toString(2)},c:function(e){return String.fromCharCode(parseInt(e,10))},d:function(e){return parseInt(e,10)},u:function(e){return Math.abs(e)},f:function(f,e){e=parseInt(e,10);f=parseFloat(f);if(isNaN(e&&f)){return NaN}return e&&f.toFixed(e)||f},o:function(e){return parseInt(e,10).toString(8)},s:function(e){return e},x:function(e){return(""+parseInt(e,10).toString(16)).toLowerCase()},X:function(e){return(""+parseInt(e,10).toString(16)).toUpperCase()}};var c=/%(?:(\d+)?(?:\.(\d+))?|\(([^)]+)\))([%bcdufosxX])/g;var b=function(f){if(f.length==1&&typeof f[0]=="object"){f=f[0];return function(i,h,k,j,g,m,l){return a[g](f[j])}}else{var e=0;return function(i,h,k,j,g,m,l){if(g=="%"){return"%"}return a[g](f[e++],k)}}};d.extend({sprintf:function(f){var e=Array.apply(null,arguments).slice(1);return f.replace(c,b(e))},vsprintf:function(f,e){return f.replace(c,b(e))}})})(jQuery);
 
 
b'\\ No newline at end of file'
 
1
/**
 
2
 * sprintf and vsprintf for jQuery
 
3
 * somewhat based on http://jan.moesen.nu/code/javascript/sprintf-and-printf-in-javascript/
 
4
 *
 
5
 * Copyright (c) 2008 Sabin Iacob (m0n5t3r) <iacobs@m0n5t3r.info>
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * @license http://www.gnu.org/licenses/gpl.html
 
17
 * @project jquery.sprintf
 
18
 */
 
19
(function($){
 
20
        var formats = {
 
21
                'b': function(val) {return parseInt(val, 10).toString(2);},
 
22
                'c': function(val) {return String.fromCharCode(parseInt(val, 10));},
 
23
                'd': function(val) {return parseInt(val, 10);},
 
24
                'u': function(val) {return Math.abs(val);},
 
25
                'f': function(val, p) {
 
26
                        p = parseInt(p, 10);
 
27
                        val = parseFloat(val);
 
28
                        if(isNaN(p && val)) {
 
29
                                return NaN;
 
30
                        }
 
31
                        return p && val.toFixed(p) || val;
 
32
                },
 
33
                'o': function(val) {return parseInt(val, 10).toString(8);},
 
34
                's': function(val) {return val;},
 
35
                'x': function(val) {return ('' + parseInt(val, 10).toString(16)).toLowerCase();},
 
36
                'X': function(val) {return ('' + parseInt(val, 10).toString(16)).toUpperCase();}
 
37
        };
 
38
 
 
39
        var re = /%(?:(\d+)?(?:\.(\d+))?|\(([^)]+)\))([%bcdufosxX])/g;
 
40
 
 
41
        var dispatch = function(data){
 
42
                if(data.length == 1 && typeof data[0] == 'object') { //python-style printf
 
43
                        data = data[0];
 
44
                        return function(match, w, p, lbl, fmt, off, str) {
 
45
                                return formats[fmt](data[lbl]);
 
46
                        };
 
47
                } else { // regular, somewhat incomplete, printf
 
48
                        var idx = 0;
 
49
                        return function(match, w, p, lbl, fmt, off, str) {
 
50
                                if(fmt == '%') {
 
51
                                        return '%';
 
52
                                }
 
53
                                return formats[fmt](data[idx++], p);
 
54
                        };
 
55
                }
 
56
        };
 
57
 
 
58
        $.extend({
 
59
                sprintf: function(format) {
 
60
                        var argv = Array.apply(null, arguments).slice(1);
 
61
                        return format.replace(re, dispatch(argv));
 
62
                },
 
63
                vsprintf: function(format, data) {
 
64
                        return format.replace(re, dispatch(data));
 
65
                }
 
66
        });
 
67
})(jQuery);
 
68