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.string.Builder");
12
dojo.require("dojo.string");
13
dojo.require("dojo.lang.common");
14
dojo.string.Builder = function (str) {
15
	this.arrConcat = (dojo.render.html.capable && dojo.render.html["ie"]);
16
	var a = [];
17
	var b = "";
18
	var length = this.length = b.length;
19
	if (this.arrConcat) {
20
		if (b.length > 0) {
21
			a.push(b);
22
		}
23
		b = "";
24
	}
25
	this.toString = this.valueOf = function () {
26
		return (this.arrConcat) ? a.join("") : b;
27
	};
28
	this.append = function () {
29
		for (var x = 0; x < arguments.length; x++) {
30
			var s = arguments[x];
31
			if (dojo.lang.isArrayLike(s)) {
32
				this.append.apply(this, s);
33
			} else {
34
				if (this.arrConcat) {
35
					a.push(s);
36
				} else {
37
					b += s;
38
				}
39
				length += s.length;
40
				this.length = length;
41
			}
42
		}
43
		return this;
44
	};
45
	this.clear = function () {
46
		a = [];
47
		b = "";
48
		length = this.length = 0;
49
		return this;
50
	};
51
	this.remove = function (f, l) {
52
		var s = "";
53
		if (this.arrConcat) {
54
			b = a.join("");
55
		}
56
		a = [];
57
		if (f > 0) {
58
			s = b.substring(0, (f - 1));
59
		}
60
		b = s + b.substring(f + l);
61
		length = this.length = b.length;
62
		if (this.arrConcat) {
63
			a.push(b);
64
			b = "";
65
		}
66
		return this;
67
	};
68
	this.replace = function (o, n) {
69
		if (this.arrConcat) {
70
			b = a.join("");
71
		}
72
		a = [];
73
		b = b.replace(o, n);
74
		length = this.length = b.length;
75
		if (this.arrConcat) {
76
			a.push(b);
77
			b = "";
78
		}
79
		return this;
80
	};
81
	this.insert = function (idx, s) {
82
		if (this.arrConcat) {
83
			b = a.join("");
84
		}
85
		a = [];
86
		if (idx == 0) {
87
			b = s + b;
88
		} else {
89
			var t = b.split("");
90
			t.splice(idx, 0, s);
91
			b = t.join("");
92
		}
93
		length = this.length = b.length;
94
		if (this.arrConcat) {
95
			a.push(b);
96
			b = "";
97
		}
98
		return this;
99
	};
100
	this.append.apply(this, arguments);
101
};
102