Most visited

Recently visited

Added in API level 24

UnicodeSetSpanner

public class UnicodeSetSpanner
extends Object

java.lang.Object
   ↳ android.icu.text.UnicodeSetSpanner


一个辅助类,用于根据UnicodeSet匹配计算,替换和修剪CharSequences。 如果源UnicodeSet被冻结,则实例是不可变的(并且因此是线程安全的)。

注意:计数,删除和替换取决于UnicodeSet.SpanCondition与其反转。 也就是说,代码跨越,然后跨越反向,然后跨越,等等。 相反,使用以下映射:

These are actually not complete inverses. However, the alternating works because there are no gaps. For example, with [a{ab}{bc}], you get the following behavior when scanning forward:
SIMPLE xxx[ab]cyyy
CONTAINED xxx[abc]yyy
NOT_CONTAINED [xxx]ab[cyyy]

所以这里是当你交替时发生的事情:

start |xxxabcyyy
NOT_CONTAINED xxx|abcyyy
CONTAINED xxxabc|yyy
NOT_CONTAINED xxxabcyyy|

整个字符串被遍历。

Summary

Nested classes

枚举 UnicodeSetSpanner.CountMethod

replaceFrom和countIn选项用于控制如何处理每个匹配的跨度。

枚举 UnicodeSetSpanner.TrimOption

trim()方法的选项

Public constructors

UnicodeSetSpanner(UnicodeSet source)

从UnicodeSet创建一个扳手。

Public methods

int countIn(CharSequence sequence)

返回在字符序列中找到的匹配字符的数量,通过使用SpanCondition.SIMPLE的CountMethod.MIN_ELEMENTS进行计数。

int countIn(CharSequence sequence, UnicodeSetSpanner.CountMethod countMethod, UnicodeSet.SpanCondition spanCondition)

返回在字符序列中找到的匹配字符数。

int countIn(CharSequence sequence, UnicodeSetSpanner.CountMethod countMethod)

使用SpanCondition.SIMPLE返回在字符序列中找到的匹配字符数。

String deleteFrom(CharSequence sequence, UnicodeSet.SpanCondition spanCondition)

根据spanCondition,依次删除所有匹配的跨度。

String deleteFrom(CharSequence sequence)

按顺序删除所有匹配的跨度,使用SpanCondition.SIMPLE代码交替跨越; 有关边界条件的说明,请参阅UnicodeSetSpanner的班级文档。

boolean equals(Object other)

指示其他某个对象是否“等于”这一个。

UnicodeSet getUnicodeSet()

返回用于处理的UnicodeSet。

int hashCode()

返回对象的哈希码值。

String replaceFrom(CharSequence sequence, CharSequence replacement, UnicodeSetSpanner.CountMethod countMethod, UnicodeSet.SpanCondition spanCondition)

根据countMethod和spanCondition按替换顺序替换所有匹配的跨度。

String replaceFrom(CharSequence sequence, CharSequence replacement)

用替换项替换所有匹配的跨度,使用SpanCondition.SIMPLE通过CountMethod.MIN_ELEMENTS进行计数。

String replaceFrom(CharSequence sequence, CharSequence replacement, UnicodeSetSpanner.CountMethod countMethod)

根据CountMethod,使用SpanCondition.SIMPLE按替换顺序替换所有匹配的跨度。

CharSequence trim(CharSequence sequence, UnicodeSetSpanner.TrimOption trimOption, UnicodeSet.SpanCondition spanCondition)

返回一个修剪过的序列(使用CharSequence.subsequence()),它忽略了字符串开始或结尾的匹配元素,具体取决于trimOption和spanCondition。

CharSequence trim(CharSequence sequence, UnicodeSetSpanner.TrimOption trimOption)

返回一个修剪过的序列(使用CharSequence.subsequence()),它使用trimOption和SpanCondition.SIMPLE省略了字符串开头或结尾的匹配元素。

CharSequence trim(CharSequence sequence)

使用TrimOption.BOTH和SpanCondition.SIMPLE返回一个修剪过的序列(使用CharSequence.subsequence()),它省略了字符串开始和结尾的匹配元素。

Inherited methods

From class java.lang.Object

Public constructors

UnicodeSetSpanner

Added in API level 24
UnicodeSetSpanner (UnicodeSet source)

从UnicodeSet创建一个扳手。 为了速度和安全性,UnicodeSet应该被冻结。 但是,该类可以与非冻结版一起使用,以避免冻结成本。

Parameters
source UnicodeSet: the original UnicodeSet

Public methods

countIn

Added in API level 24
int countIn (CharSequence sequence)

返回在字符序列中找到的匹配字符的数量,通过使用SpanCondition.SIMPLE的CountMethod.MIN_ELEMENTS进行计数。 代码交替跨越; 有关边界条件的说明,请参阅UnicodeSetSpanner的班级文档。

Parameters
sequence CharSequence: the sequence to count characters in
Returns
int the count. Zero if there are none.

countIn

Added in API level 24
int countIn (CharSequence sequence, 
                UnicodeSetSpanner.CountMethod countMethod, 
                UnicodeSet.SpanCondition spanCondition)

返回在字符序列中找到的匹配字符数。 代码交替跨越; 有关边界条件的说明,请参阅UnicodeSetSpanner的班级文档。

Parameters
sequence CharSequence: the sequence to count characters in
countMethod UnicodeSetSpanner.CountMethod: whether to treat an entire span as a match, or individual elements as matches
spanCondition UnicodeSet.SpanCondition: the spanCondition to use. SIMPLE or CONTAINED means only count the elements in the span; NOT_CONTAINED is the reverse.
WARNING: when a UnicodeSet contains strings, there may be unexpected behavior in edge cases.
Returns
int the count. Zero if there are none.

countIn

Added in API level 24
int countIn (CharSequence sequence, 
                UnicodeSetSpanner.CountMethod countMethod)

使用SpanCondition.SIMPLE返回在字符序列中找到的匹配字符数。 代码交替跨越; 有关边界条件的说明,请参阅UnicodeSetSpanner的班级文档。

Parameters
sequence CharSequence: the sequence to count characters in
countMethod UnicodeSetSpanner.CountMethod: whether to treat an entire span as a match, or individual elements as matches
Returns
int the count. Zero if there are none.

deleteFrom

Added in API level 24
String deleteFrom (CharSequence sequence, 
                UnicodeSet.SpanCondition spanCondition)

根据spanCondition,依次删除所有匹配的跨度。 代码交替跨越; 有关边界条件的说明,请参阅UnicodeSetSpanner的班级文档。

Parameters
sequence CharSequence: charsequence to replace matching spans in.
spanCondition UnicodeSet.SpanCondition: specify whether to modify the matching spans (CONTAINED or SIMPLE) or the non-matching (NOT_CONTAINED)
Returns
String modified string.

deleteFrom

Added in API level 24
String deleteFrom (CharSequence sequence)

按顺序删除所有匹配的跨度,使用SpanCondition.SIMPLE代码交替跨越; 有关边界条件的说明,请参阅UnicodeSetSpanner的班级文档。

Parameters
sequence CharSequence: charsequence to replace matching spans in.
Returns
String modified string.

equals

Added in API level 24
boolean equals (Object other)

指示其他某个对象是否“等于”这一个。

equals方法在非空对象引用上实现等价关系:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

equals类的方法Object实现了对象上最可能的等价关系; 也就是说,对于任何非空参考值xy ,此方法返回true当且仅当xy引用同一对象( x == y具有值true )。

请注意,通常需要覆盖 hashCode方法(每当此方法被覆盖时),以便维护 hashCode方法的一般合同,该方法声明等同对象必须具有相同的散列代码。

Parameters
other Object: the reference object with which to compare.
Returns
boolean true if this object is the same as the obj argument; false otherwise.

getUnicodeSet

Added in API level 24
UnicodeSet getUnicodeSet ()

返回用于处理的UnicodeSet。 如果原始文件被冻结,它就会被冻结。

Returns
UnicodeSet the construction set.

hashCode

Added in API level 24
int hashCode ()

返回对象的哈希码值。 此方法支持散列表的好处,例如HashMap提供的HashMap

hashCode的总合同是:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

