UnicodeSetSpanner
open class UnicodeSetSpanner
kotlin.Any | |
↳ | android.icu.text.UnicodeSetSpanner |
A helper class used to count, replace, and trim CharSequences based on UnicodeSet matches. An instance is immutable (and thus thread-safe) iff the source UnicodeSet is frozen.
Note: The counting, deletion, and replacement depend on alternating a SpanCondition
with its inverse. That is, the code spans, then spans for the inverse, then spans, and so on. For the inverse, the following mapping is used:
UnicodeSet.SpanCondition.SIMPLE
→UnicodeSet.SpanCondition.NOT_CONTAINED
UnicodeSet.SpanCondition.CONTAINED
→UnicodeSet.SpanCondition.NOT_CONTAINED
UnicodeSet.SpanCondition.NOT_CONTAINED
→UnicodeSet.SpanCondition.SIMPLE
SIMPLE | xxx[ab]cyyy |
---|---|
CONTAINED | xxx[abc]yyy |
NOT_CONTAINED | [xxx]ab[cyyy] |
So here is what happens when you alternate:
start | |xxxabcyyy |
---|---|
NOT_CONTAINED | xxx|abcyyy |
CONTAINED | xxxabc|yyy |
NOT_CONTAINED | xxxabcyyy| |
The entire string is traversed.
Summary
Nested classes | |
---|---|
Options for replaceFrom and countIn to control how to treat each matched span. |
|
Options for the trim() method |
Public constructors | |
---|---|
UnicodeSetSpanner(source: UnicodeSet!) Create a spanner from a UnicodeSet. |
Public methods | |
---|---|
open Int |
countIn(sequence: CharSequence!) Returns the number of matching characters found in a character sequence, counting by CountMethod. |
open Int |
countIn(sequence: CharSequence!, countMethod: UnicodeSetSpanner.CountMethod!) Returns the number of matching characters found in a character sequence, using SpanCondition. |
open Int |
countIn(sequence: CharSequence!, countMethod: UnicodeSetSpanner.CountMethod!, spanCondition: UnicodeSet.SpanCondition!) Returns the number of matching characters found in a character sequence. |
open String! |
deleteFrom(sequence: CharSequence!) Delete all the matching spans in sequence, using SpanCondition. |
open String! |
deleteFrom(sequence: CharSequence!, spanCondition: UnicodeSet.SpanCondition!) Delete all matching spans in sequence, according to the spanCondition. |
open Boolean |
Indicates whether some other object is "equal to" this one. |
open UnicodeSet! |
Returns the UnicodeSet used for processing. |
open Int |
hashCode() Returns a hash code value for the object. |
open String! |
replaceFrom(sequence: CharSequence!, replacement: CharSequence!) Replace all matching spans in sequence by the replacement, counting by CountMethod. |
open String! |
replaceFrom(sequence: CharSequence!, replacement: CharSequence!, countMethod: UnicodeSetSpanner.CountMethod!) Replace all matching spans in sequence by replacement, according to the CountMethod, using SpanCondition. |
open String! |
replaceFrom(sequence: CharSequence!, replacement: CharSequence!, countMethod: UnicodeSetSpanner.CountMethod!, spanCondition: UnicodeSet.SpanCondition!) Replace all matching spans in sequence by replacement, according to the countMethod and spanCondition. |
open CharSequence! |
trim(sequence: CharSequence!) Returns a trimmed sequence (using CharSequence.subsequence()), that omits matching elements at the start and end of the string, using TrimOption. |
open CharSequence! |
trim(sequence: CharSequence!, trimOption: UnicodeSetSpanner.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. |
open CharSequence! |
trim(sequence: CharSequence!, trimOption: UnicodeSetSpanner.TrimOption!, spanCondition: UnicodeSet.SpanCondition!) Returns a trimmed sequence (using CharSequence.subsequence()), that omits matching elements at the start or end of the string, depending on the trimOption and spanCondition. |
Public constructors
UnicodeSetSpanner
UnicodeSetSpanner(source: UnicodeSet!)
Create a spanner from a UnicodeSet. For speed and safety, the UnicodeSet should be frozen. However, this class can be used with a non-frozen version to avoid the cost of freezing.
Parameters | |
---|---|
source |
UnicodeSet!: the original UnicodeSet |
Public methods
countIn
open fun countIn(sequence: CharSequence!): Int
Returns the number of matching characters found in a character sequence, counting by CountMethod.MIN_ELEMENTS using SpanCondition.SIMPLE. The code alternates spans; see the class doc for UnicodeSetSpanner
for a note about boundary conditions.
Parameters | |
---|---|
sequence |
CharSequence!: the sequence to count characters in |
Return | |
---|---|
Int |
the count. Zero if there are none. |
countIn
open fun countIn(
sequence: CharSequence!,
countMethod: UnicodeSetSpanner.CountMethod!
): Int
Returns the number of matching characters found in a character sequence, using SpanCondition.SIMPLE. The code alternates spans; see the class doc for UnicodeSetSpanner
for a note about boundary conditions.
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 |
Return | |
---|---|
Int |
the count. Zero if there are none. |
countIn
open fun countIn(
sequence: CharSequence!,
countMethod: UnicodeSetSpanner.CountMethod!,
spanCondition: UnicodeSet.SpanCondition!
): Int
Returns the number of matching characters found in a character sequence. The code alternates spans; see the class doc for UnicodeSetSpanner
for a note about boundary conditions.
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. |
Return | |
---|---|
Int |
the count. Zero if there are none. |
deleteFrom
open fun deleteFrom(sequence: CharSequence!): String!
Delete all the matching spans in sequence, using SpanCondition.SIMPLE The code alternates spans; see the class doc for UnicodeSetSpanner
for a note about boundary conditions.
Parameters | |
---|---|
sequence |
CharSequence!: charsequence to replace matching spans in. |
Return | |
---|---|
String! |
modified string. |
deleteFrom
open fun deleteFrom(
sequence: CharSequence!,
spanCondition: UnicodeSet.SpanCondition!
): String!
Delete all matching spans in sequence, according to the spanCondition. The code alternates spans; see the class doc for UnicodeSetSpanner
for a note about boundary conditions.
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) |
Return | |
---|---|
String! |
modified string. |
equals
open fun equals(other: Any?): Boolean
Indicates whether some other object is "equal to" this one.
The equals
method implements an equivalence relation on non-null object references:
- It is reflexive: for any non-null reference value
x
,x.equals(x)
should returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
Parameters | |
---|---|
obj |
the reference object with which to compare. |
Return | |
---|---|
Boolean |
true if this object is the same as the obj argument; false otherwise. |
getUnicodeSet
open fun getUnicodeSet(): UnicodeSet!
Returns the UnicodeSet used for processing. It is frozen iff the original was.
Return | |
---|---|
UnicodeSet! |
the construction set. |
hashCode
open fun hashCode(): Int
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap
.
The general contract of hashCode
is:
- 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 inequals
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
method, then calling thehashCode
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
method, then calling thehashCode
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.
Return | |
---|---|
Int |
a hash code value for this object. |
replaceFrom
open fun replaceFrom(
sequence: CharSequence!,
replacement: CharSequence!
): String!
Replace all matching spans in sequence by the replacement, counting by CountMethod.MIN_ELEMENTS using SpanCondition.SIMPLE. The code alternates spans; see the class doc for UnicodeSetSpanner
for a note about boundary conditions.
Parameters | |
---|---|
sequence |
CharSequence!: charsequence to replace matching spans in. |
replacement |
CharSequence!: replacement sequence. To delete, use "" |
Return | |
---|---|
String! |
modified string. |
replaceFrom
open fun replaceFrom(
sequence: CharSequence!,
replacement: CharSequence!,
countMethod: UnicodeSetSpanner.CountMethod!
): String!
Replace all matching spans in sequence by replacement, according to the CountMethod, using SpanCondition.SIMPLE. The code alternates spans; see the class doc for UnicodeSetSpanner
for a note about boundary conditions.
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 |
Return | |
---|---|
String! |
modified string. |
replaceFrom
open fun replaceFrom(
sequence: CharSequence!,
replacement: CharSequence!,
countMethod: UnicodeSetSpanner.CountMethod!,
spanCondition: UnicodeSet.SpanCondition!
): String!
Replace all matching spans in sequence by replacement, according to the countMethod and spanCondition. The code alternates spans; see the class doc for UnicodeSetSpanner
for a note about boundary conditions.
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) |
Return | |
---|---|
String! |
modified string. |
trim
open fun trim(sequence: CharSequence!): CharSequence!
Returns a trimmed sequence (using CharSequence.subsequence()), that omits matching elements at the start and end of the string, using TrimOption.BOTH and SpanCondition.SIMPLE. For example:
<code>new UnicodeSet("[ab]").trim("abacatbab")</code>
"cat"
.
Parameters | |
---|---|
sequence |
CharSequence!: the sequence to trim |
Return | |
---|---|
CharSequence! |
a subsequence |
trim
open fun trim(
sequence: CharSequence!,
trimOption: UnicodeSetSpanner.TrimOption!
): CharSequence!
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:
<code>new UnicodeSet("[ab]").trim("abacatbab", TrimOption.LEADING)</code>
"catbab"
.
Parameters | |
---|---|
sequence |
CharSequence!: the sequence to trim |
trimOption |
UnicodeSetSpanner.TrimOption!: LEADING, TRAILING, or BOTH |
Return | |
---|---|
CharSequence! |
a subsequence |
trim
open fun trim(
sequence: CharSequence!,
trimOption: UnicodeSetSpanner.TrimOption!,
spanCondition: UnicodeSet.SpanCondition!
): CharSequence!
Returns a trimmed sequence (using CharSequence.subsequence()), that omits matching elements at the start or end of the string, depending on the trimOption and spanCondition. For example:
<code>new UnicodeSet("[ab]").trim("abacatbab", TrimOption.LEADING, SpanCondition.SIMPLE)</code>
"catbab"
.
Parameters | |
---|---|
sequence |
CharSequence!: the sequence to trim |
trimOption |
UnicodeSetSpanner.TrimOption!: LEADING, TRAILING, or BOTH |
spanCondition |
UnicodeSet.SpanCondition!: SIMPLE, CONTAINED or NOT_CONTAINED |
Return | |
---|---|
CharSequence! |
a subsequence |