Merge branch 'paladox2015-patch-1'
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
http://www.JSON.org/json2.js
|
json2.js
|
||||||
2009-08-17
|
2014-02-04
|
||||||
|
|
||||||
Public Domain.
|
Public Domain.
|
||||||
|
|
||||||
@@ -8,6 +8,14 @@
|
|||||||
|
|
||||||
See http://www.JSON.org/js.html
|
See http://www.JSON.org/js.html
|
||||||
|
|
||||||
|
|
||||||
|
This code should be minified before deployment.
|
||||||
|
See http://javascript.crockford.com/jsmin.html
|
||||||
|
|
||||||
|
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||||
|
NOT CONTROL.
|
||||||
|
|
||||||
|
|
||||||
This file creates a global JSON object containing two methods: stringify
|
This file creates a global JSON object containing two methods: stringify
|
||||||
and parse.
|
and parse.
|
||||||
|
|
||||||
@@ -136,15 +144,9 @@
|
|||||||
|
|
||||||
This is a reference implementation. You are free to copy, modify, or
|
This is a reference implementation. You are free to copy, modify, or
|
||||||
redistribute.
|
redistribute.
|
||||||
|
|
||||||
This code should be minified before deployment.
|
|
||||||
See http://javascript.crockford.com/jsmin.html
|
|
||||||
|
|
||||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
|
||||||
NOT CONTROL.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*jslint evil: true */
|
/*jslint evil: true, regexp: true */
|
||||||
|
|
||||||
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
||||||
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||||
@@ -153,16 +155,16 @@
|
|||||||
test, toJSON, toString, valueOf
|
test, toJSON, toString, valueOf
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// Create a JSON object only if one does not already exist. We create the
|
// Create a JSON object only if one does not already exist. We create the
|
||||||
// methods in a closure to avoid creating global variables.
|
// methods in a closure to avoid creating global variables.
|
||||||
|
|
||||||
if (!this.JSON) {
|
if (typeof JSON !== 'object') {
|
||||||
this.JSON = {};
|
JSON = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function f(n) {
|
function f(n) {
|
||||||
// Format integers to have at least two digits.
|
// Format integers to have at least two digits.
|
||||||
@@ -171,37 +173,30 @@ if (!this.JSON) {
|
|||||||
|
|
||||||
if (typeof Date.prototype.toJSON !== 'function') {
|
if (typeof Date.prototype.toJSON !== 'function') {
|
||||||
|
|
||||||
Date.prototype.toJSON = function (key) {
|
Date.prototype.toJSON = function () {
|
||||||
|
|
||||||
return isFinite(this.valueOf()) ?
|
return isFinite(this.valueOf())
|
||||||
this.getUTCFullYear() + '-' +
|
? this.getUTCFullYear() + '-' +
|
||||||
f(this.getUTCMonth() + 1) + '-' +
|
f(this.getUTCMonth() + 1) + '-' +
|
||||||
f(this.getUTCDate()) + 'T' +
|
f(this.getUTCDate()) + 'T' +
|
||||||
f(this.getUTCHours()) + ':' +
|
f(this.getUTCHours()) + ':' +
|
||||||
f(this.getUTCMinutes()) + ':' +
|
f(this.getUTCMinutes()) + ':' +
|
||||||
f(this.getUTCSeconds()) + 'Z' : null;
|
f(this.getUTCSeconds()) + 'Z'
|
||||||
|
: null;
|
||||||
};
|
};
|
||||||
|
|
||||||
String.prototype.toJSON =
|
String.prototype.toJSON =
|
||||||
Number.prototype.toJSON =
|
Number.prototype.toJSON =
|
||||||
Boolean.prototype.toJSON = function (key) {
|
Boolean.prototype.toJSON = function () {
|
||||||
return this.valueOf();
|
return this.valueOf();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
var cx,
|
||||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
escapable,
|
||||||
gap,
|
gap,
|
||||||
indent,
|
indent,
|
||||||
meta = { // table of character substitutions
|
meta,
|
||||||
'\b': '\\b',
|
|
||||||
'\t': '\\t',
|
|
||||||
'\n': '\\n',
|
|
||||||
'\f': '\\f',
|
|
||||||
'\r': '\\r',
|
|
||||||
'"' : '\\"',
|
|
||||||
'\\': '\\\\'
|
|
||||||
},
|
|
||||||
rep;
|
rep;
|
||||||
|
|
||||||
|
|
||||||
@@ -213,17 +208,17 @@ if (!this.JSON) {
|
|||||||
// sequences.
|
// sequences.
|
||||||
|
|
||||||
escapable.lastIndex = 0;
|
escapable.lastIndex = 0;
|
||||||
return escapable.test(string) ?
|
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
||||||
'"' + string.replace(escapable, function (a) {
|
var c = meta[a];
|
||||||
var c = meta[a];
|
return typeof c === 'string'
|
||||||
return typeof c === 'string' ? c :
|
? c
|
||||||
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||||
}) + '"' :
|
}) + '"' : '"' + string + '"';
|
||||||
'"' + string + '"';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function str(key, holder) {
|
function str(key, holder) {
|
||||||
|
|
||||||
// Produce a string from holder[key].
|
// Produce a string from holder[key].
|
||||||
|
|
||||||
var i, // The loop counter.
|
var i, // The loop counter.
|
||||||
@@ -301,11 +296,11 @@ if (!this.JSON) {
|
|||||||
// Join all of the elements together, separated with commas, and wrap them in
|
// Join all of the elements together, separated with commas, and wrap them in
|
||||||
// brackets.
|
// brackets.
|
||||||
|
|
||||||
v = partial.length === 0 ? '[]' :
|
v = partial.length === 0
|
||||||
gap ? '[\n' + gap +
|
? '[]'
|
||||||
partial.join(',\n' + gap) + '\n' +
|
: gap
|
||||||
mind + ']' :
|
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||||
'[' + partial.join(',') + ']';
|
: '[' + partial.join(',') + ']';
|
||||||
gap = mind;
|
gap = mind;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -315,8 +310,8 @@ if (!this.JSON) {
|
|||||||
if (rep && typeof rep === 'object') {
|
if (rep && typeof rep === 'object') {
|
||||||
length = rep.length;
|
length = rep.length;
|
||||||
for (i = 0; i < length; i += 1) {
|
for (i = 0; i < length; i += 1) {
|
||||||
k = rep[i];
|
if (typeof rep[i] === 'string') {
|
||||||
if (typeof k === 'string') {
|
k = rep[i];
|
||||||
v = str(k, value);
|
v = str(k, value);
|
||||||
if (v) {
|
if (v) {
|
||||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||||
@@ -328,7 +323,7 @@ if (!this.JSON) {
|
|||||||
// Otherwise, iterate through all of the keys in the object.
|
// Otherwise, iterate through all of the keys in the object.
|
||||||
|
|
||||||
for (k in value) {
|
for (k in value) {
|
||||||
if (Object.hasOwnProperty.call(value, k)) {
|
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||||
v = str(k, value);
|
v = str(k, value);
|
||||||
if (v) {
|
if (v) {
|
||||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||||
@@ -340,9 +335,11 @@ if (!this.JSON) {
|
|||||||
// Join all of the member texts together, separated with commas,
|
// Join all of the member texts together, separated with commas,
|
||||||
// and wrap them in braces.
|
// and wrap them in braces.
|
||||||
|
|
||||||
v = partial.length === 0 ? '{}' :
|
v = partial.length === 0
|
||||||
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
|
? '{}'
|
||||||
mind + '}' : '{' + partial.join(',') + '}';
|
: gap
|
||||||
|
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||||
|
: '{' + partial.join(',') + '}';
|
||||||
gap = mind;
|
gap = mind;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -351,7 +348,18 @@ if (!this.JSON) {
|
|||||||
// If the JSON object does not yet have a stringify method, give it one.
|
// If the JSON object does not yet have a stringify method, give it one.
|
||||||
|
|
||||||
if (typeof JSON.stringify !== 'function') {
|
if (typeof JSON.stringify !== 'function') {
|
||||||
|
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||||
|
meta = { // table of character substitutions
|
||||||
|
'\b': '\\b',
|
||||||
|
'\t': '\\t',
|
||||||
|
'\n': '\\n',
|
||||||
|
'\f': '\\f',
|
||||||
|
'\r': '\\r',
|
||||||
|
'"' : '\\"',
|
||||||
|
'\\': '\\\\'
|
||||||
|
};
|
||||||
JSON.stringify = function (value, replacer, space) {
|
JSON.stringify = function (value, replacer, space) {
|
||||||
|
|
||||||
// The stringify method takes a value and an optional replacer, and an optional
|
// The stringify method takes a value and an optional replacer, and an optional
|
||||||
// space parameter, and returns a JSON text. The replacer can be a function
|
// space parameter, and returns a JSON text. The replacer can be a function
|
||||||
// that can replace values, or an array of strings that will select the keys.
|
// that can replace values, or an array of strings that will select the keys.
|
||||||
@@ -382,7 +390,7 @@ if (!this.JSON) {
|
|||||||
rep = replacer;
|
rep = replacer;
|
||||||
if (replacer && typeof replacer !== 'function' &&
|
if (replacer && typeof replacer !== 'function' &&
|
||||||
(typeof replacer !== 'object' ||
|
(typeof replacer !== 'object' ||
|
||||||
typeof replacer.length !== 'number')) {
|
typeof replacer.length !== 'number')) {
|
||||||
throw new Error('JSON.stringify');
|
throw new Error('JSON.stringify');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,6 +405,7 @@ if (!this.JSON) {
|
|||||||
// If the JSON object does not yet have a parse method, give it one.
|
// If the JSON object does not yet have a parse method, give it one.
|
||||||
|
|
||||||
if (typeof JSON.parse !== 'function') {
|
if (typeof JSON.parse !== 'function') {
|
||||||
|
cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||||
JSON.parse = function (text, reviver) {
|
JSON.parse = function (text, reviver) {
|
||||||
|
|
||||||
// The parse method takes a text and an optional reviver function, and returns
|
// The parse method takes a text and an optional reviver function, and returns
|
||||||
@@ -412,7 +421,7 @@ if (!this.JSON) {
|
|||||||
var k, v, value = holder[key];
|
var k, v, value = holder[key];
|
||||||
if (value && typeof value === 'object') {
|
if (value && typeof value === 'object') {
|
||||||
for (k in value) {
|
for (k in value) {
|
||||||
if (Object.hasOwnProperty.call(value, k)) {
|
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||||
v = walk(value, k);
|
v = walk(value, k);
|
||||||
if (v !== undefined) {
|
if (v !== undefined) {
|
||||||
value[k] = v;
|
value[k] = v;
|
||||||
@@ -430,6 +439,7 @@ if (!this.JSON) {
|
|||||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||||
|
|
||||||
|
text = String(text);
|
||||||
cx.lastIndex = 0;
|
cx.lastIndex = 0;
|
||||||
if (cx.test(text)) {
|
if (cx.test(text)) {
|
||||||
text = text.replace(cx, function (a) {
|
text = text.replace(cx, function (a) {
|
||||||
@@ -451,10 +461,10 @@ if (!this.JSON) {
|
|||||||
// we look to see that the remaining characters are only whitespace or ']' or
|
// we look to see that the remaining characters are only whitespace or ']' or
|
||||||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||||
|
|
||||||
if (/^[\],:{}\s]*$/.
|
if (/^[\],:{}\s]*$/
|
||||||
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
|
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||||
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
|
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||||
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||||
|
|
||||||
// In the third stage we use the eval function to compile the text into a
|
// In the third stage we use the eval function to compile the text into a
|
||||||
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
||||||
@@ -466,8 +476,9 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
|||||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||||
// each name/value pair to a reviver function for possible transformation.
|
// each name/value pair to a reviver function for possible transformation.
|
||||||
|
|
||||||
return typeof reviver === 'function' ?
|
return typeof reviver === 'function'
|
||||||
walk({'': j}, '') : j;
|
? walk({'': j}, '')
|
||||||
|
: j;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||||
|
|||||||
Reference in New Issue
Block a user