1/* GENERATED SOURCE. DO NOT MODIFY. */ 2// © 2016 and later: Unicode, Inc. and others. 3// License & terms of use: http://www.unicode.org/copyright.html#License 4/* 5 ******************************************************************************* 6 * Copyright (C) 1996-2016, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 */ 10package android.icu.text; 11 12/** 13 * <code>Replaceable</code> is an interface representing a 14 * string of characters that supports the replacement of a range of 15 * itself with a new string of characters. It is used by APIs that 16 * change a piece of text while retaining metadata. Metadata is data 17 * other than the Unicode characters returned by char32At(). One 18 * example of metadata is style attributes; another is an edit 19 * history, marking each character with an author and revision number. 20 * 21 * <p>An implicit aspect of the <code>Replaceable</code> API is that 22 * during a replace operation, new characters take on the metadata of 23 * the old characters. For example, if the string "the <b>bold</b> 24 * font" has range (4, 8) replaced with "strong", then it becomes "the 25 * <b>strong</b> font". 26 * 27 * <p><code>Replaceable</code> specifies ranges using a start 28 * offset and a limit offset. The range of characters thus specified 29 * includes the characters at offset start..limit-1. That is, the 30 * start offset is inclusive, and the limit offset is exclusive. 31 * 32 * <p><code>Replaceable</code> also includes API to access characters 33 * in the string: <code>length()</code>, <code>charAt()</code>, 34 * <code>char32At()</code>, and <code>extractBetween()</code>. 35 * 36 * <p>For a subclass to support metadata, typical behavior of 37 * <code>replace()</code> is the following: 38 * <ul> 39 * <li>Set the metadata of the new text to the metadata of the first 40 * character replaced</li> 41 * <li>If no characters are replaced, use the metadata of the 42 * previous character</li> 43 * <li>If there is no previous character (i.e. start == 0), use the 44 * following character</li> 45 * <li>If there is no following character (i.e. the replaceable was 46 * empty), use default metadata<br> 47 * <li>If the code point U+FFFF is seen, it should be interpreted as 48 * a special marker having no metadata<li> 49 * </li> 50 * </ul> 51 * If this is not the behavior, the subclass should document any differences. 52 * 53 * @author Alan Liu 54 */ 55public interface Replaceable { 56 /** 57 * Returns the number of 16-bit code units in the text. 58 * @return number of 16-bit code units in text 59 */ 60 int length(); 61 62 /** 63 * Returns the 16-bit code unit at the given offset into the text. 64 * @param offset an integer between 0 and <code>length()</code>-1 65 * inclusive 66 * @return 16-bit code unit of text at given offset 67 */ 68 char charAt(int offset); 69 70 /** 71 * Returns the 32-bit code point at the given 16-bit offset into 72 * the text. This assumes the text is stored as 16-bit code units 73 * with surrogate pairs intermixed. If the offset of a leading or 74 * trailing code unit of a surrogate pair is given, return the 75 * code point of the surrogate pair. 76 * 77 * <p>Most subclasses can return 78 * <code>android.icu.text.UTF16.charAt(this, offset)</code>. 79 * @param offset an integer between 0 and <code>length()</code>-1 80 * inclusive 81 * @return 32-bit code point of text at given offset 82 */ 83 int char32At(int offset); 84 85 /** 86 * Copies characters from this object into the destination 87 * character array. The first character to be copied is at index 88 * <code>srcStart</code>; the last character to be copied is at 89 * index <code>srcLimit-1</code> (thus the total number of 90 * characters to be copied is <code>srcLimit-srcStart</code>). The 91 * characters are copied into the subarray of <code>dst</code> 92 * starting at index <code>dstStart</code> and ending at index 93 * <code>dstStart + (srcLimit-srcStart) - 1</code>. 94 * 95 * @param srcStart the beginning index to copy, inclusive; <code>0 96 * <= start <= limit</code>. 97 * @param srcLimit the ending index to copy, exclusive; 98 * <code>start <= limit <= length()</code>. 99 * @param dst the destination array. 100 * @param dstStart the start offset in the destination array. 101 */ 102 void getChars(int srcStart, int srcLimit, char dst[], int dstStart); 103 104 /** 105 * Replaces a substring of this object with the given text. 106 * 107 * <p>Subclasses must ensure that if the text between start and 108 * limit is equal to the replacement text, that replace has no 109 * effect. That is, any metadata 110 * should be unaffected. In addition, subclasses are encouraged to 111 * check for initial and trailing identical characters, and make a 112 * smaller replacement if possible. This will preserve as much 113 * metadata as possible. 114 * @param start the beginning index, inclusive; <code>0 <= start 115 * <= limit</code>. 116 * @param limit the ending index, exclusive; <code>start <= limit 117 * <= length()</code>. 118 * @param text the text to replace characters <code>start</code> 119 * to <code>limit - 1</code> 120 */ 121 void replace(int start, int limit, String text); 122 123 /** 124 * Replaces a substring of this object with the given text. 125 * 126 * <p>Subclasses must ensure that if the text between start and 127 * limit is equal to the replacement text, that replace has no 128 * effect. That is, any metadata 129 * should be unaffected. In addition, subclasses are encouraged to 130 * check for initial and trailing identical characters, and make a 131 * smaller replacement if possible. This will preserve as much 132 * metadata as possible. 133 * @param start the beginning index, inclusive; <code>0 <= start 134 * <= limit</code>. 135 * @param limit the ending index, exclusive; <code>start <= limit 136 * <= length()</code>. 137 * @param chars the text to replace characters <code>start</code> 138 * to <code>limit - 1</code> 139 * @param charsStart the beginning index into <code>chars</code>, 140 * inclusive; <code>0 <= start <= limit</code>. 141 * @param charsLen the number of characters of <code>chars</code>. 142 */ 143 void replace(int start, int limit, char[] chars, 144 int charsStart, int charsLen); 145 // Note: We use length rather than limit to conform to StringBuffer 146 // and System.arraycopy. 147 148 /** 149 * Copies a substring of this object, retaining metadata. 150 * This method is used to duplicate or reorder substrings. 151 * The destination index must not overlap the source range. 152 * If <code>hasMetaData()</code> returns false, subclasses 153 * may use the naive implementation: 154 * 155 * <pre> char[] text = new char[limit - start]; 156 * getChars(start, limit, text, 0); 157 * replace(dest, dest, text, 0, limit - start);</pre> 158 * 159 * @param start the beginning index, inclusive; <code>0 <= start <= 160 * limit</code>. 161 * @param limit the ending index, exclusive; <code>start <= limit <= 162 * length()</code>. 163 * @param dest the destination index. The characters from 164 * <code>start..limit-1</code> will be copied to <code>dest</code>. 165 * Implementations of this method may assume that <code>dest <= start || 166 * dest >= limit</code>. 167 */ 168 void copy(int start, int limit, int dest); 169 170 /**R 171 * Returns true if this object contains metadata. If a 172 * Replaceable object has metadata, calls to the Replaceable API 173 * must be made so as to preserve metadata. If it does not, calls 174 * to the Replaceable API may be optimized to improve performance. 175 * @return true if this object contains metadata 176 */ 177 boolean hasMetaData(); 178} 179