Created
April 30, 2010 05:00
-
-
Save bga/384769 to your computer and use it in GitHub Desktop.
This file contains 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
var | |
parseAcceptRE = new RegExp(/[{}\[\]:,]+|\"([^\\\"]*?\\.)*[^\"]*?\"|[+\-]?\d+(?:\.\d+)?(?:[eE][+\-]?\d+)?|true|false|null|\s+/g), | |
// var name at begin | |
// keywords, which can be written space separeted | |
// specific keywords | |
// operator and var name or object | |
// property access (but not number point delimiter) | |
// property access via square bracket (but not array declaration) | |
unsafeCharsRE = new RegExp(/^[a-zA-Z_\$\/]|var|new|instanceof|var|function|typeof|(?![\[,:]\[)[\+\-\*\/%\^&\|~\!\=<>\:,\[\(]\s*[a-zA-Z_\$\/\[]|\.[a-zA-Z_\$]|[\w\$\/\)\]]\s*\[/); | |
JSON_OBJ_NAME.parse = function(str) | |
{ | |
if(unsafeCharsRE.test(str)) | |
{ | |
str = '//' + str.replace(parseAcceptRE, '\n$&//') + '\n'; | |
console.log(str); | |
} | |
return eval('(' + str + ')'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment