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