Subversion Repositories cryptochat

Rev

View as "text/javascript" | Blame | Last modification | View Log | RSS feed

  1. //http://www.JSON.org/json_parse_state.js 2009-04-18
  2. if(!this.JSON){this.JSON={}}if(typeof(JSON.parse)=="undefined"){this.JSON.parse=(function(){var state,stack,container,key,value,escapes={'\\':'\\','"':'"','/':'/','t':'\t','n':'\n','r':'\r','f':'\f','b':'\b'},string={go:function(){state='ok'},firstokey:function(){key=value;state='colon'},okey:function(){key=value;state='colon'},ovalue:function(){state='ocomma'},firstavalue:function(){state='acomma'},avalue:function(){state='acomma'}},number={go:function(){state='ok'},ovalue:function(){state='ocomma'},firstavalue:function(){state='acomma'},avalue:function(){state='acomma'}},action={'{':{go:function(){stack.push({state:'ok'});container={};state='firstokey'},ovalue:function(){stack.push({container:container,state:'ocomma',key:key});container={};state='firstokey'},firstavalue:function(){stack.push({container:container,state:'acomma'});container={};state='firstokey'},avalue:function(){stack.push({container:container,state:'acomma'});container={};state='firstokey'}},'}':{firstokey:function(){var pop=stack.pop();value=container;container=pop.container;key=pop.key;state=pop.state},ocomma:function(){var pop=stack.pop();container[key]=value;value=container;container=pop.container;key=pop.key;state=pop.state}},'[':{go:function(){stack.push({state:'ok'});container=[];state='firstavalue'},ovalue:function(){stack.push({container:container,state:'ocomma',key:key});container=[];state='firstavalue'},firstavalue:function(){stack.push({container:container,state:'acomma'});container=[];state='firstavalue'},avalue:function(){stack.push({container:container,state:'acomma'});container=[];state='firstavalue'}},']':{firstavalue:function(){var pop=stack.pop();value=container;container=pop.container;key=pop.key;state=pop.state},acomma:function(){var pop=stack.pop();container.push(value);value=container;container=pop.container;key=pop.key;state=pop.state}},':':{colon:function(){if(Object.hasOwnProperty.call(container,key)){throw new SyntaxError('Duplicate key "'+key+'"');}state='ovalue'}},',':{ocomma:function(){container[key]=value;state='okey'},acomma:function(){container.push(value);state='avalue'}},'true':{go:function(){value=true;state='ok'},ovalue:function(){value=true;state='ocomma'},firstavalue:function(){value=true;state='acomma'},avalue:function(){value=true;state='acomma'}},'false':{go:function(){value=false;state='ok'},ovalue:function(){value=false;state='ocomma'},firstavalue:function(){value=false;state='acomma'},avalue:function(){value=false;state='acomma'}},'null':{go:function(){value=null;state='ok'},ovalue:function(){value=null;state='ocomma'},firstavalue:function(){value=null;state='acomma'},avalue:function(){value=null;state='acomma'}}};function debackslashify(text){return text.replace(/\\(?:u(.{4})|([^u]))/g,function(a,b,c){return b?String.fromCharCode(parseInt(b,16)):escapes[c]})}return function(source,reviver){var r,tx=/^[\x20\t\n\r]*(?:([,:\[\]{}]|true|false|null)|(-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)|"((?:[^\r\n\t\\\"]|\\(?:["\\\/trnfb]|u[0-9a-fA-F]{4}))*)")/;state='go';stack=[];try{for(;;){r=tx.exec(source);if(!r){break}if(r[1]){action[r[1]][state]()}else if(r[2]){value=+r[2];number[state]()}else{value=debackslashify(r[3]);string[state]()}source=source.slice(r[0].length)}}catch(e){state=e}if(state!=='ok'||/[^\x20\t\n\r]/.test(source)){throw state instanceof SyntaxError?state:new SyntaxError('JSON');}return typeof reviver==='function'?(function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}({'':value},'')):value}}())}