Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.lang.repr");
14
dojo.require("dojo.lang.common");
15
dojo.require("dojo.AdapterRegistry");
16
dojo.require("dojo.string.extras");
17
dojo.lang.reprRegistry = new dojo.AdapterRegistry();
18
dojo.lang.registerRepr = function (name, check, wrap, override) {
19
	dojo.lang.reprRegistry.register(name, check, wrap, override);
20
};
21
dojo.lang.repr = function (obj) {
22
	if (typeof (obj) == "undefined") {
23
		return "undefined";
24
	} else {
25
		if (obj === null) {
26
			return "null";
27
		}
28
	}
29
	try {
30
		if (typeof (obj["__repr__"]) == "function") {
31
			return obj["__repr__"]();
32
		} else {
33
			if ((typeof (obj["repr"]) == "function") && (obj.repr != arguments.callee)) {
34
				return obj["repr"]();
35
			}
36
		}
37
		return dojo.lang.reprRegistry.match(obj);
38
	}
39
	catch (e) {
40
		if (typeof (obj.NAME) == "string" && (obj.toString == Function.prototype.toString || obj.toString == Object.prototype.toString)) {
41
			return obj.NAME;
42
		}
43
	}
44
	if (typeof (obj) == "function") {
45
		obj = (obj + "").replace(/^\s+/, "");
46
		var idx = obj.indexOf("{");
47
		if (idx != -1) {
48
			obj = obj.substr(0, idx) + "{...}";
49
		}
50
	}
51
	return obj + "";
52
};
53
dojo.lang.reprArrayLike = function (arr) {
54
	try {
55
		var na = dojo.lang.map(arr, dojo.lang.repr);
56
		return "[" + na.join(", ") + "]";
57
	}
58
	catch (e) {
59
	}
60
};
61
(function () {
62
	var m = dojo.lang;
63
	m.registerRepr("arrayLike", m.isArrayLike, m.reprArrayLike);
64
	m.registerRepr("string", m.isString, m.reprString);
65
	m.registerRepr("numbers", m.isNumber, m.reprNumber);
66
	m.registerRepr("boolean", m.isBoolean, m.reprNumber);
67
})();
68