Created
February 25, 2010 21:29
-
-
Save bga/315053 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(window.JSONBga==null) | |
| window.JSONBga=new Object(); | |
| if(typeof(JSONBga.stringify)!="function") | |
| { | |
| (function() | |
| { | |
| var escapeCharMap= | |
| { | |
| "\\":"\\\\", | |
| "\b":"\\b", | |
| "\t":"\\t", | |
| "\n":"\\n", | |
| "\f":"\\f", | |
| "\r":"\\r", | |
| "\"":"\\\"" | |
| }; | |
| var escapeRE=new RegExp(/[\x00-\x1f\x7f-\uffff]/g); | |
| var _escapeReplacer=null; | |
| var _stringifyWrap=null; | |
| var indStep=null; | |
| var _filter; | |
| JSONBga._stringifyWrap=null; | |
| Object.prototype.toJSONBga=null; | |
| Array.prototype.toJSONBga=null; | |
| JSONBga._escapeString=function(t) | |
| { | |
| return t.replace(escapeRE,_escapeReplacer); | |
| }; | |
| String.prototype.toJSONBga=function(key) | |
| { | |
| return "\""+this.replace(escapeRE,_escapeReplacer)+"\""; | |
| }; | |
| var __stringifyWrapFilter=function(key,v) | |
| { | |
| if((v=_filter(key,v))==null) | |
| return null; | |
| return this.__stringify(key,v); | |
| }; | |
| var __stringifyWrapAcceptNames=function(key,v) | |
| { | |
| if(_filter.indexOf(key)===-1) | |
| return null; | |
| return this.__stringify(key,v); | |
| }; | |
| if(window.opera) | |
| { | |
| var hexMap=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]; | |
| _escapeReplacer=function(c) | |
| { | |
| var a,hexMapC=hexMap; | |
| return escapeCharMap[c] || "\\u"+hexMapC[((a=c.charCodeAt(0))>>24)&0xF]+hexMapC[(a>>16)&0xF]+hexMapC[(a>>8)&0xF]+hexMapC[a&0xF]; | |
| }; | |
| Number.prototype.toJSONBga=function(key) | |
| { | |
| return (isFinite(this)) ? v : "null"; | |
| }; | |
| __stringify=function(key,v) | |
| { | |
| if(v==null) | |
| return "null"; | |
| switch(typeof(obj)) | |
| { | |
| case "function": | |
| return null; | |
| case "number": | |
| return (isFinite(v)) ? v : "null"; | |
| case "string": | |
| return "\""+v.replace(escapeRE,_escapeReplacer)+"\""; | |
| case "boolean": | |
| return ""+v; | |
| default: | |
| return v.toJSONBga (key,arguments[2]); | |
| } | |
| }; | |
| } | |
| else | |
| { | |
| _escapeReplacer=function(c) | |
| { | |
| return escapeCharMap[c] || "\\u"+(c.charCodeAt(0)|0x10000).toString(16).substring(1); | |
| }; | |
| Number.prototype.toJSONBga=function(key) | |
| { | |
| var temp; | |
| return ((temp=this+"")!=="NaN") ? temp : "null";; | |
| }; | |
| __stringify=function(key,v) | |
| { | |
| if(v==null) | |
| return "null"; | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| return null; | |
| case "number": | |
| var temp; | |
| return ((temp=v+"")!=="NaN") ? temp : "null";; | |
| case "string": | |
| return "\""+v.replace(escapeRE,_escapeReplacer)+"\""; | |
| case "boolean": | |
| return ""+v; | |
| default: | |
| return v.toJSONBga (key,arguments[2],arguments[3]) | |
| } | |
| }; | |
| var __ArrayToJSONAcceptNames=__ArrayToJSON; | |
| var __ArrayToJSONAcceptNamesInd=__ArrayToJSONInd; | |
| var | |
| __ObjectToJSON=function(key) | |
| { | |
| var t="{",v; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| for(var key in this) | |
| { | |
| if(this.hasOwnProperty(key)) | |
| { | |
| if((v=this[key])!=null) | |
| { | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":"+((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":"+v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key) | |
| )!=null) | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":"+ temp +","; | |
| continue; | |
| } | |
| } | |
| else | |
| { | |
| t+="\""+ "\""+key.replace(escapeREC,_escapeReplacerC)+"\":null,"; | |
| } | |
| } | |
| } | |
| if(t==="{") | |
| return "{}" | |
| ; | |
| return t.substring(0,t.length-1)+"}"; | |
| }; | |
| var | |
| __ObjectToJSONInd=function(key,ind) | |
| { | |
| var t="{",v; | |
| var nInd=ind+indStep; | |
| var sep=nInd +"\"" | |
| ; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| for(var key in this) | |
| { | |
| if(this.hasOwnProperty(key)) | |
| { | |
| if((v=this[key])!=null) | |
| { | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":"+((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":"+v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key,nInd) | |
| )!=null) | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":"+ temp +","; | |
| continue; | |
| } | |
| } | |
| else | |
| { | |
| t+=sep+ "\""+key.replace(escapeREC,_escapeReplacerC)+"\":null,"; | |
| } | |
| } | |
| } | |
| if(t==="{") | |
| return "{}"; | |
| return t.substring(0,t.length-1)+ind+"}"; | |
| }; | |
| var | |
| __ObjectToJSONFilter=function(key) | |
| { | |
| var t="{",v; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| var _filterC=_filter; | |
| for(var key in this) | |
| { | |
| if(this.hasOwnProperty(key) && _filterC(key,(v=this[key]))!=null) | |
| { | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":"+((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":"+v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key) | |
| )!=null) | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":"+ temp +","; | |
| continue; | |
| } | |
| } | |
| } | |
| if(t==="{") | |
| return "{}" | |
| ; | |
| return t.substring(0,t.length-1)+"}"; | |
| }; | |
| var | |
| __ObjectToJSONFilterInd=function(key,ind) | |
| { | |
| var t="{",v; | |
| var nInd=ind+indStep; | |
| var sep=nInd +"\"" | |
| ; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| var _filterC=_filter; | |
| for(var key in this) | |
| { | |
| if(this.hasOwnProperty(key) && _filterC(key,(v=this[key]))!=null) | |
| { | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":"+((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":"+v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key,nInd) | |
| )!=null) | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":"+ temp +","; | |
| continue; | |
| } | |
| } | |
| } | |
| if(t==="{") | |
| return "{}"; | |
| return t.substring(0,t.length-1)+ind+"}"; | |
| }; | |
| var | |
| __ObjectToJSONAcceptNames=function(key) | |
| { | |
| var t="{",v; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| var _filterC=_filter,i=_filter.length; | |
| while(i--) | |
| { | |
| if((key=_filterC[i]) && this.hasOwnProperty(key)) | |
| { | |
| v=this[key]; | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":"+((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":"+v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key) | |
| )!=null) | |
| t+="\""+ key.replace(escapeREC,_escapeReplacerC)+"\":"+ temp +","; | |
| continue; | |
| } | |
| } | |
| } | |
| if(t==="{") | |
| return "{}" | |
| ; | |
| return t.substring(0,t.length-1)+"}"; | |
| }; | |
| var | |
| __ObjectToJSONAcceptNamesInd=function(key,ind) | |
| { | |
| var t="{",v; | |
| var nInd=ind+indStep; | |
| var sep=nInd +"\"" | |
| ; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| var _filterC=_filter,i=_filter.length; | |
| while(i--) | |
| { | |
| if((key=_filterC[i]) && this.hasOwnProperty(key)) | |
| { | |
| v=this[key]; | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":"+((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":"+v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key,nInd) | |
| )!=null) | |
| t+=sep+ key.replace(escapeREC,_escapeReplacerC)+"\":"+ temp +","; | |
| continue; | |
| } | |
| } | |
| } | |
| if(t==="{") | |
| return "{}"; | |
| return t.substring(0,t.length-1)+ind+"}"; | |
| }; | |
| var | |
| __ArrayToJSON=function(key) | |
| { | |
| var t="[",v; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| for(var key=0,len=this.length;key<len;++key) | |
| { | |
| if((v=this[key])!=null) | |
| { | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+= ((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+= "\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+= v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key) | |
| )!=null) | |
| t+= temp +","; | |
| continue; | |
| } | |
| } | |
| else | |
| { | |
| t+= "null,"; | |
| } | |
| } | |
| if(t==="[") | |
| return "[]" | |
| ; | |
| return t.substring(0,t.length-1)+"]"; | |
| }; | |
| var | |
| __ArrayToJSONInd=function(key,ind) | |
| { | |
| var t="[",v; | |
| var nInd=ind+indStep; | |
| var sep=nInd ; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| for(var key=0,len=this.length;key<len;++key) | |
| { | |
| if((v=this[key])!=null) | |
| { | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+=sep+ ((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+=sep+ "\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+=sep+ v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key,nInd) | |
| )!=null) | |
| t+=sep+ temp +","; | |
| continue; | |
| } | |
| } | |
| else | |
| { | |
| t+=sep+ "null,"; | |
| } | |
| } | |
| if(t==="[") | |
| return "[]" | |
| ; | |
| return t.substring(0,t.length-1)+ind+"]"; | |
| }; | |
| var | |
| __ArrayToJSONFilter=function(key) | |
| { | |
| var t="[",v; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| var _filterC=_filter; | |
| for(var key=0,len=this.length;key<len;++key) | |
| { | |
| if(_filterC(key,(v=this[key]))!=null) | |
| { | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+= ((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+= "\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+= v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key) | |
| )!=null) | |
| t+= temp +","; | |
| continue; | |
| } | |
| } | |
| } | |
| if(t==="[") | |
| return "[]" | |
| ; | |
| return t.substring(0,t.length-1)+"]"; | |
| }; | |
| var | |
| __ArrayToJSONFilterInd=function(key,ind) | |
| { | |
| var t="[",v; | |
| var nInd=ind+indStep; | |
| var sep=nInd ; | |
| var escapeREC=escapeRE,_escapeReplacerC=_escapeReplacer,_isFinite=isFinite,temp; | |
| var _filterC=_filter; | |
| for(var key=0,len=this.length;key<len;++key) | |
| { | |
| if(_filterC(key,(v=this[key]))!=null) | |
| { | |
| switch(typeof(v)) | |
| { | |
| case "function": | |
| continue; | |
| case "number": | |
| t+=sep+ ((_isFinite(v)) ? v+"," : "null,") | |
| ; | |
| continue; | |
| case "string": | |
| t+=sep+ "\""+v.replace(escapeREC,_escapeReplacerC)+"\","; | |
| continue; | |
| case "boolean": | |
| t+=sep+ v+","; | |
| continue; | |
| default: | |
| if((temp=v.toJSONBga (key,nInd) | |
| )!=null) | |
| t+=sep+ temp +","; | |
| continue; | |
| } | |
| } | |
| } | |
| if(t==="[") | |
| return "[]" | |
| ; | |
| return t.substring(0,t.length-1)+ind+"]"; | |
| }; | |
| JSONBga.stringify=function(obj,_filterArg,indStepArg) | |
| { | |
| if(_filterArg==null) | |
| { | |
| JSONBga._stringifyWrap=_stringifyWrap=__stringify; | |
| if(indStepArg!=null) | |
| { | |
| Array.prototype.toJSONBga=__ArrayToJSONInd; | |
| Object.prototype.toJSONBga=__ObjectToJSONInd; | |
| } | |
| else | |
| { | |
| Array.prototype.toJSONBga=__ArrayToJSON; | |
| Object.prototype.toJSONBga=__ObjectToJSON; | |
| } | |
| } | |
| else if(_filterArg instanceof Function) | |
| { | |
| _filter=_filterArg; | |
| JSONBga._stringifyWrap=_stringifyWrap=__stringifyWrapFilter; | |
| if(indStepArg!=null) | |
| { | |
| Array.prototype.toJSONBga=__ArrayToJSONFilterInd; | |
| Object.prototype.toJSONBga=__ObjectToJSONFilterInd; | |
| } | |
| else | |
| { | |
| Array.prototype.toJSONBga=__ArrayToJSONFilter; | |
| Object.prototype.toJSONBga=__ObjectToJSONFilter; | |
| } | |
| } | |
| else if(_filterArg instanceof Array) | |
| { | |
| _filter=_filterArg; | |
| JSONBga._stringifyWrap=_stringifyWrap=__stringifyWrapAcceptNames; | |
| if(indStepArg!=null) | |
| { | |
| Array.prototype.toJSONBga=__ArrayToJSONAcceptNamesInd; | |
| Object.prototype.toJSONBga=__ObjectToJSONAcceptNamesInd; | |
| } | |
| else | |
| { | |
| Array.prototype.toJSONBga=__ArrayToJSONAcceptNames; | |
| Object.prototype.toJSONBga=__ObjectToJSONAcceptNames; | |
| } | |
| } | |
| else | |
| { | |
| return null; | |
| } | |
| ; | |
| if(indStepArg!=null) | |
| indStep=indStepArg+""; | |
| else | |
| indStep=null; | |
| return __stringify(null,obj,"\n"); | |
| }; | |
| } | |
| })(); | |
| Boolean.prototype.toJSONBga=function(key) | |
| { | |
| return this; | |
| }; | |
| Function.prototype.toJSONBga=function(key) | |
| { | |
| return null; | |
| }; | |
| Date.prototype.toJSONBga=function(key) | |
| { | |
| var temp; | |
| if(isFinite(+this)) | |
| { | |
| return this.getUTCFullYear()+'-'+ | |
| (((temp=this.getUTCMonth() + 1)<10) ? "0"+temp : temp)+'-'+ | |
| (((temp=this.getUTCDate())<10) ? "0"+temp : temp)+'T'+ | |
| (((temp=this.getUTCHours())<10) ? "0"+temp : temp)+':'+ | |
| (((temp=this.getUTCMinutes())<10) ? "0"+temp : temp)+':'+ | |
| (((temp=this.getUTCSeconds())<10) ? "0"+temp : temp)+'Z'; | |
| } | |
| return null; | |
| }; | |
| Boolean.prototype.toJSONBgaPush=function(key,p) | |
| { | |
| tPushs[p++]=this; | |
| return p; | |
| }; | |
| Function.prototype.toJSONBgaPush=function(key,p) | |
| { | |
| return p; | |
| }; | |
| Date.prototype.toJSONBgaPush=function(key) | |
| { | |
| var t=tPushs,temp; | |
| if(isFinite(+this)) | |
| { | |
| t[p++]=this.getUTCFullYear(); | |
| t[p++]='-'; | |
| t[p++]=((temp=this.getUTCMonth() + 1)<10) ? "0"+temp : temp; | |
| t[p++]='-'; | |
| t[p++]=((temp=this.getUTCDate())<10) ? "0"+temp : temp; | |
| t[p++]='T'; | |
| t[p++]=((temp=this.getUTCHours())<10) ? "0"+temp : temp; | |
| t[p++]=':'; | |
| t[p++]=((temp=this.getUTCMinutes())<10) ? "0"+temp : temp; | |
| t[p++]=':'; | |
| t[p++]=((temp=this.getUTCSeconds())<10) ? "0"+temp : temp; | |
| t[p++]='Z'; | |
| } | |
| return p; | |
| }; | |
| } | |
| (function() | |
| { | |
| if(typeof(JSONBga.parse)!="function") | |
| { | |
| var parseAcceptRE=new RegExp(/([{}\[\]:,]|\x22([^\\\x22]*\\.)*[^\x22]*\x22|[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null|\s+)/g); | |
| JSONBga.parse=function(str) | |
| { | |
| return eval("(//"+str.replace(parseAcceptRE,"\n$1//")+"\n)"); | |
| }; | |
| } | |
| var reviverSupported=true; | |
| (function() | |
| { | |
| Object.prototype.JSON2FastTemp=Array.prototype.JSON2FastTemp={}; | |
| try | |
| { | |
| reviverSupported=JSONBga.parse('{"a":"a"}',function(key,value){ return undefined; })===""; | |
| } | |
| catch(err) | |
| { | |
| reviverSupported=false; | |
| } | |
| delete Object.prototype.JSON2FastTemp; | |
| delete Array.prototype.JSON2FastTemp; | |
| })(); | |
| if(reviverSupported) | |
| { | |
| var _oldParse=JSONBga.parse; | |
| var _reviver=null; | |
| var _walk=function(v) | |
| { | |
| var _reviverC=_reviver,temp; | |
| if(v instanceof Array) | |
| { | |
| var key=v.length; | |
| while(key--) | |
| { | |
| if((temp=_reviverC(key,v[key]))==null) | |
| { | |
| delete v[key]; | |
| } | |
| else | |
| { | |
| v[key]=temp; | |
| if(typeof(temp)==="object") | |
| _walk(temp); | |
| } | |
| } | |
| } | |
| else | |
| { | |
| for(var key in v) | |
| { | |
| if(v.hasOwnProperty(key)) | |
| { | |
| if((temp=_reviverC(key,v[key]))==null) | |
| { | |
| delete v[key]; | |
| } | |
| else | |
| { | |
| v[key]=temp; | |
| if(typeof(temp)==="object") | |
| _walk(temp); | |
| } | |
| } | |
| } | |
| } | |
| }; | |
| JSONBga.parse=function(str,_reviverArg) | |
| { | |
| var json=_oldParse.call(JSONBga,str); | |
| if(_reviverArg==null) | |
| return json; | |
| _reviver=_reviverArg; | |
| _walk(json); | |
| return json; | |
| }; | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment