62 function get_type(variable) {
63 return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase();
65 function str_repeat(
input, multiplier) {
71 if (!str_format.cache.hasOwnProperty(arguments[0])) {
72 str_format.cache[arguments[0]] = str_format.parse(arguments[0]);
74 return str_format.format.call(null, str_format.cache[arguments[0]], arguments);
77 str_format.format =
function(
parse_tree, argv) {
78 var cursor = 1, tree_length =
parse_tree.length, node_type =
'', arg,
output = [],
i, k, match, pad, pad_character, pad_length;
79 for (
i = 0;
i < tree_length;
i++) {
81 if (node_type ===
'string') {
84 else if (node_type ===
'array') {
88 for (k = 0; k < match[2].length; k++) {
89 if (!arg.hasOwnProperty(match[2][k])) {
90 throw(
sprintf(
'[sprintf] property "%s" does not exist', match[2][k]));
92 arg = arg[match[2][k]];
102 if (/[^s]/.test(match[8]) && (get_type(arg) !=
'number')) {
103 throw(
sprintf(
'[sprintf] expecting number but found %s', get_type(arg)));
106 case 'b': arg = arg.toString(2);
break;
107 case 'c': arg = String.fromCharCode(arg);
break;
108 case 'd': arg = parseInt(arg, 10);
break;
109 case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential();
break;
110 case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg);
break;
111 case 'o': arg = arg.toString(8);
break;
112 case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg);
break;
113 case 'u': arg = Math.abs(arg);
break;
114 case 'x': arg = arg.toString(16);
break;
115 case 'X': arg = arg.toString(16).toUpperCase();
break;
117 arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ?
'+'+ arg : arg);
118 pad_character = match[4] ? match[4] ==
'0' ?
'0' : match[4].charAt(1) :
' ';
119 pad_length = match[6] - String(arg).length;
120 pad = match[6] ? str_repeat(pad_character, pad_length) :
'';
121 output.push(match[5] ? arg + pad : pad + arg);
124 return output.join(
'');
127 str_format.cache = {};
129 str_format.parse =
function(fmt) {
130 var _fmt = fmt, match = [],
parse_tree = [], arg_names = 0;
132 if ((match = /^[^\x25]+/.exec(_fmt)) !== null) {
135 else if ((match = /^\x25{2}/.exec(_fmt)) !== null) {
138 else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|
'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { 141 var field_list = [], replacement_field = match[2], field_match = []; 142 if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { 143 field_list.push(field_match[1]); 144 while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { 145 if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { 146 field_list.push(field_match[1]); 148 else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { 149 field_list.push(field_match[1]); 159 match[2] = field_list; 164 if (arg_names === 3) { 165 throw('[
sprintf] mixing positional
and named placeholders is not (yet) supported
'); 167 parse_tree.push(match); 172 _fmt = _fmt.substring(match[0].length); 180 var vsprintf = function(fmt, argv) { 182 return sprintf.apply(null, argv);
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
var sprintf
sprintf() for JavaScript 0.7-beta1 http://www.diveintojavascript.com/projects/javascript-sprintf ...
elgg table input[type=checkbox]