/** Retrieves the character at the {@code index}. * * @param index the index of the character to retrieve. * @return the char value. * @throws IndexOutOfBoundsException if {@code index} is negative or greater than or equal to the current {@link #length()}. */ public char charAt (int index) { if (index < 0 || index >= length) { throw new StringIndexOutOfBoundsException(index); } return chars[index]; }
/** Sets the character at the {@code index}. * * @param index the zero-based index of the character to replace. * @param ch the character to set. * @throws IndexOutOfBoundsException if {@code index} is negative or greater than or equal to the current {@link #length()}. */ public void setCharAt (int index, char ch) { if (0 > index || index >= length) { throw new StringIndexOutOfBoundsException(index); } chars[index] = ch; }
/** Retrieves the character at the {@code index}. * * @param index the index of the character to retrieve. * @return the char value. * @throws IndexOutOfBoundsException if {@code index} is negative or greater than or equal to the current {@link #length()}. */ public char charAt (int index) { if (index < 0 || index >= length) { throw new StringIndexOutOfBoundsException(index); } return chars[index]; }
/** Sets the character at the {@code index}. * * @param index the zero-based index of the character to replace. * @param ch the character to set. * @throws IndexOutOfBoundsException if {@code index} is negative or greater than or equal to the current {@link #length()}. */ public void setCharAt (int index, char ch) { if (0 > index || index >= length) { throw new StringIndexOutOfBoundsException(index); } chars[index] = ch; }
/** * Validates parameters defining a single index in the builder. * * @param index the index, must be valid * @throws IndexOutOfBoundsException if the index is invalid */ protected void validateIndex(final int index) { if (index < 0 || index > size) { throw new StringIndexOutOfBoundsException(index); } }
public final String subString(int offset, int count) { if (count < 0) { throw new StringIndexOutOfBoundsException(count); } return new String(buf, offset, count); // return text.substring(offset, offset + count); }
public final char[] sub_chars(int offset, int count) { if (count < 0) { throw new StringIndexOutOfBoundsException(count); } if (offset == 0) { return buf; } char[] chars = new char[count]; System.arraycopy(buf, offset, chars, 0, count); return chars; }
final void deleteCharAt0 (int location) { if (0 > location || location >= length) { throw new StringIndexOutOfBoundsException(location); } int count = length - location - 1; if (count > 0) { System.arraycopy(chars, location + 1, chars, location, count); } length--; }
final void deleteCharAt0 (int location) { if (0 > location || location >= length) { throw new StringIndexOutOfBoundsException(location); } int count = length - location - 1; if (count > 0) { System.arraycopy(chars, location + 1, chars, location, count); } length--; }
/** Retrieves the Unicode code point value at the {@code index}. * * @param index the index to the {@code char} code unit. * @return the Unicode code point value. * @throws IndexOutOfBoundsException if {@code index} is negative or greater than or equal to {@link #length()}. * @see Character * @see Character#codePointAt(char[], int, int) * @since 1.5 */ public int codePointAt (int index) { if (index < 0 || index >= length) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointAt(chars, index, length); }
/** Retrieves the Unicode code point value at the {@code index}. * * @param index the index to the {@code char} code unit. * @return the Unicode code point value. * @throws IndexOutOfBoundsException if {@code index} is negative or greater than or equal to {@link #length()}. * @see Character * @see Character#codePointAt(char[], int, int) * @since 1.5 */ public int codePointAt (int index) { if (index < 0 || index >= length) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointAt(chars, index, length); }
/** Copies the requested sequence of characters to the {@code char[]} passed starting at {@code destStart}. * * @param start the inclusive start index of the characters to copy. * @param end the exclusive end index of the characters to copy. * @param dest the {@code char[]} to copy the characters to. * @param destStart the inclusive start index of {@code dest} to begin copying to. * @throws IndexOutOfBoundsException if the {@code start} is negative, the {@code destStart} is negative, the {@code start} is * greater than {@code end}, the {@code end} is greater than the current {@link #length()} or * {@code destStart + end - begin} is greater than {@code dest.length}. */ public void getChars (int start, int end, char[] dest, int destStart) { if (start > length || end > length || start > end) { throw new StringIndexOutOfBoundsException(); } System.arraycopy(chars, start, dest, destStart, end - start); }
/** Copies the requested sequence of characters to the {@code char[]} passed starting at {@code destStart}. * * @param start the inclusive start index of the characters to copy. * @param end the exclusive end index of the characters to copy. * @param dest the {@code char[]} to copy the characters to. * @param destStart the inclusive start index of {@code dest} to begin copying to. * @throws IndexOutOfBoundsException if the {@code start} is negative, the {@code destStart} is negative, the {@code start} is * greater than {@code end}, the {@code end} is greater than the current {@link #length()} or * {@code destStart + end - begin} is greater than {@code dest.length}. */ public void getChars (int start, int end, char[] dest, int destStart) { if (start > length || end > length || start > end) { throw new StringIndexOutOfBoundsException(); } System.arraycopy(chars, start, dest, destStart, end - start); }
final void insert0 (int index, char[] value, int start, int length) { if (0 <= index && index <= length) { // start + length could overflow, start/length maybe MaxInt if (start >= 0 && 0 <= length && length <= value.length - start) { if (length != 0) { move(length, index); System.arraycopy(value, start, chars, index, length); this.length += length; } return; } throw new StringIndexOutOfBoundsException("offset " + start + ", length " + length + ", char[].length " + value.length); } throw new StringIndexOutOfBoundsException(index); }
final void insert0 (int index, char[] value) { if (0 > index || index > length) { throw new StringIndexOutOfBoundsException(index); } if (value.length != 0) { move(value.length, index); System.arraycopy(value, 0, value, index, value.length); length += value.length; } }
final void insert0 (int index, char[] value) { if (0 > index || index > length) { throw new StringIndexOutOfBoundsException(index); } if (value.length != 0) { move(value.length, index); System.arraycopy(value, 0, value, index, value.length); length += value.length; } }
/** Retrieves the Unicode code point value that precedes the {@code index}. * * @param index the index to the {@code char} code unit within this object. * @return the Unicode code point value. * @throws IndexOutOfBoundsException if {@code index} is less than 1 or greater than {@link #length()}. * @see Character * @see Character#codePointBefore(char[], int, int) * @since 1.5 */ public int codePointBefore (int index) { if (index < 1 || index > length) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointBefore(chars, index); }
/** Retrieves the Unicode code point value that precedes the {@code index}. * * @param index the index to the {@code char} code unit within this object. * @return the Unicode code point value. * @throws IndexOutOfBoundsException if {@code index} is less than 1 or greater than {@link #length()}. * @see Character * @see Character#codePointBefore(char[], int, int) * @since 1.5 */ public int codePointBefore (int index) { if (index < 1 || index > length) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointBefore(chars, index); }
final void insert0 (int index, String string) { if (0 <= index && index <= length) { if (string == null) { string = "null"; } int min = string.length(); if (min != 0) { move(min, index); string.getChars(0, min, chars, index); length += min; } } else { throw new StringIndexOutOfBoundsException(index); } }
final void insert0 (int index, String string) { if (0 <= index && index <= length) { if (string == null) { string = "null"; } int min = string.length(); if (min != 0) { move(min, index); string.getChars(0, min, chars, index); length += min; } } else { throw new StringIndexOutOfBoundsException(index); } }