/** * Removes the codepoint at the specified position in this target (shortening target by 1 * character if the codepoint is a non-supplementary, 2 otherwise). * * @param target String buffer to remove codepoint from * @param offset16 Offset which the codepoint will be removed * @return a reference to target * @exception IndexOutOfBoundsException Thrown if offset16 is invalid. * @stable ICU 2.1 */ public static StringBuffer delete(StringBuffer target, int offset16) { int count = 1; switch (bounds(target, offset16)) { case LEAD_SURROGATE_BOUNDARY: count++; break; case TRAIL_SURROGATE_BOUNDARY: count++; offset16--; break; } target.delete(offset16, offset16 + count); return target; }
/** * Removes the codepoint at the specified position in this target (shortening target by 1 * character if the codepoint is a non-supplementary, 2 otherwise). * * @param target String buffer to remove codepoint from * @param limit End index of the char array, limit <= target.length * @param offset16 Offset which the codepoint will be removed * @return a new limit size * @exception IndexOutOfBoundsException Thrown if offset16 is invalid. * @stable ICU 2.1 */ public static int delete(char target[], int limit, int offset16) { int count = 1; switch (bounds(target, 0, limit, offset16)) { case LEAD_SURROGATE_BOUNDARY: count++; break; case TRAIL_SURROGATE_BOUNDARY: count++; offset16--; break; } System.arraycopy(target, offset16 + count, target, offset16, limit - (offset16 + count)); target[limit - count] = 0; return limit - count; }
/** * Convenience method corresponding to StringBuffer.valueOf(codepoint at offset16). Returns a * one or two char string containing the UTF-32 value in UTF16 format. If offset16 indexes a * surrogate character, the whole supplementary codepoint will be returned. If a validity check * is required, use {@link com.ibm.icu.lang.UCharacter#isLegal(int)} on * the codepoint at offset16 before calling. The result returned will be a newly created String * obtained by calling source.substring(..) with the appropriate indexes. * * @param source The input string buffer. * @param offset16 The UTF16 index to the codepoint in source * @return string value of char32 in UTF16 format * @stable ICU 2.1 */ public static String valueOf(StringBuffer source, int offset16) { switch (bounds(source, offset16)) { case LEAD_SURROGATE_BOUNDARY: return source.substring(offset16, offset16 + 2); case TRAIL_SURROGATE_BOUNDARY: return source.substring(offset16 - 1, offset16 + 1); default: return source.substring(offset16, offset16 + 1); } }
/** * Convenience method corresponding to String.valueOf(codepoint at offset16). Returns a one or * two char string containing the UTF-32 value in UTF16 format. If offset16 indexes a surrogate * character, the whole supplementary codepoint will be returned. If a validity check is * required, use {@link com.ibm.icu.lang.UCharacter#isLegal(int)} on the * codepoint at offset16 before calling. The result returned will be a newly created String * obtained by calling source.substring(..) with the appropriate indexes. * * @param source The input string. * @param offset16 The UTF16 index to the codepoint in source * @return string value of char32 in UTF16 format * @stable ICU 2.1 */ public static String valueOf(String source, int offset16) { switch (bounds(source, offset16)) { case LEAD_SURROGATE_BOUNDARY: return source.substring(offset16, offset16 + 2); case TRAIL_SURROGATE_BOUNDARY: return source.substring(offset16 - 1, offset16 + 1); default: return source.substring(offset16, offset16 + 1); } }
/** * Convenience method. Returns a one or two char string containing the UTF-32 value in UTF16 * format. If offset16 indexes a surrogate character, the whole supplementary codepoint will be * returned, except when either the leading or trailing surrogate character lies out of the * specified subarray. In the latter case, only the surrogate character within bounds will be * returned. If a validity check is required, use * {@link com.ibm.icu.lang.UCharacter#isLegal(int)} on the codepoint at * offset16 before calling. The result returned will be a newly created String containing the * relevant characters. * * @param source The input char array. * @param start Start index of the subarray * @param limit End index of the subarray * @param offset16 The UTF16 index to the codepoint in source relative to start * @return string value of char32 in UTF16 format * @stable ICU 2.1 */ public static String valueOf(char source[], int start, int limit, int offset16) { switch (bounds(source, start, limit, offset16)) { case LEAD_SURROGATE_BOUNDARY: return new String(source, start + offset16, 2); case TRAIL_SURROGATE_BOUNDARY: return new String(source, start + offset16 - 1, 2); } return new String(source, start + offset16, 1); }
/** * Inserts char32 codepoint into target at the argument offset16. If the offset16 is in the * middle of a supplementary codepoint, char32 will be inserted after the supplementary * codepoint. The length of target increases by one if codepoint is non-supplementary, 2 * otherwise. * <p> * The overall effect is exactly as if the argument were converted to a string by the method * valueOf(char) and the characters in that string were then inserted into target at the * position indicated by offset16. * </p> * <p> * The offset argument must be greater than or equal to 0, and less than or equal to the length * of source. * * @param target String buffer to insert to * @param offset16 Offset which char32 will be inserted in * @param char32 Codepoint to be inserted * @return a reference to target * @exception IndexOutOfBoundsException Thrown if offset16 is invalid. * @stable ICU 2.1 */ public static StringBuffer insert(StringBuffer target, int offset16, int char32) { String str = valueOf(char32); if (offset16 != target.length() && bounds(target, offset16) == TRAIL_SURROGATE_BOUNDARY) { offset16++; } target.insert(offset16, str); return target; }
if (offset16 != limit && bounds(target, 0, limit, offset16) == TRAIL_SURROGATE_BOUNDARY) { offset16++;