~ubuntu-branches/ubuntu/utopic/json-js/utopic

« back to all changes in this revision

Viewing changes to json2.js

  • Committer: Package Import Robot
  • Author(s): Jonas Smedegaard, Jonas Smedegaard
  • Date: 2011-12-23 13:29:11 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111223132911-vjzj2s0682gry4yz
Tags: 0~20111020-1
* New snapshot of upstream VCS.

[ Jonas Smedegaard ]
* Drop local-options file: defaults since dpkg-source 1.16.1.
* Relax to build-depend unversioned on debhelper: Needed version
  satisfied even in oldstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    http://www.JSON.org/json2.js
3
 
    2011-02-23
 
3
    2011-10-19
4
4
 
5
5
    Public Domain.
6
6
 
146
146
    redistribute.
147
147
*/
148
148
 
149
 
/*jslint evil: true, strict: false, regexp: false */
 
149
/*jslint evil: true, regexp: true */
150
150
 
151
151
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
152
152
    call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
165
165
}
166
166
 
167
167
(function () {
168
 
    "use strict";
 
168
    'use strict';
169
169
 
170
170
    function f(n) {
171
171
        // Format integers to have at least two digits.
176
176
 
177
177
        Date.prototype.toJSON = function (key) {
178
178
 
179
 
            return isFinite(this.valueOf()) ?
180
 
                this.getUTCFullYear()     + '-' +
181
 
                f(this.getUTCMonth() + 1) + '-' +
182
 
                f(this.getUTCDate())      + 'T' +
183
 
                f(this.getUTCHours())     + ':' +
184
 
                f(this.getUTCMinutes())   + ':' +
185
 
                f(this.getUTCSeconds())   + 'Z' : null;
 
179
            return isFinite(this.valueOf())
 
180
                ? this.getUTCFullYear()     + '-' +
 
181
                    f(this.getUTCMonth() + 1) + '-' +
 
182
                    f(this.getUTCDate())      + 'T' +
 
183
                    f(this.getUTCHours())     + ':' +
 
184
                    f(this.getUTCMinutes())   + ':' +
 
185
                    f(this.getUTCSeconds())   + 'Z'
 
186
                : null;
186
187
        };
187
188
 
188
189
        String.prototype.toJSON      =
218
219
        escapable.lastIndex = 0;
219
220
        return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
220
221
            var c = meta[a];
221
 
            return typeof c === 'string' ? c :
222
 
                '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
 
222
            return typeof c === 'string'
 
223
                ? c
 
224
                : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
223
225
        }) + '"' : '"' + string + '"';
224
226
    }
225
227
 
303
305
// Join all of the elements together, separated with commas, and wrap them in
304
306
// brackets.
305
307
 
306
 
                v = partial.length === 0 ? '[]' : gap ?
307
 
                    '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
308
 
                    '[' + partial.join(',') + ']';
 
308
                v = partial.length === 0
 
309
                    ? '[]'
 
310
                    : gap
 
311
                    ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
 
312
                    : '[' + partial.join(',') + ']';
309
313
                gap = mind;
310
314
                return v;
311
315
            }
340
344
// Join all of the member texts together, separated with commas,
341
345
// and wrap them in braces.
342
346
 
343
 
            v = partial.length === 0 ? '{}' : gap ?
344
 
                '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
345
 
                '{' + partial.join(',') + '}';
 
347
            v = partial.length === 0
 
348
                ? '{}'
 
349
                : gap
 
350
                ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
 
351
                : '{' + partial.join(',') + '}';
346
352
            gap = mind;
347
353
            return v;
348
354
        }
468
474
// In the optional fourth stage, we recursively walk the new structure, passing
469
475
// each name/value pair to a reviver function for possible transformation.
470
476
 
471
 
                return typeof reviver === 'function' ?
472
 
                    walk({'': j}, '') : j;
 
477
                return typeof reviver === 'function'
 
478
                    ? walk({'': j}, '')
 
479
                    : j;
473
480
            }
474
481
 
475
482
// If the text is not JSON parseable, then a SyntaxError is thrown.