Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.string.Builder"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.string.Builder"] = true;
3
dojo.provide("dojox.string.Builder");
4
 
5
(function(){
6
	dojox.string.Builder = function(/*String?*/str){
7
		// summary:
8
		//		A fast buffer for creating large strings
9
		// str: The initial string to seed the buffer with
10
		this.b = dojo.isIE ? [] : "";
11
		if(str){ this.append(str); }
12
	};
13
 
14
	var m = {
15
	 	append: function(/*String*/s){
16
			// summary: Append all arguments to the end of the buffer
17
			return this.appendArray(dojo._toArray(arguments)); // dojox.string.Builder
18
		},
19
		concat: function(/*String*/s){
20
			return this.append(s);
21
		},
22
		appendArray: function(/*Array*/strings) {
23
			this.b = String.prototype.concat.apply(this.b, strings);
24
			return this;
25
		},
26
		clear: function(){
27
			// summary: Remove all characters from the buffer
28
			this._clear();
29
			this.length = 0;
30
			return this;
31
		},
32
		replace: function(oldStr,newStr){
33
			// summary: Replace instances of one string with another in the buffer
34
			var s = this.toString();
35
			s = s.replace(oldStr,newStr);
36
			this._reset(s);
37
			this.length = s.length;
38
			return this;
39
		},
40
		remove: function(start, len){
41
			// summary: Remove len characters starting at index start
42
			if(len == 0){ return this; }
43
			var s = this.toString();
44
			this.clear();
45
			if(start > 0){
46
				this.append(s.substring(0, start));
47
			}
48
			if(start+len < s.length){
49
				this.append(s.substring(start+len));
50
			}
51
			return this;
52
		},
53
		insert: function(index, str){
54
			// summary: Insert string str starting at index
55
			var s = this.toString();
56
			this.clear();
57
			if(index == 0){
58
				this.append(str);
59
				this.append(s);
60
				return this;
61
			}else{
62
				this.append(s.substring(0, index));
63
				this.append(str);
64
				this.append(s.substring(index));
65
			}
66
			return this;
67
		},
68
		toString: function(){
69
			return this.b;
70
		},
71
		_clear: function(){
72
			this.b = "";
73
		},
74
		_reset: function(s){
75
			this.b = s;
76
		}
77
	}; // will hold methods for Builder
78
 
79
	if(dojo.isIE){
80
		dojo.mixin(m, {
81
			toString: function(){
82
				// Summary: Get the buffer as a string
83
				return this.b.join("");
84
			},
85
			appendArray: function(strings){
86
				this.b = this.b.concat(strings);
87
				return this;
88
			},
89
			_clear: function(){
90
				this.b = [];
91
			},
92
			_reset: function(s){
93
				this.b = [ s ];
94
			}
95
		});
96
	}
97
 
98
	dojo.extend(dojox.string.Builder, m);
99
})();
100
 
101
}