]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui3/build/json/json-parse.js
Release 6.2.2
[Github/sugarcrm.git] / include / javascript / yui3 / build / json / json-parse.js
1 /*
2  Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3  Code licensed under the BSD License:
4  http://developer.yahoo.com/yui/license.html
5  version: 3.3.0
6  build: 3167
7  */
8 YUI.add('json-parse',function(Y){function fromGlobal(ref){return(Y.config.win||this||{})[ref];}
9 var _JSON=fromGlobal('JSON'),_eval=fromGlobal('eval'),Native=(Object.prototype.toString.call(_JSON)==='[object JSON]'&&_JSON),useNative=!!Native,_UNICODE_EXCEPTIONS=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_ESCAPES=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,_VALUES=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,_BRACKETS=/(?:^|:|,)(?:\s*\[)+/g,_UNSAFE=/[^\],:{}\s]/,_escapeException=function(c){return'\\u'+('0000'+(+(c.charCodeAt(0))).toString(16)).slice(-4);},_revive=function(data,reviver){var walk=function(o,key){var k,v,value=o[key];if(value&&typeof value==='object'){for(k in value){if(value.hasOwnProperty(k)){v=walk(value,k);if(v===undefined){delete value[k];}else{value[k]=v;}}}}
10 return reviver.call(o,key,value);};return typeof reviver==='function'?walk({'':data},''):data;},_parse=function(s,reviver){s=s.replace(_UNICODE_EXCEPTIONS,_escapeException);if(!_UNSAFE.test(s.replace(_ESCAPES,'@').replace(_VALUES,']').replace(_BRACKETS,''))){return _revive(_eval('('+s+')'),reviver);}
11 throw new SyntaxError('JSON.parse');};Y.namespace('JSON').parse=function(s,reviver){if(typeof s!=='string'){s+='';}
12 return Native&&Y.JSON.useNativeParse?Native.parse(s,reviver):_parse(s,reviver);};function workingNative(k,v){return k==="ok"?true:v;}
13 if(Native){try{useNative=(Native.parse('{"ok":false}',workingNative)).ok;}
14 catch(e){useNative=false;}}
15 Y.JSON.useNativeParse=useNative;},'3.3.0');