/** * Returns the code point preceding the given index of the * {@code char} array. If the {@code char} value at * {@code (index - 1)} in the {@code char} array is in * the low-surrogate range, {@code (index - 2)} is not * negative, and the {@code char} value at {@code (index - 2)} * in the {@code char} array is in the * high-surrogate range, then the supplementary code point * corresponding to this surrogate pair is returned. Otherwise, * the {@code char} value at {@code (index - 1)} is * returned. * * @param a the {@code char} array * @param index the index following the code point that should be returned * @return the Unicode code point value before the given index. * @exception NullPointerException if {@code a} is null. * @exception IndexOutOfBoundsException if the {@code index} * argument is less than 1 or greater than the length of the * {@code char} array * @since 1.5 */ public static int codePointBefore(char[] a, int index) { return codePointBeforeImpl(a, index, 0); }
/** * Returns the code point preceding the given index of the * {@code char} array. If the {@code char} value at * {@code (index - 1)} in the {@code char} array is in * the low-surrogate range, {@code (index - 2)} is not * negative, and the {@code char} value at {@code (index - 2)} * in the {@code char} array is in the * high-surrogate range, then the supplementary code point * corresponding to this surrogate pair is returned. Otherwise, * the {@code char} value at {@code (index - 1)} is * returned. * * @param a the {@code char} array * @param index the index following the code point that should be returned * @return the Unicode code point value before the given index. * @exception NullPointerException if {@code a} is null. * @exception IndexOutOfBoundsException if the {@code index} * argument is less than 1 or greater than the length of the * {@code char} array * @since 1.5 */ public static int codePointBefore(char[] a, int index) { return codePointBeforeImpl(a, index, 0); }
throw new IndexOutOfBoundsException(); return codePointBeforeImpl(a, index, start);
throw new IndexOutOfBoundsException(); return codePointBeforeImpl(a, index, start);
/** * Returns the character (Unicode code point) before the specified * index. The index refers to <code>char</code> values * (Unicode code units) and ranges from <code>1</code> to {@link * CharSequence#length() length}. * * <p> If the <code>char</code> value at <code>(index - 1)</code> * is in the low-surrogate range, <code>(index - 2)</code> is not * negative, and the <code>char</code> value at <code>(index - * 2)</code> is in the high-surrogate range, then the * supplementary code point value of the surrogate pair is * returned. If the <code>char</code> value at <code>index - * 1</code> is an unpaired low-surrogate or a high-surrogate, the * surrogate value is returned. * * @param index the index following the code point that should be returned * @return the Unicode code point value before the given index. * @exception IndexOutOfBoundsException if the <code>index</code> * argument is less than 1 or greater than the length * of this string. * @since 1.5 */ public int codePointBefore(int index) { int i = index - 1; if ((i < 0) || (i >= length())) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointBeforeImpl(toCharArray(), offset() + index, offset()); }
/** * Returns the character (Unicode code point) before the specified * index. The index refers to <code>char</code> values * (Unicode code units) and ranges from <code>1</code> to {@link * CharSequence#length() length}. * * <p> If the <code>char</code> value at <code>(index - 1)</code> * is in the low-surrogate range, <code>(index - 2)</code> is not * negative, and the <code>char</code> value at <code>(index - * 2)</code> is in the high-surrogate range, then the * supplementary code point value of the surrogate pair is * returned. If the <code>char</code> value at <code>index - * 1</code> is an unpaired low-surrogate or a high-surrogate, the * surrogate value is returned. * * @param index the index following the code point that should be returned * @return the Unicode code point value before the given index. * @exception IndexOutOfBoundsException if the <code>index</code> * argument is less than 1 or greater than the length * of this string. * @since 1.5 */ public int codePointBefore(int index) { int i = index - 1; if ((i < 0) || (i >= length())) { throw new StringIndexOutOfBoundsException(index); } return Character.codePointBeforeImpl(toCharArray(), offset() + index, offset()); }
//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); }