printj/bits/54_convmisc.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-09-19 06:33:23 +00:00
/* JS has no concept of pointers so interpret the `l` key as an address */
case /*p*/ 112:
Vnum = typeof arg == "number" ? arg : arg ? Number(arg.l) : -1;
2016-09-19 06:33:23 +00:00
if(isnan(Vnum)) Vnum = -1;
if(alt) O = Vnum.toString(10);
else {
CONV_SIZE_T(Vnum)
O = "0x" + SIZE_T_TO_HEX(Vnum).toLowerCase();
}
break;
/* store length in the `len` key */
case /*n*/ 110:
if(arg) { arg.len=0; for(var oo/*:number*/ = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
2016-09-19 06:33:23 +00:00
continue;
/* process error */
case /*m*/ 109:
if(!(arg instanceof Error)) O = "Success";
else if(arg.message) O = arg.message;
else if(arg.errno) O = "Error number " + arg.errno;
else O = "Error " + String(arg);
break;
/* JS-specific conversions (extension) */
case /*J*/ 74: O = (alt ? u_inspect : JSON.stringify)(arg); break;
case /*V*/ 86: O = arg == null ? "null" : String(arg.valueOf()); break;
2016-09-19 06:33:23 +00:00
case /*T*/ 84:
if(alt) { /* from '[object %s]' extract %s */
O = Object.prototype.toString.call(arg).substr(8);
O = O.substr(0, O.length - 1);
} else O = typeof arg;
break;
/* boolean (extension) */
case /*Y*/ 89:
case /*y*/ 121:
O = Boolean(arg) ? (alt ? "yes" : "true") : (alt ? "no" : "false");
if(c == /*Y*/ 89) O = O.toUpperCase();
PREC_STR(O, prec)
WIDTH(O, width, flags)
break;