[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 /*############################################################################## 2 # ____________________________________________________________________ 3 # / \ 4 # | ____ __ ___ _____ / ___ ___ | 5 # | ____ / \/ \ ' / \ / / /__ / \ / \ | 6 # | / _ \ / / / / / / ___/ \__ / /____/ / / | 7 # | / |_ / / / / / / / / / \ / / /____/ | 8 # | \____/ / / \/_/ / \__/ _____/ \__/ \___/ / | 9 # | / | 10 # | | 11 # | Copyright (c) 2007 MindStep SCOP SARL | 12 # | Herve Masson | 13 # | | 14 # | www.mindstep.com www.mjslib.com | 15 # | [email protected] [email protected] | 16 # \____________________________________________________________________/ 17 # 18 # Version: 1.0.0 19 # 20 # (Svn version: $Id: jquery.printf.js 3434 2007-08-27 09:31:20Z herve $) 21 # 22 #----------[This product is distributed under a BSD license]----------------- 23 ##############################################################################*/ 24 25 (function($){$.sprintf=function(fmt) 26 {return _sprintf_(fmt,arguments,1);} 27 $.vsprintf=function(args,offset) 28 {if(offset===undefined) 29 {offset=0;} 30 return _sprintf_(args[offset],args,offset+1);} 31 $.alertf=function() 32 {return alert($.vsprintf(arguments));} 33 $.vlogf=function(args) 34 {if("console"in window) 35 {console.info($.vsprintf(args));}} 36 $.verrorf=function(args) 37 {if("console"in window) 38 {console.error($.vsprintf(args));}} 39 $.errorf=function() 40 {$.verrorf(arguments);} 41 $.logf=function() 42 {$.vlogf(arguments);} 43 FREGEXP=/^([^%]*)%([-+])?(0)?(\d+)?(\.(\d+))?([doxXcsf])(.*)$/;HDIGITS=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function _empty(str) 44 {if(str===undefined||str===null) 45 {return true;} 46 return(str=="")?true:false;} 47 function _int_(val) 48 {return Math.floor(val);} 49 function _printf_num_(val,base,pad,sign,width) 50 {val=parseInt(val,10);if(isNaN(val)) 51 {return"NaN";} 52 aval=(val<0)?-val:val;var ret="";if(aval==0) 53 {ret="0";} 54 else 55 {while(aval>0) 56 {ret=HDIGITS[aval%base]+ret;aval=_int_(aval/base);}} 57 if(val<0) 58 {ret="-"+ret;} 59 if(sign=="-") 60 {pad=" ";} 61 return _printf_str_(ret,pad,sign,width,-1);} 62 function _printf_float_(val,base,pad,sign,prec) 63 {if(prec==undefined) 64 {if(parseInt(val)!=val) 65 {return""+val;} 66 prec=5;} 67 var p10=Math.pow(10,prec);var ival=""+Math.round(val*p10);var ilen=ival.length-prec;if(ilen==0) 68 {return"0."+ival.substr(ilen,prec);} 69 return ival.substr(0,ilen)+"."+ival.substr(ilen,prec);} 70 function _printf_str_(val,pad,sign,width,prec) 71 {var npad;if(val===undefined) 72 {return"(undefined)";} 73 if(val===null) 74 {return"(null)";} 75 if((npad=width-val.length)>0) 76 {if(sign=="-") 77 {while(npad>0) 78 {val+=pad;npad--;}} 79 else 80 {while(npad>0) 81 {val=pad+val;npad--;}}} 82 if(prec>0) 83 {return val.substr(0,prec);} 84 return val;} 85 function _sprintf_(fmt,av,index) 86 {var output="";var i,m,line,match;line=fmt.split("\n");for(i=0;i<line.length;i++) 87 {if(i>0) 88 {output+="\n";} 89 fmt=line[i];while(match=FREGEXP.exec(fmt)) 90 {var sign="";var pad=" ";if(!_empty(match[1])) 91 {output+=match[1];} 92 if(!_empty(match[2])) 93 {sign=match[2];} 94 if(!_empty(match[3])) 95 {pad="0";} 96 var width=match[4];var prec=match[6];var type=match[7];fmt=match[8];if(index>=av.length) 97 {output+="[missing parameter for type '"+type+"']";continue;} 98 var val=av[index++];switch(type) 99 {case"d":output+=_printf_num_(val,10,pad,sign,width);break;case"o":output+=_printf_num_(val,8,pad,sign,width);break;case"x":output+=_printf_num_(val,16,pad,sign,width);break;case"X":output+=_printf_num_(val,16,pad,sign,width).toUpperCase();break;case"c":output+=String.fromCharCode(parseInt(val,10));break;case"s":output+=_printf_str_(val,pad,sign,width,prec);break;case"f":output+=_printf_float_(val,pad,sign,width,prec);break;default:output+="[unknown format '"+type+"']";break;}} 100 output+=fmt;} 101 return output;}})(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |