Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

printj.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /* printj.js (C) 2016-present SheetJS -- http://sheetjs.com */
  2. /* vim: set ts=2: */
  3. /*jshint sub:true, eqnull:true */
  4. /*exported PRINTJ */
  5. var PRINTJ;
  6. (function (factory) {
  7. /*jshint ignore:start */
  8. /*eslint-disable */
  9. if(typeof DO_NOT_EXPORT_PRINTJ === 'undefined') {
  10. if('object' === typeof exports) {
  11. factory(exports);
  12. } else if ('function' === typeof define && define.amd) {
  13. define(function () {
  14. var module = {};
  15. factory(module);
  16. return module;
  17. });
  18. } else {
  19. factory(PRINTJ = {});
  20. }
  21. } else {
  22. factory(PRINTJ = {});
  23. }
  24. /*eslint-enable */
  25. /*jshint ignore:end */
  26. }(function(PRINTJ) {
  27. PRINTJ.version = '1.1.2';
  28. function tokenize(fmt) {
  29. var out = [];
  30. var start = 0;
  31. var i = 0;
  32. var infmt = false;
  33. var fmtparam = "", fmtflags = "", fmtwidth = "", fmtprec = "", fmtlen = "";
  34. var c = 0;
  35. var L = fmt.length;
  36. for(; i < L; ++i) {
  37. c = fmt.charCodeAt(i);
  38. if(!infmt) {
  39. if(c !== 37) continue;
  40. if(start < i) out.push(["L", fmt.substring(start, i)]);
  41. start = i;
  42. infmt = true;
  43. continue;
  44. }
  45. if(c >= 48 && c < 58) {
  46. if(fmtprec.length) fmtprec += String.fromCharCode(c);
  47. else if(c == 48 && !fmtwidth.length) fmtflags += String.fromCharCode(c);
  48. else fmtwidth += String.fromCharCode(c);
  49. } else switch(c) {
  50. /* positional */
  51. case 36:
  52. if(fmtprec.length) fmtprec += "$";
  53. else if(fmtwidth.charAt(0) == "*") fmtwidth += "$";
  54. else { fmtparam = fmtwidth + "$"; fmtwidth = ""; }
  55. break;
  56. /* flags */
  57. case 39: fmtflags += "'"; break;
  58. case 45: fmtflags += "-"; break;
  59. case 43: fmtflags += "+"; break;
  60. case 32: fmtflags += " "; break;
  61. case 35: fmtflags += "#"; break;
  62. /* width and precision */
  63. case 46: fmtprec = "."; break;
  64. case 42:
  65. if(fmtprec.charAt(0) == ".") fmtprec += "*";
  66. else fmtwidth += "*";
  67. break;
  68. /* length */
  69. case 104:
  70. case 108:
  71. if(fmtlen.length > 1) throw "bad length " + fmtlen + String(c);
  72. fmtlen += String.fromCharCode(c);
  73. break;
  74. case 76:
  75. case 106:
  76. case 122:
  77. case 116:
  78. case 113:
  79. case 90:
  80. case 119:
  81. if(fmtlen !== "") throw "bad length " + fmtlen + String.fromCharCode(c);
  82. fmtlen = String.fromCharCode(c);
  83. break;
  84. case 73:
  85. if(fmtlen !== "") throw "bad length " + fmtlen + 'I';
  86. fmtlen = 'I';
  87. break;
  88. /* conversion */
  89. case 100:
  90. case 105:
  91. case 111:
  92. case 117:
  93. case 120:
  94. case 88:
  95. case 102:
  96. case 70:
  97. case 101:
  98. case 69:
  99. case 103:
  100. case 71:
  101. case 97:
  102. case 65:
  103. case 99:
  104. case 67:
  105. case 115:
  106. case 83:
  107. case 112:
  108. case 110:
  109. case 68:
  110. case 85:
  111. case 79:
  112. case 109:
  113. case 98:
  114. case 66:
  115. case 121:
  116. case 89:
  117. case 74:
  118. case 86:
  119. case 84:
  120. case 37:
  121. infmt = false;
  122. if(fmtprec.length > 1) fmtprec = fmtprec.substr(1);
  123. out.push([String.fromCharCode(c), fmt.substring(start, i+1), fmtparam, fmtflags, fmtwidth, fmtprec, fmtlen]);
  124. start = i+1;
  125. fmtlen = fmtprec = fmtwidth = fmtflags = fmtparam = "";
  126. break;
  127. default:
  128. throw new Error("Invalid format string starting with |" + fmt.substring(start, i+1) + "|");
  129. }
  130. }
  131. if(start < fmt.length) out.push(["L", fmt.substring(start)]);
  132. return out;
  133. }
  134. //#define PAD_(x,c) (x >= 0 ? new Array(((x)|0) + 1).join((c)) : "")
  135. var padstr = {
  136. " ": " ",
  137. "0": "000000000000000000000000000000000",
  138. "7": "777777777777777777777777777777777",
  139. "f": "fffffffffffffffffffffffffffffffff"
  140. };
  141. /*global process:true, util:true, require:true */
  142. if(typeof process !== 'undefined' && !!process.versions && !!process.versions.node) util=require("util");
  143. var u_inspect = (typeof util != 'undefined') ? util.inspect : JSON.stringify;
  144. function doit(t, args) {
  145. var o = [];
  146. var argidx = 0, idx = 0;
  147. var Vnum = 0;
  148. var pad = "";
  149. for(var i = 0; i < t.length; ++i) {
  150. var m = t[i], c = (m[0]).charCodeAt(0);
  151. /* m order: conv full param flags width prec length */
  152. if(c === /*L*/ 76) { o.push(m[1]); continue; }
  153. if(c === /*%*/ 37) { o.push("%"); continue; }
  154. var O = "";
  155. var isnum = 0, radix = 10, bytes = 4, sign = false;
  156. /* flags */
  157. var flags = m[3]||"";
  158. var alt = flags.indexOf("#") > -1;
  159. /* position */
  160. if(m[2]) argidx = parseInt(m[2])-1;
  161. /* %m special case */
  162. else if(c === /*m*/ 109 && !alt) { o.push("Success"); continue; }
  163. /* grab width */
  164. var width = 0; if(m[ 4] != null && m[ 4].length > 0) { if(m[ 4].charAt(0) !== '*') width = parseInt(m[ 4], 10); else if(m[ 4].length === 1) width = args[idx++]; else width = args[parseInt(m[ 4].substr(1), 10)-1]; }
  165. /* grab precision */
  166. var prec = -1; if(m[ 5] != null && m[ 5].length > 0) { if(m[ 5].charAt(0) !== '*') prec = parseInt(m[ 5], 10); else if(m[ 5].length === 1) prec = args[idx++]; else prec = args[parseInt(m[ 5].substr(1), 10)-1]; }
  167. /* position not specified */
  168. if(!m[2]) argidx = idx++;
  169. /* grab argument */
  170. var arg = args[argidx];
  171. /* grab length */
  172. var len = m[6] || "";
  173. switch(c) {
  174. /* str cCsS */
  175. case /*S*/ 83:
  176. case /*s*/ 115:
  177. /* only valid flag is "-" for left justification */
  178. O = String(arg);
  179. if( prec >= 0) O = O.substr(0, prec);
  180. if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
  181. break;
  182. /* first char of string or convert */
  183. case /*C*/ 67:
  184. case /*c*/ 99:
  185. switch(typeof arg) {
  186. case "number":
  187. var cc = arg;
  188. if(c == 67 || len.charCodeAt(0) === /*l*/ 108) { cc &= 0xFFFFFFFF; O = String.fromCharCode( cc); }
  189. else { cc &= 0xFF; O = String.fromCharCode( cc); }
  190. break;
  191. case "string": O = arg.charAt(0); break;
  192. default: O = String(arg).charAt(0);
  193. }
  194. if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
  195. break;
  196. /* int diDuUoOxXbB */
  197. /* signed integer */
  198. case /*D*/ 68: bytes = 8;
  199. /* falls through */
  200. case /*d*/ 100:
  201. case /*i*/ 105: isnum = -1; sign = true; break;
  202. /* unsigned integer */
  203. case /*U*/ 85: bytes = 8;
  204. /* falls through */
  205. case /*u*/ 117: isnum = -1; break;
  206. /* unsigned octal */
  207. case /*O*/ 79: bytes = 8;
  208. /* falls through */
  209. case /*o*/ 111: isnum = -1; radix = (8); break;
  210. /* unsigned hex */
  211. case /*x*/ 120: isnum = -1; radix = (-16); break;
  212. case /*X*/ 88: isnum = -1; radix = (16); break;
  213. /* unsigned binary (extension) */
  214. case /*B*/ 66: bytes = 8;
  215. /* falls through */
  216. case /*b*/ 98: isnum = -1; radix = (2); break;
  217. /* flt fegFEGaA */
  218. /* floating point logic */
  219. case /*F*/ 70:
  220. case /*f*/ 102: isnum = (1); break;
  221. case /*E*/ 69:
  222. case /*e*/ 101: isnum = (2); break;
  223. case /*G*/ 71:
  224. case /*g*/ 103: isnum = (3); break;
  225. /* floating hex */
  226. case /*A*/ 65:
  227. case /*a*/ 97: isnum = (4); break;
  228. /* misc pnmJVTyY */
  229. /* JS has no concept of pointers so interpret the `l` key as an address */
  230. case /*p*/ 112:
  231. Vnum = typeof arg == "number" ? arg : arg ? Number(arg.l) : -1;
  232. if(isNaN(Vnum)) Vnum = -1;
  233. if(alt) O = Vnum.toString(10);
  234. else {
  235. Vnum = Math.abs(Vnum);
  236. O = "0x" + Vnum.toString(16).toLowerCase();
  237. }
  238. break;
  239. /* store length in the `len` key */
  240. case /*n*/ 110:
  241. if(arg) { arg.len=0; for(var oo = 0; oo < o.length; ++oo) arg.len += o[oo].length; }
  242. continue;
  243. /* process error */
  244. case /*m*/ 109:
  245. if(!(arg instanceof Error)) O = "Success";
  246. else if(arg.message) O = arg.message;
  247. else if(arg.errno) O = "Error number " + arg.errno;
  248. else O = "Error " + String(arg);
  249. break;
  250. /* JS-specific conversions (extension) */
  251. case /*J*/ 74: O = (alt ? u_inspect : JSON.stringify)(arg); break;
  252. case /*V*/ 86: O = arg == null ? "null" : String(arg.valueOf()); break;
  253. case /*T*/ 84:
  254. if(alt) { /* from '[object %s]' extract %s */
  255. O = Object.prototype.toString.call(arg).substr(8);
  256. O = O.substr(0, O.length - 1);
  257. } else O = typeof arg;
  258. break;
  259. /* boolean (extension) */
  260. case /*Y*/ 89:
  261. case /*y*/ 121:
  262. O = Boolean(arg) ? (alt ? "yes" : "true") : (alt ? "no" : "false");
  263. if(c == /*Y*/ 89) O = O.toUpperCase();
  264. if( prec >= 0) O = O.substr(0, prec);
  265. if( width > O.length || - width > O.length) { if(( flags.indexOf("-") == -1 || width < 0) && flags.indexOf("0") != -1) { pad = ( width - O.length >= 0 ? padstr["0"].substr(0, width - O.length) : ""); O = pad + O; } else { pad = ( width - O.length >= 0 ? padstr[" "].substr(0, width - O.length) : ""); O = flags.indexOf("-") > -1 ? O + pad : pad + O; } }
  266. break;
  267. }
  268. if(width < 0) { width = -width; flags += "-"; }
  269. if(isnum == -1) {
  270. Vnum = Number(arg);
  271. /* parse byte length field */
  272. switch(len) {
  273. /* char */
  274. case "hh": { bytes = 1; } break;
  275. /* short */
  276. case "h": { bytes = 2; } break;
  277. /* long */
  278. case "l": { if(bytes == 4) bytes = 8; } break;
  279. /* long long */
  280. case "L":
  281. case "q":
  282. case "ll": { if(bytes == 4) bytes = 8; } break;
  283. /* intmax_t */
  284. case "j": { if(bytes == 4) bytes = 8; } break;
  285. /* ptrdiff_t */
  286. case "t": { if(bytes == 4) bytes = 8; } break;
  287. /* size_t */
  288. case "z":
  289. case "Z": { if(bytes == 4) bytes = 8; } break;
  290. /* CRT size_t or ptrdiff_t */
  291. case "I":
  292. { if(bytes == 4) bytes = 8; }
  293. break;
  294. /* CRT wchar_t */
  295. case "w": break;
  296. }
  297. /* restrict value */
  298. switch(bytes) {
  299. case 1: Vnum = (Vnum & 0xFF); if(sign && (Vnum > 0x7F)) Vnum -= (0xFF + 1); break;
  300. case 2: Vnum = (Vnum & 0xFFFF); if(sign && (Vnum > 0x7FFF)) Vnum -= (0xFFFF + 1); break;
  301. case 4: Vnum = sign ? (Vnum | 0) : (Vnum >>> 0); break;
  302. default: Vnum = isNaN(Vnum) ? 0 : Math.round(Vnum); break;
  303. }
  304. /* generate string */
  305. if(bytes > 4 && Vnum < 0 && !sign) {
  306. if(radix == 16 || radix == -16) {
  307. O = (Vnum>>>0).toString(16);
  308. Vnum = Math.floor((Vnum - (Vnum >>> 0)) / Math.pow(2,32));
  309. O = (Vnum>>>0).toString(16) + (8 - O.length >= 0 ? padstr[ "0"].substr(0,8 - O.length) : "") + O;
  310. O = (16 - O.length >= 0 ? padstr[ "f"].substr(0,16 - O.length) : "") + O;
  311. if(radix == 16) O = O.toUpperCase();
  312. } else if(radix == 8) {
  313. O = (Vnum>>>0).toString(8);
  314. O = (10 - O.length >= 0 ? padstr[ "0"].substr(0,10 - O.length) : "") + O;
  315. Vnum = Math.floor((Vnum - ((Vnum >>> 0)&0x3FFFFFFF)) / Math.pow(2,30));
  316. O = (Vnum>>>0).toString(8) + O.substr(O.length - 10);
  317. O = O.substr(O.length - 20);
  318. O = "1" + (21 - O.length >= 0 ? padstr[ "7"].substr(0,21 - O.length) : "") + O;
  319. } else {
  320. Vnum = (-Vnum) % 1e16;
  321. var d1 = [1,8,4,4,6,7,4,4,0,7,3,7,0,9,5,5,1,6,1,6];
  322. var di = d1.length - 1;
  323. while(Vnum > 0) {
  324. if((d1[di] -= (Vnum % 10)) < 0) { d1[di] += 10; d1[di-1]--; }
  325. --di; Vnum = Math.floor(Vnum / 10);
  326. }
  327. O = d1.join("");
  328. }
  329. } else {
  330. if(radix === -16) O = Vnum.toString(16).toLowerCase();
  331. else if(radix === 16) O = Vnum.toString(16).toUpperCase();
  332. else O = Vnum.toString(radix);
  333. }
  334. /* apply precision */
  335. if(prec ===0 && O == "0" && !(radix == 8 && alt)) O = ""; /* bail out */
  336. else {
  337. if(O.length < prec + (O.substr(0,1) == "-" ? 1 : 0)) {
  338. if(O.substr(0,1) != "-") O = (prec - O.length >= 0 ? padstr[ "0"].substr(0,prec - O.length) : "") + O;
  339. else O = O.substr(0,1) + (prec + 1 - O.length >= 0 ? padstr[ "0"].substr(0,prec + 1 - O.length) : "") + O.substr(1);
  340. }
  341. /* add prefix for # form */
  342. if(!sign && alt && Vnum !== 0) switch(radix) {
  343. case -16: O = "0x" + O; break;
  344. case 16: O = "0X" + O; break;
  345. case 8: if(O.charAt(0) != "0") O = "0" + O; break;
  346. case 2: O = "0b" + O; break;
  347. }
  348. }
  349. /* add sign character */
  350. if(sign && O.charAt(0) != "-") {
  351. if(flags.indexOf("+") > -1) O = "+" + O;
  352. else if(flags.indexOf(" ") > -1) O = " " + O;
  353. }
  354. /* width */
  355. if(width > 0) {
  356. if(O.length < width) {
  357. if(flags.indexOf("-") > -1) {
  358. O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
  359. } else if(flags.indexOf("0") > -1 && prec < 0 && O.length > 0) {
  360. if(prec > O.length) O = ((prec - O.length) >= 0 ? padstr[ "0"].substr(0,(prec - O.length)) : "") + O;
  361. pad = ((width - O.length) >= 0 ? padstr[ (prec > 0 ? " " : "0")].substr(0,(width - O.length)) : "");
  362. if(O.charCodeAt(0) < 48) {
  363. if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
  364. else O = O.substr(0,1) + pad + O.substring(1);
  365. }
  366. else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
  367. else O = pad + O;
  368. } else {
  369. O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
  370. }
  371. }
  372. }
  373. } else if(isnum > 0) {
  374. Vnum = Number(arg);
  375. if(arg === null) Vnum = 0/0;
  376. if(len == "L") bytes = 12;
  377. var isf = isFinite(Vnum);
  378. if(!isf) { /* Infinity or NaN */
  379. if(Vnum < 0) O = "-";
  380. else if(flags.indexOf("+") > -1) O = "+";
  381. else if(flags.indexOf(" ") > -1) O = " ";
  382. O += (isNaN(Vnum)) ? "nan" : "inf";
  383. } else {
  384. var E = 0;
  385. if(prec == -1 && isnum != 4) prec = 6;
  386. /* g/G conditional behavior */
  387. if(isnum == 3) {
  388. O = Vnum.toExponential(1);
  389. E = +O.substr(O.indexOf("e") + 1);
  390. if(prec === 0) prec = 1;
  391. if(prec > E && E >= -4) { isnum = (11); prec = prec -(E + 1); }
  392. else { isnum = (12); prec = prec - 1; }
  393. }
  394. /* sign: workaround for negative zero */
  395. var sg = (Vnum < 0 || 1/Vnum == -Infinity) ? "-" : "";
  396. if(Vnum < 0) Vnum = -Vnum;
  397. switch(isnum) {
  398. /* f/F standard */
  399. case 1: case 11:
  400. if(Vnum < 1e21) {
  401. O = Vnum.toFixed(prec);
  402. if(isnum == 1) { if(prec===0 &&alt&& O.indexOf(".")==-1) O+="."; }
  403. else if(!alt) O=O.replace(/(\.\d*[1-9])0*$/,"$1").replace(/\.0*$/,"");
  404. else if(O.indexOf(".") == -1) O+= ".";
  405. break;
  406. }
  407. O = Vnum.toExponential(20);
  408. E = +O.substr(O.indexOf("e")+1);
  409. O = O.charAt(0) + O.substr(2,O.indexOf("e")-2);
  410. O = O + (E - O.length + 1 >= 0 ? padstr[ "0"].substr(0,E - O.length + 1) : "");
  411. if(alt || (prec > 0 && isnum !== 11)) O = O + "." + (prec >= 0 ? padstr[ "0"].substr(0,prec) : "");
  412. break;
  413. /* e/E exponential */
  414. case 2: case 12:
  415. O = Vnum.toExponential(prec);
  416. E = O.indexOf("e");
  417. if(O.length - E === 3) O = O.substr(0, E+2) + "0" + O.substr(E+2);
  418. if(alt && O.indexOf(".") == -1) O = O.substr(0,E) +"."+ O.substr(E);
  419. else if(!alt && isnum == 12) O = O.replace(/\.0*e/, "e").replace(/\.(\d*[1-9])0*e/, ".$1e");
  420. break;
  421. /* a/A hex */
  422. case 4:
  423. if(Vnum===0){O= "0x0"+((alt||prec>0)?"."+(prec >= 0 ? padstr["0"].substr(0,prec) : ""):"")+"p+0"; break;}
  424. O = Vnum.toString(16);
  425. /* First char 0-9 */
  426. var ac = O.charCodeAt(0);
  427. if(ac == 48) {
  428. ac = 2; E = -4; Vnum *= 16;
  429. while(O.charCodeAt(ac++) == 48) { E -= 4; Vnum *= 16; }
  430. O = Vnum.toString(16);
  431. ac = O.charCodeAt(0);
  432. }
  433. var ai = O.indexOf(".");
  434. if(O.indexOf("(") > -1) {
  435. /* IE exponential form */
  436. var am = O.match(/\(e(.*)\)/);
  437. var ae = am ? (+am[1]) : 0;
  438. E += 4 * ae; Vnum /= Math.pow(16, ae);
  439. } else if(ai > 1) {
  440. E += 4 * (ai - 1); Vnum /= Math.pow(16, ai - 1);
  441. } else if(ai == -1) {
  442. E += 4 * (O.length - 1); Vnum /= Math.pow(16, O.length - 1);
  443. }
  444. /* at this point 1 <= Vnum < 16 */
  445. if(bytes > 8) {
  446. if(ac < 50) { E -= 3; Vnum *= 8; }
  447. else if(ac < 52) { E -= 2; Vnum *= 4; }
  448. else if(ac < 56) { E -= 1; Vnum *= 2; }
  449. /* at this point 8 <= Vnum < 16 */
  450. } else {
  451. if(ac >= 56) { E += 3; Vnum /= 8; }
  452. else if(ac >= 52) { E += 2; Vnum /= 4; }
  453. else if(ac >= 50) { E += 1; Vnum /= 2; }
  454. /* at this point 1 <= Vnum < 2 */
  455. }
  456. O = Vnum.toString(16);
  457. if(O.length > 1) {
  458. if(O.length > prec+2 && O.charCodeAt(prec+2) >= 56) {
  459. var _f = O.charCodeAt(0) == 102;
  460. O = (Vnum + 8 * Math.pow(16, -prec-1)).toString(16);
  461. if(_f && O.charCodeAt(0) == 49) E += 4;
  462. }
  463. if(prec > 0) {
  464. O = O.substr(0, prec + 2);
  465. if(O.length < prec + 2) {
  466. if(O.charCodeAt(0) < 48) O = O.charAt(0) + ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "") + O.substr(1);
  467. else O += ((prec + 2 - O.length) >= 0 ? padstr[ "0"].substr(0,(prec + 2 - O.length)) : "");
  468. }
  469. } else if(prec === 0) O = O.charAt(0) + (alt ? "." : "");
  470. } else if(prec > 0) O = O + "." + (prec >= 0 ? padstr["0"].substr(0,prec) : "");
  471. else if(alt) O = O + ".";
  472. O = "0x" + O + "p" + (E>=0 ? "+" + E : E);
  473. break;
  474. }
  475. if(sg === "") {
  476. if(flags.indexOf("+") > -1) sg = "+";
  477. else if(flags.indexOf(" ") > -1) sg = " ";
  478. }
  479. O = sg + O;
  480. }
  481. /* width */
  482. if(width > O.length) {
  483. if(flags.indexOf("-") > -1) {
  484. O = O + ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "");
  485. } else if(flags.indexOf("0") > -1 && O.length > 0 && isf) {
  486. pad = ((width - O.length) >= 0 ? padstr[ "0"].substr(0,(width - O.length)) : "");
  487. if(O.charCodeAt(0) < 48) {
  488. if(O.charAt(2).toLowerCase() == "x") O = O.substr(0,3) + pad + O.substring(3);
  489. else O = O.substr(0,1) + pad + O.substring(1);
  490. }
  491. else if(O.charAt(1).toLowerCase() == "x") O = O.substr(0,2) + pad + O.substring(2);
  492. else O = pad + O;
  493. } else {
  494. O = ((width - O.length) >= 0 ? padstr[ " "].substr(0,(width - O.length)) : "") + O;
  495. }
  496. }
  497. if(c < 96) O = O.toUpperCase();
  498. }
  499. o.push(O);
  500. }
  501. return o.join("");
  502. }
  503. function vsprintf(fmt, args) { return doit(tokenize(fmt), args); }
  504. function sprintf() {
  505. var args = new Array(arguments.length - 1);
  506. for(var i = 0; i < args.length; ++i) args[i] = arguments[i+1];
  507. return doit(tokenize(arguments[0]), args);
  508. }
  509. PRINTJ.sprintf = sprintf;
  510. PRINTJ.vsprintf = vsprintf;
  511. PRINTJ._doit = doit;
  512. PRINTJ._tokenize = tokenize;
  513. }));