BMLT Root Server
Functions | Variables
json2.js File Reference

Go to the source code of this file.

Functions

 if (typeof JSON!== 'object')
 
function f (n)
 
function str (key, holder)
 

Variables

var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g
 
var escapable
 
 __pad0__
 

Function Documentation

function f (   n)

Definition at line 169 of file json2.js.

References n.

170  {
171  // Format integers to have at least two digits.
172  return n < 10 ? '0' + n : n;
173  }
var n
if (   typeof JSON! = = 'object')

Definition at line 162 of file json2.js.

162  {
163  JSON = {};
164 }
function str (   key,
  holder 
)

Definition at line 229 of file json2.js.

References g, n, and r.

230  {
231 
232 // Produce a string from holder[key].
233 
234  var i, // The loop counter.
235  k, // The member key.
236  v, // The member value.
237  length,
238  mind = gap,
239  partial,
240  value = holder[key];
241 
242 // If the value has a toJSON method, call it to obtain a replacement value.
243 
244  if (value && typeof value === 'object' &&
245  typeof value.toJSON === 'function') {
246  value = value.toJSON(key);
247  }
248 
249 // If we were called with a replacer function, then call the replacer to
250 // obtain a replacement value.
251 
252  if (typeof rep === 'function') {
253  value = rep.call(holder, key, value);
254  }
255 
256 // What happens next depends on the value's type.
257 
258  switch (typeof value) {
259  case 'string':
260  return quote(value);
261 
262  case 'number':
263 
264  // JSON numbers must be finite. Encode non-finite numbers as null.
265 
266  return isFinite(value) ? String(value) : 'null';
267 
268  case 'boolean':
269  case 'null':
270 
271  // If the value is a boolean or null, convert it to a string. Note:
272  // typeof null does not produce 'null'. The case is included here in
273  // the remote chance that this gets fixed someday.
274 
275  return String(value);
276 
277 // If the type is 'object', we might be dealing with an object or an array or
278 // null.
279 
280  case 'object':
281 
282  // Due to a specification blunder in ECMAScript, typeof null is 'object',
283  // so watch out for that case.
284 
285  if (!value) {
286  return 'null';
287  }
288 
289  // Make an array to hold the partial results of stringifying this object value.
290 
291  gap += indent;
292  partial = [];
293 
294  // Is the value an array?
295 
296  if (Object.prototype.toString.apply(value) === '[object Array]') {
297  // The value is an array. Stringify every element. Use null as a placeholder
298  // for non-JSON values.
299 
300  length = value.length;
301  for (i = 0; i < length; i += 1) {
302  partial[i] = str(i, value) || 'null';
303  }
304 
305  // Join all of the elements together, separated with commas, and wrap them in
306  // brackets.
307 
308  v = partial.length === 0
309  ? '[]'
310  : gap
311  ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
312  : '[' + partial.join(',') + ']';
313  gap = mind;
314  return v;
315  }
316 
317  // If the replacer is an array, use it to select the members to be stringified.
318 
319  if (rep && typeof rep === 'object') {
320  length = rep.length;
321  for (i = 0; i < length; i += 1) {
322  if (typeof rep[i] === 'string') {
323  k = rep[i];
324  v = str(k, value);
325  if (v) {
326  partial.push(quote(k) + (gap ? ': ' : ':') + v);
327  }
328  }
329  }
330  } else {
331  // Otherwise, iterate through all of the keys in the object.
332 
333  for (k in value) {
334  if (Object.prototype.hasOwnProperty.call(value, k)) {
335  v = str(k, value);
336  if (v) {
337  partial.push(quote(k) + (gap ? ': ' : ':') + v);
338  }
339  }
340  }
341  }
342 
343  // Join all of the member texts together, separated with commas,
344  // and wrap them in braces.
345 
346  v = partial.length === 0
347  ? '{}'
348  : gap
349  ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
350  : '{' + partial.join(',') + '}';
351  gap = mind;
352  return v;
353  }
354  }
355 
356 // If the JSON object does not yet have a stringify method, give it one.
357 
358  if (typeof JSON.stringify !== 'function') {
359  JSON.stringify = function (value, replacer, space) {
360 
361 // The stringify method takes a value and an optional replacer, and an optional
362 // space parameter, and returns a JSON text. The replacer can be a function
363 // that can replace values, or an array of strings that will select the keys.
364 // A default replacer method can be provided. Use of the space parameter can
365 // produce text that is more easily readable.
366 
367  var i;
368  gap = '';
369  indent = '';
370 
371 // If the space parameter is a number, make an indent string containing that
372 // many spaces.
373 
374  if (typeof space === 'number') {
375  for (i = 0; i < space; i += 1) {
376  indent += ' ';
377  }
378 
379 // If the space parameter is a string, it will be used as the indent string.
380  } else if (typeof space === 'string') {
381  indent = space;
382  }
383 
384 // If there is a replacer, it must be a function or an array.
385 // Otherwise, throw an error.
386 
387  rep = replacer;
388  if (replacer && typeof replacer !== 'function' &&
389  (typeof replacer !== 'object' ||
390  typeof replacer.length !== 'number')) {
391  throw new Error('JSON.stringify');
392  }
393 
394 // Make a fake root object containing our value under the key of ''.
395 // Return the result of stringifying the value.
396 
397  return str('', {'': value});
398  };
399  }
var v
function str(key, holder)
Definition: json2.js:229
var i

Variable Documentation

__pad0__

Definition at line 225 of file json2.js.

var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g

Definition at line 195 of file json2.js.

var escapable
Initial value:
= /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap,
indent,
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
},
rep;
function quote(string)
{
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string'
? c
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4)
var u

Definition at line 196 of file json2.js.