< prev index next >

src/java.base/share/classes/java/lang/String.java

Print this page

        

*** 248,258 **** * the character array does not affect the newly created string. * * @param value * The initial value of the string */ ! public String(char value[]) { this(value, 0, value.length, null); } /** * Allocates a new {@code String} that contains characters from a subarray --- 248,258 ---- * the character array does not affect the newly created string. * * @param value * The initial value of the string */ ! public String(char[] value) { this(value, 0, value.length, null); } /** * Allocates a new {@code String} that contains characters from a subarray
*** 273,283 **** * * @throws IndexOutOfBoundsException * If {@code offset} is negative, {@code count} is negative, or * {@code offset} is greater than {@code value.length - count} */ ! public String(char value[], int offset, int count) { this(value, offset, count, rangeCheck(value, offset, count)); } private static Void rangeCheck(char[] value, int offset, int count) { checkBoundsOffCount(offset, count, value.length); --- 273,283 ---- * * @throws IndexOutOfBoundsException * If {@code offset} is negative, {@code count} is negative, or * {@code offset} is greater than {@code value.length - count} */ ! public String(char[] value, int offset, int count) { this(value, offset, count, rangeCheck(value, offset, count)); } private static Void rangeCheck(char[] value, int offset, int count) { checkBoundsOffCount(offset, count, value.length);
*** 370,380 **** * @see #String(byte[], java.lang.String) * @see #String(byte[], java.nio.charset.Charset) * @see #String(byte[]) */ @Deprecated(since="1.1") ! public String(byte ascii[], int hibyte, int offset, int count) { checkBoundsOffCount(offset, count, ascii.length); if (count == 0) { this.value = "".value; this.coder = "".coder; return; --- 370,380 ---- * @see #String(byte[], java.lang.String) * @see #String(byte[], java.nio.charset.Charset) * @see #String(byte[]) */ @Deprecated(since="1.1") ! public String(byte[] ascii, int hibyte, int offset, int count) { checkBoundsOffCount(offset, count, ascii.length); if (count == 0) { this.value = "".value; this.coder = "".coder; return;
*** 422,432 **** * @see #String(byte[], java.lang.String) * @see #String(byte[], java.nio.charset.Charset) * @see #String(byte[]) */ @Deprecated(since="1.1") ! public String(byte ascii[], int hibyte) { this(ascii, hibyte, 0, ascii.length); } /** * Constructs a new {@code String} by decoding the specified subarray of --- 422,432 ---- * @see #String(byte[], java.lang.String) * @see #String(byte[], java.nio.charset.Charset) * @see #String(byte[]) */ @Deprecated(since="1.1") ! public String(byte[] ascii, int hibyte) { this(ascii, hibyte, 0, ascii.length); } /** * Constructs a new {@code String} by decoding the specified subarray of
*** 459,469 **** * If {@code offset} is negative, {@code length} is negative, or * {@code offset} is greater than {@code bytes.length - length} * * @since 1.1 */ ! public String(byte bytes[], int offset, int length, String charsetName) throws UnsupportedEncodingException { if (charsetName == null) throw new NullPointerException("charsetName"); checkBoundsOffCount(offset, length, bytes.length); StringCoding.Result ret = --- 459,469 ---- * If {@code offset} is negative, {@code length} is negative, or * {@code offset} is greater than {@code bytes.length - length} * * @since 1.1 */ ! public String(byte[] bytes, int offset, int length, String charsetName) throws UnsupportedEncodingException { if (charsetName == null) throw new NullPointerException("charsetName"); checkBoundsOffCount(offset, length, bytes.length); StringCoding.Result ret =
*** 500,510 **** * If {@code offset} is negative, {@code length} is negative, or * {@code offset} is greater than {@code bytes.length - length} * * @since 1.6 */ ! public String(byte bytes[], int offset, int length, Charset charset) { if (charset == null) throw new NullPointerException("charset"); checkBoundsOffCount(offset, length, bytes.length); StringCoding.Result ret = StringCoding.decode(charset, bytes, offset, length); --- 500,510 ---- * If {@code offset} is negative, {@code length} is negative, or * {@code offset} is greater than {@code bytes.length - length} * * @since 1.6 */ ! public String(byte[] bytes, int offset, int length, Charset charset) { if (charset == null) throw new NullPointerException("charset"); checkBoundsOffCount(offset, length, bytes.length); StringCoding.Result ret = StringCoding.decode(charset, bytes, offset, length);
*** 533,543 **** * @throws UnsupportedEncodingException * If the named charset is not supported * * @since 1.1 */ ! public String(byte bytes[], String charsetName) throws UnsupportedEncodingException { this(bytes, 0, bytes.length, charsetName); } /** --- 533,543 ---- * @throws UnsupportedEncodingException * If the named charset is not supported * * @since 1.1 */ ! public String(byte[] bytes, String charsetName) throws UnsupportedEncodingException { this(bytes, 0, bytes.length, charsetName); } /**
*** 558,568 **** * The {@linkplain java.nio.charset.Charset charset} to be used to * decode the {@code bytes} * * @since 1.6 */ ! public String(byte bytes[], Charset charset) { this(bytes, 0, bytes.length, charset); } /** * Constructs a new {@code String} by decoding the specified subarray of --- 558,568 ---- * The {@linkplain java.nio.charset.Charset charset} to be used to * decode the {@code bytes} * * @since 1.6 */ ! public String(byte[] bytes, Charset charset) { this(bytes, 0, bytes.length, charset); } /** * Constructs a new {@code String} by decoding the specified subarray of
*** 588,598 **** * If {@code offset} is negative, {@code length} is negative, or * {@code offset} is greater than {@code bytes.length - length} * * @since 1.1 */ ! public String(byte bytes[], int offset, int length) { checkBoundsOffCount(offset, length, bytes.length); StringCoding.Result ret = StringCoding.decode(bytes, offset, length); this.value = ret.value; this.coder = ret.coder; } --- 588,598 ---- * If {@code offset} is negative, {@code length} is negative, or * {@code offset} is greater than {@code bytes.length - length} * * @since 1.1 */ ! public String(byte[] bytes, int offset, int length) { checkBoundsOffCount(offset, length, bytes.length); StringCoding.Result ret = StringCoding.decode(bytes, offset, length); this.value = ret.value; this.coder = ret.coder; }
*** 851,861 **** * string * <li>{@code dstBegin} is negative * <li>{@code dstBegin+(srcEnd-srcBegin)} is larger than * {@code dst.length}</ul> */ ! public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) { checkBoundsBeginEnd(srcBegin, srcEnd, length()); checkBoundsOffCount(dstBegin, srcEnd - srcBegin, dst.length); if (isLatin1()) { StringLatin1.getChars(value, srcBegin, srcEnd, dst, dstBegin); } else { --- 851,861 ---- * string * <li>{@code dstBegin} is negative * <li>{@code dstBegin+(srcEnd-srcBegin)} is larger than * {@code dst.length}</ul> */ ! public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) { checkBoundsBeginEnd(srcBegin, srcEnd, length()); checkBoundsOffCount(dstBegin, srcEnd - srcBegin, dst.length); if (isLatin1()) { StringLatin1.getChars(value, srcBegin, srcEnd, dst, dstBegin); } else {
*** 905,915 **** * <li> {@code dstBegin+(srcEnd-srcBegin)} is larger than {@code * dst.length} * </ul> */ @Deprecated(since="1.1") ! public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) { checkBoundsBeginEnd(srcBegin, srcEnd, length()); Objects.requireNonNull(dst); checkBoundsOffCount(dstBegin, srcEnd - srcBegin, dst.length); if (isLatin1()) { StringLatin1.getBytes(value, srcBegin, srcEnd, dst, dstBegin); --- 905,915 ---- * <li> {@code dstBegin+(srcEnd-srcBegin)} is larger than {@code * dst.length} * </ul> */ @Deprecated(since="1.1") ! public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) { checkBoundsBeginEnd(srcBegin, srcEnd, length()); Objects.requireNonNull(dst); checkBoundsOffCount(dstBegin, srcEnd - srcBegin, dst.length); if (isLatin1()) { StringLatin1.getBytes(value, srcBegin, srcEnd, dst, dstBegin);
*** 1041,1052 **** private boolean nonSyncContentEquals(AbstractStringBuilder sb) { int len = length(); if (len != sb.length()) { return false; } ! byte v1[] = value; ! byte v2[] = sb.getValue(); if (coder() == sb.getCoder()) { int n = v1.length; for (int i = 0; i < n; i++) { if (v1[i] != v2[i]) { return false; --- 1041,1052 ---- private boolean nonSyncContentEquals(AbstractStringBuilder sb) { int len = length(); if (len != sb.length()) { return false; } ! byte[] v1 = value; ! byte[] v2 = sb.getValue(); if (coder() == sb.getCoder()) { int n = v1.length; for (int i = 0; i < n; i++) { if (v1[i] != v2[i]) { return false;
*** 1193,1204 **** * is lexicographically less than the string argument; and a * value greater than {@code 0} if this string is * lexicographically greater than the string argument. */ public int compareTo(String anotherString) { ! byte v1[] = value; ! byte v2[] = anotherString.value; if (coder() == anotherString.coder()) { return isLatin1() ? StringLatin1.compareTo(v1, v2) : StringUTF16.compareTo(v1, v2); } return isLatin1() ? StringLatin1.compareToUTF16(v1, v2) --- 1193,1204 ---- * is lexicographically less than the string argument; and a * value greater than {@code 0} if this string is * lexicographically greater than the string argument. */ public int compareTo(String anotherString) { ! byte[] v1 = value; ! byte[] v2 = anotherString.value; if (coder() == anotherString.coder()) { return isLatin1() ? StringLatin1.compareTo(v1, v2) : StringUTF16.compareTo(v1, v2); } return isLatin1() ? StringLatin1.compareToUTF16(v1, v2)
*** 1222,1233 **** implements Comparator<String>, java.io.Serializable { // use serialVersionUID from JDK 1.2.2 for interoperability private static final long serialVersionUID = 8575799808933029326L; public int compare(String s1, String s2) { ! byte v1[] = s1.value; ! byte v2[] = s2.value; if (s1.coder() == s2.coder()) { return s1.isLatin1() ? StringLatin1.compareToCI(v1, v2) : StringUTF16.compareToCI(v1, v2); } return s1.isLatin1() ? StringLatin1.compareToCI_UTF16(v1, v2) --- 1222,1233 ---- implements Comparator<String>, java.io.Serializable { // use serialVersionUID from JDK 1.2.2 for interoperability private static final long serialVersionUID = 8575799808933029326L; public int compare(String s1, String s2) { ! byte[] v1 = s1.value; ! byte[] v2 = s2.value; if (s1.coder() == s2.coder()) { return s1.isLatin1() ? StringLatin1.compareToCI(v1, v2) : StringUTF16.compareToCI(v1, v2); } return s1.isLatin1() ? StringLatin1.compareToCI_UTF16(v1, v2)
*** 1295,1306 **** * @return {@code true} if the specified subregion of this string * exactly matches the specified subregion of the string argument; * {@code false} otherwise. */ public boolean regionMatches(int toffset, String other, int ooffset, int len) { ! byte tv[] = value; ! byte ov[] = other.value; // Note: toffset, ooffset, or len might be near -1>>>1. if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) || (ooffset > (long)other.length() - len)) { return false; --- 1295,1306 ---- * @return {@code true} if the specified subregion of this string * exactly matches the specified subregion of the string argument; * {@code false} otherwise. */ public boolean regionMatches(int toffset, String other, int ooffset, int len) { ! byte[] tv = value; ! byte[] ov = other.value; // Note: toffset, ooffset, or len might be near -1>>>1. if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) || (ooffset > (long)other.length() - len)) { return false;
*** 1395,1406 **** if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) || (ooffset > (long)other.length() - len)) { return false; } ! byte tv[] = value; ! byte ov[] = other.value; if (coder() == other.coder()) { return isLatin1() ? StringLatin1.regionMatchesCI(tv, toffset, ov, ooffset, len) : StringUTF16.regionMatchesCI(tv, toffset, ov, ooffset, len); } --- 1395,1406 ---- if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) || (ooffset > (long)other.length() - len)) { return false; } ! byte[] tv = value; ! byte[] ov = other.value; if (coder() == other.coder()) { return isLatin1() ? StringLatin1.regionMatchesCI(tv, toffset, ov, ooffset, len) : StringUTF16.regionMatchesCI(tv, toffset, ov, ooffset, len); }
*** 1429,1440 **** public boolean startsWith(String prefix, int toffset) { // Note: toffset might be near -1>>>1. if (toffset < 0 || toffset > length() - prefix.length()) { return false; } ! byte ta[] = value; ! byte pa[] = prefix.value; int po = 0; int pc = pa.length; if (coder() == prefix.coder()) { int to = isLatin1() ? toffset : toffset << 1; while (po < pc) { --- 1429,1440 ---- public boolean startsWith(String prefix, int toffset) { // Note: toffset might be near -1>>>1. if (toffset < 0 || toffset > length() - prefix.length()) { return false; } ! byte[] ta = value; ! byte[] pa = prefix.value; int po = 0; int pc = pa.length; if (coder() == prefix.coder()) { int to = isLatin1() ? toffset : toffset << 1; while (po < pc) {
*** 3132,3142 **** * * @param data the character array. * @return a {@code String} that contains the characters of the * character array. */ ! public static String valueOf(char data[]) { return new String(data); } /** * Returns the string representation of a specific subarray of the --- 3132,3142 ---- * * @param data the character array. * @return a {@code String} that contains the characters of the * character array. */ ! public static String valueOf(char[] data) { return new String(data); } /** * Returns the string representation of a specific subarray of the
*** 3156,3166 **** * @exception IndexOutOfBoundsException if {@code offset} is * negative, or {@code count} is negative, or * {@code offset+count} is larger than * {@code data.length}. */ ! public static String valueOf(char data[], int offset, int count) { return new String(data, offset, count); } /** * Equivalent to {@link #valueOf(char[], int, int)}. --- 3156,3166 ---- * @exception IndexOutOfBoundsException if {@code offset} is * negative, or {@code count} is negative, or * {@code offset+count} is larger than * {@code data.length}. */ ! public static String valueOf(char[] data, int offset, int count) { return new String(data, offset, count); } /** * Equivalent to {@link #valueOf(char[], int, int)}.
*** 3173,3194 **** * @exception IndexOutOfBoundsException if {@code offset} is * negative, or {@code count} is negative, or * {@code offset+count} is larger than * {@code data.length}. */ ! public static String copyValueOf(char data[], int offset, int count) { return new String(data, offset, count); } /** * Equivalent to {@link #valueOf(char[])}. * * @param data the character array. * @return a {@code String} that contains the characters of the * character array. */ ! public static String copyValueOf(char data[]) { return new String(data); } /** * Returns the string representation of the {@code boolean} argument. --- 3173,3194 ---- * @exception IndexOutOfBoundsException if {@code offset} is * negative, or {@code count} is negative, or * {@code offset+count} is larger than * {@code data.length}. */ ! public static String copyValueOf(char[] data, int offset, int count) { return new String(data, offset, count); } /** * Equivalent to {@link #valueOf(char[])}. * * @param data the character array. * @return a {@code String} that contains the characters of the * character array. */ ! public static String copyValueOf(char[] data) { return new String(data); } /** * Returns the string representation of the {@code boolean} argument.
*** 3358,3368 **** * coders are different, and dst is big enough (range check) * * @param dstBegin the char index, not offset of byte[] * @param coder the coder of dst[] */ ! void getBytes(byte dst[], int dstBegin, byte coder) { if (coder() == coder) { System.arraycopy(value, 0, dst, dstBegin << coder, value.length); } else { // this.coder == LATIN && coder == UTF16 StringLatin1.inflate(value, 0, dst, dstBegin, value.length); } --- 3358,3368 ---- * coders are different, and dst is big enough (range check) * * @param dstBegin the char index, not offset of byte[] * @param coder the coder of dst[] */ ! void getBytes(byte[] dst, int dstBegin, byte coder) { if (coder() == coder) { System.arraycopy(value, 0, dst, dstBegin << coder, value.length); } else { // this.coder == LATIN && coder == UTF16 StringLatin1.inflate(value, 0, dst, dstBegin, value.length); }
< prev index next >