r24958: This is the final text, and the final version. I'll send the release
[jelmer/samba4-debian.git] / webapps / qooxdoo-0.6.5-sdk / frontend / framework / source / class / qx / util / StringBuilder.js
1 /* ************************************************************************
2
3    qooxdoo - the new era of web development
4
5    http://qooxdoo.org
6
7    Copyright:
8      2004-2007 1&1 Internet AG, Germany, http://www.1and1.org
9
10    License:
11      LGPL: http://www.gnu.org/licenses/lgpl.html
12      EPL: http://www.eclipse.org/org/documents/epl-v10.php
13      See the LICENSE file in the project's top-level directory for details.
14
15    Authors:
16      * Sebastian Werner (wpbasti)
17      * Andreas Ecker (ecker)
18
19 ************************************************************************ */
20
21 /* ************************************************************************
22
23 #require(qx.core.Client)
24
25 ************************************************************************ */
26
27 /**
28  * A string builder class
29  * <p>
30  * += operator is faster in Firefox and Opera.
31  * Array push/join is faster in Internet Explorer
32  * </p><p>
33  * Even with this wrapper, which costs some time, this is
34  * faster in Firefox than the alternative Array concat in
35  * all browsers (which is in relation to IE's performance issues
36  * only marginal). The IE performance loss caused by this
37  * wrapper is not relevant.
38  * </p><p>
39  * So this class seems to be the best compromise to handle
40  * string concatenation.</p>
41  */
42 qx.OO.defineClass("qx.util.StringBuilder", qx.core.Object,
43 function()
44 {
45   qx.core.Object.call(this);
46
47   this.init();
48   this.add.apply(this, arguments);
49 });
50
51
52 /**
53  * Resets the contents of the Stringbuilder
54  * equivalent to <pre>str = ""; </pre>
55  */
56 qx.Proto.clear = function() {}
57
58 /**
59  * Returns the contents of the concatenated string
60  *
61  * @return {String} string content
62  */
63 qx.Proto.get = function() {}
64
65 /**
66  * Append a variable number of string arguments
67  *
68  * @param varargs {String} variable number os strings to be added
69  */
70 qx.Proto.add = function(varargs) {}
71
72 /**
73  * Initializes the contents of the Stringbuilder
74  * equivalent to <pre>str = ""; </pre>
75  */
76 qx.Proto.init = function() {}
77
78 /** Destructor */
79 qx.Proto.dispose = function() {}
80
81 /**
82  * Returns the contents of the concatenated string
83  *
84  * @return {String} string content
85  */
86 qx.Proto.toString = function() {}
87
88
89 if (qx.core.Client.getInstance().isMshtml())
90 {
91   qx.Proto.clear = function() {
92     this._array = [];
93   }
94
95   qx.Proto.get = function() {
96     return this._array.join("");
97   }
98
99   qx.Proto.add = function() {
100     this._array.push.apply(this._array, arguments);
101   }
102
103   qx.Proto.init = function() {
104     this._array = [];
105   }
106
107   qx.Proto.dispose = function()
108   {
109     if (this.getDisposed()) {
110       return;
111     }
112
113     this._array = null;
114
115     qx.core.Object.prototype.dispose.call(this);
116   }
117 }
118 else
119 {
120   qx.Proto.clear = function() {
121     this._string = "";
122   }
123
124   qx.Proto.get = function() {
125     return this._string;
126   }
127
128   qx.Proto.add = function() {
129     this._string += Array.prototype.join.call(arguments, "");
130   }
131
132   qx.Proto.init = function() {
133     this._string = "";
134   }
135
136   qx.Proto.dispose = function()
137   {
138     if (this.getDisposed()) {
139       return;
140     }
141
142     this._string = null;
143
144     qx.core.Object.prototype.dispose.call(this);
145   }
146 }
147
148 qx.Proto.toString = qx.Proto.get;