vzaar 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,345 @@
1
+ /*
2
+ http://www.JSON.org/json_parse.js
3
+ 2009-05-31
4
+
5
+ Public Domain.
6
+
7
+ NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
8
+
9
+ This file creates a json_parse function.
10
+
11
+ json_parse(text, reviver)
12
+ This method parses a JSON text to produce an object or array.
13
+ It can throw a SyntaxError exception.
14
+
15
+ The optional reviver parameter is a function that can filter and
16
+ transform the results. It receives each of the keys and values,
17
+ and its return value is used instead of the original value.
18
+ If it returns what it received, then the structure is not modified.
19
+ If it returns undefined then the member is deleted.
20
+
21
+ Example:
22
+
23
+ // Parse the text. Values that look like ISO date strings will
24
+ // be converted to Date objects.
25
+
26
+ myData = json_parse(text, function (key, value) {
27
+ var a;
28
+ if (typeof value === 'string') {
29
+ a =
30
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
31
+ if (a) {
32
+ return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
33
+ +a[5], +a[6]));
34
+ }
35
+ }
36
+ return value;
37
+ });
38
+
39
+ This is a reference implementation. You are free to copy, modify, or
40
+ redistribute.
41
+
42
+ This code should be minified before deployment.
43
+ See http://javascript.crockford.com/jsmin.html
44
+
45
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
46
+ NOT CONTROL.
47
+ */
48
+
49
+ /*members "", "\"", "\/", "\\", at, b, call, charAt, f, fromCharCode,
50
+ hasOwnProperty, message, n, name, push, r, t, text
51
+ */
52
+
53
+ var json_parse = (function () {
54
+
55
+ // This is a function that can parse a JSON text, producing a JavaScript
56
+ // data structure. It is a simple, recursive descent parser. It does not use
57
+ // eval or regular expressions, so it can be used as a model for implementing
58
+ // a JSON parser in other languages.
59
+
60
+ // We are defining the function inside of another function to avoid creating
61
+ // global variables.
62
+
63
+ var at, // The index of the current character
64
+ ch, // The current character
65
+ escapee = {
66
+ '"': '"',
67
+ '\\': '\\',
68
+ '/': '/',
69
+ b: '\b',
70
+ f: '\f',
71
+ n: '\n',
72
+ r: '\r',
73
+ t: '\t'
74
+ },
75
+ text,
76
+
77
+ error = function (m) {
78
+
79
+ // Call error when something is wrong.
80
+
81
+ throw {
82
+ name: 'SyntaxError',
83
+ message: m,
84
+ at: at,
85
+ text: text
86
+ };
87
+ },
88
+
89
+ next = function (c) {
90
+
91
+ // If a c parameter is provided, verify that it matches the current character.
92
+
93
+ if (c && c !== ch) {
94
+ error("Expected '" + c + "' instead of '" + ch + "'");
95
+ }
96
+
97
+ // Get the next character. When there are no more characters,
98
+ // return the empty string.
99
+
100
+ ch = text.charAt(at);
101
+ at += 1;
102
+ return ch;
103
+ },
104
+
105
+ number = function () {
106
+
107
+ // Parse a number value.
108
+
109
+ var number,
110
+ string = '';
111
+
112
+ if (ch === '-') {
113
+ string = '-';
114
+ next('-');
115
+ }
116
+ while (ch >= '0' && ch <= '9') {
117
+ string += ch;
118
+ next();
119
+ }
120
+ if (ch === '.') {
121
+ string += '.';
122
+ while (next() && ch >= '0' && ch <= '9') {
123
+ string += ch;
124
+ }
125
+ }
126
+ if (ch === 'e' || ch === 'E') {
127
+ string += ch;
128
+ next();
129
+ if (ch === '-' || ch === '+') {
130
+ string += ch;
131
+ next();
132
+ }
133
+ while (ch >= '0' && ch <= '9') {
134
+ string += ch;
135
+ next();
136
+ }
137
+ }
138
+ number = +string;
139
+ if (isNaN(number)) {
140
+ error("Bad number");
141
+ } else {
142
+ return number;
143
+ }
144
+ },
145
+
146
+ string = function () {
147
+
148
+ // Parse a string value.
149
+
150
+ var hex,
151
+ i,
152
+ string = '',
153
+ uffff;
154
+
155
+ // When parsing for string values, we must look for " and \ characters.
156
+
157
+ if (ch === '"') {
158
+ while (next()) {
159
+ if (ch === '"') {
160
+ next();
161
+ return string;
162
+ } else if (ch === '\\') {
163
+ next();
164
+ if (ch === 'u') {
165
+ uffff = 0;
166
+ for (i = 0; i < 4; i += 1) {
167
+ hex = parseInt(next(), 16);
168
+ if (!isFinite(hex)) {
169
+ break;
170
+ }
171
+ uffff = uffff * 16 + hex;
172
+ }
173
+ string += String.fromCharCode(uffff);
174
+ } else if (typeof escapee[ch] === 'string') {
175
+ string += escapee[ch];
176
+ } else {
177
+ break;
178
+ }
179
+ } else {
180
+ string += ch;
181
+ }
182
+ }
183
+ }
184
+ error("Bad string");
185
+ },
186
+
187
+ white = function () {
188
+
189
+ // Skip whitespace.
190
+
191
+ while (ch && ch <= ' ') {
192
+ next();
193
+ }
194
+ },
195
+
196
+ word = function () {
197
+
198
+ // true, false, or null.
199
+
200
+ switch (ch) {
201
+ case 't':
202
+ next('t');
203
+ next('r');
204
+ next('u');
205
+ next('e');
206
+ return true;
207
+ case 'f':
208
+ next('f');
209
+ next('a');
210
+ next('l');
211
+ next('s');
212
+ next('e');
213
+ return false;
214
+ case 'n':
215
+ next('n');
216
+ next('u');
217
+ next('l');
218
+ next('l');
219
+ return null;
220
+ }
221
+ error("Unexpected '" + ch + "'");
222
+ },
223
+
224
+ value, // Place holder for the value function.
225
+
226
+ array = function () {
227
+
228
+ // Parse an array value.
229
+
230
+ var array = [];
231
+
232
+ if (ch === '[') {
233
+ next('[');
234
+ white();
235
+ if (ch === ']') {
236
+ next(']');
237
+ return array; // empty array
238
+ }
239
+ while (ch) {
240
+ array.push(value());
241
+ white();
242
+ if (ch === ']') {
243
+ next(']');
244
+ return array;
245
+ }
246
+ next(',');
247
+ white();
248
+ }
249
+ }
250
+ error("Bad array");
251
+ },
252
+
253
+ object = function () {
254
+
255
+ // Parse an object value.
256
+
257
+ var key,
258
+ object = {};
259
+
260
+ if (ch === '{') {
261
+ next('{');
262
+ white();
263
+ if (ch === '}') {
264
+ next('}');
265
+ return object; // empty object
266
+ }
267
+ while (ch) {
268
+ key = string();
269
+ white();
270
+ next(':');
271
+ if (Object.hasOwnProperty.call(object, key)) {
272
+ error('Duplicate key "' + key + '"');
273
+ }
274
+ object[key] = value();
275
+ white();
276
+ if (ch === '}') {
277
+ next('}');
278
+ return object;
279
+ }
280
+ next(',');
281
+ white();
282
+ }
283
+ }
284
+ error("Bad object");
285
+ };
286
+
287
+ value = function () {
288
+
289
+ // Parse a JSON value. It could be an object, an array, a string, a number,
290
+ // or a word.
291
+
292
+ white();
293
+ switch (ch) {
294
+ case '{':
295
+ return object();
296
+ case '[':
297
+ return array();
298
+ case '"':
299
+ return string();
300
+ case '-':
301
+ return number();
302
+ default:
303
+ return ch >= '0' && ch <= '9' ? number() : word();
304
+ }
305
+ };
306
+
307
+ // Return the json_parse function. It will have access to all of the above
308
+ // functions and variables.
309
+
310
+ return function (source, reviver) {
311
+ var result;
312
+
313
+ text = source;
314
+ at = 0;
315
+ ch = ' ';
316
+ result = value();
317
+ white();
318
+ if (ch) {
319
+ error("Syntax error");
320
+ }
321
+
322
+ // If there is a reviver function, we recursively walk the new structure,
323
+ // passing each name/value pair to the reviver function for possible
324
+ // transformation, starting with a temporary root object that holds the result
325
+ // in an empty key. If there is not a reviver function, we simply return the
326
+ // result.
327
+
328
+ return typeof reviver === 'function' ? (function walk(holder, key) {
329
+ var k, v, value = holder[key];
330
+ if (value && typeof value === 'object') {
331
+ for (k in value) {
332
+ if (Object.hasOwnProperty.call(value, k)) {
333
+ v = walk(value, k);
334
+ if (v !== undefined) {
335
+ value[k] = v;
336
+ } else {
337
+ delete value[k];
338
+ }
339
+ }
340
+ }
341
+ }
342
+ return reviver.call(holder, key, value);
343
+ }({'': result}, '')) : result;
344
+ };
345
+ }());