ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

338 lines
11 KiB

  1. /*
  2. http://www.JSON.org/json2.js
  3. 2011-02-23
  4. Public Domain.
  5. NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
  6. See http://www.JSON.org/js.html
  7. */
  8. // Create a JSON object only if one does not already exist. We create the
  9. // methods in a closure to avoid creating global variables.
  10. var JSON;
  11. if (!JSON) {
  12. JSON = {};
  13. }
  14. (function () {
  15. "use strict";
  16. function f(n) {
  17. // Format integers to have at least two digits.
  18. return n < 10 ? '0' + n : n;
  19. }
  20. if (typeof Date.prototype.toJSON !== 'function') {
  21. Date.prototype.toJSON = function (key) {
  22. return isFinite(this.valueOf()) ?
  23. this.getUTCFullYear() + '-' +
  24. f(this.getUTCMonth() + 1) + '-' +
  25. f(this.getUTCDate()) + 'T' +
  26. f(this.getUTCHours()) + ':' +
  27. f(this.getUTCMinutes()) + ':' +
  28. f(this.getUTCSeconds()) + 'Z' : null;
  29. };
  30. String.prototype.toJSON =
  31. Number.prototype.toJSON =
  32. Boolean.prototype.toJSON = function (key) {
  33. return this.valueOf();
  34. };
  35. }
  36. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  37. escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  38. gap,
  39. indent,
  40. meta = { // table of character substitutions
  41. '\b': '\\b',
  42. '\t': '\\t',
  43. '\n': '\\n',
  44. '\f': '\\f',
  45. '\r': '\\r',
  46. '"' : '\\"',
  47. '\\': '\\\\'
  48. },
  49. rep;
  50. function quote(string) {
  51. // If the string contains no control characters, no quote characters, and no
  52. // backslash characters, then we can safely slap some quotes around it.
  53. // Otherwise we must also replace the offending characters with safe escape
  54. // sequences.
  55. escapable.lastIndex = 0;
  56. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  57. var c = meta[a];
  58. return typeof c === 'string' ? c :
  59. '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  60. }) + '"' : '"' + string + '"';
  61. }
  62. function str(key, holder) {
  63. // Produce a string from holder[key].
  64. var i, // The loop counter.
  65. k, // The member key.
  66. v, // The member value.
  67. length,
  68. mind = gap,
  69. partial,
  70. value = holder[key];
  71. // If the value has a toJSON method, call it to obtain a replacement value.
  72. if (value && typeof value === 'object' &&
  73. typeof value.toJSON === 'function') {
  74. value = value.toJSON(key);
  75. }
  76. // If we were called with a replacer function, then call the replacer to
  77. // obtain a replacement value.
  78. if (typeof rep === 'function') {
  79. value = rep.call(holder, key, value);
  80. }
  81. // What happens next depends on the value's type.
  82. switch (typeof value) {
  83. case 'string':
  84. return quote(value);
  85. case 'number':
  86. // JSON numbers must be finite. Encode non-finite numbers as null.
  87. return isFinite(value) ? String(value) : 'null';
  88. case 'boolean':
  89. case 'null':
  90. // If the value is a boolean or null, convert it to a string. Note:
  91. // typeof null does not produce 'null'. The case is included here in
  92. // the remote chance that this gets fixed someday.
  93. return String(value);
  94. // If the type is 'object', we might be dealing with an object or an array or
  95. // null.
  96. case 'object':
  97. // Due to a specification blunder in ECMAScript, typeof null is 'object',
  98. // so watch out for that case.
  99. if (!value) {
  100. return 'null';
  101. }
  102. // Make an array to hold the partial results of stringifying this object value.
  103. gap += indent;
  104. partial = [];
  105. // Is the value an array?
  106. if (Object.prototype.toString.apply(value) === '[object Array]') {
  107. // The value is an array. Stringify every element. Use null as a placeholder
  108. // for non-JSON values.
  109. length = value.length;
  110. for (i = 0; i < length; i += 1) {
  111. partial[i] = str(i, value) || 'null';
  112. }
  113. // Join all of the elements together, separated with commas, and wrap them in
  114. // brackets.
  115. v = partial.length === 0 ? '[]' : gap ?
  116. '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
  117. '[' + partial.join(',') + ']';
  118. gap = mind;
  119. return v;
  120. }
  121. // If the replacer is an array, use it to select the members to be stringified.
  122. if (rep && typeof rep === 'object') {
  123. length = rep.length;
  124. for (i = 0; i < length; i += 1) {
  125. if (typeof rep[i] === 'string') {
  126. k = rep[i];
  127. v = str(k, value);
  128. if (v) {
  129. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  130. }
  131. }
  132. }
  133. } else {
  134. // Otherwise, iterate through all of the keys in the object.
  135. for (k in value) {
  136. if (Object.prototype.hasOwnProperty.call(value, k)) {
  137. v = str(k, value);
  138. if (v) {
  139. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  140. }
  141. }
  142. }
  143. }
  144. // Join all of the member texts together, separated with commas,
  145. // and wrap them in braces.
  146. v = partial.length === 0 ? '{}' : gap ?
  147. '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
  148. '{' + partial.join(',') + '}';
  149. gap = mind;
  150. return v;
  151. }
  152. }
  153. // If the JSON object does not yet have a stringify method, give it one.
  154. if (typeof JSON.stringify !== 'function') {
  155. JSON.stringify = function (value, replacer, space) {
  156. // The stringify method takes a value and an optional replacer, and an optional
  157. // space parameter, and returns a JSON text. The replacer can be a function
  158. // that can replace values, or an array of strings that will select the keys.
  159. // A default replacer method can be provided. Use of the space parameter can
  160. // produce text that is more easily readable.
  161. var i;
  162. gap = '';
  163. indent = '';
  164. // If the space parameter is a number, make an indent string containing that
  165. // many spaces.
  166. if (typeof space === 'number') {
  167. for (i = 0; i < space; i += 1) {
  168. indent += ' ';
  169. }
  170. // If the space parameter is a string, it will be used as the indent string.
  171. } else if (typeof space === 'string') {
  172. indent = space;
  173. }
  174. // If there is a replacer, it must be a function or an array.
  175. // Otherwise, throw an error.
  176. rep = replacer;
  177. if (replacer && typeof replacer !== 'function' &&
  178. (typeof replacer !== 'object' ||
  179. typeof replacer.length !== 'number')) {
  180. throw new Error('JSON.stringify');
  181. }
  182. // Make a fake root object containing our value under the key of ''.
  183. // Return the result of stringifying the value.
  184. return str('', {'': value});
  185. };
  186. }
  187. // If the JSON object does not yet have a parse method, give it one.
  188. if (typeof JSON.parse !== 'function') {
  189. JSON.parse = function (text, reviver) {
  190. // The parse method takes a text and an optional reviver function, and returns
  191. // a JavaScript value if the text is a valid JSON text.
  192. var j;
  193. function walk(holder, key) {
  194. // The walk method is used to recursively walk the resulting structure so
  195. // that modifications can be made.
  196. var k, v, value = holder[key];
  197. if (value && typeof value === 'object') {
  198. for (k in value) {
  199. if (Object.prototype.hasOwnProperty.call(value, k)) {
  200. v = walk(value, k);
  201. if (v !== undefined) {
  202. value[k] = v;
  203. } else {
  204. delete value[k];
  205. }
  206. }
  207. }
  208. }
  209. return reviver.call(holder, key, value);
  210. }
  211. // Parsing happens in four stages. In the first stage, we replace certain
  212. // Unicode characters with escape sequences. JavaScript handles many characters
  213. // incorrectly, either silently deleting them, or treating them as line endings.
  214. text = String(text);
  215. cx.lastIndex = 0;
  216. if (cx.test(text)) {
  217. text = text.replace(cx, function (a) {
  218. return '\\u' +
  219. ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  220. });
  221. }
  222. // In the second stage, we run the text against regular expressions that look
  223. // for non-JSON patterns. We are especially concerned with '()' and 'new'
  224. // because they can cause invocation, and '=' because it can cause mutation.
  225. // But just to be safe, we want to reject all unexpected forms.
  226. // We split the second stage into 4 regexp operations in order to work around
  227. // crippling inefficiencies in IE's and Safari's regexp engines. First we
  228. // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
  229. // replace all simple value tokens with ']' characters. Third, we delete all
  230. // open brackets that follow a colon or comma or that begin the text. Finally,
  231. // we look to see that the remaining characters are only whitespace or ']' or
  232. // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
  233. if (/^[\],:{}\s]*$/
  234. .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
  235. .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
  236. .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  237. // In the third stage we use the eval function to compile the text into a
  238. // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
  239. // in JavaScript: it can begin a block or an object literal. We wrap the text
  240. // in parens to eliminate the ambiguity.
  241. j = eval('(' + text + ')');
  242. // In the optional fourth stage, we recursively walk the new structure, passing
  243. // each name/value pair to a reviver function for possible transformation.
  244. return typeof reviver === 'function' ?
  245. walk({'': j}, '') : j;
  246. }
  247. // If the text is not JSON parseable, then a SyntaxError is thrown.
  248. throw new SyntaxError('JSON.parse');
  249. };
  250. }
  251. }());