metadata: Hand back NullTags if we find a file we don't know how to get the tags for
2 Copyright (c) 2005 JSON.org
3 Copyright (c) 2005, 2006 tonyg@kcbbs.gen.nz
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The Software shall be used for Good, not Evil.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 - September 2005: changes by tonyg@kcbbs.gen.nz for constructors and
27 customisable serialisation
29 - 23 June 2006: changes by tonyg@kcbbs.gen.nz for Rhino JS support
30 - 24 June 2006: changes by tonyg@kcbbs.gen.nz for better array-detection
31 - 8 November 2006: tonyg: conditionalise Java-specific code
36 org: 'http://www.JSON.org',
37 copyright: '(c)2005 JSON.org',
38 license: 'http://www.crockford.com/JSON/license.html',
41 "java.lang.Object": function (arg) { return JSON.stringify(String(arg)); }
44 rhinoSupport: false, /* set to true to enable Java JSON serialization */
45 isJavaObject: function (o) {
46 if (this.rhinoSupport) {
47 if (o instanceof java.lang.Object) {
54 findJavaSerializer: function (o) {
57 if (typeof this.javaSerializers[c.getName()] != 'undefined') {
58 return this.javaSerializers[c.getName()];
60 var interfaces = c.getInterfaces();
61 for (var i = 0; i < interfaces.length; i++) {
62 if (typeof this.javaSerializers[interfaces[i].getName()] != 'undefined') {
63 return this.javaSerializers[interfaces[i].getName()];
66 c = c.getSuperclass();
71 stringify: function (arg) {
72 var c, i, l, s = '', v;
77 if (arg instanceof Array) {
78 for (i = 0; i < arg.length; ++i) {
79 v = this.stringify(arg[i]);
86 } else if (typeof arg.toJsonString != 'undefined') {
87 return arg.toJsonString();
88 } else if (this.isJavaObject(arg)) {
89 v = this.findJavaSerializer(arg);
93 } else if (typeof arg.toString != 'undefined') {
96 if (typeof v != 'undefined' && typeof v != 'function') {
97 v = this.stringify(v);
101 s += this.stringify(i) + ':' + v;
104 return '{' + s + '}';
109 return isFinite(arg) ? String(arg) : 'null';
113 for (i = 0; i < l; i += 1) {
116 if (c == '\\' || c == '"') {
139 s += '\\u00' + Math.floor(c / 16).toString(16) +
140 (c % 16).toString(16);
151 parse: function (text, ctors) {
165 ch = text.charAt(at);
171 while (ch != '' && ch <= ' ') {
180 outer: while (next()) {
184 } else if (ch == '\\') {
203 for (i = 0; i < 4; i += 1) {
204 t = parseInt(next(), 16);
210 s += String.fromCharCode(u);
239 } else if (ch != ',') {
271 } else if (ch != ',') {
287 while (ch >= '0' && ch <= '9') {
293 while (next() && ch >= '0' && ch <= '9') {
297 if (ch == 'e' || ch == 'E') {
300 if (ch == '-' || ch == '+') {
304 while (ch >= '0' && ch <= '9') {
320 if (next() == 'r' && next() == 'u' && next() == 'e') {
326 if (next() == 'a' && next() == 'l' && next() == 's' &&
333 if (next() == 'u' && next() == 'l' && next() == 'l') {
339 error("Syntax error");
346 while (ch == '.' || (ch.toUpperCase() >= 'A' &&
347 ch.toUpperCase() <= 'Z')) {
353 return ctors[name](arg);
355 error("Unknown ctor " + name);
375 return ch >= '0' && ch <= '9' ? num() : word();