public interface Replaceable
| android.icu.text.Replaceable |
Replaceable是一个接口,表示一个字符串,它支持用一个新的字符串替换它自己的一个范围。 它由API使用,在保留元数据的同时更改一段文本。 元数据是char32At()返回的Unicode字符以外的数据。 元数据的一个例子是样式属性; 另一个是编辑历史记录,用作者和修订号标记每个字符。
Replaceable API的一个隐含方面是,在替换操作期间,新字符会采用旧字符的元数据。 例如,如果字符串“ 粗体字体”将范围(4,8)替换为“强”,则它变成“ 强体字体”。
Replaceable使用起始偏移量和极限偏移量指定范围。 由此指定的字符范围包括偏移量为start..limit-1的字符。 也就是说,起始偏移量是包含性的,并且限制偏移量是排他性的。
Replaceable还包括API在字符串中的字符的访问: length() , charAt() , char32At() ,和 extractBetween() 。
对于支持元数据的子类, replace()典型行为如下:
版权所有(c)IBM Corporation 1999.保留所有权利。
公共方法(Public methods) |
|
|---|---|
abstract int |
char32At(int offset) 将给定的16位偏移量的32位代码点返回到文本中。 |
abstract char |
charAt(int offset) 将给定偏移量的16位代码单元返回到文本中。 |
abstract void |
copy(int start, int limit, int dest) 复制此对象的子字符串,保留元数据。 |
abstract void |
getChars(int srcStart, int srcLimit, char[] dst, int dstStart) 将此对象的字符复制到目标字符数组中。 |
abstract boolean |
hasMetaData() R如果此对象包含元数据,则返回true。 |
abstract int |
length() 返回文本中的16位代码单元的数量。 |
abstract void |
replace(int start, int limit, char[] chars, int charsStart, int charsLen) 用给定的文本替换此对象的子字符串。 |
abstract void |
replace(int start, int limit, String text) 用给定的文本替换此对象的子字符串。 |
int char32At (int offset)
将给定的16位偏移量的32位代码点返回到文本中。 这假定文本以混合代理对的16位代码单元存储。 如果给出了代理对的前导或尾随代码单元的偏移量,则返回代理对的代码点。
大多数的子类可以返回 android.icu.text.UTF16.charAt(this, offset) 。
| 参数(Parameters) | |
|---|---|
offset |
int: an integer between 0 and length()-1 inclusive |
| 返回(Returns) | |
|---|---|
int |
32-bit code point of text at given offset |
char charAt (int offset)
将给定偏移量的16位代码单元返回到文本中。
| 参数(Parameters) | |
|---|---|
offset |
int: an integer between 0 and length()-1 inclusive |
| 返回(Returns) | |
|---|---|
char |
16-bit code unit of text at given offset |
void copy (int start,
int limit,
int dest)
复制此对象的子字符串,保留元数据。 此方法用于复制或重新排序子字符串。 目标索引不得与源范围重叠。 如果hasMetaData()返回false,则子类可能使用朴素的实现:
char[] text = new char[limit - start]; getChars(start, limit, text, 0); replace(dest, dest, text, 0, limit - start);
| 参数(Parameters) | |
|---|---|
start |
int: the beginning index, inclusive; 0 <= start <= limit. |
limit |
int: the ending index, exclusive; start <= limit <= length(). |
dest |
int: the destination index. The characters from start..limit-1 will be copied to dest. Implementations of this method may assume that dest <= start || dest >= limit. |
void getChars (int srcStart,
int srcLimit,
char[] dst,
int dstStart)
将此对象的字符复制到目标字符数组中。 要复制的第一个字符位于索引srcStart ; 要复制的最后一个字符位于索引srcLimit-1 (因此要复制的字符总数为srcLimit-srcStart )。 将字符复制到从索引dstStart开始并以索引dstStart结束的dst的子dstStart + (srcLimit-srcStart) - 1 。
| 参数(Parameters) | |
|---|---|
srcStart |
int: the beginning index to copy, inclusive; 0 <= start <= limit. |
srcLimit |
int: the ending index to copy, exclusive; start <= limit <= length(). |
dst |
char: the destination array. |
dstStart |
int: the start offset in the destination array. |
boolean hasMetaData ()
R如果此对象包含元数据,则返回true。 如果可替换对象具有元数据,则必须调用可替换API以保留元数据。 如果不支持,可调用可更换API可能会优化以提高性能。
| 返回(Returns) | |
|---|---|
boolean |
true if this object contains metadata |
int length ()
返回文本中的16位代码单元的数量。
| 返回(Returns) | |
|---|---|
int |
number of 16-bit code units in text |
void replace (int start,
int limit,
char[] chars,
int charsStart,
int charsLen)
用给定的文本替换此对象的子字符串。
子类必须确保如果start和limit之间的文本等于替换文本,则替换不起作用。 也就是说,任何元数据都应该不受影响。 此外,鼓励子类检查初始和尾部相同的字符,如果可能的话进行更小的替换。 这将尽可能地保留元数据。
| 参数(Parameters) | |
|---|---|
start |
int: the beginning index, inclusive; 0 <= start <= limit. |
limit |
int: the ending index, exclusive; start <= limit <= length(). |
chars |
char: the text to replace characters start to limit - 1 |
charsStart |
int: the beginning index into chars, inclusive; 0 <= start <= limit. |
charsLen |
int: the number of characters of chars. |
void replace (int start,
int limit,
String text)
用给定的文本替换此对象的子字符串。
子类必须确保如果start和limit之间的文本等于替换文本,则替换不起作用。 也就是说,任何元数据都应该不受影响。 此外,鼓励子类检查初始和尾部相同的字符,如果可能的话进行更小的替换。 这将尽可能地保留元数据。
| 参数(Parameters) | |
|---|---|
start |
int: the beginning index, inclusive; 0 <= start <= limit. |
limit |
int: the ending index, exclusive; start <= limit <= length(). |
text |
String: the text to replace characters start to limit - 1 |