jaroslav@56
|
1 |
/*
|
jaroslav@56
|
2 |
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
|
jaroslav@56
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jaroslav@56
|
4 |
*
|
jaroslav@56
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
jaroslav@56
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
jaroslav@56
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
jaroslav@56
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@56
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
jaroslav@56
|
10 |
*
|
jaroslav@56
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jaroslav@56
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jaroslav@56
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jaroslav@56
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jaroslav@56
|
15 |
* accompanied this code).
|
jaroslav@56
|
16 |
*
|
jaroslav@56
|
17 |
* You should have received a copy of the GNU General Public License version
|
jaroslav@56
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jaroslav@56
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jaroslav@56
|
20 |
*
|
jaroslav@56
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jaroslav@56
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
jaroslav@56
|
23 |
* questions.
|
jaroslav@56
|
24 |
*/
|
jaroslav@56
|
25 |
|
jaroslav@56
|
26 |
package java.lang;
|
jaroslav@56
|
27 |
|
jaroslav@56
|
28 |
/**
|
jaroslav@56
|
29 |
* A mutable sequence of characters.
|
jaroslav@56
|
30 |
* <p>
|
jaroslav@56
|
31 |
* Implements a modifiable string. At any point in time it contains some
|
jaroslav@56
|
32 |
* particular sequence of characters, but the length and content of the
|
jaroslav@56
|
33 |
* sequence can be changed through certain method calls.
|
jaroslav@56
|
34 |
*
|
jaroslav@56
|
35 |
* @author Michael McCloskey
|
jaroslav@56
|
36 |
* @author Martin Buchholz
|
jaroslav@56
|
37 |
* @author Ulf Zibis
|
jaroslav@56
|
38 |
* @since 1.5
|
jaroslav@56
|
39 |
*/
|
jaroslav@56
|
40 |
abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
jaroslav@56
|
41 |
/**
|
jaroslav@56
|
42 |
* The value is used for character storage.
|
jaroslav@56
|
43 |
*/
|
jaroslav@56
|
44 |
char[] value;
|
jaroslav@56
|
45 |
|
jaroslav@56
|
46 |
/**
|
jaroslav@56
|
47 |
* The count is the number of characters used.
|
jaroslav@56
|
48 |
*/
|
jaroslav@56
|
49 |
int count;
|
jaroslav@56
|
50 |
|
jaroslav@56
|
51 |
/**
|
jaroslav@56
|
52 |
* This no-arg constructor is necessary for serialization of subclasses.
|
jaroslav@56
|
53 |
*/
|
jaroslav@56
|
54 |
AbstractStringBuilder() {
|
jaroslav@56
|
55 |
}
|
jaroslav@56
|
56 |
|
jaroslav@56
|
57 |
/**
|
jaroslav@56
|
58 |
* Creates an AbstractStringBuilder of the specified capacity.
|
jaroslav@56
|
59 |
*/
|
jaroslav@56
|
60 |
AbstractStringBuilder(int capacity) {
|
jaroslav@56
|
61 |
value = new char[capacity];
|
jaroslav@56
|
62 |
}
|
jaroslav@56
|
63 |
|
jaroslav@56
|
64 |
/**
|
jaroslav@56
|
65 |
* Returns the length (character count).
|
jaroslav@56
|
66 |
*
|
jaroslav@56
|
67 |
* @return the length of the sequence of characters currently
|
jaroslav@56
|
68 |
* represented by this object
|
jaroslav@56
|
69 |
*/
|
jaroslav@56
|
70 |
public int length() {
|
jaroslav@56
|
71 |
return count;
|
jaroslav@56
|
72 |
}
|
jaroslav@56
|
73 |
|
jaroslav@56
|
74 |
/**
|
jaroslav@56
|
75 |
* Returns the current capacity. The capacity is the amount of storage
|
jaroslav@56
|
76 |
* available for newly inserted characters, beyond which an allocation
|
jaroslav@56
|
77 |
* will occur.
|
jaroslav@56
|
78 |
*
|
jaroslav@56
|
79 |
* @return the current capacity
|
jaroslav@56
|
80 |
*/
|
jaroslav@56
|
81 |
public int capacity() {
|
jaroslav@56
|
82 |
return value.length;
|
jaroslav@56
|
83 |
}
|
jaroslav@56
|
84 |
|
jaroslav@56
|
85 |
/**
|
jaroslav@56
|
86 |
* Ensures that the capacity is at least equal to the specified minimum.
|
jaroslav@56
|
87 |
* If the current capacity is less than the argument, then a new internal
|
jaroslav@56
|
88 |
* array is allocated with greater capacity. The new capacity is the
|
jaroslav@56
|
89 |
* larger of:
|
jaroslav@56
|
90 |
* <ul>
|
jaroslav@56
|
91 |
* <li>The <code>minimumCapacity</code> argument.
|
jaroslav@56
|
92 |
* <li>Twice the old capacity, plus <code>2</code>.
|
jaroslav@56
|
93 |
* </ul>
|
jaroslav@56
|
94 |
* If the <code>minimumCapacity</code> argument is nonpositive, this
|
jaroslav@56
|
95 |
* method takes no action and simply returns.
|
jaroslav@56
|
96 |
*
|
jaroslav@56
|
97 |
* @param minimumCapacity the minimum desired capacity.
|
jaroslav@56
|
98 |
*/
|
jaroslav@56
|
99 |
public void ensureCapacity(int minimumCapacity) {
|
jaroslav@56
|
100 |
if (minimumCapacity > 0)
|
jaroslav@56
|
101 |
ensureCapacityInternal(minimumCapacity);
|
jaroslav@56
|
102 |
}
|
jaroslav@56
|
103 |
|
jaroslav@56
|
104 |
/**
|
jaroslav@56
|
105 |
* This method has the same contract as ensureCapacity, but is
|
jaroslav@56
|
106 |
* never synchronized.
|
jaroslav@56
|
107 |
*/
|
jaroslav@56
|
108 |
private void ensureCapacityInternal(int minimumCapacity) {
|
jaroslav@56
|
109 |
// overflow-conscious code
|
jaroslav@56
|
110 |
if (minimumCapacity - value.length > 0)
|
jaroslav@56
|
111 |
expandCapacity(minimumCapacity);
|
jaroslav@56
|
112 |
}
|
jaroslav@56
|
113 |
|
jaroslav@56
|
114 |
/**
|
jaroslav@56
|
115 |
* This implements the expansion semantics of ensureCapacity with no
|
jaroslav@56
|
116 |
* size check or synchronization.
|
jaroslav@56
|
117 |
*/
|
jaroslav@56
|
118 |
void expandCapacity(int minimumCapacity) {
|
jaroslav@56
|
119 |
int newCapacity = value.length * 2 + 2;
|
jaroslav@56
|
120 |
if (newCapacity - minimumCapacity < 0)
|
jaroslav@56
|
121 |
newCapacity = minimumCapacity;
|
jaroslav@56
|
122 |
if (newCapacity < 0) {
|
jaroslav@56
|
123 |
if (minimumCapacity < 0) // overflow
|
jaroslav@56
|
124 |
throw new OutOfMemoryError();
|
jaroslav@56
|
125 |
newCapacity = Integer.MAX_VALUE;
|
jaroslav@56
|
126 |
}
|
jaroslav@104
|
127 |
value = copyOf(value, newCapacity);
|
jaroslav@56
|
128 |
}
|
jaroslav@56
|
129 |
|
jaroslav@56
|
130 |
/**
|
jaroslav@56
|
131 |
* Attempts to reduce storage used for the character sequence.
|
jaroslav@56
|
132 |
* If the buffer is larger than necessary to hold its current sequence of
|
jaroslav@56
|
133 |
* characters, then it may be resized to become more space efficient.
|
jaroslav@56
|
134 |
* Calling this method may, but is not required to, affect the value
|
jaroslav@56
|
135 |
* returned by a subsequent call to the {@link #capacity()} method.
|
jaroslav@56
|
136 |
*/
|
jaroslav@56
|
137 |
public void trimToSize() {
|
jaroslav@56
|
138 |
if (count < value.length) {
|
jaroslav@104
|
139 |
value = copyOf(value, count);
|
jaroslav@56
|
140 |
}
|
jaroslav@56
|
141 |
}
|
jaroslav@56
|
142 |
|
jaroslav@56
|
143 |
/**
|
jaroslav@56
|
144 |
* Sets the length of the character sequence.
|
jaroslav@56
|
145 |
* The sequence is changed to a new character sequence
|
jaroslav@56
|
146 |
* whose length is specified by the argument. For every nonnegative
|
jaroslav@56
|
147 |
* index <i>k</i> less than <code>newLength</code>, the character at
|
jaroslav@56
|
148 |
* index <i>k</i> in the new character sequence is the same as the
|
jaroslav@56
|
149 |
* character at index <i>k</i> in the old sequence if <i>k</i> is less
|
jaroslav@56
|
150 |
* than the length of the old character sequence; otherwise, it is the
|
jaroslav@56
|
151 |
* null character <code>'\u0000'</code>.
|
jaroslav@56
|
152 |
*
|
jaroslav@56
|
153 |
* In other words, if the <code>newLength</code> argument is less than
|
jaroslav@56
|
154 |
* the current length, the length is changed to the specified length.
|
jaroslav@56
|
155 |
* <p>
|
jaroslav@56
|
156 |
* If the <code>newLength</code> argument is greater than or equal
|
jaroslav@56
|
157 |
* to the current length, sufficient null characters
|
jaroslav@56
|
158 |
* (<code>'\u0000'</code>) are appended so that
|
jaroslav@56
|
159 |
* length becomes the <code>newLength</code> argument.
|
jaroslav@56
|
160 |
* <p>
|
jaroslav@56
|
161 |
* The <code>newLength</code> argument must be greater than or equal
|
jaroslav@56
|
162 |
* to <code>0</code>.
|
jaroslav@56
|
163 |
*
|
jaroslav@56
|
164 |
* @param newLength the new length
|
jaroslav@56
|
165 |
* @throws IndexOutOfBoundsException if the
|
jaroslav@56
|
166 |
* <code>newLength</code> argument is negative.
|
jaroslav@56
|
167 |
*/
|
jaroslav@56
|
168 |
public void setLength(int newLength) {
|
jaroslav@56
|
169 |
if (newLength < 0)
|
jaroslav@56
|
170 |
throw new StringIndexOutOfBoundsException(newLength);
|
jaroslav@56
|
171 |
ensureCapacityInternal(newLength);
|
jaroslav@56
|
172 |
|
jaroslav@56
|
173 |
if (count < newLength) {
|
jaroslav@56
|
174 |
for (; count < newLength; count++)
|
jaroslav@56
|
175 |
value[count] = '\0';
|
jaroslav@56
|
176 |
} else {
|
jaroslav@56
|
177 |
count = newLength;
|
jaroslav@56
|
178 |
}
|
jaroslav@56
|
179 |
}
|
jaroslav@56
|
180 |
|
jaroslav@56
|
181 |
/**
|
jaroslav@56
|
182 |
* Returns the <code>char</code> value in this sequence at the specified index.
|
jaroslav@56
|
183 |
* The first <code>char</code> value is at index <code>0</code>, the next at index
|
jaroslav@56
|
184 |
* <code>1</code>, and so on, as in array indexing.
|
jaroslav@56
|
185 |
* <p>
|
jaroslav@56
|
186 |
* The index argument must be greater than or equal to
|
jaroslav@56
|
187 |
* <code>0</code>, and less than the length of this sequence.
|
jaroslav@56
|
188 |
*
|
jaroslav@56
|
189 |
* <p>If the <code>char</code> value specified by the index is a
|
jaroslav@56
|
190 |
* <a href="Character.html#unicode">surrogate</a>, the surrogate
|
jaroslav@56
|
191 |
* value is returned.
|
jaroslav@56
|
192 |
*
|
jaroslav@56
|
193 |
* @param index the index of the desired <code>char</code> value.
|
jaroslav@56
|
194 |
* @return the <code>char</code> value at the specified index.
|
jaroslav@56
|
195 |
* @throws IndexOutOfBoundsException if <code>index</code> is
|
jaroslav@56
|
196 |
* negative or greater than or equal to <code>length()</code>.
|
jaroslav@56
|
197 |
*/
|
jaroslav@56
|
198 |
public char charAt(int index) {
|
jaroslav@56
|
199 |
if ((index < 0) || (index >= count))
|
jaroslav@56
|
200 |
throw new StringIndexOutOfBoundsException(index);
|
jaroslav@56
|
201 |
return value[index];
|
jaroslav@56
|
202 |
}
|
jaroslav@56
|
203 |
|
jaroslav@56
|
204 |
/**
|
jaroslav@56
|
205 |
* Returns the character (Unicode code point) at the specified
|
jaroslav@56
|
206 |
* index. The index refers to <code>char</code> values
|
jaroslav@56
|
207 |
* (Unicode code units) and ranges from <code>0</code> to
|
jaroslav@56
|
208 |
* {@link #length()}<code> - 1</code>.
|
jaroslav@56
|
209 |
*
|
jaroslav@56
|
210 |
* <p> If the <code>char</code> value specified at the given index
|
jaroslav@56
|
211 |
* is in the high-surrogate range, the following index is less
|
jaroslav@56
|
212 |
* than the length of this sequence, and the
|
jaroslav@56
|
213 |
* <code>char</code> value at the following index is in the
|
jaroslav@56
|
214 |
* low-surrogate range, then the supplementary code point
|
jaroslav@56
|
215 |
* corresponding to this surrogate pair is returned. Otherwise,
|
jaroslav@56
|
216 |
* the <code>char</code> value at the given index is returned.
|
jaroslav@56
|
217 |
*
|
jaroslav@56
|
218 |
* @param index the index to the <code>char</code> values
|
jaroslav@56
|
219 |
* @return the code point value of the character at the
|
jaroslav@56
|
220 |
* <code>index</code>
|
jaroslav@56
|
221 |
* @exception IndexOutOfBoundsException if the <code>index</code>
|
jaroslav@56
|
222 |
* argument is negative or not less than the length of this
|
jaroslav@56
|
223 |
* sequence.
|
jaroslav@56
|
224 |
*/
|
jaroslav@56
|
225 |
public int codePointAt(int index) {
|
jaroslav@56
|
226 |
if ((index < 0) || (index >= count)) {
|
jaroslav@56
|
227 |
throw new StringIndexOutOfBoundsException(index);
|
jaroslav@56
|
228 |
}
|
jaroslav@56
|
229 |
return Character.codePointAt(value, index);
|
jaroslav@56
|
230 |
}
|
jaroslav@56
|
231 |
|
jaroslav@56
|
232 |
/**
|
jaroslav@56
|
233 |
* Returns the character (Unicode code point) before the specified
|
jaroslav@56
|
234 |
* index. The index refers to <code>char</code> values
|
jaroslav@56
|
235 |
* (Unicode code units) and ranges from <code>1</code> to {@link
|
jaroslav@56
|
236 |
* #length()}.
|
jaroslav@56
|
237 |
*
|
jaroslav@56
|
238 |
* <p> If the <code>char</code> value at <code>(index - 1)</code>
|
jaroslav@56
|
239 |
* is in the low-surrogate range, <code>(index - 2)</code> is not
|
jaroslav@56
|
240 |
* negative, and the <code>char</code> value at <code>(index -
|
jaroslav@56
|
241 |
* 2)</code> is in the high-surrogate range, then the
|
jaroslav@56
|
242 |
* supplementary code point value of the surrogate pair is
|
jaroslav@56
|
243 |
* returned. If the <code>char</code> value at <code>index -
|
jaroslav@56
|
244 |
* 1</code> is an unpaired low-surrogate or a high-surrogate, the
|
jaroslav@56
|
245 |
* surrogate value is returned.
|
jaroslav@56
|
246 |
*
|
jaroslav@56
|
247 |
* @param index the index following the code point that should be returned
|
jaroslav@56
|
248 |
* @return the Unicode code point value before the given index.
|
jaroslav@56
|
249 |
* @exception IndexOutOfBoundsException if the <code>index</code>
|
jaroslav@56
|
250 |
* argument is less than 1 or greater than the length
|
jaroslav@56
|
251 |
* of this sequence.
|
jaroslav@56
|
252 |
*/
|
jaroslav@56
|
253 |
public int codePointBefore(int index) {
|
jaroslav@56
|
254 |
int i = index - 1;
|
jaroslav@56
|
255 |
if ((i < 0) || (i >= count)) {
|
jaroslav@56
|
256 |
throw new StringIndexOutOfBoundsException(index);
|
jaroslav@56
|
257 |
}
|
jaroslav@56
|
258 |
return Character.codePointBefore(value, index);
|
jaroslav@56
|
259 |
}
|
jaroslav@56
|
260 |
|
jaroslav@56
|
261 |
/**
|
jaroslav@56
|
262 |
* Returns the number of Unicode code points in the specified text
|
jaroslav@56
|
263 |
* range of this sequence. The text range begins at the specified
|
jaroslav@56
|
264 |
* <code>beginIndex</code> and extends to the <code>char</code> at
|
jaroslav@56
|
265 |
* index <code>endIndex - 1</code>. Thus the length (in
|
jaroslav@56
|
266 |
* <code>char</code>s) of the text range is
|
jaroslav@56
|
267 |
* <code>endIndex-beginIndex</code>. Unpaired surrogates within
|
jaroslav@56
|
268 |
* this sequence count as one code point each.
|
jaroslav@56
|
269 |
*
|
jaroslav@56
|
270 |
* @param beginIndex the index to the first <code>char</code> of
|
jaroslav@56
|
271 |
* the text range.
|
jaroslav@56
|
272 |
* @param endIndex the index after the last <code>char</code> of
|
jaroslav@56
|
273 |
* the text range.
|
jaroslav@56
|
274 |
* @return the number of Unicode code points in the specified text
|
jaroslav@56
|
275 |
* range
|
jaroslav@56
|
276 |
* @exception IndexOutOfBoundsException if the
|
jaroslav@56
|
277 |
* <code>beginIndex</code> is negative, or <code>endIndex</code>
|
jaroslav@56
|
278 |
* is larger than the length of this sequence, or
|
jaroslav@56
|
279 |
* <code>beginIndex</code> is larger than <code>endIndex</code>.
|
jaroslav@56
|
280 |
*/
|
jaroslav@56
|
281 |
public int codePointCount(int beginIndex, int endIndex) {
|
jaroslav@56
|
282 |
if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
|
jaroslav@56
|
283 |
throw new IndexOutOfBoundsException();
|
jaroslav@56
|
284 |
}
|
jaroslav@56
|
285 |
return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
|
jaroslav@56
|
286 |
}
|
jaroslav@56
|
287 |
|
jaroslav@56
|
288 |
/**
|
jaroslav@56
|
289 |
* Returns the index within this sequence that is offset from the
|
jaroslav@56
|
290 |
* given <code>index</code> by <code>codePointOffset</code> code
|
jaroslav@56
|
291 |
* points. Unpaired surrogates within the text range given by
|
jaroslav@56
|
292 |
* <code>index</code> and <code>codePointOffset</code> count as
|
jaroslav@56
|
293 |
* one code point each.
|
jaroslav@56
|
294 |
*
|
jaroslav@56
|
295 |
* @param index the index to be offset
|
jaroslav@56
|
296 |
* @param codePointOffset the offset in code points
|
jaroslav@56
|
297 |
* @return the index within this sequence
|
jaroslav@56
|
298 |
* @exception IndexOutOfBoundsException if <code>index</code>
|
jaroslav@56
|
299 |
* is negative or larger then the length of this sequence,
|
jaroslav@56
|
300 |
* or if <code>codePointOffset</code> is positive and the subsequence
|
jaroslav@56
|
301 |
* starting with <code>index</code> has fewer than
|
jaroslav@56
|
302 |
* <code>codePointOffset</code> code points,
|
jaroslav@56
|
303 |
* or if <code>codePointOffset</code> is negative and the subsequence
|
jaroslav@56
|
304 |
* before <code>index</code> has fewer than the absolute value of
|
jaroslav@56
|
305 |
* <code>codePointOffset</code> code points.
|
jaroslav@56
|
306 |
*/
|
jaroslav@56
|
307 |
public int offsetByCodePoints(int index, int codePointOffset) {
|
jaroslav@56
|
308 |
if (index < 0 || index > count) {
|
jaroslav@56
|
309 |
throw new IndexOutOfBoundsException();
|
jaroslav@56
|
310 |
}
|
jaroslav@56
|
311 |
return Character.offsetByCodePointsImpl(value, 0, count,
|
jaroslav@56
|
312 |
index, codePointOffset);
|
jaroslav@56
|
313 |
}
|
jaroslav@56
|
314 |
|
jaroslav@56
|
315 |
/**
|
jaroslav@56
|
316 |
* Characters are copied from this sequence into the
|
jaroslav@56
|
317 |
* destination character array <code>dst</code>. The first character to
|
jaroslav@56
|
318 |
* be copied is at index <code>srcBegin</code>; the last character to
|
jaroslav@56
|
319 |
* be copied is at index <code>srcEnd-1</code>. The total number of
|
jaroslav@56
|
320 |
* characters to be copied is <code>srcEnd-srcBegin</code>. The
|
jaroslav@56
|
321 |
* characters are copied into the subarray of <code>dst</code> starting
|
jaroslav@56
|
322 |
* at index <code>dstBegin</code> and ending at index:
|
jaroslav@56
|
323 |
* <p><blockquote><pre>
|
jaroslav@56
|
324 |
* dstbegin + (srcEnd-srcBegin) - 1
|
jaroslav@56
|
325 |
* </pre></blockquote>
|
jaroslav@56
|
326 |
*
|
jaroslav@56
|
327 |
* @param srcBegin start copying at this offset.
|
jaroslav@56
|
328 |
* @param srcEnd stop copying at this offset.
|
jaroslav@56
|
329 |
* @param dst the array to copy the data into.
|
jaroslav@56
|
330 |
* @param dstBegin offset into <code>dst</code>.
|
jaroslav@56
|
331 |
* @throws NullPointerException if <code>dst</code> is
|
jaroslav@56
|
332 |
* <code>null</code>.
|
jaroslav@56
|
333 |
* @throws IndexOutOfBoundsException if any of the following is true:
|
jaroslav@56
|
334 |
* <ul>
|
jaroslav@56
|
335 |
* <li><code>srcBegin</code> is negative
|
jaroslav@56
|
336 |
* <li><code>dstBegin</code> is negative
|
jaroslav@56
|
337 |
* <li>the <code>srcBegin</code> argument is greater than
|
jaroslav@56
|
338 |
* the <code>srcEnd</code> argument.
|
jaroslav@56
|
339 |
* <li><code>srcEnd</code> is greater than
|
jaroslav@56
|
340 |
* <code>this.length()</code>.
|
jaroslav@56
|
341 |
* <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
|
jaroslav@56
|
342 |
* <code>dst.length</code>
|
jaroslav@56
|
343 |
* </ul>
|
jaroslav@56
|
344 |
*/
|
jaroslav@56
|
345 |
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
|
jaroslav@56
|
346 |
{
|
jaroslav@56
|
347 |
if (srcBegin < 0)
|
jaroslav@56
|
348 |
throw new StringIndexOutOfBoundsException(srcBegin);
|
jaroslav@56
|
349 |
if ((srcEnd < 0) || (srcEnd > count))
|
jaroslav@56
|
350 |
throw new StringIndexOutOfBoundsException(srcEnd);
|
jaroslav@56
|
351 |
if (srcBegin > srcEnd)
|
jaroslav@56
|
352 |
throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
|
jaroslav@104
|
353 |
arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
|
jaroslav@56
|
354 |
}
|
jaroslav@56
|
355 |
|
jaroslav@56
|
356 |
/**
|
jaroslav@56
|
357 |
* The character at the specified index is set to <code>ch</code>. This
|
jaroslav@56
|
358 |
* sequence is altered to represent a new character sequence that is
|
jaroslav@56
|
359 |
* identical to the old character sequence, except that it contains the
|
jaroslav@56
|
360 |
* character <code>ch</code> at position <code>index</code>.
|
jaroslav@56
|
361 |
* <p>
|
jaroslav@56
|
362 |
* The index argument must be greater than or equal to
|
jaroslav@56
|
363 |
* <code>0</code>, and less than the length of this sequence.
|
jaroslav@56
|
364 |
*
|
jaroslav@56
|
365 |
* @param index the index of the character to modify.
|
jaroslav@56
|
366 |
* @param ch the new character.
|
jaroslav@56
|
367 |
* @throws IndexOutOfBoundsException if <code>index</code> is
|
jaroslav@56
|
368 |
* negative or greater than or equal to <code>length()</code>.
|
jaroslav@56
|
369 |
*/
|
jaroslav@56
|
370 |
public void setCharAt(int index, char ch) {
|
jaroslav@56
|
371 |
if ((index < 0) || (index >= count))
|
jaroslav@56
|
372 |
throw new StringIndexOutOfBoundsException(index);
|
jaroslav@56
|
373 |
value[index] = ch;
|
jaroslav@56
|
374 |
}
|
jaroslav@56
|
375 |
|
jaroslav@56
|
376 |
/**
|
jaroslav@56
|
377 |
* Appends the string representation of the {@code Object} argument.
|
jaroslav@56
|
378 |
* <p>
|
jaroslav@56
|
379 |
* The overall effect is exactly as if the argument were converted
|
jaroslav@56
|
380 |
* to a string by the method {@link String#valueOf(Object)},
|
jaroslav@56
|
381 |
* and the characters of that string were then
|
jaroslav@56
|
382 |
* {@link #append(String) appended} to this character sequence.
|
jaroslav@56
|
383 |
*
|
jaroslav@56
|
384 |
* @param obj an {@code Object}.
|
jaroslav@56
|
385 |
* @return a reference to this object.
|
jaroslav@56
|
386 |
*/
|
jaroslav@56
|
387 |
public AbstractStringBuilder append(Object obj) {
|
jaroslav@56
|
388 |
return append(String.valueOf(obj));
|
jaroslav@56
|
389 |
}
|
jaroslav@56
|
390 |
|
jaroslav@56
|
391 |
/**
|
jaroslav@56
|
392 |
* Appends the specified string to this character sequence.
|
jaroslav@56
|
393 |
* <p>
|
jaroslav@56
|
394 |
* The characters of the {@code String} argument are appended, in
|
jaroslav@56
|
395 |
* order, increasing the length of this sequence by the length of the
|
jaroslav@56
|
396 |
* argument. If {@code str} is {@code null}, then the four
|
jaroslav@56
|
397 |
* characters {@code "null"} are appended.
|
jaroslav@56
|
398 |
* <p>
|
jaroslav@56
|
399 |
* Let <i>n</i> be the length of this character sequence just prior to
|
jaroslav@56
|
400 |
* execution of the {@code append} method. Then the character at
|
jaroslav@56
|
401 |
* index <i>k</i> in the new character sequence is equal to the character
|
jaroslav@56
|
402 |
* at index <i>k</i> in the old character sequence, if <i>k</i> is less
|
jaroslav@56
|
403 |
* than <i>n</i>; otherwise, it is equal to the character at index
|
jaroslav@56
|
404 |
* <i>k-n</i> in the argument {@code str}.
|
jaroslav@56
|
405 |
*
|
jaroslav@56
|
406 |
* @param str a string.
|
jaroslav@56
|
407 |
* @return a reference to this object.
|
jaroslav@56
|
408 |
*/
|
jaroslav@56
|
409 |
public AbstractStringBuilder append(String str) {
|
jaroslav@56
|
410 |
if (str == null) str = "null";
|
jaroslav@56
|
411 |
int len = str.length();
|
jaroslav@56
|
412 |
ensureCapacityInternal(count + len);
|
jaroslav@56
|
413 |
str.getChars(0, len, value, count);
|
jaroslav@56
|
414 |
count += len;
|
jaroslav@56
|
415 |
return this;
|
jaroslav@56
|
416 |
}
|
jaroslav@56
|
417 |
|
jaroslav@56
|
418 |
// Documentation in subclasses because of synchro difference
|
jaroslav@56
|
419 |
public AbstractStringBuilder append(StringBuffer sb) {
|
jaroslav@56
|
420 |
if (sb == null)
|
jaroslav@56
|
421 |
return append("null");
|
jaroslav@56
|
422 |
int len = sb.length();
|
jaroslav@56
|
423 |
ensureCapacityInternal(count + len);
|
jaroslav@56
|
424 |
sb.getChars(0, len, value, count);
|
jaroslav@56
|
425 |
count += len;
|
jaroslav@56
|
426 |
return this;
|
jaroslav@56
|
427 |
}
|
jaroslav@56
|
428 |
|
jaroslav@56
|
429 |
// Documentation in subclasses because of synchro difference
|
jaroslav@56
|
430 |
public AbstractStringBuilder append(CharSequence s) {
|
jaroslav@56
|
431 |
if (s == null)
|
jaroslav@56
|
432 |
s = "null";
|
jaroslav@56
|
433 |
if (s instanceof String)
|
jaroslav@56
|
434 |
return this.append((String)s);
|
jaroslav@56
|
435 |
if (s instanceof StringBuffer)
|
jaroslav@56
|
436 |
return this.append((StringBuffer)s);
|
jaroslav@56
|
437 |
return this.append(s, 0, s.length());
|
jaroslav@56
|
438 |
}
|
jaroslav@56
|
439 |
|
jaroslav@56
|
440 |
/**
|
jaroslav@56
|
441 |
* Appends a subsequence of the specified {@code CharSequence} to this
|
jaroslav@56
|
442 |
* sequence.
|
jaroslav@56
|
443 |
* <p>
|
jaroslav@56
|
444 |
* Characters of the argument {@code s}, starting at
|
jaroslav@56
|
445 |
* index {@code start}, are appended, in order, to the contents of
|
jaroslav@56
|
446 |
* this sequence up to the (exclusive) index {@code end}. The length
|
jaroslav@56
|
447 |
* of this sequence is increased by the value of {@code end - start}.
|
jaroslav@56
|
448 |
* <p>
|
jaroslav@56
|
449 |
* Let <i>n</i> be the length of this character sequence just prior to
|
jaroslav@56
|
450 |
* execution of the {@code append} method. Then the character at
|
jaroslav@56
|
451 |
* index <i>k</i> in this character sequence becomes equal to the
|
jaroslav@56
|
452 |
* character at index <i>k</i> in this sequence, if <i>k</i> is less than
|
jaroslav@56
|
453 |
* <i>n</i>; otherwise, it is equal to the character at index
|
jaroslav@56
|
454 |
* <i>k+start-n</i> in the argument {@code s}.
|
jaroslav@56
|
455 |
* <p>
|
jaroslav@56
|
456 |
* If {@code s} is {@code null}, then this method appends
|
jaroslav@56
|
457 |
* characters as if the s parameter was a sequence containing the four
|
jaroslav@56
|
458 |
* characters {@code "null"}.
|
jaroslav@56
|
459 |
*
|
jaroslav@56
|
460 |
* @param s the sequence to append.
|
jaroslav@56
|
461 |
* @param start the starting index of the subsequence to be appended.
|
jaroslav@56
|
462 |
* @param end the end index of the subsequence to be appended.
|
jaroslav@56
|
463 |
* @return a reference to this object.
|
jaroslav@56
|
464 |
* @throws IndexOutOfBoundsException if
|
jaroslav@56
|
465 |
* {@code start} is negative, or
|
jaroslav@56
|
466 |
* {@code start} is greater than {@code end} or
|
jaroslav@56
|
467 |
* {@code end} is greater than {@code s.length()}
|
jaroslav@56
|
468 |
*/
|
jaroslav@56
|
469 |
public AbstractStringBuilder append(CharSequence s, int start, int end) {
|
jaroslav@56
|
470 |
if (s == null)
|
jaroslav@56
|
471 |
s = "null";
|
jaroslav@56
|
472 |
if ((start < 0) || (start > end) || (end > s.length()))
|
jaroslav@56
|
473 |
throw new IndexOutOfBoundsException(
|
jaroslav@56
|
474 |
"start " + start + ", end " + end + ", s.length() "
|
jaroslav@56
|
475 |
+ s.length());
|
jaroslav@56
|
476 |
int len = end - start;
|
jaroslav@56
|
477 |
ensureCapacityInternal(count + len);
|
jaroslav@56
|
478 |
for (int i = start, j = count; i < end; i++, j++)
|
jaroslav@56
|
479 |
value[j] = s.charAt(i);
|
jaroslav@56
|
480 |
count += len;
|
jaroslav@56
|
481 |
return this;
|
jaroslav@56
|
482 |
}
|
jaroslav@56
|
483 |
|
jaroslav@56
|
484 |
/**
|
jaroslav@56
|
485 |
* Appends the string representation of the {@code char} array
|
jaroslav@56
|
486 |
* argument to this sequence.
|
jaroslav@56
|
487 |
* <p>
|
jaroslav@56
|
488 |
* The characters of the array argument are appended, in order, to
|
jaroslav@56
|
489 |
* the contents of this sequence. The length of this sequence
|
jaroslav@56
|
490 |
* increases by the length of the argument.
|
jaroslav@56
|
491 |
* <p>
|
jaroslav@56
|
492 |
* The overall effect is exactly as if the argument were converted
|
jaroslav@56
|
493 |
* to a string by the method {@link String#valueOf(char[])},
|
jaroslav@56
|
494 |
* and the characters of that string were then
|
jaroslav@56
|
495 |
* {@link #append(String) appended} to this character sequence.
|
jaroslav@56
|
496 |
*
|
jaroslav@56
|
497 |
* @param str the characters to be appended.
|
jaroslav@56
|
498 |
* @return a reference to this object.
|
jaroslav@56
|
499 |
*/
|
jaroslav@56
|
500 |
public AbstractStringBuilder append(char[] str) {
|
jaroslav@56
|
501 |
int len = str.length;
|
jaroslav@56
|
502 |
ensureCapacityInternal(count + len);
|
jaroslav@104
|
503 |
arraycopy(str, 0, value, count, len);
|
jaroslav@56
|
504 |
count += len;
|
jaroslav@56
|
505 |
return this;
|
jaroslav@56
|
506 |
}
|
jaroslav@56
|
507 |
|
jaroslav@56
|
508 |
/**
|
jaroslav@56
|
509 |
* Appends the string representation of a subarray of the
|
jaroslav@56
|
510 |
* {@code char} array argument to this sequence.
|
jaroslav@56
|
511 |
* <p>
|
jaroslav@56
|
512 |
* Characters of the {@code char} array {@code str}, starting at
|
jaroslav@56
|
513 |
* index {@code offset}, are appended, in order, to the contents
|
jaroslav@56
|
514 |
* of this sequence. The length of this sequence increases
|
jaroslav@56
|
515 |
* by the value of {@code len}.
|
jaroslav@56
|
516 |
* <p>
|
jaroslav@56
|
517 |
* The overall effect is exactly as if the arguments were converted
|
jaroslav@56
|
518 |
* to a string by the method {@link String#valueOf(char[],int,int)},
|
jaroslav@56
|
519 |
* and the characters of that string were then
|
jaroslav@56
|
520 |
* {@link #append(String) appended} to this character sequence.
|
jaroslav@56
|
521 |
*
|
jaroslav@56
|
522 |
* @param str the characters to be appended.
|
jaroslav@56
|
523 |
* @param offset the index of the first {@code char} to append.
|
jaroslav@56
|
524 |
* @param len the number of {@code char}s to append.
|
jaroslav@56
|
525 |
* @return a reference to this object.
|
jaroslav@56
|
526 |
* @throws IndexOutOfBoundsException
|
jaroslav@56
|
527 |
* if {@code offset < 0} or {@code len < 0}
|
jaroslav@56
|
528 |
* or {@code offset+len > str.length}
|
jaroslav@56
|
529 |
*/
|
jaroslav@56
|
530 |
public AbstractStringBuilder append(char str[], int offset, int len) {
|
jaroslav@56
|
531 |
if (len > 0) // let arraycopy report AIOOBE for len < 0
|
jaroslav@56
|
532 |
ensureCapacityInternal(count + len);
|
jaroslav@104
|
533 |
arraycopy(str, offset, value, count, len);
|
jaroslav@56
|
534 |
count += len;
|
jaroslav@56
|
535 |
return this;
|
jaroslav@56
|
536 |
}
|
jaroslav@56
|
537 |
|
jaroslav@56
|
538 |
/**
|
jaroslav@56
|
539 |
* Appends the string representation of the {@code boolean}
|
jaroslav@56
|
540 |
* argument to the sequence.
|
jaroslav@56
|
541 |
* <p>
|
jaroslav@56
|
542 |
* The overall effect is exactly as if the argument were converted
|
jaroslav@56
|
543 |
* to a string by the method {@link String#valueOf(boolean)},
|
jaroslav@56
|
544 |
* and the characters of that string were then
|
jaroslav@56
|
545 |
* {@link #append(String) appended} to this character sequence.
|
jaroslav@56
|
546 |
*
|
jaroslav@56
|
547 |
* @param b a {@code boolean}.
|
jaroslav@56
|
548 |
* @return a reference to this object.
|
jaroslav@56
|
549 |
*/
|
jaroslav@56
|
550 |
public AbstractStringBuilder append(boolean b) {
|
jaroslav@56
|
551 |
if (b) {
|
jaroslav@56
|
552 |
ensureCapacityInternal(count + 4);
|
jaroslav@56
|
553 |
value[count++] = 't';
|
jaroslav@56
|
554 |
value[count++] = 'r';
|
jaroslav@56
|
555 |
value[count++] = 'u';
|
jaroslav@56
|
556 |
value[count++] = 'e';
|
jaroslav@56
|
557 |
} else {
|
jaroslav@56
|
558 |
ensureCapacityInternal(count + 5);
|
jaroslav@56
|
559 |
value[count++] = 'f';
|
jaroslav@56
|
560 |
value[count++] = 'a';
|
jaroslav@56
|
561 |
value[count++] = 'l';
|
jaroslav@56
|
562 |
value[count++] = 's';
|
jaroslav@56
|
563 |
value[count++] = 'e';
|
jaroslav@56
|
564 |
}
|
jaroslav@56
|
565 |
return this;
|
jaroslav@56
|
566 |
}
|
jaroslav@56
|
567 |
|
jaroslav@56
|
568 |
/**
|
jaroslav@56
|
569 |
* Appends the string representation of the {@code char}
|
jaroslav@56
|
570 |
* argument to this sequence.
|
jaroslav@56
|
571 |
* <p>
|
jaroslav@56
|
572 |
* The argument is appended to the contents of this sequence.
|
jaroslav@56
|
573 |
* The length of this sequence increases by {@code 1}.
|
jaroslav@56
|
574 |
* <p>
|
jaroslav@56
|
575 |
* The overall effect is exactly as if the argument were converted
|
jaroslav@56
|
576 |
* to a string by the method {@link String#valueOf(char)},
|
jaroslav@56
|
577 |
* and the character in that string were then
|
jaroslav@56
|
578 |
* {@link #append(String) appended} to this character sequence.
|
jaroslav@56
|
579 |
*
|
jaroslav@56
|
580 |
* @param c a {@code char}.
|
jaroslav@56
|
581 |
* @return a reference to this object.
|
jaroslav@56
|
582 |
*/
|
jaroslav@56
|
583 |
public AbstractStringBuilder append(char c) {
|
jaroslav@56
|
584 |
ensureCapacityInternal(count + 1);
|
jaroslav@56
|
585 |
value[count++] = c;
|
jaroslav@56
|
586 |
return this;
|
jaroslav@56
|
587 |
}
|
jaroslav@56
|
588 |
|
jaroslav@56
|
589 |
/**
|
jaroslav@56
|
590 |
* Appends the string representation of the {@code int}
|
jaroslav@56
|
591 |
* argument to this sequence.
|
jaroslav@56
|
592 |
* <p>
|
jaroslav@56
|
593 |
* The overall effect is exactly as if the argument were converted
|
jaroslav@56
|
594 |
* to a string by the method {@link String#valueOf(int)},
|
jaroslav@56
|
595 |
* and the characters of that string were then
|
jaroslav@56
|
596 |
* {@link #append(String) appended} to this character sequence.
|
jaroslav@56
|
597 |
*
|
jaroslav@56
|
598 |
* @param i an {@code int}.
|
jaroslav@56
|
599 |
* @return a reference to this object.
|
jaroslav@56
|
600 |
*/
|
jaroslav@56
|
601 |
public AbstractStringBuilder append(int i) {
|
jaroslav@248
|
602 |
return append(Integer.toString(i));
|
jaroslav@56
|
603 |
}
|
jaroslav@56
|
604 |
|
jaroslav@56
|
605 |
/**
|
jaroslav@56
|
606 |
* Appends the string representation of the {@code long}
|
jaroslav@56
|
607 |
* argument to this sequence.
|
jaroslav@56
|
608 |
* <p>
|
jaroslav@56
|
609 |
* The overall effect is exactly as if the argument were converted
|
jaroslav@56
|
610 |
* to a string by the method {@link String#valueOf(long)},
|
jaroslav@56
|
611 |
* and the characters of that string were then
|
jaroslav@56
|
612 |
* {@link #append(String) appended} to this character sequence.
|
jaroslav@56
|
613 |
*
|
jaroslav@56
|
614 |
* @param l a {@code long}.
|
jaroslav@56
|
615 |
* @return a reference to this object.
|
jaroslav@56
|
616 |
*/
|
jaroslav@56
|
617 |
public AbstractStringBuilder append(long l) {
|
jaroslav@56
|
618 |
if (l == Long.MIN_VALUE) {
|
jaroslav@56
|
619 |
append("-9223372036854775808");
|
jaroslav@56
|
620 |
return this;
|
jaroslav@56
|
621 |
}
|
jaroslav@56
|
622 |
int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
|
jaroslav@56
|
623 |
: Long.stringSize(l);
|
jaroslav@56
|
624 |
int spaceNeeded = count + appendedLength;
|
jaroslav@56
|
625 |
ensureCapacityInternal(spaceNeeded);
|
jaroslav@56
|
626 |
Long.getChars(l, spaceNeeded, value);
|
jaroslav@56
|
627 |
count = spaceNeeded;
|
jaroslav@56
|
628 |
return this;
|
jaroslav@56
|
629 |
}
|
jaroslav@56
|
630 |
|
jaroslav@56
|
631 |
/**
|
jaroslav@56
|
632 |
* Appends the string representation of the {@code float}
|
jaroslav@56
|
633 |
* argument to this sequence.
|
jaroslav@56
|
634 |
* <p>
|
jaroslav@56
|
635 |
* The overall effect is exactly as if the argument were converted
|
jaroslav@56
|
636 |
* to a string by the method {@link String#valueOf(float)},
|
jaroslav@56
|
637 |
* and the characters of that string were then
|
jaroslav@56
|
638 |
* {@link #append(String) appended} to this character sequence.
|
jaroslav@56
|
639 |
*
|
jaroslav@56
|
640 |
* @param f a {@code float}.
|
jaroslav@56
|
641 |
* @return a reference to this object.
|
jaroslav@56
|
642 |
*/
|
jaroslav@56
|
643 |
public AbstractStringBuilder append(float f) {
|
jaroslav@116
|
644 |
return append(Float.toString(f));
|
jaroslav@56
|
645 |
}
|
jaroslav@56
|
646 |
|
jaroslav@56
|
647 |
/**
|
jaroslav@56
|
648 |
* Appends the string representation of the {@code double}
|
jaroslav@56
|
649 |
* argument to this sequence.
|
jaroslav@56
|
650 |
* <p>
|
jaroslav@56
|
651 |
* The overall effect is exactly as if the argument were converted
|
jaroslav@56
|
652 |
* to a string by the method {@link String#valueOf(double)},
|
jaroslav@56
|
653 |
* and the characters of that string were then
|
jaroslav@56
|
654 |
* {@link #append(String) appended} to this character sequence.
|
jaroslav@56
|
655 |
*
|
jaroslav@56
|
656 |
* @param d a {@code double}.
|
jaroslav@56
|
657 |
* @return a reference to this object.
|
jaroslav@56
|
658 |
*/
|
jaroslav@56
|
659 |
public AbstractStringBuilder append(double d) {
|
jaroslav@116
|
660 |
return append(Double.toString(d));
|
jaroslav@56
|
661 |
}
|
jaroslav@56
|
662 |
|
jaroslav@56
|
663 |
/**
|
jaroslav@56
|
664 |
* Removes the characters in a substring of this sequence.
|
jaroslav@56
|
665 |
* The substring begins at the specified {@code start} and extends to
|
jaroslav@56
|
666 |
* the character at index {@code end - 1} or to the end of the
|
jaroslav@56
|
667 |
* sequence if no such character exists. If
|
jaroslav@56
|
668 |
* {@code start} is equal to {@code end}, no changes are made.
|
jaroslav@56
|
669 |
*
|
jaroslav@56
|
670 |
* @param start The beginning index, inclusive.
|
jaroslav@56
|
671 |
* @param end The ending index, exclusive.
|
jaroslav@56
|
672 |
* @return This object.
|
jaroslav@56
|
673 |
* @throws StringIndexOutOfBoundsException if {@code start}
|
jaroslav@56
|
674 |
* is negative, greater than {@code length()}, or
|
jaroslav@56
|
675 |
* greater than {@code end}.
|
jaroslav@56
|
676 |
*/
|
jaroslav@56
|
677 |
public AbstractStringBuilder delete(int start, int end) {
|
jaroslav@56
|
678 |
if (start < 0)
|
jaroslav@56
|
679 |
throw new StringIndexOutOfBoundsException(start);
|
jaroslav@56
|
680 |
if (end > count)
|
jaroslav@56
|
681 |
end = count;
|
jaroslav@56
|
682 |
if (start > end)
|
jaroslav@56
|
683 |
throw new StringIndexOutOfBoundsException();
|
jaroslav@56
|
684 |
int len = end - start;
|
jaroslav@56
|
685 |
if (len > 0) {
|
jaroslav@104
|
686 |
arraycopy(value, start+len, value, start, count-end);
|
jaroslav@56
|
687 |
count -= len;
|
jaroslav@56
|
688 |
}
|
jaroslav@56
|
689 |
return this;
|
jaroslav@56
|
690 |
}
|
jaroslav@56
|
691 |
|
jaroslav@56
|
692 |
/**
|
jaroslav@56
|
693 |
* Appends the string representation of the {@code codePoint}
|
jaroslav@56
|
694 |
* argument to this sequence.
|
jaroslav@56
|
695 |
*
|
jaroslav@56
|
696 |
* <p> The argument is appended to the contents of this sequence.
|
jaroslav@56
|
697 |
* The length of this sequence increases by
|
jaroslav@56
|
698 |
* {@link Character#charCount(int) Character.charCount(codePoint)}.
|
jaroslav@56
|
699 |
*
|
jaroslav@56
|
700 |
* <p> The overall effect is exactly as if the argument were
|
jaroslav@56
|
701 |
* converted to a {@code char} array by the method
|
jaroslav@56
|
702 |
* {@link Character#toChars(int)} and the character in that array
|
jaroslav@56
|
703 |
* were then {@link #append(char[]) appended} to this character
|
jaroslav@56
|
704 |
* sequence.
|
jaroslav@56
|
705 |
*
|
jaroslav@56
|
706 |
* @param codePoint a Unicode code point
|
jaroslav@56
|
707 |
* @return a reference to this object.
|
jaroslav@56
|
708 |
* @exception IllegalArgumentException if the specified
|
jaroslav@56
|
709 |
* {@code codePoint} isn't a valid Unicode code point
|
jaroslav@56
|
710 |
*/
|
jaroslav@56
|
711 |
public AbstractStringBuilder appendCodePoint(int codePoint) {
|
jaroslav@56
|
712 |
final int count = this.count;
|
jaroslav@56
|
713 |
|
jaroslav@56
|
714 |
if (Character.isBmpCodePoint(codePoint)) {
|
jaroslav@56
|
715 |
ensureCapacityInternal(count + 1);
|
jaroslav@56
|
716 |
value[count] = (char) codePoint;
|
jaroslav@56
|
717 |
this.count = count + 1;
|
jaroslav@56
|
718 |
} else if (Character.isValidCodePoint(codePoint)) {
|
jaroslav@56
|
719 |
ensureCapacityInternal(count + 2);
|
jaroslav@56
|
720 |
Character.toSurrogates(codePoint, value, count);
|
jaroslav@56
|
721 |
this.count = count + 2;
|
jaroslav@56
|
722 |
} else {
|
jaroslav@56
|
723 |
throw new IllegalArgumentException();
|
jaroslav@56
|
724 |
}
|
jaroslav@56
|
725 |
return this;
|
jaroslav@56
|
726 |
}
|
jaroslav@56
|
727 |
|
jaroslav@56
|
728 |
/**
|
jaroslav@56
|
729 |
* Removes the <code>char</code> at the specified position in this
|
jaroslav@56
|
730 |
* sequence. This sequence is shortened by one <code>char</code>.
|
jaroslav@56
|
731 |
*
|
jaroslav@56
|
732 |
* <p>Note: If the character at the given index is a supplementary
|
jaroslav@56
|
733 |
* character, this method does not remove the entire character. If
|
jaroslav@56
|
734 |
* correct handling of supplementary characters is required,
|
jaroslav@56
|
735 |
* determine the number of <code>char</code>s to remove by calling
|
jaroslav@56
|
736 |
* <code>Character.charCount(thisSequence.codePointAt(index))</code>,
|
jaroslav@56
|
737 |
* where <code>thisSequence</code> is this sequence.
|
jaroslav@56
|
738 |
*
|
jaroslav@56
|
739 |
* @param index Index of <code>char</code> to remove
|
jaroslav@56
|
740 |
* @return This object.
|
jaroslav@56
|
741 |
* @throws StringIndexOutOfBoundsException if the <code>index</code>
|
jaroslav@56
|
742 |
* is negative or greater than or equal to
|
jaroslav@56
|
743 |
* <code>length()</code>.
|
jaroslav@56
|
744 |
*/
|
jaroslav@56
|
745 |
public AbstractStringBuilder deleteCharAt(int index) {
|
jaroslav@56
|
746 |
if ((index < 0) || (index >= count))
|
jaroslav@56
|
747 |
throw new StringIndexOutOfBoundsException(index);
|
jaroslav@104
|
748 |
arraycopy(value, index+1, value, index, count-index-1);
|
jaroslav@56
|
749 |
count--;
|
jaroslav@56
|
750 |
return this;
|
jaroslav@56
|
751 |
}
|
jaroslav@56
|
752 |
|
jaroslav@56
|
753 |
/**
|
jaroslav@56
|
754 |
* Replaces the characters in a substring of this sequence
|
jaroslav@56
|
755 |
* with characters in the specified <code>String</code>. The substring
|
jaroslav@56
|
756 |
* begins at the specified <code>start</code> and extends to the character
|
jaroslav@56
|
757 |
* at index <code>end - 1</code> or to the end of the
|
jaroslav@56
|
758 |
* sequence if no such character exists. First the
|
jaroslav@56
|
759 |
* characters in the substring are removed and then the specified
|
jaroslav@56
|
760 |
* <code>String</code> is inserted at <code>start</code>. (This
|
jaroslav@56
|
761 |
* sequence will be lengthened to accommodate the
|
jaroslav@56
|
762 |
* specified String if necessary.)
|
jaroslav@56
|
763 |
*
|
jaroslav@56
|
764 |
* @param start The beginning index, inclusive.
|
jaroslav@56
|
765 |
* @param end The ending index, exclusive.
|
jaroslav@56
|
766 |
* @param str String that will replace previous contents.
|
jaroslav@56
|
767 |
* @return This object.
|
jaroslav@56
|
768 |
* @throws StringIndexOutOfBoundsException if <code>start</code>
|
jaroslav@56
|
769 |
* is negative, greater than <code>length()</code>, or
|
jaroslav@56
|
770 |
* greater than <code>end</code>.
|
jaroslav@56
|
771 |
*/
|
jaroslav@56
|
772 |
public AbstractStringBuilder replace(int start, int end, String str) {
|
jaroslav@56
|
773 |
if (start < 0)
|
jaroslav@56
|
774 |
throw new StringIndexOutOfBoundsException(start);
|
jaroslav@56
|
775 |
if (start > count)
|
jaroslav@56
|
776 |
throw new StringIndexOutOfBoundsException("start > length()");
|
jaroslav@56
|
777 |
if (start > end)
|
jaroslav@56
|
778 |
throw new StringIndexOutOfBoundsException("start > end");
|
jaroslav@56
|
779 |
|
jaroslav@56
|
780 |
if (end > count)
|
jaroslav@56
|
781 |
end = count;
|
jaroslav@56
|
782 |
int len = str.length();
|
jaroslav@56
|
783 |
int newCount = count + len - (end - start);
|
jaroslav@56
|
784 |
ensureCapacityInternal(newCount);
|
jaroslav@56
|
785 |
|
jaroslav@104
|
786 |
arraycopy(value, end, value, start + len, count - end);
|
jaroslav@56
|
787 |
str.getChars(value, start);
|
jaroslav@56
|
788 |
count = newCount;
|
jaroslav@56
|
789 |
return this;
|
jaroslav@56
|
790 |
}
|
jaroslav@56
|
791 |
|
jaroslav@56
|
792 |
/**
|
jaroslav@56
|
793 |
* Returns a new <code>String</code> that contains a subsequence of
|
jaroslav@56
|
794 |
* characters currently contained in this character sequence. The
|
jaroslav@56
|
795 |
* substring begins at the specified index and extends to the end of
|
jaroslav@56
|
796 |
* this sequence.
|
jaroslav@56
|
797 |
*
|
jaroslav@56
|
798 |
* @param start The beginning index, inclusive.
|
jaroslav@56
|
799 |
* @return The new string.
|
jaroslav@56
|
800 |
* @throws StringIndexOutOfBoundsException if <code>start</code> is
|
jaroslav@56
|
801 |
* less than zero, or greater than the length of this object.
|
jaroslav@56
|
802 |
*/
|
jaroslav@56
|
803 |
public String substring(int start) {
|
jaroslav@56
|
804 |
return substring(start, count);
|
jaroslav@56
|
805 |
}
|
jaroslav@56
|
806 |
|
jaroslav@56
|
807 |
/**
|
jaroslav@56
|
808 |
* Returns a new character sequence that is a subsequence of this sequence.
|
jaroslav@56
|
809 |
*
|
jaroslav@56
|
810 |
* <p> An invocation of this method of the form
|
jaroslav@56
|
811 |
*
|
jaroslav@56
|
812 |
* <blockquote><pre>
|
jaroslav@56
|
813 |
* sb.subSequence(begin, end)</pre></blockquote>
|
jaroslav@56
|
814 |
*
|
jaroslav@56
|
815 |
* behaves in exactly the same way as the invocation
|
jaroslav@56
|
816 |
*
|
jaroslav@56
|
817 |
* <blockquote><pre>
|
jaroslav@56
|
818 |
* sb.substring(begin, end)</pre></blockquote>
|
jaroslav@56
|
819 |
*
|
jaroslav@56
|
820 |
* This method is provided so that this class can
|
jaroslav@56
|
821 |
* implement the {@link CharSequence} interface. </p>
|
jaroslav@56
|
822 |
*
|
jaroslav@56
|
823 |
* @param start the start index, inclusive.
|
jaroslav@56
|
824 |
* @param end the end index, exclusive.
|
jaroslav@56
|
825 |
* @return the specified subsequence.
|
jaroslav@56
|
826 |
*
|
jaroslav@56
|
827 |
* @throws IndexOutOfBoundsException
|
jaroslav@56
|
828 |
* if <tt>start</tt> or <tt>end</tt> are negative,
|
jaroslav@56
|
829 |
* if <tt>end</tt> is greater than <tt>length()</tt>,
|
jaroslav@56
|
830 |
* or if <tt>start</tt> is greater than <tt>end</tt>
|
jaroslav@56
|
831 |
* @spec JSR-51
|
jaroslav@56
|
832 |
*/
|
jaroslav@56
|
833 |
public CharSequence subSequence(int start, int end) {
|
jaroslav@56
|
834 |
return substring(start, end);
|
jaroslav@56
|
835 |
}
|
jaroslav@56
|
836 |
|
jaroslav@56
|
837 |
/**
|
jaroslav@56
|
838 |
* Returns a new <code>String</code> that contains a subsequence of
|
jaroslav@56
|
839 |
* characters currently contained in this sequence. The
|
jaroslav@56
|
840 |
* substring begins at the specified <code>start</code> and
|
jaroslav@56
|
841 |
* extends to the character at index <code>end - 1</code>.
|
jaroslav@56
|
842 |
*
|
jaroslav@56
|
843 |
* @param start The beginning index, inclusive.
|
jaroslav@56
|
844 |
* @param end The ending index, exclusive.
|
jaroslav@56
|
845 |
* @return The new string.
|
jaroslav@56
|
846 |
* @throws StringIndexOutOfBoundsException if <code>start</code>
|
jaroslav@56
|
847 |
* or <code>end</code> are negative or greater than
|
jaroslav@56
|
848 |
* <code>length()</code>, or <code>start</code> is
|
jaroslav@56
|
849 |
* greater than <code>end</code>.
|
jaroslav@56
|
850 |
*/
|
jaroslav@56
|
851 |
public String substring(int start, int end) {
|
jaroslav@56
|
852 |
if (start < 0)
|
jaroslav@56
|
853 |
throw new StringIndexOutOfBoundsException(start);
|
jaroslav@56
|
854 |
if (end > count)
|
jaroslav@56
|
855 |
throw new StringIndexOutOfBoundsException(end);
|
jaroslav@56
|
856 |
if (start > end)
|
jaroslav@56
|
857 |
throw new StringIndexOutOfBoundsException(end - start);
|
jaroslav@56
|
858 |
return new String(value, start, end - start);
|
jaroslav@56
|
859 |
}
|
jaroslav@56
|
860 |
|
jaroslav@56
|
861 |
/**
|
jaroslav@56
|
862 |
* Inserts the string representation of a subarray of the {@code str}
|
jaroslav@56
|
863 |
* array argument into this sequence. The subarray begins at the
|
jaroslav@56
|
864 |
* specified {@code offset} and extends {@code len} {@code char}s.
|
jaroslav@56
|
865 |
* The characters of the subarray are inserted into this sequence at
|
jaroslav@56
|
866 |
* the position indicated by {@code index}. The length of this
|
jaroslav@56
|
867 |
* sequence increases by {@code len} {@code char}s.
|
jaroslav@56
|
868 |
*
|
jaroslav@56
|
869 |
* @param index position at which to insert subarray.
|
jaroslav@56
|
870 |
* @param str A {@code char} array.
|
jaroslav@56
|
871 |
* @param offset the index of the first {@code char} in subarray to
|
jaroslav@56
|
872 |
* be inserted.
|
jaroslav@56
|
873 |
* @param len the number of {@code char}s in the subarray to
|
jaroslav@56
|
874 |
* be inserted.
|
jaroslav@56
|
875 |
* @return This object
|
jaroslav@56
|
876 |
* @throws StringIndexOutOfBoundsException if {@code index}
|
jaroslav@56
|
877 |
* is negative or greater than {@code length()}, or
|
jaroslav@56
|
878 |
* {@code offset} or {@code len} are negative, or
|
jaroslav@56
|
879 |
* {@code (offset+len)} is greater than
|
jaroslav@56
|
880 |
* {@code str.length}.
|
jaroslav@56
|
881 |
*/
|
jaroslav@56
|
882 |
public AbstractStringBuilder insert(int index, char[] str, int offset,
|
jaroslav@56
|
883 |
int len)
|
jaroslav@56
|
884 |
{
|
jaroslav@56
|
885 |
if ((index < 0) || (index > length()))
|
jaroslav@56
|
886 |
throw new StringIndexOutOfBoundsException(index);
|
jaroslav@56
|
887 |
if ((offset < 0) || (len < 0) || (offset > str.length - len))
|
jaroslav@56
|
888 |
throw new StringIndexOutOfBoundsException(
|
jaroslav@56
|
889 |
"offset " + offset + ", len " + len + ", str.length "
|
jaroslav@56
|
890 |
+ str.length);
|
jaroslav@56
|
891 |
ensureCapacityInternal(count + len);
|
jaroslav@104
|
892 |
arraycopy(value, index, value, index + len, count - index);
|
jaroslav@104
|
893 |
arraycopy(str, offset, value, index, len);
|
jaroslav@56
|
894 |
count += len;
|
jaroslav@56
|
895 |
return this;
|
jaroslav@56
|
896 |
}
|
jaroslav@56
|
897 |
|
jaroslav@56
|
898 |
/**
|
jaroslav@56
|
899 |
* Inserts the string representation of the {@code Object}
|
jaroslav@56
|
900 |
* argument into this character sequence.
|
jaroslav@56
|
901 |
* <p>
|
jaroslav@56
|
902 |
* The overall effect is exactly as if the second argument were
|
jaroslav@56
|
903 |
* converted to a string by the method {@link String#valueOf(Object)},
|
jaroslav@56
|
904 |
* and the characters of that string were then
|
jaroslav@56
|
905 |
* {@link #insert(int,String) inserted} into this character
|
jaroslav@56
|
906 |
* sequence at the indicated offset.
|
jaroslav@56
|
907 |
* <p>
|
jaroslav@56
|
908 |
* The {@code offset} argument must be greater than or equal to
|
jaroslav@56
|
909 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
910 |
* of this sequence.
|
jaroslav@56
|
911 |
*
|
jaroslav@56
|
912 |
* @param offset the offset.
|
jaroslav@56
|
913 |
* @param obj an {@code Object}.
|
jaroslav@56
|
914 |
* @return a reference to this object.
|
jaroslav@56
|
915 |
* @throws StringIndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
916 |
*/
|
jaroslav@56
|
917 |
public AbstractStringBuilder insert(int offset, Object obj) {
|
jaroslav@56
|
918 |
return insert(offset, String.valueOf(obj));
|
jaroslav@56
|
919 |
}
|
jaroslav@56
|
920 |
|
jaroslav@56
|
921 |
/**
|
jaroslav@56
|
922 |
* Inserts the string into this character sequence.
|
jaroslav@56
|
923 |
* <p>
|
jaroslav@56
|
924 |
* The characters of the {@code String} argument are inserted, in
|
jaroslav@56
|
925 |
* order, into this sequence at the indicated offset, moving up any
|
jaroslav@56
|
926 |
* characters originally above that position and increasing the length
|
jaroslav@56
|
927 |
* of this sequence by the length of the argument. If
|
jaroslav@56
|
928 |
* {@code str} is {@code null}, then the four characters
|
jaroslav@56
|
929 |
* {@code "null"} are inserted into this sequence.
|
jaroslav@56
|
930 |
* <p>
|
jaroslav@56
|
931 |
* The character at index <i>k</i> in the new character sequence is
|
jaroslav@56
|
932 |
* equal to:
|
jaroslav@56
|
933 |
* <ul>
|
jaroslav@56
|
934 |
* <li>the character at index <i>k</i> in the old character sequence, if
|
jaroslav@56
|
935 |
* <i>k</i> is less than {@code offset}
|
jaroslav@56
|
936 |
* <li>the character at index <i>k</i>{@code -offset} in the
|
jaroslav@56
|
937 |
* argument {@code str}, if <i>k</i> is not less than
|
jaroslav@56
|
938 |
* {@code offset} but is less than {@code offset+str.length()}
|
jaroslav@56
|
939 |
* <li>the character at index <i>k</i>{@code -str.length()} in the
|
jaroslav@56
|
940 |
* old character sequence, if <i>k</i> is not less than
|
jaroslav@56
|
941 |
* {@code offset+str.length()}
|
jaroslav@56
|
942 |
* </ul><p>
|
jaroslav@56
|
943 |
* The {@code offset} argument must be greater than or equal to
|
jaroslav@56
|
944 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
945 |
* of this sequence.
|
jaroslav@56
|
946 |
*
|
jaroslav@56
|
947 |
* @param offset the offset.
|
jaroslav@56
|
948 |
* @param str a string.
|
jaroslav@56
|
949 |
* @return a reference to this object.
|
jaroslav@56
|
950 |
* @throws StringIndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
951 |
*/
|
jaroslav@56
|
952 |
public AbstractStringBuilder insert(int offset, String str) {
|
jaroslav@56
|
953 |
if ((offset < 0) || (offset > length()))
|
jaroslav@56
|
954 |
throw new StringIndexOutOfBoundsException(offset);
|
jaroslav@56
|
955 |
if (str == null)
|
jaroslav@56
|
956 |
str = "null";
|
jaroslav@56
|
957 |
int len = str.length();
|
jaroslav@56
|
958 |
ensureCapacityInternal(count + len);
|
jaroslav@104
|
959 |
arraycopy(value, offset, value, offset + len, count - offset);
|
jaroslav@56
|
960 |
str.getChars(value, offset);
|
jaroslav@56
|
961 |
count += len;
|
jaroslav@56
|
962 |
return this;
|
jaroslav@56
|
963 |
}
|
jaroslav@56
|
964 |
|
jaroslav@56
|
965 |
/**
|
jaroslav@56
|
966 |
* Inserts the string representation of the {@code char} array
|
jaroslav@56
|
967 |
* argument into this sequence.
|
jaroslav@56
|
968 |
* <p>
|
jaroslav@56
|
969 |
* The characters of the array argument are inserted into the
|
jaroslav@56
|
970 |
* contents of this sequence at the position indicated by
|
jaroslav@56
|
971 |
* {@code offset}. The length of this sequence increases by
|
jaroslav@56
|
972 |
* the length of the argument.
|
jaroslav@56
|
973 |
* <p>
|
jaroslav@56
|
974 |
* The overall effect is exactly as if the second argument were
|
jaroslav@56
|
975 |
* converted to a string by the method {@link String#valueOf(char[])},
|
jaroslav@56
|
976 |
* and the characters of that string were then
|
jaroslav@56
|
977 |
* {@link #insert(int,String) inserted} into this character
|
jaroslav@56
|
978 |
* sequence at the indicated offset.
|
jaroslav@56
|
979 |
* <p>
|
jaroslav@56
|
980 |
* The {@code offset} argument must be greater than or equal to
|
jaroslav@56
|
981 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
982 |
* of this sequence.
|
jaroslav@56
|
983 |
*
|
jaroslav@56
|
984 |
* @param offset the offset.
|
jaroslav@56
|
985 |
* @param str a character array.
|
jaroslav@56
|
986 |
* @return a reference to this object.
|
jaroslav@56
|
987 |
* @throws StringIndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
988 |
*/
|
jaroslav@56
|
989 |
public AbstractStringBuilder insert(int offset, char[] str) {
|
jaroslav@56
|
990 |
if ((offset < 0) || (offset > length()))
|
jaroslav@56
|
991 |
throw new StringIndexOutOfBoundsException(offset);
|
jaroslav@56
|
992 |
int len = str.length;
|
jaroslav@56
|
993 |
ensureCapacityInternal(count + len);
|
jaroslav@104
|
994 |
arraycopy(value, offset, value, offset + len, count - offset);
|
jaroslav@104
|
995 |
arraycopy(str, 0, value, offset, len);
|
jaroslav@56
|
996 |
count += len;
|
jaroslav@56
|
997 |
return this;
|
jaroslav@56
|
998 |
}
|
jaroslav@56
|
999 |
|
jaroslav@56
|
1000 |
/**
|
jaroslav@56
|
1001 |
* Inserts the specified {@code CharSequence} into this sequence.
|
jaroslav@56
|
1002 |
* <p>
|
jaroslav@56
|
1003 |
* The characters of the {@code CharSequence} argument are inserted,
|
jaroslav@56
|
1004 |
* in order, into this sequence at the indicated offset, moving up
|
jaroslav@56
|
1005 |
* any characters originally above that position and increasing the length
|
jaroslav@56
|
1006 |
* of this sequence by the length of the argument s.
|
jaroslav@56
|
1007 |
* <p>
|
jaroslav@56
|
1008 |
* The result of this method is exactly the same as if it were an
|
jaroslav@56
|
1009 |
* invocation of this object's
|
jaroslav@56
|
1010 |
* {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
|
jaroslav@56
|
1011 |
* method.
|
jaroslav@56
|
1012 |
*
|
jaroslav@56
|
1013 |
* <p>If {@code s} is {@code null}, then the four characters
|
jaroslav@56
|
1014 |
* {@code "null"} are inserted into this sequence.
|
jaroslav@56
|
1015 |
*
|
jaroslav@56
|
1016 |
* @param dstOffset the offset.
|
jaroslav@56
|
1017 |
* @param s the sequence to be inserted
|
jaroslav@56
|
1018 |
* @return a reference to this object.
|
jaroslav@56
|
1019 |
* @throws IndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
1020 |
*/
|
jaroslav@56
|
1021 |
public AbstractStringBuilder insert(int dstOffset, CharSequence s) {
|
jaroslav@56
|
1022 |
if (s == null)
|
jaroslav@56
|
1023 |
s = "null";
|
jaroslav@56
|
1024 |
if (s instanceof String)
|
jaroslav@56
|
1025 |
return this.insert(dstOffset, (String)s);
|
jaroslav@56
|
1026 |
return this.insert(dstOffset, s, 0, s.length());
|
jaroslav@56
|
1027 |
}
|
jaroslav@56
|
1028 |
|
jaroslav@56
|
1029 |
/**
|
jaroslav@56
|
1030 |
* Inserts a subsequence of the specified {@code CharSequence} into
|
jaroslav@56
|
1031 |
* this sequence.
|
jaroslav@56
|
1032 |
* <p>
|
jaroslav@56
|
1033 |
* The subsequence of the argument {@code s} specified by
|
jaroslav@56
|
1034 |
* {@code start} and {@code end} are inserted,
|
jaroslav@56
|
1035 |
* in order, into this sequence at the specified destination offset, moving
|
jaroslav@56
|
1036 |
* up any characters originally above that position. The length of this
|
jaroslav@56
|
1037 |
* sequence is increased by {@code end - start}.
|
jaroslav@56
|
1038 |
* <p>
|
jaroslav@56
|
1039 |
* The character at index <i>k</i> in this sequence becomes equal to:
|
jaroslav@56
|
1040 |
* <ul>
|
jaroslav@56
|
1041 |
* <li>the character at index <i>k</i> in this sequence, if
|
jaroslav@56
|
1042 |
* <i>k</i> is less than {@code dstOffset}
|
jaroslav@56
|
1043 |
* <li>the character at index <i>k</i>{@code +start-dstOffset} in
|
jaroslav@56
|
1044 |
* the argument {@code s}, if <i>k</i> is greater than or equal to
|
jaroslav@56
|
1045 |
* {@code dstOffset} but is less than {@code dstOffset+end-start}
|
jaroslav@56
|
1046 |
* <li>the character at index <i>k</i>{@code -(end-start)} in this
|
jaroslav@56
|
1047 |
* sequence, if <i>k</i> is greater than or equal to
|
jaroslav@56
|
1048 |
* {@code dstOffset+end-start}
|
jaroslav@56
|
1049 |
* </ul><p>
|
jaroslav@56
|
1050 |
* The {@code dstOffset} argument must be greater than or equal to
|
jaroslav@56
|
1051 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
1052 |
* of this sequence.
|
jaroslav@56
|
1053 |
* <p>The start argument must be nonnegative, and not greater than
|
jaroslav@56
|
1054 |
* {@code end}.
|
jaroslav@56
|
1055 |
* <p>The end argument must be greater than or equal to
|
jaroslav@56
|
1056 |
* {@code start}, and less than or equal to the length of s.
|
jaroslav@56
|
1057 |
*
|
jaroslav@56
|
1058 |
* <p>If {@code s} is {@code null}, then this method inserts
|
jaroslav@56
|
1059 |
* characters as if the s parameter was a sequence containing the four
|
jaroslav@56
|
1060 |
* characters {@code "null"}.
|
jaroslav@56
|
1061 |
*
|
jaroslav@56
|
1062 |
* @param dstOffset the offset in this sequence.
|
jaroslav@56
|
1063 |
* @param s the sequence to be inserted.
|
jaroslav@56
|
1064 |
* @param start the starting index of the subsequence to be inserted.
|
jaroslav@56
|
1065 |
* @param end the end index of the subsequence to be inserted.
|
jaroslav@56
|
1066 |
* @return a reference to this object.
|
jaroslav@56
|
1067 |
* @throws IndexOutOfBoundsException if {@code dstOffset}
|
jaroslav@56
|
1068 |
* is negative or greater than {@code this.length()}, or
|
jaroslav@56
|
1069 |
* {@code start} or {@code end} are negative, or
|
jaroslav@56
|
1070 |
* {@code start} is greater than {@code end} or
|
jaroslav@56
|
1071 |
* {@code end} is greater than {@code s.length()}
|
jaroslav@56
|
1072 |
*/
|
jaroslav@56
|
1073 |
public AbstractStringBuilder insert(int dstOffset, CharSequence s,
|
jaroslav@56
|
1074 |
int start, int end) {
|
jaroslav@56
|
1075 |
if (s == null)
|
jaroslav@56
|
1076 |
s = "null";
|
jaroslav@56
|
1077 |
if ((dstOffset < 0) || (dstOffset > this.length()))
|
jaroslav@56
|
1078 |
throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
|
jaroslav@56
|
1079 |
if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
|
jaroslav@56
|
1080 |
throw new IndexOutOfBoundsException(
|
jaroslav@56
|
1081 |
"start " + start + ", end " + end + ", s.length() "
|
jaroslav@56
|
1082 |
+ s.length());
|
jaroslav@56
|
1083 |
int len = end - start;
|
jaroslav@56
|
1084 |
ensureCapacityInternal(count + len);
|
jaroslav@104
|
1085 |
arraycopy(value, dstOffset, value, dstOffset + len,
|
jaroslav@56
|
1086 |
count - dstOffset);
|
jaroslav@56
|
1087 |
for (int i=start; i<end; i++)
|
jaroslav@56
|
1088 |
value[dstOffset++] = s.charAt(i);
|
jaroslav@56
|
1089 |
count += len;
|
jaroslav@56
|
1090 |
return this;
|
jaroslav@56
|
1091 |
}
|
jaroslav@56
|
1092 |
|
jaroslav@56
|
1093 |
/**
|
jaroslav@56
|
1094 |
* Inserts the string representation of the {@code boolean}
|
jaroslav@56
|
1095 |
* argument into this sequence.
|
jaroslav@56
|
1096 |
* <p>
|
jaroslav@56
|
1097 |
* The overall effect is exactly as if the second argument were
|
jaroslav@56
|
1098 |
* converted to a string by the method {@link String#valueOf(boolean)},
|
jaroslav@56
|
1099 |
* and the characters of that string were then
|
jaroslav@56
|
1100 |
* {@link #insert(int,String) inserted} into this character
|
jaroslav@56
|
1101 |
* sequence at the indicated offset.
|
jaroslav@56
|
1102 |
* <p>
|
jaroslav@56
|
1103 |
* The {@code offset} argument must be greater than or equal to
|
jaroslav@56
|
1104 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
1105 |
* of this sequence.
|
jaroslav@56
|
1106 |
*
|
jaroslav@56
|
1107 |
* @param offset the offset.
|
jaroslav@56
|
1108 |
* @param b a {@code boolean}.
|
jaroslav@56
|
1109 |
* @return a reference to this object.
|
jaroslav@56
|
1110 |
* @throws StringIndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
1111 |
*/
|
jaroslav@56
|
1112 |
public AbstractStringBuilder insert(int offset, boolean b) {
|
jaroslav@56
|
1113 |
return insert(offset, String.valueOf(b));
|
jaroslav@56
|
1114 |
}
|
jaroslav@56
|
1115 |
|
jaroslav@56
|
1116 |
/**
|
jaroslav@56
|
1117 |
* Inserts the string representation of the {@code char}
|
jaroslav@56
|
1118 |
* argument into this sequence.
|
jaroslav@56
|
1119 |
* <p>
|
jaroslav@56
|
1120 |
* The overall effect is exactly as if the second argument were
|
jaroslav@56
|
1121 |
* converted to a string by the method {@link String#valueOf(char)},
|
jaroslav@56
|
1122 |
* and the character in that string were then
|
jaroslav@56
|
1123 |
* {@link #insert(int,String) inserted} into this character
|
jaroslav@56
|
1124 |
* sequence at the indicated offset.
|
jaroslav@56
|
1125 |
* <p>
|
jaroslav@56
|
1126 |
* The {@code offset} argument must be greater than or equal to
|
jaroslav@56
|
1127 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
1128 |
* of this sequence.
|
jaroslav@56
|
1129 |
*
|
jaroslav@56
|
1130 |
* @param offset the offset.
|
jaroslav@56
|
1131 |
* @param c a {@code char}.
|
jaroslav@56
|
1132 |
* @return a reference to this object.
|
jaroslav@56
|
1133 |
* @throws IndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
1134 |
*/
|
jaroslav@56
|
1135 |
public AbstractStringBuilder insert(int offset, char c) {
|
jaroslav@56
|
1136 |
ensureCapacityInternal(count + 1);
|
jaroslav@104
|
1137 |
arraycopy(value, offset, value, offset + 1, count - offset);
|
jaroslav@56
|
1138 |
value[offset] = c;
|
jaroslav@56
|
1139 |
count += 1;
|
jaroslav@56
|
1140 |
return this;
|
jaroslav@56
|
1141 |
}
|
jaroslav@56
|
1142 |
|
jaroslav@56
|
1143 |
/**
|
jaroslav@56
|
1144 |
* Inserts the string representation of the second {@code int}
|
jaroslav@56
|
1145 |
* argument into this sequence.
|
jaroslav@56
|
1146 |
* <p>
|
jaroslav@56
|
1147 |
* The overall effect is exactly as if the second argument were
|
jaroslav@56
|
1148 |
* converted to a string by the method {@link String#valueOf(int)},
|
jaroslav@56
|
1149 |
* and the characters of that string were then
|
jaroslav@56
|
1150 |
* {@link #insert(int,String) inserted} into this character
|
jaroslav@56
|
1151 |
* sequence at the indicated offset.
|
jaroslav@56
|
1152 |
* <p>
|
jaroslav@56
|
1153 |
* The {@code offset} argument must be greater than or equal to
|
jaroslav@56
|
1154 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
1155 |
* of this sequence.
|
jaroslav@56
|
1156 |
*
|
jaroslav@56
|
1157 |
* @param offset the offset.
|
jaroslav@56
|
1158 |
* @param i an {@code int}.
|
jaroslav@56
|
1159 |
* @return a reference to this object.
|
jaroslav@56
|
1160 |
* @throws StringIndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
1161 |
*/
|
jaroslav@56
|
1162 |
public AbstractStringBuilder insert(int offset, int i) {
|
jaroslav@56
|
1163 |
return insert(offset, String.valueOf(i));
|
jaroslav@56
|
1164 |
}
|
jaroslav@56
|
1165 |
|
jaroslav@56
|
1166 |
/**
|
jaroslav@56
|
1167 |
* Inserts the string representation of the {@code long}
|
jaroslav@56
|
1168 |
* argument into this sequence.
|
jaroslav@56
|
1169 |
* <p>
|
jaroslav@56
|
1170 |
* The overall effect is exactly as if the second argument were
|
jaroslav@56
|
1171 |
* converted to a string by the method {@link String#valueOf(long)},
|
jaroslav@56
|
1172 |
* and the characters of that string were then
|
jaroslav@56
|
1173 |
* {@link #insert(int,String) inserted} into this character
|
jaroslav@56
|
1174 |
* sequence at the indicated offset.
|
jaroslav@56
|
1175 |
* <p>
|
jaroslav@56
|
1176 |
* The {@code offset} argument must be greater than or equal to
|
jaroslav@56
|
1177 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
1178 |
* of this sequence.
|
jaroslav@56
|
1179 |
*
|
jaroslav@56
|
1180 |
* @param offset the offset.
|
jaroslav@56
|
1181 |
* @param l a {@code long}.
|
jaroslav@56
|
1182 |
* @return a reference to this object.
|
jaroslav@56
|
1183 |
* @throws StringIndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
1184 |
*/
|
jaroslav@56
|
1185 |
public AbstractStringBuilder insert(int offset, long l) {
|
jaroslav@56
|
1186 |
return insert(offset, String.valueOf(l));
|
jaroslav@56
|
1187 |
}
|
jaroslav@56
|
1188 |
|
jaroslav@56
|
1189 |
/**
|
jaroslav@56
|
1190 |
* Inserts the string representation of the {@code float}
|
jaroslav@56
|
1191 |
* argument into this sequence.
|
jaroslav@56
|
1192 |
* <p>
|
jaroslav@56
|
1193 |
* The overall effect is exactly as if the second argument were
|
jaroslav@56
|
1194 |
* converted to a string by the method {@link String#valueOf(float)},
|
jaroslav@56
|
1195 |
* and the characters of that string were then
|
jaroslav@56
|
1196 |
* {@link #insert(int,String) inserted} into this character
|
jaroslav@56
|
1197 |
* sequence at the indicated offset.
|
jaroslav@56
|
1198 |
* <p>
|
jaroslav@56
|
1199 |
* The {@code offset} argument must be greater than or equal to
|
jaroslav@56
|
1200 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
1201 |
* of this sequence.
|
jaroslav@56
|
1202 |
*
|
jaroslav@56
|
1203 |
* @param offset the offset.
|
jaroslav@56
|
1204 |
* @param f a {@code float}.
|
jaroslav@56
|
1205 |
* @return a reference to this object.
|
jaroslav@56
|
1206 |
* @throws StringIndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
1207 |
*/
|
jaroslav@56
|
1208 |
public AbstractStringBuilder insert(int offset, float f) {
|
jaroslav@56
|
1209 |
return insert(offset, String.valueOf(f));
|
jaroslav@56
|
1210 |
}
|
jaroslav@56
|
1211 |
|
jaroslav@56
|
1212 |
/**
|
jaroslav@56
|
1213 |
* Inserts the string representation of the {@code double}
|
jaroslav@56
|
1214 |
* argument into this sequence.
|
jaroslav@56
|
1215 |
* <p>
|
jaroslav@56
|
1216 |
* The overall effect is exactly as if the second argument were
|
jaroslav@56
|
1217 |
* converted to a string by the method {@link String#valueOf(double)},
|
jaroslav@56
|
1218 |
* and the characters of that string were then
|
jaroslav@56
|
1219 |
* {@link #insert(int,String) inserted} into this character
|
jaroslav@56
|
1220 |
* sequence at the indicated offset.
|
jaroslav@56
|
1221 |
* <p>
|
jaroslav@56
|
1222 |
* The {@code offset} argument must be greater than or equal to
|
jaroslav@56
|
1223 |
* {@code 0}, and less than or equal to the {@linkplain #length() length}
|
jaroslav@56
|
1224 |
* of this sequence.
|
jaroslav@56
|
1225 |
*
|
jaroslav@56
|
1226 |
* @param offset the offset.
|
jaroslav@56
|
1227 |
* @param d a {@code double}.
|
jaroslav@56
|
1228 |
* @return a reference to this object.
|
jaroslav@56
|
1229 |
* @throws StringIndexOutOfBoundsException if the offset is invalid.
|
jaroslav@56
|
1230 |
*/
|
jaroslav@56
|
1231 |
public AbstractStringBuilder insert(int offset, double d) {
|
jaroslav@56
|
1232 |
return insert(offset, String.valueOf(d));
|
jaroslav@56
|
1233 |
}
|
jaroslav@56
|
1234 |
|
jaroslav@56
|
1235 |
/**
|
jaroslav@56
|
1236 |
* Returns the index within this string of the first occurrence of the
|
jaroslav@56
|
1237 |
* specified substring. The integer returned is the smallest value
|
jaroslav@56
|
1238 |
* <i>k</i> such that:
|
jaroslav@56
|
1239 |
* <blockquote><pre>
|
jaroslav@56
|
1240 |
* this.toString().startsWith(str, <i>k</i>)
|
jaroslav@56
|
1241 |
* </pre></blockquote>
|
jaroslav@56
|
1242 |
* is <code>true</code>.
|
jaroslav@56
|
1243 |
*
|
jaroslav@56
|
1244 |
* @param str any string.
|
jaroslav@56
|
1245 |
* @return if the string argument occurs as a substring within this
|
jaroslav@56
|
1246 |
* object, then the index of the first character of the first
|
jaroslav@56
|
1247 |
* such substring is returned; if it does not occur as a
|
jaroslav@56
|
1248 |
* substring, <code>-1</code> is returned.
|
jaroslav@56
|
1249 |
* @throws java.lang.NullPointerException if <code>str</code> is
|
jaroslav@56
|
1250 |
* <code>null</code>.
|
jaroslav@56
|
1251 |
*/
|
jaroslav@56
|
1252 |
public int indexOf(String str) {
|
jaroslav@56
|
1253 |
return indexOf(str, 0);
|
jaroslav@56
|
1254 |
}
|
jaroslav@56
|
1255 |
|
jaroslav@56
|
1256 |
/**
|
jaroslav@56
|
1257 |
* Returns the index within this string of the first occurrence of the
|
jaroslav@56
|
1258 |
* specified substring, starting at the specified index. The integer
|
jaroslav@56
|
1259 |
* returned is the smallest value <tt>k</tt> for which:
|
jaroslav@56
|
1260 |
* <blockquote><pre>
|
jaroslav@56
|
1261 |
* k >= Math.min(fromIndex, str.length()) &&
|
jaroslav@56
|
1262 |
* this.toString().startsWith(str, k)
|
jaroslav@56
|
1263 |
* </pre></blockquote>
|
jaroslav@56
|
1264 |
* If no such value of <i>k</i> exists, then -1 is returned.
|
jaroslav@56
|
1265 |
*
|
jaroslav@56
|
1266 |
* @param str the substring for which to search.
|
jaroslav@56
|
1267 |
* @param fromIndex the index from which to start the search.
|
jaroslav@56
|
1268 |
* @return the index within this string of the first occurrence of the
|
jaroslav@56
|
1269 |
* specified substring, starting at the specified index.
|
jaroslav@56
|
1270 |
* @throws java.lang.NullPointerException if <code>str</code> is
|
jaroslav@56
|
1271 |
* <code>null</code>.
|
jaroslav@56
|
1272 |
*/
|
jaroslav@56
|
1273 |
public int indexOf(String str, int fromIndex) {
|
jaroslav@56
|
1274 |
return String.indexOf(value, 0, count,
|
jaroslav@56
|
1275 |
str.toCharArray(), 0, str.length(), fromIndex);
|
jaroslav@56
|
1276 |
}
|
jaroslav@56
|
1277 |
|
jaroslav@56
|
1278 |
/**
|
jaroslav@56
|
1279 |
* Returns the index within this string of the rightmost occurrence
|
jaroslav@56
|
1280 |
* of the specified substring. The rightmost empty string "" is
|
jaroslav@56
|
1281 |
* considered to occur at the index value <code>this.length()</code>.
|
jaroslav@56
|
1282 |
* The returned index is the largest value <i>k</i> such that
|
jaroslav@56
|
1283 |
* <blockquote><pre>
|
jaroslav@56
|
1284 |
* this.toString().startsWith(str, k)
|
jaroslav@56
|
1285 |
* </pre></blockquote>
|
jaroslav@56
|
1286 |
* is true.
|
jaroslav@56
|
1287 |
*
|
jaroslav@56
|
1288 |
* @param str the substring to search for.
|
jaroslav@56
|
1289 |
* @return if the string argument occurs one or more times as a substring
|
jaroslav@56
|
1290 |
* within this object, then the index of the first character of
|
jaroslav@56
|
1291 |
* the last such substring is returned. If it does not occur as
|
jaroslav@56
|
1292 |
* a substring, <code>-1</code> is returned.
|
jaroslav@56
|
1293 |
* @throws java.lang.NullPointerException if <code>str</code> is
|
jaroslav@56
|
1294 |
* <code>null</code>.
|
jaroslav@56
|
1295 |
*/
|
jaroslav@56
|
1296 |
public int lastIndexOf(String str) {
|
jaroslav@56
|
1297 |
return lastIndexOf(str, count);
|
jaroslav@56
|
1298 |
}
|
jaroslav@56
|
1299 |
|
jaroslav@56
|
1300 |
/**
|
jaroslav@56
|
1301 |
* Returns the index within this string of the last occurrence of the
|
jaroslav@56
|
1302 |
* specified substring. The integer returned is the largest value <i>k</i>
|
jaroslav@56
|
1303 |
* such that:
|
jaroslav@56
|
1304 |
* <blockquote><pre>
|
jaroslav@56
|
1305 |
* k <= Math.min(fromIndex, str.length()) &&
|
jaroslav@56
|
1306 |
* this.toString().startsWith(str, k)
|
jaroslav@56
|
1307 |
* </pre></blockquote>
|
jaroslav@56
|
1308 |
* If no such value of <i>k</i> exists, then -1 is returned.
|
jaroslav@56
|
1309 |
*
|
jaroslav@56
|
1310 |
* @param str the substring to search for.
|
jaroslav@56
|
1311 |
* @param fromIndex the index to start the search from.
|
jaroslav@56
|
1312 |
* @return the index within this sequence of the last occurrence of the
|
jaroslav@56
|
1313 |
* specified substring.
|
jaroslav@56
|
1314 |
* @throws java.lang.NullPointerException if <code>str</code> is
|
jaroslav@56
|
1315 |
* <code>null</code>.
|
jaroslav@56
|
1316 |
*/
|
jaroslav@56
|
1317 |
public int lastIndexOf(String str, int fromIndex) {
|
jaroslav@56
|
1318 |
return String.lastIndexOf(value, 0, count,
|
jaroslav@56
|
1319 |
str.toCharArray(), 0, str.length(), fromIndex);
|
jaroslav@56
|
1320 |
}
|
jaroslav@56
|
1321 |
|
jaroslav@56
|
1322 |
/**
|
jaroslav@56
|
1323 |
* Causes this character sequence to be replaced by the reverse of
|
jaroslav@56
|
1324 |
* the sequence. If there are any surrogate pairs included in the
|
jaroslav@56
|
1325 |
* sequence, these are treated as single characters for the
|
jaroslav@56
|
1326 |
* reverse operation. Thus, the order of the high-low surrogates
|
jaroslav@56
|
1327 |
* is never reversed.
|
jaroslav@56
|
1328 |
*
|
jaroslav@56
|
1329 |
* Let <i>n</i> be the character length of this character sequence
|
jaroslav@56
|
1330 |
* (not the length in <code>char</code> values) just prior to
|
jaroslav@56
|
1331 |
* execution of the <code>reverse</code> method. Then the
|
jaroslav@56
|
1332 |
* character at index <i>k</i> in the new character sequence is
|
jaroslav@56
|
1333 |
* equal to the character at index <i>n-k-1</i> in the old
|
jaroslav@56
|
1334 |
* character sequence.
|
jaroslav@56
|
1335 |
*
|
jaroslav@56
|
1336 |
* <p>Note that the reverse operation may result in producing
|
jaroslav@56
|
1337 |
* surrogate pairs that were unpaired low-surrogates and
|
jaroslav@56
|
1338 |
* high-surrogates before the operation. For example, reversing
|
jaroslav@56
|
1339 |
* "\uDC00\uD800" produces "\uD800\uDC00" which is
|
jaroslav@56
|
1340 |
* a valid surrogate pair.
|
jaroslav@56
|
1341 |
*
|
jaroslav@56
|
1342 |
* @return a reference to this object.
|
jaroslav@56
|
1343 |
*/
|
jaroslav@56
|
1344 |
public AbstractStringBuilder reverse() {
|
jaroslav@56
|
1345 |
boolean hasSurrogate = false;
|
jaroslav@56
|
1346 |
int n = count - 1;
|
jaroslav@56
|
1347 |
for (int j = (n-1) >> 1; j >= 0; --j) {
|
jaroslav@56
|
1348 |
char temp = value[j];
|
jaroslav@56
|
1349 |
char temp2 = value[n - j];
|
jaroslav@56
|
1350 |
if (!hasSurrogate) {
|
jaroslav@56
|
1351 |
hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE)
|
jaroslav@56
|
1352 |
|| (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE);
|
jaroslav@56
|
1353 |
}
|
jaroslav@56
|
1354 |
value[j] = temp2;
|
jaroslav@56
|
1355 |
value[n - j] = temp;
|
jaroslav@56
|
1356 |
}
|
jaroslav@56
|
1357 |
if (hasSurrogate) {
|
jaroslav@56
|
1358 |
// Reverse back all valid surrogate pairs
|
jaroslav@56
|
1359 |
for (int i = 0; i < count - 1; i++) {
|
jaroslav@56
|
1360 |
char c2 = value[i];
|
jaroslav@56
|
1361 |
if (Character.isLowSurrogate(c2)) {
|
jaroslav@56
|
1362 |
char c1 = value[i + 1];
|
jaroslav@56
|
1363 |
if (Character.isHighSurrogate(c1)) {
|
jaroslav@56
|
1364 |
value[i++] = c1;
|
jaroslav@56
|
1365 |
value[i] = c2;
|
jaroslav@56
|
1366 |
}
|
jaroslav@56
|
1367 |
}
|
jaroslav@56
|
1368 |
}
|
jaroslav@56
|
1369 |
}
|
jaroslav@56
|
1370 |
return this;
|
jaroslav@56
|
1371 |
}
|
jaroslav@56
|
1372 |
|
jaroslav@56
|
1373 |
/**
|
jaroslav@56
|
1374 |
* Returns a string representing the data in this sequence.
|
jaroslav@56
|
1375 |
* A new <code>String</code> object is allocated and initialized to
|
jaroslav@56
|
1376 |
* contain the character sequence currently represented by this
|
jaroslav@56
|
1377 |
* object. This <code>String</code> is then returned. Subsequent
|
jaroslav@56
|
1378 |
* changes to this sequence do not affect the contents of the
|
jaroslav@56
|
1379 |
* <code>String</code>.
|
jaroslav@56
|
1380 |
*
|
jaroslav@56
|
1381 |
* @return a string representation of this sequence of characters.
|
jaroslav@56
|
1382 |
*/
|
jaroslav@56
|
1383 |
public abstract String toString();
|
jaroslav@56
|
1384 |
|
jaroslav@56
|
1385 |
/**
|
jaroslav@56
|
1386 |
* Needed by <tt>String</tt> for the contentEquals method.
|
jaroslav@56
|
1387 |
*/
|
jaroslav@56
|
1388 |
final char[] getValue() {
|
jaroslav@56
|
1389 |
return value;
|
jaroslav@56
|
1390 |
}
|
jaroslav@56
|
1391 |
|
jaroslav@104
|
1392 |
static char[] copyOfRange(char[] original, int from, int to) {
|
jaroslav@104
|
1393 |
int newLength = to - from;
|
jaroslav@104
|
1394 |
if (newLength < 0) {
|
jaroslav@104
|
1395 |
throw new IllegalArgumentException(from + " > " + to);
|
jaroslav@104
|
1396 |
}
|
jaroslav@104
|
1397 |
char[] copy = new char[newLength];
|
jaroslav@104
|
1398 |
arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
|
jaroslav@104
|
1399 |
return copy;
|
jaroslav@104
|
1400 |
}
|
jaroslav@104
|
1401 |
|
jaroslav@104
|
1402 |
static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
|
jtulach@192
|
1403 |
if (srcBegin < dstBegin) {
|
jtulach@192
|
1404 |
while (count-- > 0) {
|
jtulach@192
|
1405 |
dst[dstBegin + count] = value[srcBegin + count];
|
jtulach@192
|
1406 |
}
|
jtulach@192
|
1407 |
} else {
|
jtulach@192
|
1408 |
while (count-- > 0) {
|
jtulach@192
|
1409 |
dst[dstBegin++] = value[srcBegin++];
|
jtulach@192
|
1410 |
}
|
jaroslav@104
|
1411 |
}
|
jaroslav@104
|
1412 |
}
|
jaroslav@104
|
1413 |
|
jaroslav@104
|
1414 |
// access system property
|
jaroslav@104
|
1415 |
static String getProperty(String nm) {
|
jaroslav@104
|
1416 |
return null;
|
jaroslav@104
|
1417 |
}
|
jaroslav@104
|
1418 |
|
jaroslav@104
|
1419 |
static char[] copyOf(char[] original, int newLength) {
|
jaroslav@104
|
1420 |
char[] copy = new char[newLength];
|
jaroslav@104
|
1421 |
arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
|
jaroslav@104
|
1422 |
return copy;
|
jaroslav@104
|
1423 |
}
|
jaroslav@104
|
1424 |
|
jaroslav@56
|
1425 |
}
|