/** * Returns the code point at the given index of the * {@code char} array. If the {@code char} value at * the given index in the {@code char} array is in the * high-surrogate range, the following index is less than the * length of the {@code char} array, and the * {@code char} value at the following index is in the * low-surrogate range, then the supplementary code point * corresponding to this surrogate pair is returned. Otherwise, * the {@code char} value at the given index is returned. * * @param a the {@code char} array * @param index the index to the {@code char} values (Unicode * code units) in the {@code char} array to be converted * @return the Unicode code point at the given index * @exception NullPointerException if {@code a} is null. * @exception IndexOutOfBoundsException if the value * {@code index} is negative or not less than * the length of the {@code char} array. * @since 1.5 */ public static int codePointAt(char[] a, int index) { return codePointAtImpl(a, index, a.length); }
/** * Returns the code point at the given index of the * {@code char} array. If the {@code char} value at * the given index in the {@code char} array is in the * high-surrogate range, the following index is less than the * length of the {@code char} array, and the * {@code char} value at the following index is in the * low-surrogate range, then the supplementary code point * corresponding to this surrogate pair is returned. Otherwise, * the {@code char} value at the given index is returned. * * @param a the {@code char} array * @param index the index to the {@code char} values (Unicode * code units) in the {@code char} array to be converted * @return the Unicode code point at the given index * @exception NullPointerException if {@code a} is null. * @exception IndexOutOfBoundsException if the value * {@code index} is negative or not less than * the length of the {@code char} array. * @since 1.5 */ public static int codePointAt(char[] a, int index) { return codePointAtImpl(a, index, a.length); }
throw new IndexOutOfBoundsException(); return codePointAtImpl(a, index, limit);
throw new IndexOutOfBoundsException(); return codePointAtImpl(a, index, limit);
/** * Returns the character (Unicode code point) at the specified * index. The index refers to <code>char</code> values * (Unicode code units) and ranges from <code>0</code> to * {@link #length()}<code> - 1</code>. * * <p> If the <code>char</code> value specified at the given index * is in the high-surrogate range, the following index is less * than the length of this <code>String</code>, and the * <code>char</code> value at the following index is in the * low-surrogate range, then the supplementary code point * corresponding to this surrogate pair is returned. Otherwise, * the <code>char</code> value at the given index is returned. * * @param index the index to the <code>char</code> values * @return the code point value of the character at the * <code>index</code> * @exception IndexOutOfBoundsException if the <code>index</code> * argument is negative or not less than the length of this * string. * @since 1.5 */ public int codePointAt(int index) { if ((index < 0) || (index >= length())) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointAtImpl(toCharArray(), offset() + index, offset() + length()); }
/** * Returns the character (Unicode code point) at the specified * index. The index refers to <code>char</code> values * (Unicode code units) and ranges from <code>0</code> to * {@link #length()}<code> - 1</code>. * * <p> If the <code>char</code> value specified at the given index * is in the high-surrogate range, the following index is less * than the length of this <code>String</code>, and the * <code>char</code> value at the following index is in the * low-surrogate range, then the supplementary code point * corresponding to this surrogate pair is returned. Otherwise, * the <code>char</code> value at the given index is returned. * * @param index the index to the <code>char</code> values * @return the code point value of the character at the * <code>index</code> * @exception IndexOutOfBoundsException if the <code>index</code> * argument is negative or not less than the length of this * string. * @since 1.5 */ public int codePointAt(int index) { if ((index < 0) || (index >= length())) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointAtImpl(toCharArray(), offset() + index, offset() + length()); }
//Java 8 java.lang.String source code public int codePointAt(int index) { if ((index < 0) || (index >= value.length)) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointAtImpl(value, index, value.length); } //... public int codePointBefore(int index) { int i = index - 1; if ((i < 0) || (i >= value.length)) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointBeforeImpl(value, index, 0); }