Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.lang.repr");
12
dojo.require("dojo.lang.common");
13
dojo.require("dojo.AdapterRegistry");
14
dojo.require("dojo.string.extras");
15
dojo.lang.reprRegistry = new dojo.AdapterRegistry();
16
dojo.lang.registerRepr = function (name, check, wrap, override) {
17
	dojo.lang.reprRegistry.register(name, check, wrap, override);
18
};
19
dojo.lang.repr = function (obj) {
20
	if (typeof (obj) == "undefined") {
21
		return "undefined";
22
	} else {
23
		if (obj === null) {
24
			return "null";
25
		}
26
	}
27
	try {
28
		if (typeof (obj["__repr__"]) == "function") {
29
			return obj["__repr__"]();
30
		} else {
31
			if ((typeof (obj["repr"]) == "function") && (obj.repr != arguments.callee)) {
32
				return obj["repr"]();
33
			}
34
		}
35
		return dojo.lang.reprRegistry.match(obj);
36
	}
37
	catch (e) {
38
		if (typeof (obj.NAME) == "string" && (obj.toString == Function.prototype.toString || obj.toString == Object.prototype.toString)) {
39
			return obj.NAME;
40
		}
41
	}
42
	if (typeof (obj) == "function") {
43
		obj = (obj + "").replace(/^\s+/, "");
44
		var idx = obj.indexOf("{");
45
		if (idx != -1) {
46
			obj = obj.substr(0, idx) + "{...}";
47
		}
48
	}
49
	return obj + "";
50
};
51
dojo.lang.reprArrayLike = function (arr) {
52
	try {
53
		var na = dojo.lang.map(arr, dojo.lang.repr);
54
		return "[" + na.join(", ") + "]";
55
	}
56
	catch (e) {
57
	}
58
};
59
(function () {
60
	var m = dojo.lang;
61
	m.registerRepr("arrayLike", m.isArrayLike, m.reprArrayLike);
62
	m.registerRepr("string", m.isString, m.reprString);
63
	m.registerRepr("numbers", m.isNumber, m.reprNumber);
64
	m.registerRepr("boolean", m.isBoolean, m.reprNumber);
65
})();
66