尽可能合理实用,由类Object定义的hashCode方法确实为不同的对象返回不同的整数。 (这通常通过将对象的内部地址转换为整数来实现,但Java TM编程语言不需要此实现技术。)

Returns
int a hash code value for this object.

replaceFrom

Added in API level 24
String replaceFrom (CharSequence sequence, 
                CharSequence replacement, 
                UnicodeSetSpanner.CountMethod countMethod, 
                UnicodeSet.SpanCondition spanCondition)

根据countMethod和spanCondition按替换顺序替换所有匹配的跨度。 代码交替跨越; 有关边界条件的说明,请参阅UnicodeSetSpanner的班级文档。

Parameters
sequence CharSequence: charsequence to replace matching spans in.
replacement CharSequence: replacement sequence. To delete, use ""
countMethod UnicodeSetSpanner.CountMethod: whether to treat an entire span as a match, or individual elements as matches
spanCondition UnicodeSet.SpanCondition: specify whether to modify the matching spans (CONTAINED or SIMPLE) or the non-matching (NOT_CONTAINED)
Returns
String modified string.

replaceFrom

Added in API level 24
String replaceFrom (CharSequence sequence, 
                CharSequence replacement)

用替换项替换所有匹配的跨度,使用SpanCondition.SIMPLE通过CountMethod.MIN_ELEMENTS进行计数。 代码交替跨越; 有关边界条件的说明,请参阅UnicodeSetSpanner的班级文档。

Parameters
sequence CharSequence: charsequence to replace matching spans in.
replacement CharSequence: replacement sequence. To delete, use ""
Returns
String modified string.

replaceFrom

Added in API level 24
String replaceFrom (CharSequence sequence, 
                CharSequence replacement, 
                UnicodeSetSpanner.CountMethod countMethod)

根据CountMethod,使用SpanCondition.SIMPLE按替换顺序替换所有匹配的跨度。 代码交替跨越; 有关边界条件的说明,请参阅UnicodeSetSpanner的班级文档。

Parameters
sequence CharSequence: charsequence to replace matching spans in.
replacement CharSequence: replacement sequence. To delete, use ""
countMethod UnicodeSetSpanner.CountMethod: whether to treat an entire span as a match, or individual elements as matches
Returns
String modified string.

trim

Added in API level 24
CharSequence trim (CharSequence sequence, 
                UnicodeSetSpanner.TrimOption trimOption, 
                UnicodeSet.SpanCondition spanCondition)

返回一个修剪过的序列(使用CharSequence.subsequence()),它忽略了字符串开始或结尾的匹配元素,具体取决于trimOption和spanCondition。 例如:

 new UnicodeSet("[ab]").trim("abacatbab", TrimOption.LEADING, SpanCondition.SIMPLE)
 
... returns "catbab".

Parameters
sequence CharSequence: the sequence to trim
trimOption UnicodeSetSpanner.TrimOption: LEADING, TRAILING, or BOTH
spanCondition UnicodeSet.SpanCondition: SIMPLE, CONTAINED or NOT_CONTAINED
Returns
CharSequence a subsequence

trim

Added in API level 24
CharSequence trim (CharSequence sequence, 
                UnicodeSetSpanner.TrimOption trimOption)

Returns a trimmed sequence (using CharSequence.subsequence()), that omits matching elements at the start or end of the string, using the trimOption and SpanCondition.SIMPLE. For example:

 new UnicodeSet("[ab]").trim("abacatbab", TrimOption.LEADING)
 
... returns "catbab".

Parameters
sequence CharSequence: the sequence to trim
trimOption UnicodeSetSpanner.TrimOption: LEADING, TRAILING, or BOTH
Returns
CharSequence a subsequence

trim

Added in API level 24
CharSequence trim (CharSequence sequence)

使用TrimOption.BOTH和SpanCondition.SIMPLE返回一个修剪过的序列(使用CharSequence.subsequence()),它省略了字符串开始和结尾的匹配元素。 例如:

 new UnicodeSet("[ab]").trim("abacatbab")
 
... returns "cat".

Parameters
sequence CharSequence: the sequence to trim
Returns
CharSequence a subsequence

Hooray!