Lines Matching refs:fmt

266 function write_date(type, fmt, val, ss0) {  argument
273 switch(fmt.length) {
278 switch(fmt.length) {
279 case 1: case 2: out = val.m; outl = fmt.length; break;
285 switch(fmt.length) {
286 case 1: case 2: out = val.d; outl = fmt.length; break;
291 switch(fmt.length) {
292 case 1: case 2: out = 1+(val.H+11)%12; outl = fmt.length; break;
293 default: throw 'bad hour format: ' + fmt;
296 switch(fmt.length) {
297 case 1: case 2: out = val.H; outl = fmt.length; break;
298 default: throw 'bad hour format: ' + fmt;
301 switch(fmt.length) {
302 case 1: case 2: out = val.M; outl = fmt.length; break;
303 default: throw 'bad minute format: ' + fmt;
306 if(val.u === 0) switch(fmt) {
307 case 's': case 'ss': return pad0(val.S, fmt.length);
310 switch(fmt) {
316 if(fmt === 's') return ss === 0 ? "0" : ""+ss/tt;
318 if(fmt === 'ss') return o.substr(0,2);
319 return "." + o.substr(2,fmt.length-1);
320 default: throw 'bad second format: ' + fmt;
323 switch(fmt) {
327 default: throw 'bad abstime format: ' + fmt;
328 } outl = fmt.length === 3 ? 1 : 2; break;
343 function write_num_pct(type, fmt, val){ argument
344 var sfmt = fmt.replace(pct1,""), mul = fmt.length - sfmt.length;
347 function write_num_cm(type, fmt, val){ argument
348 var idx = fmt.length - 1;
349 while(fmt.charCodeAt(idx-1) === 44) --idx;
350 return write_num(type, fmt.substr(0,idx), val / Math.pow(10,3*(fmt.length-idx)));
352 function write_num_exp(fmt, val){ argument
354 var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1;
355 if(fmt.match(/^#+0.0E\+0$/)) {
356 var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E');
372 if(fmt.match(/E\+00$/) && o.match(/e[+-]\d$/)) o = o.substr(0,o.length-1) + "0" + o[o.length-1];
373 if(fmt.match(/E\-/) && o.match(/e\+/)) o = o.replace(/e\+/,"e");
401 function write_num_flt(type, fmt, val) {
402 if(type.charCodeAt(0) === 40 && !fmt.match(closeparen)) {
403 var ffmt = fmt.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,"");
407 if(fmt.charCodeAt(fmt.length - 1) === 44) return write_num_cm(type, fmt, val);
408 if(fmt.indexOf('%') !== -1) return write_num_pct(type, fmt, val);
409 if(fmt.indexOf('E') !== -1) return write_num_exp(fmt, val);
410 if(fmt.charCodeAt(0) === 36) return "$"+write_num_flt(type,fmt.substr(fmt[1]==' '?2:1),val);
413 if(fmt.match(/^00+$/)) return sign + pad0r(aval,fmt.length);
414 if(fmt.match(/^[#?]+$/)) {
416 return o.length > fmt.length ? o : hashq(fmt.substr(0,fmt.length-o.length)) + o;
418 if((r = fmt.match(frac1)) !== null) return write_num_f1(r, aval, sign);
419 if(fmt.match(/^#+0+$/) !== null) return sign + pad0r(aval,fmt.length - fmt.indexOf("0"));
420 if((r = fmt.match(dec1)) !== null) {
422 return fmt.indexOf("0.") !== -1 ? o : o.replace(/^0\./,".");
424 fmt = fmt.replace(/^#+([0.])/, "$1");
425 if((r = fmt.match(/^(0*)\.(#*)$/)) !== null) {
428 if((r = fmt.match(/^#,##0(\.?)$/)) !== null) return sign + commaify(pad0r(aval,0));
429 if((r = fmt.match(/^#,##0\.([#0]*0)$/)) !== null) {
430 …return val < 0 ? "-" + write_num_flt(type, fmt, -val) : commaify(""+(Math.floor(val))) + "." + pad…
432 … if((r = fmt.match(/^#,#*,#0/)) !== null) return write_num_flt(type,fmt.replace(/^#,#*,/,""),val);
433 if((r = fmt.match(/^([0#]+)(\\?-([0#]+))+$/)) !== null) {
434 o = _strrev(write_num_flt(type, fmt.replace(/[\\-]/g,""), val));
436 …return _strrev(_strrev(fmt.replace(/\\/g,"")).replace(/[0#]/g,function(x){return ri<o.length?o[ri+…
438 if(fmt.match(phone) !== null) {
443 if((r = fmt.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/)) !== null) {
455 if((r = fmt.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/)) !== null) {
460 if((r = fmt.match(/^[#0?]+$/)) !== null) {
462 if(fmt.length <= o.length) return o;
463 return hashq(fmt.substr(0,fmt.length-o.length)) + o;
465 if((r = fmt.match(/^([#0?]+)\.([#0]+)$/)) !== null) {
468 var lres = fmt.indexOf(".") - ri, rres = fmt.length - o.length - lres;
469 return hashq(fmt.substr(0,lres) + o + fmt.substr(fmt.length-rres));
471 if((r = fmt.match(/^00,000\.([#0]*0)$/)) !== null) {
473 …return val < 0 ? "-" + write_num_flt(type, fmt, -val) : commaify(flr(val)).replace(/^\d,\d{3}$/,"0…
475 switch(fmt) {
479 throw new Error("unsupported format |" + fmt + "|");
481 function write_num_cm2(type, fmt, val){
482 var idx = fmt.length - 1;
483 while(fmt.charCodeAt(idx-1) === 44) --idx;
484 return write_num(type, fmt.substr(0,idx), val / Math.pow(10,3*(fmt.length-idx)));
486 function write_num_pct2(type, fmt, val){
487 var sfmt = fmt.replace(pct1,""), mul = fmt.length - sfmt.length;
490 function write_num_exp2(fmt, val){
492 var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1;
493 if(fmt.match(/^#+0.0E\+0$/)) {
494 var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E');
506 if(fmt.match(/E\+00$/) && o.match(/e[+-]\d$/)) o = o.substr(0,o.length-1) + "0" + o[o.length-1];
507 if(fmt.match(/E\-/) && o.match(/e\+/)) o = o.replace(/e\+/,"e");
510 function write_num_int(type, fmt, val) {
511 if(type.charCodeAt(0) === 40 && !fmt.match(closeparen)) {
512 var ffmt = fmt.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,"");
516 if(fmt.charCodeAt(fmt.length - 1) === 44) return write_num_cm2(type, fmt, val);
517 if(fmt.indexOf('%') !== -1) return write_num_pct2(type, fmt, val);
518 if(fmt.indexOf('E') !== -1) return write_num_exp2(fmt, val);
519 if(fmt.charCodeAt(0) === 36) return "$"+write_num_int(type,fmt.substr(fmt[1]==' '?2:1),val);
522 if(fmt.match(/^00+$/)) return sign + pad0(aval,fmt.length);
523 if(fmt.match(/^[#?]+$/)) {
525 return o.length > fmt.length ? o : hashq(fmt.substr(0,fmt.length-o.length)) + o;
527 if((r = fmt.match(frac1)) !== null) return write_num_f2(r, aval, sign);
528 if(fmt.match(/^#+0+$/) !== null) return sign + pad0(aval,fmt.length - fmt.indexOf("0"));
529 if((r = fmt.match(dec1)) !== null) {
531 return fmt.indexOf("0.") !== -1 ? o : o.replace(/^0\./,".");
533 fmt = fmt.replace(/^#+([0.])/, "$1");
534 if((r = fmt.match(/^(0*)\.(#*)$/)) !== null) {
537 if((r = fmt.match(/^#,##0(\.?)$/)) !== null) return sign + commaify((""+aval));
538 if((r = fmt.match(/^#,##0\.([#0]*0)$/)) !== null) {
539 …return val < 0 ? "-" + write_num_int(type, fmt, -val) : commaify((""+val)) + "." + fill('0',r[1].l…
541 … if((r = fmt.match(/^#,#*,#0/)) !== null) return write_num_int(type,fmt.replace(/^#,#*,/,""),val);
542 if((r = fmt.match(/^([0#]+)(\\?-([0#]+))+$/)) !== null) {
543 o = _strrev(write_num_int(type, fmt.replace(/[\\-]/g,""), val));
545 …return _strrev(_strrev(fmt.replace(/\\/g,"")).replace(/[0#]/g,function(x){return ri<o.length?o[ri+…
547 if(fmt.match(phone) !== null) {
552 if((r = fmt.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/)) !== null) {
564 if((r = fmt.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/)) !== null) {
569 if((r = fmt.match(/^[#0?]+$/)) !== null) {
571 if(fmt.length <= o.length) return o;
572 return hashq(fmt.substr(0,fmt.length-o.length)) + o;
574 if((r = fmt.match(/^([#0]+)\.([#0]+)$/)) !== null) {
577 var lres = fmt.indexOf(".") - ri, rres = fmt.length - o.length - lres;
578 return hashq(fmt.substr(0,lres) + o + fmt.substr(fmt.length-rres));
580 if((r = fmt.match(/^00,000\.([#0]*0)$/)) !== null) {
581 …return val < 0 ? "-" + write_num_int(type, fmt, -val) : commaify(""+val).replace(/^\d,\d{3}$/,"0$&…
583 switch(fmt) {
587 throw new Error("unsupported format |" + fmt + "|");
589 return function write_num(type, fmt, val) {
590 return (val|0) === val ? write_num_int(type, fmt, val) : write_num_flt(type, fmt, val);
592 function split_fmt(fmt) { argument
595 for(var i = 0, j = 0; i < fmt.length; ++i) switch((cc=fmt.charCodeAt(i))) {
601 out[out.length] = fmt.substr(j,i-j);
604 out[out.length] = fmt.substr(j);
605 if(in_str === true) throw new Error("Format |" + fmt + "| unterminated string ");
610 function eval_fmt(fmt, v, opts, flen) { argument
614 while(i < fmt.length) {
615 switch((c = fmt[i])) {
617 if(!isgeneral(fmt, i)) throw new Error('unrecognized character ' + c + ' in ' +fmt);
620 … for(o="";(cc=fmt.charCodeAt(++i)) !== 34 && i < fmt.length;) o += String.fromCharCode(cc);
622 case '\\': var w = fmt[++i], t = (w === "(" || w === ")") ? w : 't';
628 if(fmt[i+1] === "1" || fmt[i+1] === "2") {
629 if(dt==null) { dt=parse_date_code(v, opts, fmt[i+1] === "2"); if(dt==null) return ""; }
630 out[out.length] = {t:'X', v:fmt.substr(i,2)}; lst = c; i+=2; break;
639 o = c; while(++i<fmt.length && fmt[i].toLowerCase() === c) o+=c;
646 …if(fmt.substr(i, 3) === "A/P") { if(dt!=null) q.v = dt.H >= 12 ? "P" : "A"; q.t = 'T'; hr='h';i+=3…
647 …else if(fmt.substr(i,5) === "AM/PM") { if(dt!=null) q.v = dt.H >= 12 ? "PM" : "AM"; q.t = 'T'; i+=…
653 while(fmt[i++] !== ']' && i < fmt.length) o += fmt[i];
663 o = c; while((c=fmt[++i]) === "0") o += c;
668 …o = c; while("0#?.,E+-%".indexOf(c=fmt[++i]) > -1 || c=='\\' && fmt[i+1] == "-" && "0#".indexOf(fm…
671 o = c; while(fmt[++i] === c) o+=c;
673 case '*': ++i; if(fmt[i] == ' ' || fmt[i] == '*') ++i; break; // **
676 o = c; while("0123456789".indexOf(fmt[++i]) > -1) o+=fmt[i];
680 …cfijklopqrtuvwxz".indexOf(c) === -1) throw new Error('unrecognized character ' + c + ' in ' + fmt);
812 var fmt = split_fmt(f);
813 var l = fmt.length, lat = fmt[l-1].indexOf("@");
815 if(fmt.length > 4) throw "cannot find right format for |" + fmt + "|";
816 if(typeof v !== "number") return [4, fmt.length === 4 || lat>-1?fmt[fmt.length-1]:"@"];
817 switch(fmt.length) {
818 …case 1: fmt = lat>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; …
819 … case 2: fmt = lat>-1 ? [fmt[0], fmt[0], fmt[0], fmt[1]] : [fmt[0], fmt[1], fmt[0], "@"]; break;
820 … case 3: fmt = lat>-1 ? [fmt[0], fmt[1], fmt[0], fmt[2]] : [fmt[0], fmt[1], fmt[2], "@"]; break;
823 var ff = v > 0 ? fmt[0] : v < 0 ? fmt[1] : fmt[2];
824 if(fmt[0].indexOf("[") === -1 && fmt[1].indexOf("[") === -1) return [l, ff];
825 if(fmt[0].match(cfregex) != null || fmt[1].match(cfregex) != null) {
826 var m1 = fmt[0].match(cfregex2);
827 var m2 = fmt[1].match(cfregex2);
828 …return chkcond(v, m1) ? [l, fmt[0]] : chkcond(v, m2) ? [l, fmt[1]] : [l, fmt[m1 != null && m2 != n…
832 function format(fmt,v,o) { argument
835 switch(typeof fmt) {
836 case "string": sfmt = fmt; break;
837 case "number": sfmt = (o.table != null ? o.table : table_fmt)[fmt]; break;
847 SSF.load = function load_entry(fmt, idx) { table_fmt[idx] = fmt; }; argument
8518 var fmt = XLMLFormatMap[format] || unescapexml(format);
8519 if(fmt === "General") return SSF._general(value);
8520 return SSF.format(fmt, value);