1. // We split the second stage into 4 regexp operations in order to work around
  2. // crippling inefficiencies in IE's and Safari's regexp engines. First we
  3. // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
  4. // replace all simple value tokens with ']' characters. Third, we delete all
  5. // open brackets that follow a colon or comma or that begin the text. Finally,
  6. // we look to see that the remaining characters are only whitespace or ']' or
  7. // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
  8.  
  9. if (/^[\],:{}\s]*$/
  10. .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
  11. .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
  12. .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {