Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public Class UnicodeSetSpanner

extends Object
Class Inheritance
Imports
com.ibm.icu.text.UnicodeSet.SpanCondition, com.ibm.icu.util.OutputInt

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:

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:
SIMPLExxx[ab]cyyy
CONTAINEDxxx[abc]yyy
NOT_CONTAINED[xxx]ab[cyyy]

So here is what happens when you alternate:

start|xxxabcyyy
NOT_CONTAINEDxxx|abcyyy
CONTAINEDxxxabc|yyy
NOT_CONTAINEDxxxabcyyy|

The entire string is traversed.

ICU Status
Stable since ICU 54.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
UnicodeSetSpanner.CountMethod

Options for replaceFrom and countIn to control how to treat each matched span.

public static enum
UnicodeSetSpanner.TrimOption

Options for the trim() method

Field Summary

Modifier and TypeField and Description
private final UnicodeSet

Constructor Summary

AccessConstructor and Description
public
UnicodeSetSpanner(UnicodeSet
the original UnicodeSet
source
)

Create a spanner from a UnicodeSet.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the count. Zero if there are none.
countIn
(CharSequence
the sequence to count characters in
sequence
)

Returns the number of matching characters found in a character sequence, counting by CountMethod.MIN_ELEMENTS using SpanCondition.SIMPLE.

public int

Returns:

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

Returns the number of matching characters found in a character sequence, using SpanCondition.SIMPLE.

public int

Returns:

the count. Zero if there are none.
countIn
(CharSequence
the sequence to count characters in
sequence
,
UnicodeSetSpanner.CountMethod
whether to treat an entire span as a match, or individual elements as matches
countMethod
,
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.

spanCondition
)

Returns the number of matching characters found in a character sequence.

public String

Returns:

modified string.
deleteFrom
(CharSequence
charsequence to replace matching spans in.
sequence
)

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.

public String

Returns:

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

Delete all matching spans in sequence, according to the spanCondition.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public UnicodeSet

Returns:

the construction set.
getUnicodeSet
()

Returns the UnicodeSet used for processing.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String

Returns:

modified string.
replaceFrom
(CharSequence
charsequence to replace matching spans in.
sequence
,
CharSequence
replacement sequence. To delete, use ""
replacement
)

Replace all matching spans in sequence by the replacement, counting by CountMethod.MIN_ELEMENTS using SpanCondition.SIMPLE.

public String

Returns:

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

Replace all matching spans in sequence by replacement, according to the CountMethod, using SpanCondition.SIMPLE.

public String

Returns:

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

Replace all matching spans in sequence by replacement, according to the countMethod and spanCondition.

public CharSequence

Returns:

a subsequence
trim
(CharSequence
the sequence to trim
sequence
)

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.

public CharSequence

Returns:

a subsequence
trim
(CharSequence
the sequence to trim
sequence
,
UnicodeSetSpanner.TrimOption
LEADING, TRAILING, or BOTH
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.

public CharSequence

Returns:

a subsequence
trim
(CharSequence
the sequence to trim
sequence
,
UnicodeSetSpanner.TrimOption
LEADING, TRAILING, or BOTH
trimOption
,
UnicodeSet.SpanCondition
SIMPLE, CONTAINED or NOT_CONTAINED
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.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

unicodeSetback to summary
private final UnicodeSet unicodeSet

Constructor Detail

UnicodeSetSpannerback to summary
public UnicodeSetSpanner(UnicodeSet source)

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

ICU Status
Stable since ICU 54.

Method Detail

countInback to summary
public int countIn(CharSequence sequence)

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

Returns:int

the count. Zero if there are none.

ICU Status
Stable since ICU 54.
countInback to summary
public int countIn(CharSequence sequence, UnicodeSetSpanner.CountMethod countMethod)

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

Returns:int

the count. Zero if there are none.

ICU Status
Stable since ICU 54.
countInback to summary
public int countIn(CharSequence sequence, UnicodeSetSpanner.CountMethod countMethod, UnicodeSet.SpanCondition spanCondition)

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.

Returns:int

the count. Zero if there are none.

ICU Status
Stable since ICU 54.
deleteFromback to summary
public String deleteFrom(CharSequence sequence)

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.

Returns:String

modified string.

ICU Status
Stable since ICU 54.
deleteFromback to summary
public String deleteFrom(CharSequence sequence, UnicodeSet.SpanCondition spanCondition)

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)

Returns:String

modified string.

ICU Status
Stable since ICU 54.
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

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 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.

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
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
ICU Status
Stable since ICU 54.
getUnicodeSetback to summary
public UnicodeSet getUnicodeSet()

Returns the UnicodeSet used for processing. It is frozen iff the original was.

Returns:UnicodeSet

the construction set.

ICU Status
Stable since ICU 54.
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

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 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 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 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.
Returns:int

a hash code value for this object.

Annotations
@Override
ICU Status
Stable since ICU 54.
replaceFromback to summary
public String replaceFrom(CharSequence sequence, CharSequence replacement)

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 ""

Returns:String

modified string.

ICU Status
Stable since ICU 54.
replaceFromback to summary
public String replaceFrom(CharSequence sequence, CharSequence replacement, UnicodeSetSpanner.CountMethod countMethod)

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

Returns:String

modified string.

ICU Status
Stable since ICU 54.
replaceFromback to summary
public String replaceFrom(CharSequence sequence, CharSequence replacement, UnicodeSetSpanner.CountMethod countMethod, UnicodeSet.SpanCondition spanCondition)

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)

Returns:String

modified string.

ICU Status
Stable since ICU 54.
trimback to summary
public CharSequence trim(CharSequence sequence)

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:

new UnicodeSet("[ab]").trim("abacatbab")
... returns "cat".
Parameters
sequence:CharSequence

the sequence to trim

Returns:CharSequence

a subsequence

ICU Status
Stable since ICU 54.
trimback to summary
public 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

ICU Status
Stable since ICU 54.
trimback to summary
public CharSequence trim(CharSequence sequence, UnicodeSetSpanner.TrimOption trimOption, UnicodeSet.SpanCondition 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. For example:

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

ICU Status
Stable since ICU 54.
com.ibm.icu.text back to summary

public final Enum UnicodeSetSpanner.CountMethod

extends Enum<UnicodeSetSpanner.CountMethod>
Class Inheritance

Options for replaceFrom and countIn to control how to treat each matched span. It is similar to whether one is replacing [abc] by x, or [abc]* by x.
ICU Status
Stable since ICU 54.

Field Summary

Modifier and TypeField and Description
public static final UnicodeSetSpanner.CountMethod
MIN_ELEMENTS

Use the smallest number of elements in the spanned range for counting and modification, based on the UnicodeSet.SpanCondition.

public static final UnicodeSetSpanner.CountMethod
WHOLE_SPAN

Collapse spans.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static UnicodeSetSpanner.CountMethod
public static UnicodeSetSpanner.CountMethod[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

MIN_ELEMENTSback to summary
public static final UnicodeSetSpanner.CountMethod MIN_ELEMENTS

Use the smallest number of elements in the spanned range for counting and modification, based on the UnicodeSet.SpanCondition. If the set has no strings, this will be the same as the number of spanned code points.

For example, in the string "abab" with SpanCondition.SIMPLE:

  • spanning with [ab] will count four MIN_ELEMENTS.
  • spanning with [{ab}] will count two MIN_ELEMENTS.
  • spanning with [ab{ab}] will also count two MIN_ELEMENTS.
ICU Status
Stable since ICU 54.
WHOLE_SPANback to summary
public static final UnicodeSetSpanner.CountMethod WHOLE_SPAN

Collapse spans. That is, modify/count the entire matching span as a single item, instead of separate set elements.

ICU Status
Stable since ICU 54.

Constructor Detail

CountMethodback to summary
private CountMethod()

Method Detail

valueOfback to summary
public static UnicodeSetSpanner.CountMethod valueOf(String name)
valuesback to summary
public static UnicodeSetSpanner.CountMethod[] values()
com.ibm.icu.text back to summary

public final Enum UnicodeSetSpanner.TrimOption

extends Enum<UnicodeSetSpanner.TrimOption>
Class Inheritance

Options for the trim() method
ICU Status
Stable since ICU 54.

Field Summary

Modifier and TypeField and Description
public static final UnicodeSetSpanner.TrimOption
BOTH

Trim leading and trailing spans.

public static final UnicodeSetSpanner.TrimOption
LEADING

Trim leading spans.

public static final UnicodeSetSpanner.TrimOption
TRAILING

Trim trailing spans.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static UnicodeSetSpanner.TrimOption
public static UnicodeSetSpanner.TrimOption[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BOTHback to summary
public static final UnicodeSetSpanner.TrimOption BOTH

Trim leading and trailing spans.

ICU Status
Stable since ICU 54.
LEADINGback to summary
public static final UnicodeSetSpanner.TrimOption LEADING

Trim leading spans.

ICU Status
Stable since ICU 54.
TRAILINGback to summary
public static final UnicodeSetSpanner.TrimOption TRAILING

Trim trailing spans.

ICU Status
Stable since ICU 54.

Constructor Detail

TrimOptionback to summary
private TrimOption()

Method Detail

valueOfback to summary
public static UnicodeSetSpanner.TrimOption valueOf(String name)
valuesback to summary
public static UnicodeSetSpanner.TrimOption[] values()