author | rriggs |
Tue, 16 Feb 2016 11:36:20 -0500 | |
changeset 35978 | 752d505da547 |
parent 35302 | e4d2275861c3 |
child 36217 | cc64f9fb2062 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang; |
|
27 |
||
34781
479b1724ab80
8145990: Move sun.misc math support classes to jdk.internal.math
chegar
parents:
34518
diff
changeset
|
28 |
import jdk.internal.math.FloatingDecimal; |
2 | 29 |
import java.util.Arrays; |
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
30 |
import java.util.Spliterator; |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
31 |
import java.util.stream.IntStream; |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
32 |
import java.util.stream.StreamSupport; |
2 | 33 |
|
33663 | 34 |
import static java.lang.String.COMPACT_STRINGS; |
35 |
import static java.lang.String.UTF16; |
|
36 |
import static java.lang.String.LATIN1; |
|
37 |
import static java.lang.String.checkIndex; |
|
38 |
import static java.lang.String.checkOffset; |
|
39 |
||
2 | 40 |
/** |
41 |
* A mutable sequence of characters. |
|
42 |
* <p> |
|
43 |
* Implements a modifiable string. At any point in time it contains some |
|
44 |
* particular sequence of characters, but the length and content of the |
|
45 |
* sequence can be changed through certain method calls. |
|
46 |
* |
|
15312
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
47 |
* <p>Unless otherwise noted, passing a {@code null} argument to a constructor |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
48 |
* or method in this class will cause a {@link NullPointerException} to be |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
49 |
* thrown. |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
50 |
* |
2 | 51 |
* @author Michael McCloskey |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
52 |
* @author Martin Buchholz |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
53 |
* @author Ulf Zibis |
2 | 54 |
* @since 1.5 |
55 |
*/ |
|
56 |
abstract class AbstractStringBuilder implements Appendable, CharSequence { |
|
57 |
/** |
|
58 |
* The value is used for character storage. |
|
59 |
*/ |
|
33663 | 60 |
byte[] value; |
61 |
||
62 |
/** |
|
63 |
* The id of the encoding used to encode the bytes in {@code value}. |
|
64 |
*/ |
|
65 |
byte coder; |
|
2 | 66 |
|
67 |
/** |
|
68 |
* The count is the number of characters used. |
|
69 |
*/ |
|
70 |
int count; |
|
71 |
||
72 |
/** |
|
73 |
* This no-arg constructor is necessary for serialization of subclasses. |
|
74 |
*/ |
|
75 |
AbstractStringBuilder() { |
|
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Creates an AbstractStringBuilder of the specified capacity. |
|
80 |
*/ |
|
81 |
AbstractStringBuilder(int capacity) { |
|
33663 | 82 |
if (COMPACT_STRINGS) { |
83 |
value = new byte[capacity]; |
|
84 |
coder = LATIN1; |
|
85 |
} else { |
|
86 |
value = StringUTF16.newBytesFor(capacity); |
|
87 |
coder = UTF16; |
|
88 |
} |
|
2 | 89 |
} |
90 |
||
91 |
/** |
|
92 |
* Returns the length (character count). |
|
93 |
* |
|
94 |
* @return the length of the sequence of characters currently |
|
95 |
* represented by this object |
|
96 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
97 |
@Override |
2 | 98 |
public int length() { |
99 |
return count; |
|
100 |
} |
|
101 |
||
102 |
/** |
|
103 |
* Returns the current capacity. The capacity is the amount of storage |
|
104 |
* available for newly inserted characters, beyond which an allocation |
|
105 |
* will occur. |
|
106 |
* |
|
107 |
* @return the current capacity |
|
108 |
*/ |
|
109 |
public int capacity() { |
|
33663 | 110 |
return value.length >> coder; |
2 | 111 |
} |
112 |
||
113 |
/** |
|
114 |
* Ensures that the capacity is at least equal to the specified minimum. |
|
115 |
* If the current capacity is less than the argument, then a new internal |
|
116 |
* array is allocated with greater capacity. The new capacity is the |
|
117 |
* larger of: |
|
118 |
* <ul> |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
119 |
* <li>The {@code minimumCapacity} argument. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
120 |
* <li>Twice the old capacity, plus {@code 2}. |
2 | 121 |
* </ul> |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
122 |
* If the {@code minimumCapacity} argument is nonpositive, this |
2 | 123 |
* method takes no action and simply returns. |
13821
02266c2bf3a8
4722265: (spec str) StringBuffer.ensureCapacity() should mention that capacity is mutable
jgish
parents:
11676
diff
changeset
|
124 |
* Note that subsequent operations on this object can reduce the |
02266c2bf3a8
4722265: (spec str) StringBuffer.ensureCapacity() should mention that capacity is mutable
jgish
parents:
11676
diff
changeset
|
125 |
* actual capacity below that requested here. |
2 | 126 |
* |
127 |
* @param minimumCapacity the minimum desired capacity. |
|
128 |
*/ |
|
129 |
public void ensureCapacity(int minimumCapacity) { |
|
33663 | 130 |
if (minimumCapacity > 0) { |
7020
25638687fe82
6992121: StringBuilder.ensureCapacity(int minCap) throws OutOfMemoryError with minCap=Integer.MIN_VALUE
mchung
parents:
6295
diff
changeset
|
131 |
ensureCapacityInternal(minimumCapacity); |
33663 | 132 |
} |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
133 |
} |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
134 |
|
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
135 |
/** |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
136 |
* This method has the same contract as ensureCapacity, but is |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
137 |
* never synchronized. |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
138 |
*/ |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
139 |
private void ensureCapacityInternal(int minimumCapacity) { |
7020
25638687fe82
6992121: StringBuilder.ensureCapacity(int minCap) throws OutOfMemoryError with minCap=Integer.MIN_VALUE
mchung
parents:
6295
diff
changeset
|
140 |
// overflow-conscious code |
33663 | 141 |
int capacity = value.length >> coder; |
142 |
if (minimumCapacity - capacity > 0) { |
|
2 | 143 |
expandCapacity(minimumCapacity); |
33663 | 144 |
} |
2 | 145 |
} |
146 |
||
147 |
/** |
|
148 |
* This implements the expansion semantics of ensureCapacity with no |
|
149 |
* size check or synchronization. |
|
150 |
*/ |
|
33663 | 151 |
private void expandCapacity(int minimumCapacity) { |
152 |
int newCapacity = (value.length >> coder) * 2 + 2; |
|
153 |
if (newCapacity - minimumCapacity < 0) { |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
154 |
newCapacity = minimumCapacity; |
33663 | 155 |
} |
2 | 156 |
if (newCapacity < 0) { |
33663 | 157 |
if (minimumCapacity < 0) {// overflow |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
158 |
throw new OutOfMemoryError(); |
33663 | 159 |
} |
2 | 160 |
newCapacity = Integer.MAX_VALUE; |
161 |
} |
|
33663 | 162 |
if (coder != LATIN1 && newCapacity > StringUTF16.MAX_LENGTH) { |
163 |
if (minimumCapacity >= StringUTF16.MAX_LENGTH) { |
|
164 |
throw new OutOfMemoryError(); |
|
165 |
} |
|
166 |
newCapacity = StringUTF16.MAX_LENGTH; |
|
167 |
} |
|
168 |
this.value = Arrays.copyOf(value, newCapacity << coder); |
|
169 |
} |
|
170 |
||
171 |
/** |
|
172 |
* If the coder is "isLatin1", this inflates the internal 8-bit storage |
|
173 |
* to 16-bit <hi=0, low> pair storage. |
|
174 |
*/ |
|
175 |
private void inflate() { |
|
176 |
if (!isLatin1()) { |
|
177 |
return; |
|
178 |
} |
|
179 |
byte[] buf = StringUTF16.newBytesFor(value.length); |
|
34517
c6e795a80c80
8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
33871
diff
changeset
|
180 |
StringLatin1.inflate(value, 0, buf, 0, count); |
33663 | 181 |
this.value = buf; |
182 |
this.coder = UTF16; |
|
2 | 183 |
} |
184 |
||
185 |
/** |
|
186 |
* Attempts to reduce storage used for the character sequence. |
|
187 |
* If the buffer is larger than necessary to hold its current sequence of |
|
188 |
* characters, then it may be resized to become more space efficient. |
|
189 |
* Calling this method may, but is not required to, affect the value |
|
190 |
* returned by a subsequent call to the {@link #capacity()} method. |
|
191 |
*/ |
|
192 |
public void trimToSize() { |
|
33663 | 193 |
int length = count << coder; |
194 |
if (length < value.length) { |
|
195 |
value = Arrays.copyOf(value, length); |
|
2 | 196 |
} |
197 |
} |
|
198 |
||
199 |
/** |
|
200 |
* Sets the length of the character sequence. |
|
201 |
* The sequence is changed to a new character sequence |
|
202 |
* whose length is specified by the argument. For every nonnegative |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
203 |
* index <i>k</i> less than {@code newLength}, the character at |
2 | 204 |
* index <i>k</i> in the new character sequence is the same as the |
205 |
* character at index <i>k</i> in the old sequence if <i>k</i> is less |
|
206 |
* than the length of the old character sequence; otherwise, it is the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
207 |
* null character {@code '\u005Cu0000'}. |
2 | 208 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
209 |
* In other words, if the {@code newLength} argument is less than |
2 | 210 |
* the current length, the length is changed to the specified length. |
211 |
* <p> |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
212 |
* If the {@code newLength} argument is greater than or equal |
2 | 213 |
* to the current length, sufficient null characters |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
214 |
* ({@code '\u005Cu0000'}) are appended so that |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
215 |
* length becomes the {@code newLength} argument. |
2 | 216 |
* <p> |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
217 |
* The {@code newLength} argument must be greater than or equal |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
218 |
* to {@code 0}. |
2 | 219 |
* |
220 |
* @param newLength the new length |
|
221 |
* @throws IndexOutOfBoundsException if the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
222 |
* {@code newLength} argument is negative. |
2 | 223 |
*/ |
224 |
public void setLength(int newLength) { |
|
33663 | 225 |
if (newLength < 0) { |
2 | 226 |
throw new StringIndexOutOfBoundsException(newLength); |
33663 | 227 |
} |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
228 |
ensureCapacityInternal(newLength); |
2 | 229 |
if (count < newLength) { |
33663 | 230 |
if (isLatin1()) { |
231 |
StringLatin1.fillNull(value, count, newLength); |
|
232 |
} else { |
|
233 |
StringUTF16.fillNull(value, count, newLength); |
|
234 |
} |
|
2 | 235 |
} |
14686
fb59583d33b2
6553074: String{Buffer,Builder}.indexOf(Str, int) contains unnecessary allocation
mduigou
parents:
14332
diff
changeset
|
236 |
count = newLength; |
2 | 237 |
} |
238 |
||
239 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
240 |
* Returns the {@code char} value in this sequence at the specified index. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
241 |
* The first {@code char} value is at index {@code 0}, the next at index |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
242 |
* {@code 1}, and so on, as in array indexing. |
2 | 243 |
* <p> |
244 |
* The index argument must be greater than or equal to |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
245 |
* {@code 0}, and less than the length of this sequence. |
2 | 246 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
247 |
* <p>If the {@code char} value specified by the index is a |
2 | 248 |
* <a href="Character.html#unicode">surrogate</a>, the surrogate |
249 |
* value is returned. |
|
250 |
* |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
251 |
* @param index the index of the desired {@code char} value. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
252 |
* @return the {@code char} value at the specified index. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
253 |
* @throws IndexOutOfBoundsException if {@code index} is |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
254 |
* negative or greater than or equal to {@code length()}. |
2 | 255 |
*/ |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
256 |
@Override |
2 | 257 |
public char charAt(int index) { |
33663 | 258 |
checkIndex(index, count); |
259 |
if (isLatin1()) { |
|
260 |
return (char)(value[index] & 0xff); |
|
261 |
} |
|
262 |
return StringUTF16.charAt(value, index); |
|
2 | 263 |
} |
264 |
||
265 |
/** |
|
266 |
* Returns the character (Unicode code point) at the specified |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
267 |
* index. The index refers to {@code char} values |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
268 |
* (Unicode code units) and ranges from {@code 0} to |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
269 |
* {@link #length()}{@code - 1}. |
2 | 270 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
271 |
* <p> If the {@code char} value specified at the given index |
2 | 272 |
* is in the high-surrogate range, the following index is less |
273 |
* than the length of this sequence, and the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
274 |
* {@code char} value at the following index is in the |
2 | 275 |
* low-surrogate range, then the supplementary code point |
276 |
* corresponding to this surrogate pair is returned. Otherwise, |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
277 |
* the {@code char} value at the given index is returned. |
2 | 278 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
279 |
* @param index the index to the {@code char} values |
2 | 280 |
* @return the code point value of the character at the |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
281 |
* {@code index} |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
282 |
* @exception IndexOutOfBoundsException if the {@code index} |
2 | 283 |
* argument is negative or not less than the length of this |
284 |
* sequence. |
|
285 |
*/ |
|
286 |
public int codePointAt(int index) { |
|
33663 | 287 |
checkIndex(index, count); |
288 |
if (isLatin1()) { |
|
289 |
return value[index] & 0xff; |
|
2 | 290 |
} |
33663 | 291 |
return StringUTF16.codePointAtSB(value, index, count); |
2 | 292 |
} |
293 |
||
294 |
/** |
|
295 |
* Returns the character (Unicode code point) before the specified |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
296 |
* index. The index refers to {@code char} values |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
297 |
* (Unicode code units) and ranges from {@code 1} to {@link |
2 | 298 |
* #length()}. |
299 |
* |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
300 |
* <p> If the {@code char} value at {@code (index - 1)} |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
301 |
* is in the low-surrogate range, {@code (index - 2)} is not |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
302 |
* negative, and the {@code char} value at {@code (index - |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
303 |
* 2)} is in the high-surrogate range, then the |
2 | 304 |
* supplementary code point value of the surrogate pair is |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
305 |
* returned. If the {@code char} value at {@code index - |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
306 |
* 1} is an unpaired low-surrogate or a high-surrogate, the |
2 | 307 |
* surrogate value is returned. |
308 |
* |
|
309 |
* @param index the index following the code point that should be returned |
|
310 |
* @return the Unicode code point value before the given index. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
311 |
* @exception IndexOutOfBoundsException if the {@code index} |
2 | 312 |
* argument is less than 1 or greater than the length |
313 |
* of this sequence. |
|
314 |
*/ |
|
315 |
public int codePointBefore(int index) { |
|
316 |
int i = index - 1; |
|
33663 | 317 |
if (i < 0 || i >= count) { |
2 | 318 |
throw new StringIndexOutOfBoundsException(index); |
319 |
} |
|
33663 | 320 |
if (isLatin1()) { |
321 |
return value[i] & 0xff; |
|
322 |
} |
|
323 |
return StringUTF16.codePointBeforeSB(value, index); |
|
2 | 324 |
} |
325 |
||
326 |
/** |
|
327 |
* Returns the number of Unicode code points in the specified text |
|
328 |
* range of this sequence. The text range begins at the specified |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
329 |
* {@code beginIndex} and extends to the {@code char} at |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
330 |
* index {@code endIndex - 1}. Thus the length (in |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
331 |
* {@code char}s) of the text range is |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
332 |
* {@code endIndex-beginIndex}. Unpaired surrogates within |
2 | 333 |
* this sequence count as one code point each. |
334 |
* |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
335 |
* @param beginIndex the index to the first {@code char} of |
2 | 336 |
* the text range. |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
337 |
* @param endIndex the index after the last {@code char} of |
2 | 338 |
* the text range. |
339 |
* @return the number of Unicode code points in the specified text |
|
340 |
* range |
|
341 |
* @exception IndexOutOfBoundsException if the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
342 |
* {@code beginIndex} is negative, or {@code endIndex} |
2 | 343 |
* is larger than the length of this sequence, or |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
344 |
* {@code beginIndex} is larger than {@code endIndex}. |
2 | 345 |
*/ |
346 |
public int codePointCount(int beginIndex, int endIndex) { |
|
347 |
if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) { |
|
348 |
throw new IndexOutOfBoundsException(); |
|
349 |
} |
|
33663 | 350 |
if (isLatin1()) { |
351 |
return endIndex - beginIndex; |
|
352 |
} |
|
353 |
return StringUTF16.codePointCountSB(value, beginIndex, endIndex); |
|
2 | 354 |
} |
355 |
||
356 |
/** |
|
357 |
* Returns the index within this sequence that is offset from the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
358 |
* given {@code index} by {@code codePointOffset} code |
2 | 359 |
* points. Unpaired surrogates within the text range given by |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
360 |
* {@code index} and {@code codePointOffset} count as |
2 | 361 |
* one code point each. |
362 |
* |
|
363 |
* @param index the index to be offset |
|
364 |
* @param codePointOffset the offset in code points |
|
365 |
* @return the index within this sequence |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
366 |
* @exception IndexOutOfBoundsException if {@code index} |
2 | 367 |
* is negative or larger then the length of this sequence, |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
368 |
* or if {@code codePointOffset} is positive and the subsequence |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
369 |
* starting with {@code index} has fewer than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
370 |
* {@code codePointOffset} code points, |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
371 |
* or if {@code codePointOffset} is negative and the subsequence |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
372 |
* before {@code index} has fewer than the absolute value of |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
373 |
* {@code codePointOffset} code points. |
2 | 374 |
*/ |
375 |
public int offsetByCodePoints(int index, int codePointOffset) { |
|
376 |
if (index < 0 || index > count) { |
|
377 |
throw new IndexOutOfBoundsException(); |
|
378 |
} |
|
33663 | 379 |
return Character.offsetByCodePoints(this, |
380 |
index, codePointOffset); |
|
2 | 381 |
} |
382 |
||
383 |
/** |
|
384 |
* Characters are copied from this sequence into the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
385 |
* destination character array {@code dst}. The first character to |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
386 |
* be copied is at index {@code srcBegin}; the last character to |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
387 |
* be copied is at index {@code srcEnd-1}. The total number of |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
388 |
* characters to be copied is {@code srcEnd-srcBegin}. The |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
389 |
* characters are copied into the subarray of {@code dst} starting |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
390 |
* at index {@code dstBegin} and ending at index: |
21334 | 391 |
* <pre>{@code |
2 | 392 |
* dstbegin + (srcEnd-srcBegin) - 1 |
21334 | 393 |
* }</pre> |
2 | 394 |
* |
395 |
* @param srcBegin start copying at this offset. |
|
396 |
* @param srcEnd stop copying at this offset. |
|
397 |
* @param dst the array to copy the data into. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
398 |
* @param dstBegin offset into {@code dst}. |
2 | 399 |
* @throws IndexOutOfBoundsException if any of the following is true: |
400 |
* <ul> |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
401 |
* <li>{@code srcBegin} is negative |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
402 |
* <li>{@code dstBegin} is negative |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
403 |
* <li>the {@code srcBegin} argument is greater than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
404 |
* the {@code srcEnd} argument. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
405 |
* <li>{@code srcEnd} is greater than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
406 |
* {@code this.length()}. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
407 |
* <li>{@code dstBegin+srcEnd-srcBegin} is greater than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
408 |
* {@code dst.length} |
2 | 409 |
* </ul> |
410 |
*/ |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
411 |
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) |
2 | 412 |
{ |
33663 | 413 |
checkRangeSIOOBE(srcBegin, srcEnd, count); // compatible to old version |
414 |
int n = srcEnd - srcBegin; |
|
415 |
checkRange(dstBegin, dstBegin + n, dst.length); |
|
416 |
if (isLatin1()) { |
|
34517
c6e795a80c80
8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
33871
diff
changeset
|
417 |
StringLatin1.getChars(value, srcBegin, srcEnd, dst, dstBegin); |
33663 | 418 |
} else { |
34517
c6e795a80c80
8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
33871
diff
changeset
|
419 |
StringUTF16.getChars(value, srcBegin, srcEnd, dst, dstBegin); |
33663 | 420 |
} |
2 | 421 |
} |
422 |
||
423 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
424 |
* The character at the specified index is set to {@code ch}. This |
2 | 425 |
* sequence is altered to represent a new character sequence that is |
426 |
* identical to the old character sequence, except that it contains the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
427 |
* character {@code ch} at position {@code index}. |
2 | 428 |
* <p> |
429 |
* The index argument must be greater than or equal to |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
430 |
* {@code 0}, and less than the length of this sequence. |
2 | 431 |
* |
432 |
* @param index the index of the character to modify. |
|
433 |
* @param ch the new character. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
434 |
* @throws IndexOutOfBoundsException if {@code index} is |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
435 |
* negative or greater than or equal to {@code length()}. |
2 | 436 |
*/ |
437 |
public void setCharAt(int index, char ch) { |
|
33663 | 438 |
checkIndex(index, count); |
439 |
if (isLatin1() && StringLatin1.canEncode(ch)) { |
|
440 |
value[index] = (byte)ch; |
|
441 |
} else { |
|
442 |
if (isLatin1()) { |
|
443 |
inflate(); |
|
444 |
} |
|
445 |
StringUTF16.putCharSB(value, index, ch); |
|
446 |
} |
|
2 | 447 |
} |
448 |
||
449 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
450 |
* Appends the string representation of the {@code Object} argument. |
2 | 451 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
452 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
453 |
* to a string by the method {@link String#valueOf(Object)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
454 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
455 |
* {@link #append(String) appended} to this character sequence. |
2 | 456 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
457 |
* @param obj an {@code Object}. |
2 | 458 |
* @return a reference to this object. |
459 |
*/ |
|
460 |
public AbstractStringBuilder append(Object obj) { |
|
461 |
return append(String.valueOf(obj)); |
|
462 |
} |
|
463 |
||
464 |
/** |
|
465 |
* Appends the specified string to this character sequence. |
|
466 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
467 |
* The characters of the {@code String} argument are appended, in |
2 | 468 |
* order, increasing the length of this sequence by the length of the |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
469 |
* argument. If {@code str} is {@code null}, then the four |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
470 |
* characters {@code "null"} are appended. |
2 | 471 |
* <p> |
472 |
* Let <i>n</i> be the length of this character sequence just prior to |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
473 |
* execution of the {@code append} method. Then the character at |
2 | 474 |
* index <i>k</i> in the new character sequence is equal to the character |
475 |
* at index <i>k</i> in the old character sequence, if <i>k</i> is less |
|
476 |
* than <i>n</i>; otherwise, it is equal to the character at index |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
477 |
* <i>k-n</i> in the argument {@code str}. |
2 | 478 |
* |
479 |
* @param str a string. |
|
480 |
* @return a reference to this object. |
|
481 |
*/ |
|
482 |
public AbstractStringBuilder append(String str) { |
|
33663 | 483 |
if (str == null) { |
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
484 |
return appendNull(); |
33663 | 485 |
} |
2 | 486 |
int len = str.length(); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
487 |
ensureCapacityInternal(count + len); |
33663 | 488 |
putStringAt(count, str); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
489 |
count += len; |
2 | 490 |
return this; |
491 |
} |
|
492 |
||
493 |
// Documentation in subclasses because of synchro difference |
|
494 |
public AbstractStringBuilder append(StringBuffer sb) { |
|
33663 | 495 |
return this.append((AbstractStringBuilder)sb); |
2 | 496 |
} |
497 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
498 |
/** |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
499 |
* @since 1.8 |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
500 |
*/ |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
501 |
AbstractStringBuilder append(AbstractStringBuilder asb) { |
33663 | 502 |
if (asb == null) { |
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
503 |
return appendNull(); |
33663 | 504 |
} |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
505 |
int len = asb.length(); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
506 |
ensureCapacityInternal(count + len); |
33663 | 507 |
if (getCoder() != asb.getCoder()) { |
508 |
inflate(); |
|
509 |
} |
|
510 |
asb.getBytes(value, count, coder); |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
511 |
count += len; |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
512 |
return this; |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
513 |
} |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
514 |
|
2 | 515 |
// Documentation in subclasses because of synchro difference |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
516 |
@Override |
2 | 517 |
public AbstractStringBuilder append(CharSequence s) { |
33663 | 518 |
if (s == null) { |
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
519 |
return appendNull(); |
33663 | 520 |
} |
521 |
if (s instanceof String) { |
|
2 | 522 |
return this.append((String)s); |
33663 | 523 |
} |
524 |
if (s instanceof AbstractStringBuilder) { |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
525 |
return this.append((AbstractStringBuilder)s); |
33663 | 526 |
} |
2 | 527 |
return this.append(s, 0, s.length()); |
528 |
} |
|
529 |
||
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
530 |
private AbstractStringBuilder appendNull() { |
33663 | 531 |
ensureCapacityInternal(count + 4); |
532 |
int count = this.count; |
|
533 |
byte[] val = this.value; |
|
534 |
if (isLatin1()) { |
|
535 |
val[count++] = 'n'; |
|
536 |
val[count++] = 'u'; |
|
537 |
val[count++] = 'l'; |
|
538 |
val[count++] = 'l'; |
|
539 |
} else { |
|
540 |
checkOffset(count + 4, val.length >> 1); |
|
541 |
StringUTF16.putChar(val, count++, 'n'); |
|
542 |
StringUTF16.putChar(val, count++, 'u'); |
|
543 |
StringUTF16.putChar(val, count++, 'l'); |
|
544 |
StringUTF16.putChar(val, count++, 'l'); |
|
545 |
} |
|
546 |
this.count = count; |
|
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
547 |
return this; |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
548 |
} |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
549 |
|
2 | 550 |
/** |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
551 |
* Appends a subsequence of the specified {@code CharSequence} to this |
2 | 552 |
* sequence. |
553 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
554 |
* Characters of the argument {@code s}, starting at |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
555 |
* index {@code start}, are appended, in order, to the contents of |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
556 |
* this sequence up to the (exclusive) index {@code end}. The length |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
557 |
* of this sequence is increased by the value of {@code end - start}. |
2 | 558 |
* <p> |
559 |
* Let <i>n</i> be the length of this character sequence just prior to |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
560 |
* execution of the {@code append} method. Then the character at |
2 | 561 |
* index <i>k</i> in this character sequence becomes equal to the |
562 |
* character at index <i>k</i> in this sequence, if <i>k</i> is less than |
|
563 |
* <i>n</i>; otherwise, it is equal to the character at index |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
564 |
* <i>k+start-n</i> in the argument {@code s}. |
2 | 565 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
566 |
* If {@code s} is {@code null}, then this method appends |
2 | 567 |
* characters as if the s parameter was a sequence containing the four |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
568 |
* characters {@code "null"}. |
2 | 569 |
* |
570 |
* @param s the sequence to append. |
|
571 |
* @param start the starting index of the subsequence to be appended. |
|
572 |
* @param end the end index of the subsequence to be appended. |
|
573 |
* @return a reference to this object. |
|
574 |
* @throws IndexOutOfBoundsException if |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
575 |
* {@code start} is negative, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
576 |
* {@code start} is greater than {@code end} or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
577 |
* {@code end} is greater than {@code s.length()} |
2 | 578 |
*/ |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
579 |
@Override |
2 | 580 |
public AbstractStringBuilder append(CharSequence s, int start, int end) { |
33663 | 581 |
if (s == null) { |
2 | 582 |
s = "null"; |
33663 | 583 |
} |
584 |
checkRange(start, end, s.length()); |
|
2 | 585 |
int len = end - start; |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
586 |
ensureCapacityInternal(count + len); |
33663 | 587 |
appendChars(s, start, end); |
2 | 588 |
return this; |
589 |
} |
|
590 |
||
591 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
592 |
* Appends the string representation of the {@code char} array |
2 | 593 |
* argument to this sequence. |
594 |
* <p> |
|
595 |
* The characters of the array argument are appended, in order, to |
|
596 |
* the contents of this sequence. The length of this sequence |
|
597 |
* increases by the length of the argument. |
|
598 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
599 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
600 |
* to a string by the method {@link String#valueOf(char[])}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
601 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
602 |
* {@link #append(String) appended} to this character sequence. |
2 | 603 |
* |
604 |
* @param str the characters to be appended. |
|
605 |
* @return a reference to this object. |
|
606 |
*/ |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
607 |
public AbstractStringBuilder append(char[] str) { |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
608 |
int len = str.length; |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
609 |
ensureCapacityInternal(count + len); |
33663 | 610 |
appendChars(str, 0, len); |
2 | 611 |
return this; |
612 |
} |
|
613 |
||
614 |
/** |
|
615 |
* Appends the string representation of a subarray of the |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
616 |
* {@code char} array argument to this sequence. |
2 | 617 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
618 |
* Characters of the {@code char} array {@code str}, starting at |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
619 |
* index {@code offset}, are appended, in order, to the contents |
2 | 620 |
* of this sequence. The length of this sequence increases |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
621 |
* by the value of {@code len}. |
2 | 622 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
623 |
* The overall effect is exactly as if the arguments were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
624 |
* to a string by the method {@link String#valueOf(char[],int,int)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
625 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
626 |
* {@link #append(String) appended} to this character sequence. |
2 | 627 |
* |
628 |
* @param str the characters to be appended. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
629 |
* @param offset the index of the first {@code char} to append. |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
630 |
* @param len the number of {@code char}s to append. |
2 | 631 |
* @return a reference to this object. |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
632 |
* @throws IndexOutOfBoundsException |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
633 |
* if {@code offset < 0} or {@code len < 0} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
634 |
* or {@code offset+len > str.length} |
2 | 635 |
*/ |
636 |
public AbstractStringBuilder append(char str[], int offset, int len) { |
|
33663 | 637 |
int end = offset + len; |
638 |
checkRange(offset, end, str.length); |
|
639 |
ensureCapacityInternal(count + len); |
|
640 |
appendChars(str, offset, end); |
|
2 | 641 |
return this; |
642 |
} |
|
643 |
||
644 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
645 |
* Appends the string representation of the {@code boolean} |
2 | 646 |
* argument to the sequence. |
647 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
648 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
649 |
* to a string by the method {@link String#valueOf(boolean)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
650 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
651 |
* {@link #append(String) appended} to this character sequence. |
2 | 652 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
653 |
* @param b a {@code boolean}. |
2 | 654 |
* @return a reference to this object. |
655 |
*/ |
|
656 |
public AbstractStringBuilder append(boolean b) { |
|
33663 | 657 |
ensureCapacityInternal(count + (b ? 4 : 5)); |
658 |
int count = this.count; |
|
659 |
byte[] val = this.value; |
|
660 |
if (isLatin1()) { |
|
661 |
if (b) { |
|
662 |
val[count++] = 't'; |
|
663 |
val[count++] = 'r'; |
|
664 |
val[count++] = 'u'; |
|
665 |
val[count++] = 'e'; |
|
666 |
} else { |
|
667 |
val[count++] = 'f'; |
|
668 |
val[count++] = 'a'; |
|
669 |
val[count++] = 'l'; |
|
670 |
val[count++] = 's'; |
|
671 |
val[count++] = 'e'; |
|
672 |
} |
|
2 | 673 |
} else { |
33663 | 674 |
if (b) { |
675 |
checkOffset(count + 4, val.length >> 1); |
|
676 |
StringUTF16.putChar(val, count++, 't'); |
|
677 |
StringUTF16.putChar(val, count++, 'r'); |
|
678 |
StringUTF16.putChar(val, count++, 'u'); |
|
679 |
StringUTF16.putChar(val, count++, 'e'); |
|
680 |
} else { |
|
681 |
checkOffset(count + 5, val.length >> 1); |
|
682 |
StringUTF16.putChar(val, count++, 'f'); |
|
683 |
StringUTF16.putChar(val, count++, 'a'); |
|
684 |
StringUTF16.putChar(val, count++, 'l'); |
|
685 |
StringUTF16.putChar(val, count++, 's'); |
|
686 |
StringUTF16.putChar(val, count++, 'e'); |
|
687 |
} |
|
2 | 688 |
} |
33663 | 689 |
this.count = count; |
2 | 690 |
return this; |
691 |
} |
|
692 |
||
693 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
694 |
* Appends the string representation of the {@code char} |
2 | 695 |
* argument to this sequence. |
696 |
* <p> |
|
697 |
* The argument is appended to the contents of this sequence. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
698 |
* The length of this sequence increases by {@code 1}. |
2 | 699 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
700 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
701 |
* to a string by the method {@link String#valueOf(char)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
702 |
* and the character in that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
703 |
* {@link #append(String) appended} to this character sequence. |
2 | 704 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
705 |
* @param c a {@code char}. |
2 | 706 |
* @return a reference to this object. |
707 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
708 |
@Override |
2 | 709 |
public AbstractStringBuilder append(char c) { |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
710 |
ensureCapacityInternal(count + 1); |
33663 | 711 |
if (isLatin1() && StringLatin1.canEncode(c)) { |
712 |
value[count++] = (byte)c; |
|
713 |
} else { |
|
714 |
if (isLatin1()) { |
|
715 |
inflate(); |
|
716 |
} |
|
717 |
StringUTF16.putCharSB(value, count++, c); |
|
718 |
} |
|
2 | 719 |
return this; |
720 |
} |
|
721 |
||
722 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
723 |
* Appends the string representation of the {@code int} |
2 | 724 |
* argument to this sequence. |
725 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
726 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
727 |
* to a string by the method {@link String#valueOf(int)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
728 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
729 |
* {@link #append(String) appended} to this character sequence. |
2 | 730 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
731 |
* @param i an {@code int}. |
2 | 732 |
* @return a reference to this object. |
733 |
*/ |
|
734 |
public AbstractStringBuilder append(int i) { |
|
34331
7b1fea58eefe
8136500: Integer/Long getChars and stringSize should be more idiomatic
shade
parents:
33871
diff
changeset
|
735 |
int spaceNeeded = count + Integer.stringSize(i); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
736 |
ensureCapacityInternal(spaceNeeded); |
33663 | 737 |
if (isLatin1()) { |
738 |
Integer.getChars(i, spaceNeeded, value); |
|
739 |
} else { |
|
740 |
byte[] val = this.value; |
|
741 |
checkOffset(spaceNeeded, val.length >> 1); |
|
742 |
Integer.getCharsUTF16(i, spaceNeeded, val); |
|
743 |
} |
|
2 | 744 |
count = spaceNeeded; |
745 |
return this; |
|
746 |
} |
|
747 |
||
748 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
749 |
* Appends the string representation of the {@code long} |
2 | 750 |
* argument to this sequence. |
751 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
752 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
753 |
* to a string by the method {@link String#valueOf(long)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
754 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
755 |
* {@link #append(String) appended} to this character sequence. |
2 | 756 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
757 |
* @param l a {@code long}. |
2 | 758 |
* @return a reference to this object. |
759 |
*/ |
|
760 |
public AbstractStringBuilder append(long l) { |
|
34331
7b1fea58eefe
8136500: Integer/Long getChars and stringSize should be more idiomatic
shade
parents:
33871
diff
changeset
|
761 |
int spaceNeeded = count + Long.stringSize(l); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
762 |
ensureCapacityInternal(spaceNeeded); |
33663 | 763 |
if (isLatin1()) { |
764 |
Long.getChars(l, spaceNeeded, value); |
|
765 |
} else { |
|
766 |
byte[] val = this.value; |
|
767 |
checkOffset(spaceNeeded, val.length >> 1); |
|
768 |
Long.getCharsUTF16(l, spaceNeeded, val); |
|
769 |
} |
|
2 | 770 |
count = spaceNeeded; |
771 |
return this; |
|
772 |
} |
|
773 |
||
774 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
775 |
* Appends the string representation of the {@code float} |
2 | 776 |
* argument to this sequence. |
777 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
778 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
779 |
* to a string by the method {@link String#valueOf(float)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
780 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
781 |
* {@link #append(String) appended} to this character sequence. |
2 | 782 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
783 |
* @param f a {@code float}. |
2 | 784 |
* @return a reference to this object. |
785 |
*/ |
|
786 |
public AbstractStringBuilder append(float f) { |
|
18143
b6ef7bd945ce
7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents:
16742
diff
changeset
|
787 |
FloatingDecimal.appendTo(f,this); |
2 | 788 |
return this; |
789 |
} |
|
790 |
||
791 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
792 |
* Appends the string representation of the {@code double} |
2 | 793 |
* argument to this sequence. |
794 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
795 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
796 |
* to a string by the method {@link String#valueOf(double)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
797 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
798 |
* {@link #append(String) appended} to this character sequence. |
2 | 799 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
800 |
* @param d a {@code double}. |
2 | 801 |
* @return a reference to this object. |
802 |
*/ |
|
803 |
public AbstractStringBuilder append(double d) { |
|
18143
b6ef7bd945ce
7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents:
16742
diff
changeset
|
804 |
FloatingDecimal.appendTo(d,this); |
2 | 805 |
return this; |
806 |
} |
|
807 |
||
808 |
/** |
|
809 |
* Removes the characters in a substring of this sequence. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
810 |
* The substring begins at the specified {@code start} and extends to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
811 |
* the character at index {@code end - 1} or to the end of the |
2 | 812 |
* sequence if no such character exists. If |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
813 |
* {@code start} is equal to {@code end}, no changes are made. |
2 | 814 |
* |
815 |
* @param start The beginning index, inclusive. |
|
816 |
* @param end The ending index, exclusive. |
|
817 |
* @return This object. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
818 |
* @throws StringIndexOutOfBoundsException if {@code start} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
819 |
* is negative, greater than {@code length()}, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
820 |
* greater than {@code end}. |
2 | 821 |
*/ |
822 |
public AbstractStringBuilder delete(int start, int end) { |
|
33663 | 823 |
if (end > count) { |
2 | 824 |
end = count; |
33663 | 825 |
} |
826 |
checkRangeSIOOBE(start, end, count); |
|
2 | 827 |
int len = end - start; |
828 |
if (len > 0) { |
|
33663 | 829 |
shift(end, -len); |
2 | 830 |
count -= len; |
831 |
} |
|
832 |
return this; |
|
833 |
} |
|
834 |
||
835 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
836 |
* Appends the string representation of the {@code codePoint} |
2 | 837 |
* argument to this sequence. |
838 |
* |
|
839 |
* <p> The argument is appended to the contents of this sequence. |
|
840 |
* The length of this sequence increases by |
|
841 |
* {@link Character#charCount(int) Character.charCount(codePoint)}. |
|
842 |
* |
|
843 |
* <p> The overall effect is exactly as if the argument were |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
844 |
* converted to a {@code char} array by the method |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
845 |
* {@link Character#toChars(int)} and the character in that array |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
846 |
* were then {@link #append(char[]) appended} to this character |
2 | 847 |
* sequence. |
848 |
* |
|
849 |
* @param codePoint a Unicode code point |
|
850 |
* @return a reference to this object. |
|
851 |
* @exception IllegalArgumentException if the specified |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
852 |
* {@code codePoint} isn't a valid Unicode code point |
2 | 853 |
*/ |
854 |
public AbstractStringBuilder appendCodePoint(int codePoint) { |
|
5986
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
855 |
if (Character.isBmpCodePoint(codePoint)) { |
33663 | 856 |
return append((char)codePoint); |
2 | 857 |
} |
33663 | 858 |
return append(Character.toChars(codePoint)); |
2 | 859 |
} |
860 |
||
861 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
862 |
* Removes the {@code char} at the specified position in this |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
863 |
* sequence. This sequence is shortened by one {@code char}. |
2 | 864 |
* |
865 |
* <p>Note: If the character at the given index is a supplementary |
|
866 |
* character, this method does not remove the entire character. If |
|
867 |
* correct handling of supplementary characters is required, |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
868 |
* determine the number of {@code char}s to remove by calling |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
869 |
* {@code Character.charCount(thisSequence.codePointAt(index))}, |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
870 |
* where {@code thisSequence} is this sequence. |
2 | 871 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
872 |
* @param index Index of {@code char} to remove |
2 | 873 |
* @return This object. |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
874 |
* @throws StringIndexOutOfBoundsException if the {@code index} |
2 | 875 |
* is negative or greater than or equal to |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
876 |
* {@code length()}. |
2 | 877 |
*/ |
878 |
public AbstractStringBuilder deleteCharAt(int index) { |
|
33663 | 879 |
checkIndex(index, count); |
880 |
shift(index + 1, -1); |
|
2 | 881 |
count--; |
882 |
return this; |
|
883 |
} |
|
884 |
||
885 |
/** |
|
886 |
* Replaces the characters in a substring of this sequence |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
887 |
* with characters in the specified {@code String}. The substring |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
888 |
* begins at the specified {@code start} and extends to the character |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
889 |
* at index {@code end - 1} or to the end of the |
2 | 890 |
* sequence if no such character exists. First the |
891 |
* characters in the substring are removed and then the specified |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
892 |
* {@code String} is inserted at {@code start}. (This |
2 | 893 |
* sequence will be lengthened to accommodate the |
894 |
* specified String if necessary.) |
|
895 |
* |
|
896 |
* @param start The beginning index, inclusive. |
|
897 |
* @param end The ending index, exclusive. |
|
898 |
* @param str String that will replace previous contents. |
|
899 |
* @return This object. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
900 |
* @throws StringIndexOutOfBoundsException if {@code start} |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
901 |
* is negative, greater than {@code length()}, or |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
902 |
* greater than {@code end}. |
2 | 903 |
*/ |
904 |
public AbstractStringBuilder replace(int start, int end, String str) { |
|
33663 | 905 |
if (end > count) { |
2 | 906 |
end = count; |
33663 | 907 |
} |
908 |
checkRangeSIOOBE(start, end, count); |
|
2 | 909 |
int len = str.length(); |
910 |
int newCount = count + len - (end - start); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
911 |
ensureCapacityInternal(newCount); |
33663 | 912 |
shift(end, newCount - count); |
2 | 913 |
count = newCount; |
33663 | 914 |
putStringAt(start, str); |
2 | 915 |
return this; |
916 |
} |
|
917 |
||
918 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
919 |
* Returns a new {@code String} that contains a subsequence of |
2 | 920 |
* characters currently contained in this character sequence. The |
921 |
* substring begins at the specified index and extends to the end of |
|
922 |
* this sequence. |
|
923 |
* |
|
924 |
* @param start The beginning index, inclusive. |
|
925 |
* @return The new string. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
926 |
* @throws StringIndexOutOfBoundsException if {@code start} is |
2 | 927 |
* less than zero, or greater than the length of this object. |
928 |
*/ |
|
929 |
public String substring(int start) { |
|
930 |
return substring(start, count); |
|
931 |
} |
|
932 |
||
933 |
/** |
|
934 |
* Returns a new character sequence that is a subsequence of this sequence. |
|
935 |
* |
|
936 |
* <p> An invocation of this method of the form |
|
937 |
* |
|
21334 | 938 |
* <pre>{@code |
939 |
* sb.subSequence(begin, end)}</pre> |
|
2 | 940 |
* |
941 |
* behaves in exactly the same way as the invocation |
|
942 |
* |
|
21334 | 943 |
* <pre>{@code |
944 |
* sb.substring(begin, end)}</pre> |
|
2 | 945 |
* |
946 |
* This method is provided so that this class can |
|
21334 | 947 |
* implement the {@link CharSequence} interface. |
2 | 948 |
* |
949 |
* @param start the start index, inclusive. |
|
950 |
* @param end the end index, exclusive. |
|
951 |
* @return the specified subsequence. |
|
952 |
* |
|
953 |
* @throws IndexOutOfBoundsException |
|
14997 | 954 |
* if {@code start} or {@code end} are negative, |
955 |
* if {@code end} is greater than {@code length()}, |
|
956 |
* or if {@code start} is greater than {@code end} |
|
2 | 957 |
* @spec JSR-51 |
958 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
959 |
@Override |
2 | 960 |
public CharSequence subSequence(int start, int end) { |
961 |
return substring(start, end); |
|
962 |
} |
|
963 |
||
964 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
965 |
* Returns a new {@code String} that contains a subsequence of |
2 | 966 |
* characters currently contained in this sequence. The |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
967 |
* substring begins at the specified {@code start} and |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
968 |
* extends to the character at index {@code end - 1}. |
2 | 969 |
* |
970 |
* @param start The beginning index, inclusive. |
|
971 |
* @param end The ending index, exclusive. |
|
972 |
* @return The new string. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
973 |
* @throws StringIndexOutOfBoundsException if {@code start} |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
974 |
* or {@code end} are negative or greater than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
975 |
* {@code length()}, or {@code start} is |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
976 |
* greater than {@code end}. |
2 | 977 |
*/ |
978 |
public String substring(int start, int end) { |
|
33663 | 979 |
checkRangeSIOOBE(start, end, count); |
980 |
if (isLatin1()) { |
|
981 |
return StringLatin1.newString(value, start, end - start); |
|
982 |
} |
|
34517
c6e795a80c80
8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
33871
diff
changeset
|
983 |
return StringUTF16.newString(value, start, end - start); |
33663 | 984 |
} |
985 |
||
986 |
private void shift(int offset, int n) { |
|
987 |
System.arraycopy(value, offset << coder, |
|
988 |
value, (offset + n) << coder, (count - offset) << coder); |
|
2 | 989 |
} |
990 |
||
991 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
992 |
* Inserts the string representation of a subarray of the {@code str} |
2 | 993 |
* array argument into this sequence. The subarray begins at the |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
994 |
* specified {@code offset} and extends {@code len} {@code char}s. |
2 | 995 |
* The characters of the subarray are inserted into this sequence at |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
996 |
* the position indicated by {@code index}. The length of this |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
997 |
* sequence increases by {@code len} {@code char}s. |
2 | 998 |
* |
999 |
* @param index position at which to insert subarray. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1000 |
* @param str A {@code char} array. |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1001 |
* @param offset the index of the first {@code char} in subarray to |
2 | 1002 |
* be inserted. |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1003 |
* @param len the number of {@code char}s in the subarray to |
2 | 1004 |
* be inserted. |
1005 |
* @return This object |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1006 |
* @throws StringIndexOutOfBoundsException if {@code index} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1007 |
* is negative or greater than {@code length()}, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1008 |
* {@code offset} or {@code len} are negative, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1009 |
* {@code (offset+len)} is greater than |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1010 |
* {@code str.length}. |
2 | 1011 |
*/ |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1012 |
public AbstractStringBuilder insert(int index, char[] str, int offset, |
2 | 1013 |
int len) |
1014 |
{ |
|
33663 | 1015 |
checkOffset(index, count); |
1016 |
checkRangeSIOOBE(offset, offset + len, str.length); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1017 |
ensureCapacityInternal(count + len); |
33663 | 1018 |
shift(index, len); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1019 |
count += len; |
33663 | 1020 |
putCharsAt(index, str, offset, offset + len); |
2 | 1021 |
return this; |
1022 |
} |
|
1023 |
||
1024 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1025 |
* Inserts the string representation of the {@code Object} |
2 | 1026 |
* argument into this character sequence. |
1027 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1028 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1029 |
* converted to a string by the method {@link String#valueOf(Object)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1030 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1031 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1032 |
* sequence at the indicated offset. |
2 | 1033 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1034 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1035 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1036 |
* of this sequence. |
2 | 1037 |
* |
1038 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1039 |
* @param obj an {@code Object}. |
2 | 1040 |
* @return a reference to this object. |
1041 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1042 |
*/ |
|
1043 |
public AbstractStringBuilder insert(int offset, Object obj) { |
|
1044 |
return insert(offset, String.valueOf(obj)); |
|
1045 |
} |
|
1046 |
||
1047 |
/** |
|
1048 |
* Inserts the string into this character sequence. |
|
1049 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1050 |
* The characters of the {@code String} argument are inserted, in |
2 | 1051 |
* order, into this sequence at the indicated offset, moving up any |
1052 |
* characters originally above that position and increasing the length |
|
1053 |
* of this sequence by the length of the argument. If |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1054 |
* {@code str} is {@code null}, then the four characters |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1055 |
* {@code "null"} are inserted into this sequence. |
2 | 1056 |
* <p> |
1057 |
* The character at index <i>k</i> in the new character sequence is |
|
1058 |
* equal to: |
|
1059 |
* <ul> |
|
1060 |
* <li>the character at index <i>k</i> in the old character sequence, if |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1061 |
* <i>k</i> is less than {@code offset} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1062 |
* <li>the character at index <i>k</i>{@code -offset} in the |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1063 |
* argument {@code str}, if <i>k</i> is not less than |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1064 |
* {@code offset} but is less than {@code offset+str.length()} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1065 |
* <li>the character at index <i>k</i>{@code -str.length()} in the |
2 | 1066 |
* old character sequence, if <i>k</i> is not less than |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1067 |
* {@code offset+str.length()} |
2 | 1068 |
* </ul><p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1069 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1070 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1071 |
* of this sequence. |
2 | 1072 |
* |
1073 |
* @param offset the offset. |
|
1074 |
* @param str a string. |
|
1075 |
* @return a reference to this object. |
|
1076 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1077 |
*/ |
|
1078 |
public AbstractStringBuilder insert(int offset, String str) { |
|
33663 | 1079 |
checkOffset(offset, count); |
1080 |
if (str == null) { |
|
2 | 1081 |
str = "null"; |
33663 | 1082 |
} |
2 | 1083 |
int len = str.length(); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1084 |
ensureCapacityInternal(count + len); |
33663 | 1085 |
shift(offset, len); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1086 |
count += len; |
33663 | 1087 |
putStringAt(offset, str); |
2 | 1088 |
return this; |
1089 |
} |
|
1090 |
||
1091 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1092 |
* Inserts the string representation of the {@code char} array |
2 | 1093 |
* argument into this sequence. |
1094 |
* <p> |
|
1095 |
* The characters of the array argument are inserted into the |
|
1096 |
* contents of this sequence at the position indicated by |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1097 |
* {@code offset}. The length of this sequence increases by |
2 | 1098 |
* the length of the argument. |
1099 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1100 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1101 |
* converted to a string by the method {@link String#valueOf(char[])}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1102 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1103 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1104 |
* sequence at the indicated offset. |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1105 |
* <p> |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1106 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1107 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1108 |
* of this sequence. |
2 | 1109 |
* |
1110 |
* @param offset the offset. |
|
1111 |
* @param str a character array. |
|
1112 |
* @return a reference to this object. |
|
1113 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1114 |
*/ |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1115 |
public AbstractStringBuilder insert(int offset, char[] str) { |
33663 | 1116 |
checkOffset(offset, count); |
2 | 1117 |
int len = str.length; |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1118 |
ensureCapacityInternal(count + len); |
33663 | 1119 |
shift(offset, len); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1120 |
count += len; |
33663 | 1121 |
putCharsAt(offset, str, 0, len); |
2 | 1122 |
return this; |
1123 |
} |
|
1124 |
||
1125 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1126 |
* Inserts the specified {@code CharSequence} into this sequence. |
2 | 1127 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1128 |
* The characters of the {@code CharSequence} argument are inserted, |
2 | 1129 |
* in order, into this sequence at the indicated offset, moving up |
1130 |
* any characters originally above that position and increasing the length |
|
1131 |
* of this sequence by the length of the argument s. |
|
1132 |
* <p> |
|
1133 |
* The result of this method is exactly the same as if it were an |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1134 |
* invocation of this object's |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1135 |
* {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length()) |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1136 |
* method. |
2 | 1137 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1138 |
* <p>If {@code s} is {@code null}, then the four characters |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1139 |
* {@code "null"} are inserted into this sequence. |
2 | 1140 |
* |
1141 |
* @param dstOffset the offset. |
|
1142 |
* @param s the sequence to be inserted |
|
1143 |
* @return a reference to this object. |
|
1144 |
* @throws IndexOutOfBoundsException if the offset is invalid. |
|
1145 |
*/ |
|
1146 |
public AbstractStringBuilder insert(int dstOffset, CharSequence s) { |
|
33663 | 1147 |
if (s == null) { |
2 | 1148 |
s = "null"; |
33663 | 1149 |
} |
1150 |
if (s instanceof String) { |
|
2 | 1151 |
return this.insert(dstOffset, (String)s); |
33663 | 1152 |
} |
2 | 1153 |
return this.insert(dstOffset, s, 0, s.length()); |
1154 |
} |
|
1155 |
||
1156 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1157 |
* Inserts a subsequence of the specified {@code CharSequence} into |
2 | 1158 |
* this sequence. |
1159 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1160 |
* The subsequence of the argument {@code s} specified by |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1161 |
* {@code start} and {@code end} are inserted, |
2 | 1162 |
* in order, into this sequence at the specified destination offset, moving |
1163 |
* up any characters originally above that position. The length of this |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1164 |
* sequence is increased by {@code end - start}. |
2 | 1165 |
* <p> |
1166 |
* The character at index <i>k</i> in this sequence becomes equal to: |
|
1167 |
* <ul> |
|
1168 |
* <li>the character at index <i>k</i> in this sequence, if |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1169 |
* <i>k</i> is less than {@code dstOffset} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1170 |
* <li>the character at index <i>k</i>{@code +start-dstOffset} in |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1171 |
* the argument {@code s}, if <i>k</i> is greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1172 |
* {@code dstOffset} but is less than {@code dstOffset+end-start} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1173 |
* <li>the character at index <i>k</i>{@code -(end-start)} in this |
2 | 1174 |
* sequence, if <i>k</i> is greater than or equal to |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1175 |
* {@code dstOffset+end-start} |
2 | 1176 |
* </ul><p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1177 |
* The {@code dstOffset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1178 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1179 |
* of this sequence. |
2 | 1180 |
* <p>The start argument must be nonnegative, and not greater than |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1181 |
* {@code end}. |
2 | 1182 |
* <p>The end argument must be greater than or equal to |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1183 |
* {@code start}, and less than or equal to the length of s. |
2 | 1184 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1185 |
* <p>If {@code s} is {@code null}, then this method inserts |
2 | 1186 |
* characters as if the s parameter was a sequence containing the four |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1187 |
* characters {@code "null"}. |
2 | 1188 |
* |
1189 |
* @param dstOffset the offset in this sequence. |
|
1190 |
* @param s the sequence to be inserted. |
|
1191 |
* @param start the starting index of the subsequence to be inserted. |
|
1192 |
* @param end the end index of the subsequence to be inserted. |
|
1193 |
* @return a reference to this object. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1194 |
* @throws IndexOutOfBoundsException if {@code dstOffset} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1195 |
* is negative or greater than {@code this.length()}, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1196 |
* {@code start} or {@code end} are negative, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1197 |
* {@code start} is greater than {@code end} or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1198 |
* {@code end} is greater than {@code s.length()} |
2 | 1199 |
*/ |
33663 | 1200 |
public AbstractStringBuilder insert(int dstOffset, CharSequence s, |
1201 |
int start, int end) |
|
1202 |
{ |
|
1203 |
if (s == null) { |
|
2 | 1204 |
s = "null"; |
33663 | 1205 |
} |
1206 |
checkOffset(dstOffset, count); |
|
1207 |
checkRange(start, end, s.length()); |
|
2 | 1208 |
int len = end - start; |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1209 |
ensureCapacityInternal(count + len); |
33663 | 1210 |
shift(dstOffset, len); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1211 |
count += len; |
33663 | 1212 |
putCharsAt(dstOffset, s, start, end); |
2 | 1213 |
return this; |
1214 |
} |
|
1215 |
||
1216 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1217 |
* Inserts the string representation of the {@code boolean} |
2 | 1218 |
* argument into this sequence. |
1219 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1220 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1221 |
* converted to a string by the method {@link String#valueOf(boolean)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1222 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1223 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1224 |
* sequence at the indicated offset. |
2 | 1225 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1226 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1227 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1228 |
* of this sequence. |
2 | 1229 |
* |
1230 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1231 |
* @param b a {@code boolean}. |
2 | 1232 |
* @return a reference to this object. |
1233 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1234 |
*/ |
|
1235 |
public AbstractStringBuilder insert(int offset, boolean b) { |
|
1236 |
return insert(offset, String.valueOf(b)); |
|
1237 |
} |
|
1238 |
||
1239 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1240 |
* Inserts the string representation of the {@code char} |
2 | 1241 |
* argument into this sequence. |
1242 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1243 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1244 |
* converted to a string by the method {@link String#valueOf(char)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1245 |
* and the character in that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1246 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1247 |
* sequence at the indicated offset. |
2 | 1248 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1249 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1250 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1251 |
* of this sequence. |
2 | 1252 |
* |
1253 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1254 |
* @param c a {@code char}. |
2 | 1255 |
* @return a reference to this object. |
1256 |
* @throws IndexOutOfBoundsException if the offset is invalid. |
|
1257 |
*/ |
|
1258 |
public AbstractStringBuilder insert(int offset, char c) { |
|
33663 | 1259 |
checkOffset(offset, count); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1260 |
ensureCapacityInternal(count + 1); |
33663 | 1261 |
shift(offset, 1); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1262 |
count += 1; |
33663 | 1263 |
if (isLatin1() && StringLatin1.canEncode(c)) { |
1264 |
value[offset] = (byte)c; |
|
1265 |
} else { |
|
1266 |
if (isLatin1()) { |
|
1267 |
inflate(); |
|
1268 |
} |
|
1269 |
StringUTF16.putCharSB(value, offset, c); |
|
1270 |
} |
|
2 | 1271 |
return this; |
1272 |
} |
|
1273 |
||
1274 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1275 |
* Inserts the string representation of the second {@code int} |
2 | 1276 |
* argument into this sequence. |
1277 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1278 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1279 |
* converted to a string by the method {@link String#valueOf(int)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1280 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1281 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1282 |
* sequence at the indicated offset. |
2 | 1283 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1284 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1285 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1286 |
* of this sequence. |
2 | 1287 |
* |
1288 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1289 |
* @param i an {@code int}. |
2 | 1290 |
* @return a reference to this object. |
1291 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1292 |
*/ |
|
1293 |
public AbstractStringBuilder insert(int offset, int i) { |
|
1294 |
return insert(offset, String.valueOf(i)); |
|
1295 |
} |
|
1296 |
||
1297 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1298 |
* Inserts the string representation of the {@code long} |
2 | 1299 |
* argument into this sequence. |
1300 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1301 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1302 |
* converted to a string by the method {@link String#valueOf(long)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1303 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1304 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1305 |
* sequence at the indicated offset. |
2 | 1306 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1307 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1308 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1309 |
* of this sequence. |
2 | 1310 |
* |
1311 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1312 |
* @param l a {@code long}. |
2 | 1313 |
* @return a reference to this object. |
1314 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1315 |
*/ |
|
1316 |
public AbstractStringBuilder insert(int offset, long l) { |
|
1317 |
return insert(offset, String.valueOf(l)); |
|
1318 |
} |
|
1319 |
||
1320 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1321 |
* Inserts the string representation of the {@code float} |
2 | 1322 |
* argument into this sequence. |
1323 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1324 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1325 |
* converted to a string by the method {@link String#valueOf(float)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1326 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1327 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1328 |
* sequence at the indicated offset. |
2 | 1329 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1330 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1331 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1332 |
* of this sequence. |
2 | 1333 |
* |
1334 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1335 |
* @param f a {@code float}. |
2 | 1336 |
* @return a reference to this object. |
1337 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1338 |
*/ |
|
1339 |
public AbstractStringBuilder insert(int offset, float f) { |
|
1340 |
return insert(offset, String.valueOf(f)); |
|
1341 |
} |
|
1342 |
||
1343 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1344 |
* Inserts the string representation of the {@code double} |
2 | 1345 |
* argument into this sequence. |
1346 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1347 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1348 |
* converted to a string by the method {@link String#valueOf(double)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1349 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1350 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1351 |
* sequence at the indicated offset. |
2 | 1352 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1353 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1354 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1355 |
* of this sequence. |
2 | 1356 |
* |
1357 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1358 |
* @param d a {@code double}. |
2 | 1359 |
* @return a reference to this object. |
1360 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1361 |
*/ |
|
1362 |
public AbstractStringBuilder insert(int offset, double d) { |
|
1363 |
return insert(offset, String.valueOf(d)); |
|
1364 |
} |
|
1365 |
||
1366 |
/** |
|
1367 |
* Returns the index within this string of the first occurrence of the |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1368 |
* specified substring. |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1369 |
* |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1370 |
* <p>The returned index is the smallest value {@code k} for which: |
21334 | 1371 |
* <pre>{@code |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1372 |
* this.toString().startsWith(str, k) |
21334 | 1373 |
* }</pre> |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1374 |
* If no such value of {@code k} exists, then {@code -1} is returned. |
2 | 1375 |
* |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1376 |
* @param str the substring to search for. |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1377 |
* @return the index of the first occurrence of the specified substring, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1378 |
* or {@code -1} if there is no such occurrence. |
2 | 1379 |
*/ |
1380 |
public int indexOf(String str) { |
|
1381 |
return indexOf(str, 0); |
|
1382 |
} |
|
1383 |
||
1384 |
/** |
|
1385 |
* Returns the index within this string of the first occurrence of the |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1386 |
* specified substring, starting at the specified index. |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1387 |
* |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1388 |
* <p>The returned index is the smallest value {@code k} for which: |
21334 | 1389 |
* <pre>{@code |
19591
80e86f94c0e9
8016018: Typo in AbstractStringBuilder#indexOf and #lastIndexOf descriptions
igerasim
parents:
18143
diff
changeset
|
1390 |
* k >= Math.min(fromIndex, this.length()) && |
2 | 1391 |
* this.toString().startsWith(str, k) |
21334 | 1392 |
* }</pre> |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1393 |
* If no such value of {@code k} exists, then {@code -1} is returned. |
2 | 1394 |
* |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1395 |
* @param str the substring to search for. |
2 | 1396 |
* @param fromIndex the index from which to start the search. |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1397 |
* @return the index of the first occurrence of the specified substring, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1398 |
* starting at the specified index, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1399 |
* or {@code -1} if there is no such occurrence. |
2 | 1400 |
*/ |
1401 |
public int indexOf(String str, int fromIndex) { |
|
33663 | 1402 |
return String.indexOf(value, coder, count, str, fromIndex); |
2 | 1403 |
} |
1404 |
||
1405 |
/** |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1406 |
* Returns the index within this string of the last occurrence of the |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1407 |
* specified substring. The last occurrence of the empty string "" is |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1408 |
* considered to occur at the index value {@code this.length()}. |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1409 |
* |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1410 |
* <p>The returned index is the largest value {@code k} for which: |
21334 | 1411 |
* <pre>{@code |
2 | 1412 |
* this.toString().startsWith(str, k) |
21334 | 1413 |
* }</pre> |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1414 |
* If no such value of {@code k} exists, then {@code -1} is returned. |
2 | 1415 |
* |
1416 |
* @param str the substring to search for. |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1417 |
* @return the index of the last occurrence of the specified substring, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1418 |
* or {@code -1} if there is no such occurrence. |
2 | 1419 |
*/ |
1420 |
public int lastIndexOf(String str) { |
|
1421 |
return lastIndexOf(str, count); |
|
1422 |
} |
|
1423 |
||
1424 |
/** |
|
1425 |
* Returns the index within this string of the last occurrence of the |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1426 |
* specified substring, searching backward starting at the specified index. |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1427 |
* |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1428 |
* <p>The returned index is the largest value {@code k} for which: |
21334 | 1429 |
* <pre>{@code |
19591
80e86f94c0e9
8016018: Typo in AbstractStringBuilder#indexOf and #lastIndexOf descriptions
igerasim
parents:
18143
diff
changeset
|
1430 |
* k <= Math.min(fromIndex, this.length()) && |
2 | 1431 |
* this.toString().startsWith(str, k) |
21334 | 1432 |
* }</pre> |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1433 |
* If no such value of {@code k} exists, then {@code -1} is returned. |
2 | 1434 |
* |
1435 |
* @param str the substring to search for. |
|
1436 |
* @param fromIndex the index to start the search from. |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1437 |
* @return the index of the last occurrence of the specified substring, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1438 |
* searching backward from the specified index, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1439 |
* or {@code -1} if there is no such occurrence. |
2 | 1440 |
*/ |
1441 |
public int lastIndexOf(String str, int fromIndex) { |
|
33663 | 1442 |
return String.lastIndexOf(value, coder, count, str, fromIndex); |
2 | 1443 |
} |
1444 |
||
1445 |
/** |
|
1446 |
* Causes this character sequence to be replaced by the reverse of |
|
1447 |
* the sequence. If there are any surrogate pairs included in the |
|
1448 |
* sequence, these are treated as single characters for the |
|
1449 |
* reverse operation. Thus, the order of the high-low surrogates |
|
1450 |
* is never reversed. |
|
1451 |
* |
|
1452 |
* Let <i>n</i> be the character length of this character sequence |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1453 |
* (not the length in {@code char} values) just prior to |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1454 |
* execution of the {@code reverse} method. Then the |
2 | 1455 |
* character at index <i>k</i> in the new character sequence is |
1456 |
* equal to the character at index <i>n-k-1</i> in the old |
|
1457 |
* character sequence. |
|
1458 |
* |
|
1459 |
* <p>Note that the reverse operation may result in producing |
|
1460 |
* surrogate pairs that were unpaired low-surrogates and |
|
1461 |
* high-surrogates before the operation. For example, reversing |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1462 |
* "\u005CuDC00\u005CuD800" produces "\u005CuD800\u005CuDC00" which is |
2 | 1463 |
* a valid surrogate pair. |
1464 |
* |
|
1465 |
* @return a reference to this object. |
|
1466 |
*/ |
|
1467 |
public AbstractStringBuilder reverse() { |
|
33663 | 1468 |
byte[] val = this.value; |
1469 |
int count = this.count; |
|
1470 |
int coder = this.coder; |
|
2 | 1471 |
int n = count - 1; |
33663 | 1472 |
if (COMPACT_STRINGS && coder == LATIN1) { |
1473 |
for (int j = (n-1) >> 1; j >= 0; j--) { |
|
1474 |
int k = n - j; |
|
1475 |
byte cj = val[j]; |
|
1476 |
val[j] = val[k]; |
|
1477 |
val[k] = cj; |
|
2 | 1478 |
} |
33663 | 1479 |
} else { |
1480 |
checkOffset(count, val.length >> 1); |
|
1481 |
boolean hasSurrogates = false; |
|
1482 |
for (int j = (n-1) >> 1; j >= 0; j--) { |
|
1483 |
int k = n - j; |
|
1484 |
char cj = StringUTF16.getChar(val, j); |
|
1485 |
char ck = StringUTF16.getChar(val, k); |
|
1486 |
StringUTF16.putChar(val, j, ck); |
|
1487 |
StringUTF16.putChar(val, k, cj); |
|
1488 |
if (Character.isSurrogate(cj) || |
|
1489 |
Character.isSurrogate(ck)) { |
|
1490 |
hasSurrogates = true; |
|
1491 |
} |
|
1492 |
} |
|
1493 |
if (hasSurrogates) { |
|
1494 |
reverseAllValidSurrogatePairs(val, count); |
|
1495 |
} |
|
2 | 1496 |
} |
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1497 |
return this; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1498 |
} |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1499 |
|
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1500 |
/** Outlined helper method for reverse() */ |
33663 | 1501 |
private void reverseAllValidSurrogatePairs(byte[] val, int count) { |
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1502 |
for (int i = 0; i < count - 1; i++) { |
33663 | 1503 |
char c2 = StringUTF16.getChar(val, i); |
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1504 |
if (Character.isLowSurrogate(c2)) { |
33663 | 1505 |
char c1 = StringUTF16.getChar(val, i + 1); |
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1506 |
if (Character.isHighSurrogate(c1)) { |
33663 | 1507 |
StringUTF16.putChar(val, i++, c1); |
1508 |
StringUTF16.putChar(val, i, c2); |
|
2 | 1509 |
} |
1510 |
} |
|
1511 |
} |
|
1512 |
} |
|
1513 |
||
1514 |
/** |
|
1515 |
* Returns a string representing the data in this sequence. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1516 |
* A new {@code String} object is allocated and initialized to |
2 | 1517 |
* contain the character sequence currently represented by this |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1518 |
* object. This {@code String} is then returned. Subsequent |
2 | 1519 |
* changes to this sequence do not affect the contents of the |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1520 |
* {@code String}. |
2 | 1521 |
* |
1522 |
* @return a string representation of this sequence of characters. |
|
1523 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
1524 |
@Override |
2 | 1525 |
public abstract String toString(); |
1526 |
||
1527 |
/** |
|
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1528 |
* {@inheritDoc} |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
34781
diff
changeset
|
1529 |
* @since 9 |
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1530 |
*/ |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1531 |
@Override |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1532 |
public IntStream chars() { |
33663 | 1533 |
byte[] val = this.value; int count = this.count; byte coder = this.coder; |
1534 |
checkOffset(count, val.length >> coder); |
|
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1535 |
// Reuse String-based spliterator. This requires a supplier to |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1536 |
// capture the value and count when the terminal operation is executed |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1537 |
return StreamSupport.intStream( |
33663 | 1538 |
() -> coder == LATIN1 ? new StringLatin1.CharsSpliterator(val, 0, count, 0) |
1539 |
: new StringUTF16.CharsSpliterator(val, 0, count, 0), |
|
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1540 |
Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED, |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1541 |
false); |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1542 |
} |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1543 |
|
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1544 |
/** |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1545 |
* {@inheritDoc} |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
34781
diff
changeset
|
1546 |
* @since 9 |
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1547 |
*/ |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1548 |
@Override |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1549 |
public IntStream codePoints() { |
33663 | 1550 |
byte[] val = this.value; int count = this.count; byte coder = this.coder; |
1551 |
checkOffset(count, val.length >> coder); |
|
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1552 |
// Reuse String-based spliterator. This requires a supplier to |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1553 |
// capture the value and count when the terminal operation is executed |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1554 |
return StreamSupport.intStream( |
33663 | 1555 |
() -> coder == LATIN1 ? new StringLatin1.CharsSpliterator(val, 0, count, 0) |
1556 |
: new StringUTF16.CodePointsSpliterator(val, 0, count, 0), |
|
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1557 |
Spliterator.ORDERED, |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1558 |
false); |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1559 |
} |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1560 |
|
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1561 |
/** |
14997 | 1562 |
* Needed by {@code String} for the contentEquals method. |
2 | 1563 |
*/ |
33663 | 1564 |
final byte[] getValue() { |
2 | 1565 |
return value; |
1566 |
} |
|
1567 |
||
33663 | 1568 |
/* |
1569 |
* Invoker guarantees it is in UTF16 (inflate itself for asb), if two |
|
1570 |
* coders are different and the dstBegin has enough space |
|
1571 |
* |
|
1572 |
* @param dstBegin the char index, not offset of byte[] |
|
1573 |
* @param coder the coder of dst[] |
|
1574 |
*/ |
|
33871
73d87430102d
8143330: Two implementation methods of AbstractStringBuilder are mistakenly declared as "protected" in JDK9b93
sherman
parents:
33663
diff
changeset
|
1575 |
void getBytes(byte dst[], int dstBegin, byte coder) { |
33663 | 1576 |
if (this.coder == coder) { |
1577 |
System.arraycopy(value, 0, dst, dstBegin << coder, count << coder); |
|
1578 |
} else { // this.coder == LATIN && coder == UTF16 |
|
34517
c6e795a80c80
8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
33871
diff
changeset
|
1579 |
StringLatin1.inflate(value, 0, dst, dstBegin, count); |
33663 | 1580 |
} |
1581 |
} |
|
1582 |
||
1583 |
/* for readObject() */ |
|
33871
73d87430102d
8143330: Two implementation methods of AbstractStringBuilder are mistakenly declared as "protected" in JDK9b93
sherman
parents:
33663
diff
changeset
|
1584 |
void initBytes(char[] value, int off, int len) { |
33663 | 1585 |
if (String.COMPACT_STRINGS) { |
1586 |
this.value = StringUTF16.compress(value, off, len); |
|
1587 |
if (this.value != null) { |
|
1588 |
this.coder = LATIN1; |
|
1589 |
return; |
|
1590 |
} |
|
1591 |
} |
|
1592 |
this.coder = UTF16; |
|
1593 |
this.value = StringUTF16.toBytes(value, off, len); |
|
1594 |
} |
|
1595 |
||
1596 |
final byte getCoder() { |
|
1597 |
return COMPACT_STRINGS ? coder : UTF16; |
|
1598 |
} |
|
1599 |
||
1600 |
final boolean isLatin1() { |
|
1601 |
return COMPACT_STRINGS && coder == LATIN1; |
|
1602 |
} |
|
1603 |
||
1604 |
private final void putCharsAt(int index, char[] s, int off, int end) { |
|
1605 |
if (isLatin1()) { |
|
1606 |
byte[] val = this.value; |
|
1607 |
for (int i = off, j = index; i < end; i++) { |
|
1608 |
char c = s[i]; |
|
1609 |
if (StringLatin1.canEncode(c)) { |
|
1610 |
val[j++] = (byte)c; |
|
1611 |
} else { |
|
1612 |
inflate(); |
|
1613 |
StringUTF16.putCharsSB(this.value, j, s, i, end); |
|
1614 |
return; |
|
1615 |
} |
|
1616 |
} |
|
1617 |
} else { |
|
1618 |
StringUTF16.putCharsSB(this.value, index, s, off, end); |
|
1619 |
} |
|
1620 |
} |
|
1621 |
||
1622 |
private final void putCharsAt(int index, CharSequence s, int off, int end) { |
|
1623 |
if (isLatin1()) { |
|
1624 |
byte[] val = this.value; |
|
1625 |
for (int i = off, j = index; i < end; i++) { |
|
1626 |
char c = s.charAt(i); |
|
1627 |
if (StringLatin1.canEncode(c)) { |
|
1628 |
val[j++] = (byte)c; |
|
1629 |
} else { |
|
1630 |
inflate(); |
|
1631 |
StringUTF16.putCharsSB(this.value, j, s, i, end); |
|
1632 |
return; |
|
1633 |
} |
|
1634 |
} |
|
1635 |
} else { |
|
1636 |
StringUTF16.putCharsSB(this.value, index, s, off, end); |
|
1637 |
} |
|
1638 |
} |
|
1639 |
||
1640 |
private final void putStringAt(int index, String str) { |
|
1641 |
if (getCoder() != str.coder()) { |
|
1642 |
inflate(); |
|
1643 |
} |
|
34517
c6e795a80c80
8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
33871
diff
changeset
|
1644 |
str.getBytes(value, index, coder); |
33663 | 1645 |
} |
1646 |
||
1647 |
private final void appendChars(char[] s, int off, int end) { |
|
1648 |
if (isLatin1()) { |
|
1649 |
byte[] val = this.value; |
|
1650 |
for (int i = off, j = count; i < end; i++) { |
|
1651 |
char c = s[i]; |
|
1652 |
if (StringLatin1.canEncode(c)) { |
|
1653 |
val[j++] = (byte)c; |
|
1654 |
} else { |
|
1655 |
count = j; |
|
1656 |
inflate(); |
|
1657 |
StringUTF16.putCharsSB(this.value, j, s, i, end); |
|
1658 |
count += end - i; |
|
1659 |
return; |
|
1660 |
} |
|
1661 |
} |
|
1662 |
} else { |
|
1663 |
StringUTF16.putCharsSB(this.value, count, s, off, end); |
|
1664 |
} |
|
1665 |
count += end - off; |
|
1666 |
} |
|
1667 |
||
1668 |
private final void appendChars(CharSequence s, int off, int end) { |
|
1669 |
if (isLatin1()) { |
|
1670 |
byte[] val = this.value; |
|
1671 |
for (int i = off, j = count; i < end; i++) { |
|
1672 |
char c = s.charAt(i); |
|
1673 |
if (StringLatin1.canEncode(c)) { |
|
1674 |
val[j++] = (byte)c; |
|
1675 |
} else { |
|
1676 |
count = j; |
|
1677 |
inflate(); |
|
1678 |
StringUTF16.putCharsSB(this.value, j, s, i, end); |
|
1679 |
count += end - i; |
|
1680 |
return; |
|
1681 |
} |
|
1682 |
} |
|
1683 |
} else { |
|
1684 |
StringUTF16.putCharsSB(this.value, count, s, off, end); |
|
1685 |
} |
|
1686 |
count += end - off; |
|
1687 |
} |
|
1688 |
||
1689 |
/* IndexOutOfBoundsException, if out of bounds */ |
|
1690 |
private static void checkRange(int start, int end, int len) { |
|
1691 |
if (start < 0 || start > end || end > len) { |
|
1692 |
throw new IndexOutOfBoundsException( |
|
1693 |
"start " + start + ", end " + end + ", length " + len); |
|
1694 |
} |
|
1695 |
} |
|
1696 |
||
1697 |
/* StringIndexOutOfBoundsException, if out of bounds */ |
|
1698 |
private static void checkRangeSIOOBE(int start, int end, int len) { |
|
1699 |
if (start < 0 || start > end || end > len) { |
|
1700 |
throw new StringIndexOutOfBoundsException( |
|
1701 |
"start " + start + ", end " + end + ", length " + len); |
|
1702 |
} |
|
1703 |
} |
|
2 | 1704 |
} |