UnicodeSet Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A mutable set of Unicode characters and multicharacter strings.
[Android.Runtime.Register("android/icu/text/UnicodeSet", ApiSince=24, DoNotGenerateAcw=true)]
public class UnicodeSet : Android.Icu.Text.UnicodeFilter, Android.Icu.Util.IFreezable, IDisposable, Java.Interop.IJavaPeerable, Java.Lang.IComparable, Java.Lang.IIterable
[<Android.Runtime.Register("android/icu/text/UnicodeSet", ApiSince=24, DoNotGenerateAcw=true)>]
type UnicodeSet = class
inherit UnicodeFilter
interface IFreezable
interface ICloneable
interface IJavaObject
interface IDisposable
interface IJavaPeerable
interface IComparable
interface IIterable
- Inheritance
- Attributes
- Implements
Remarks
A mutable set of Unicode characters and multicharacter strings. Objects of this class represent <em>character classes</em> used in regular expressions. A character specifies a subset of Unicode code points. Legal code points are U+0000 to U+10FFFF, inclusive.
Note: method freeze() will not only make the set immutable, but also makes important methods much higher performance: contains(c), containsNone(...), span(...), spanBack(...) etc. After the object is frozen, any subsequent call that wants to change the object will throw UnsupportedOperationException.
The UnicodeSet class is not designed to be subclassed.
UnicodeSet
supports two APIs. The first is the <em>operand</em> API that allows the caller to modify the value of a UnicodeSet
object. It conforms to Java 2's java.util.Set
interface, although UnicodeSet
does not actually implement that interface. All methods of Set
are supported, with the modification that they take a character range or single character instead of an Object
, and they take a UnicodeSet
instead of a Collection
. The operand API may be thought of in terms of boolean logic: a boolean OR is implemented by add
, a boolean AND is implemented by retain
, a boolean XOR is implemented by complement
taking an argument, and a boolean NOT is implemented by complement
with no argument. In terms of traditional set theory function names, add
is a union, retain
is an intersection, remove
is an asymmetric difference, and complement
with no argument is a set complement with respect to the superset range MIN_VALUE-MAX_VALUE
The second API is the applyPattern()
/toPattern()
API from the java.text.Format
-derived classes. Unlike the methods that add characters, add categories, and control the logic of the set, the method applyPattern()
sets all attributes of a UnicodeSet
at once, based on a string pattern.
<b>Pattern syntax</b>
Patterns are accepted by the constructors and the applyPattern()
methods and returned by the toPattern()
method. These patterns follow a syntax similar to that employed by version 8 regular expression character classes. Here are some simple examples:
<blockquote> <table> <tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top; horizontal-align: left;">[]
</td> <td style="vertical-align: top;">No characters</td> </tr><tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top; horizontal-align: left;">[a]
</td> <td style="vertical-align: top;">The character 'a'</td> </tr><tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top; horizontal-align: left;">[ae]
</td> <td style="vertical-align: top;">The characters 'a' and 'e'</td> </tr> <tr> <td style="white-space: nowrap; vertical-align: top; horizontal-align: left;">[a-e]
</td> <td style="vertical-align: top;">The characters 'a' through 'e' inclusive, in Unicode code point order</td> </tr> <tr> <td style="white-space: nowrap; vertical-align: top; horizontal-align: left;">[\\u4E01]
</td> <td style="vertical-align: top;">The character U+4E01</td> </tr> <tr> <td style="white-space: nowrap; vertical-align: top; horizontal-align: left;">[a{ab}{ac}]
</td> <td style="vertical-align: top;">The character 'a' and the multicharacter strings "ab" and "ac"</td> </tr> <tr> <td style="white-space: nowrap; vertical-align: top; horizontal-align: left;">[\p{Lu}]
</td> <td style="vertical-align: top;">All characters in the general category Uppercase Letter</td> </tr> </table> </blockquote>
Any character may be preceded by a backslash in order to remove any special meaning. White space characters, as defined by the Unicode Pattern_White_Space property, are ignored, unless they are escaped.
Property patterns specify a set of characters having a certain property as defined by the Unicode standard. Both the POSIX-like "[:Lu:]" and the Perl-like syntax "\p{Lu}" are recognized. For a complete list of supported property patterns, see the User's Guide for UnicodeSet at https://unicode-org.github.io/icu/userguide/strings/unicodeset. Actual determination of property data is defined by the underlying Unicode database as implemented by UCharacter.
Patterns specify individual characters, ranges of characters, and Unicode property sets. When elements are concatenated, they specify their union. To complement a set, place a '^' immediately after the opening '['. Property patterns are inverted by modifying their delimiters; "[:^foo]" and "\P{foo}". In any other location, '^' has no special meaning.
Since ICU 70, "[^...]", "[:^foo]", "\P{foo}", and "[:binaryProperty=No:]" perform a “code point complement” (all code points minus the original set), removing all multicharacter strings, equivalent to .#complement()
.#removeAllStrings()
. The #complement()
API function continues to perform a symmetric difference with all code points and thus retains all multicharacter strings.
Ranges are indicated by placing two a '-' between two characters, as in "a-z". This specifies the range of all characters from the left to the right, in Unicode order. If the left character is greater than or equal to the right character it is a syntax error. If a '-' occurs as the first character after the opening '[' or '[^', or if it occurs as the last character before the closing ']', then it is taken as a literal. Thus "[a\\-b]", "[-ab]", and "[ab-]" all indicate the same set of three characters, 'a', 'b', and '-'.
Sets may be intersected using the '&' operator or the asymmetric set difference may be taken using the '-' operator, for example, "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters with values less than 4096. Operators ('&' and '|') have equal precedence and bind left-to-right. Thus "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]". This only really matters for difference; intersection is commutative.
<table> <tr style="vertical-align: top;"><td style="white-space: nowrap;">[a]
<td>The set containing 'a' <tr style="vertical-align: top;"><td style="white-space: nowrap;">[a-z]
<td>The set containing 'a' through 'z' and all letters in between, in Unicode order <tr style="vertical-align: top;"><td style="white-space: nowrap;">[^a-z]
<td>The set containing all characters but 'a' through 'z', that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF <tr style="vertical-align: top;"><td style="white-space: nowrap;">[[<em>pat1</em>][<em>pat2</em>]]
<td>The union of sets specified by <em>pat1</em> and <em>pat2</em> <tr style="vertical-align: top;"><td style="white-space: nowrap;">[[<em>pat1</em>]&[<em>pat2</em>]]
<td>The intersection of sets specified by <em>pat1</em> and <em>pat2</em> <tr style="vertical-align: top;"><td style="white-space: nowrap;">[[<em>pat1</em>]-[<em>pat2</em>]]
<td>The asymmetric difference of sets specified by <em>pat1</em> and <em>pat2</em> <tr style="vertical-align: top;"><td style="white-space: nowrap;">[:Lu:] or \p{Lu}
<td>The set of characters having the specified Unicode property; in this case, Unicode uppercase letters <tr style="vertical-align: top;"><td style="white-space: nowrap;">[:^Lu:] or \P{Lu}
<td>The set of characters <em>not</em> having the given Unicode property </table>
<b>Formal syntax</b>
<blockquote> <table> <tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top;" align="right">pattern :=
</td> <td style="vertical-align: top;">('[' '^'? item* ']') | property
</td> </tr> <tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top;" align="right">item :=
</td> <td style="vertical-align: top;">char | (char '-' char) | pattern-expr<br>
</td> </tr> <tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top;" align="right">pattern-expr :=
</td> <td style="vertical-align: top;">pattern | pattern-expr pattern | pattern-expr op pattern<br>
</td> </tr> <tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top;" align="right">op :=
</td> <td style="vertical-align: top;">'&' | '-'<br>
</td> </tr> <tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top;" align="right">special :=
</td> <td style="vertical-align: top;">'[' | ']' | '-'<br>
</td> </tr> <tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top;" align="right">char :=
</td> <td style="vertical-align: top;"><em>any character that is not</em> special<br> | ('\\'
<em>any character</em>)<br> | ('\u' hex hex hex hex)<br>
</td> </tr> <tr style="vertical-align: top"> <td style="white-space: nowrap; vertical-align: top;" align="right">hex :=
</td> <td style="vertical-align: top;">'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |<br> 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
</td> </tr> <tr> <td style="white-space: nowrap; vertical-align: top;" align="right">property :=
</td> <td style="vertical-align: top;"><em>a Unicode property set pattern</em></td> </tr> </table> <br> <table border="1"> <tr> <td>Legend: <table> <tr> <td style="white-space: nowrap; vertical-align: top;">a := b
</td> <td style="width: 20; vertical-align: top;"> </td> <td style="vertical-align: top;">a
may be replaced by b
</td> </tr> <tr> <td style="white-space: nowrap; vertical-align: top;">a?
</td> <td style="vertical-align: top;"></td> <td style="vertical-align: top;">zero or one instance of a
<br> </td> </tr> <tr> <td style="white-space: nowrap; vertical-align: top;">a*
</td> <td style="vertical-align: top;"></td> <td style="vertical-align: top;">one or more instances of a
<br> </td> </tr> <tr> <td style="white-space: nowrap; vertical-align: top;">a | b
</td> <td style="vertical-align: top;"></td> <td style="vertical-align: top;">either a
or b
<br> </td> </tr> <tr> <td style="white-space: nowrap; vertical-align: top;">'a'
</td> <td style="vertical-align: top;"></td> <td style="vertical-align: top;">the literal string between the quotes </td> </tr> </table> </td> </tr> </table> </blockquote>
To iterate over contents of UnicodeSet, the following are available: <ul><li>#ranges()
to iterate through the ranges</li> <li>#strings()
to iterate through the strings</li> <li>#iterator()
to iterate through the entire contents in a single loop. That method is, however, not particularly efficient, since it "boxes" each code point into a String. </ul> All of the above can be used in <b>for</b> loops. The android.icu.text.UnicodeSetIterator UnicodeSetIterator
can also be used, but not in <b>for</b> loops.
To replace, count elements, or delete spans, see android.icu.text.UnicodeSetSpanner UnicodeSetSpanner
.
Java documentation for android.icu.text.UnicodeSet
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
UnicodeSet() |
Constructs an empty set. |
UnicodeSet(Int32, Int32) |
Constructs a set containing the given range. |
UnicodeSet(Int32[]) |
Quickly constructs a set from a set of ranges <s0, e0, s1, e1, s2, e2, . |
UnicodeSet(IntPtr, JniHandleOwnership) | |
UnicodeSet(String, Boolean) |
Constructs a set from the given pattern. |
UnicodeSet(String, ParsePosition, ISymbolTable, UnicodeSetOptions) |
Constructs a set from the given pattern. |
UnicodeSet(String, ParsePosition, ISymbolTable) |
Constructs a set from the given pattern. |
UnicodeSet(String, UnicodeSetOptions) |
Constructs a set from the given pattern. |
UnicodeSet(String) |
Constructs a set from the given pattern. |
UnicodeSet(UnicodeSet) |
Constructs a copy of an existing set. |
Fields
AddCaseMappings |
Obsolete.
Adds all case mappings for each element in the set. |
Case |
Obsolete.
Alias for |
CaseInsensitive |
Obsolete.
Enable case insensitive matching. |
IgnoreSpace |
Obsolete.
Bitmask for constructor and applyPattern() indicating that white space should be ignored. |
MaxValue |
Maximum value that can be stored in a UnicodeSet. |
MinValue |
Minimum value that can be stored in a UnicodeSet. |
Properties
AllCodePoints |
Constant for the set of all code points. |
Class |
Returns the runtime class of this |
Empty |
Constant for the empty set. |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
HasStrings | |
IsEmpty |
Returns |
IsFrozen |
Is this frozen, according to the Freezable interface? |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
PeerReference | (Inherited from Object) |
RangeCount |
Iteration method that returns the number of ranges contained in this set. |
ThresholdClass | |
ThresholdType |
Methods
_generatePattern(StringBuffer, Boolean, Boolean) |
Generate and append a string representation of this set to result. |
_generatePattern(StringBuffer, Boolean) |
Generate and append a string representation of this set to result. |
Add(ICharSequence) |
Adds the specified multicharacter to this set if it is not already present. |
Add(IIterable) |
Add the contents of the collection (as strings) into this UnicodeSet. |
Add(Int32, Int32) |
Adds the specified range to this set if it is not already present. |
Add(Int32) |
Adds the specified character to this set if it is not already present. |
Add(String) |
Adds the specified multicharacter to this set if it is not already present. |
AddAll(ICharSequence) |
Adds each of the characters in this string to the set. |
AddAll(IIterable) |
Add a collection (as strings) into this UnicodeSet. |
AddAll(Int32, Int32) |
Adds all characters in range (uses preferred naming convention). |
AddAll(String) |
Adds each of the characters in this string to the set. |
AddAll(UnicodeSet) |
Adds all of the elements in the specified set to this set if they're not already present. |
AddAllTo(Object) |
Add the contents of the UnicodeSet (as strings) into a collection. |
AddMatchSetTo(UnicodeSet) |
Implementation of UnicodeMatcher API. |
ApplyIntPropertyValue(Int32, Int32) |
Modifies this set to contain those code points which have the given value for the given binary or enumerated property, as returned by UCharacter. |
ApplyPattern(String, Boolean) |
Modifies this set to represent the set specified by the given pattern, optionally ignoring whitespace. |
ApplyPattern(String, UnicodeSetOptions) |
Modifies this set to represent the set specified by the given pattern, optionally ignoring whitespace. |
ApplyPattern(String) |
Modifies this set to represent the set specified by the given pattern. |
ApplyPropertyAlias(String, String, ISymbolTable) |
Modifies this set to contain those code points which have the given value for the given property. |
ApplyPropertyAlias(String, String) |
Modifies this set to contain those code points which have the given value for the given property. |
CharAt(Int32) |
Returns the character at the given index within this set, where the set is ordered by ascending code point. |
Clear() |
Removes all of the elements from this set. |
Clone() |
Return a new set that is equivalent to this one. |
CloneAsThawed() |
Clone a thawed version of this class, according to the Freezable interface. |
CloseOver(Int32) |
Close this set over the given attribute. |
Compact() |
Reallocate this objects internal structures to take up the least possible space, without changing this object's value. |
CompareTo(IIterable) | |
CompareTo(UnicodeSet, UnicodeSet+ComparisonStyle) | |
CompareTo(UnicodeSet) |
Compares UnicodeSets, where shorter come first, and otherwise lexicographically (according to the comparison of the first characters that differ). |
Complement() |
This is equivalent to
|
Complement(ICharSequence) |
Complement the specified string in this set. |
Complement(Int32, Int32) |
Complements the specified range in this set. |
Complement(Int32) |
Complements the specified character in this set. |
Complement(String) |
Complement the specified string in this set. |
ComplementAll(ICharSequence) |
Complement EACH of the characters in this string. |
ComplementAll(String) |
Complement EACH of the characters in this string. |
ComplementAll(UnicodeSet) |
Complements in this set all elements contained in the specified set. |
Contains(ICharSequence) |
Returns |
Contains(Int32, Int32) |
Returns true if this set contains every character of the given range. |
Contains(Int32) |
Returns true if this set contains the given character. |
Contains(String) |
Returns |
ContainsAll(IIterable) | |
ContainsAll(String) |
Returns true if there is a partition of the string such that this set contains each of the partitioned strings. |
ContainsAll(UnicodeSet) |
Returns true if this set contains all the characters and strings of the given set. |
ContainsNone(ICharSequence) |
Returns true if this set contains none of the characters of the given string. |
ContainsNone(IIterable) | |
ContainsNone(Int32, Int32) |
Returns true if this set contains none of the characters of the given range. |
ContainsNone(String) |
Returns true if this set contains none of the characters of the given string. |
ContainsNone(UnicodeSet) |
Returns true if none of the characters or strings in this UnicodeSet appears in the string. |
ContainsSome(ICharSequence) |
Returns true if this set contains one or more of the characters of the given string. |
ContainsSome(IIterable) | |
ContainsSome(Int32, Int32) |
Returns true if this set contains one or more of the characters in the given range. |
ContainsSome(String) |
Returns true if this set contains one or more of the characters of the given string. |
ContainsSome(UnicodeSet) |
Returns true if this set contains one or more of the characters and strings of the given set. |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
Freeze() |
Freeze this class, according to the Freezable interface. |
From(ICharSequence) |
Makes a set from a multicharacter string. |
From(String) |
Makes a set from a multicharacter string. |
FromAll(ICharSequence) |
Makes a set from each of the characters in the string. |
FromAll(String) |
Makes a set from each of the characters in the string. |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
GetRangeEnd(Int32) |
Iteration method that returns the last character in the specified range of this set. |
GetRangeStart(Int32) |
Iteration method that returns the first character in the specified range of this set. |
IndexOf(Int32) |
Returns the index of the given character within this set, where the set is ordered by ascending code point. |
Iterator() |
Returns a string iterator. |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
Matches(IReplaceable, Int32[], Int32, Boolean) |
Default implementation of UnicodeMatcher::matches() for Unicode filters. (Inherited from UnicodeFilter) |
MatchesIndexValue(Int32) |
Implementation of UnicodeMatcher API. |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
Ranges() |
Provide for faster iteration than by String. |
Remove(ICharSequence) |
Removes the specified string from this set if it is present. |
Remove(Int32, Int32) |
Removes the specified range from this set if it is present. |
Remove(Int32) |
Removes the specified character from this set if it is present. |
Remove(String) |
Removes the specified string from this set if it is present. |
RemoveAll(ICharSequence) |
Remove EACH of the characters in this string. |
RemoveAll(IIterable) | |
RemoveAll(String) |
Remove EACH of the characters in this string. |
RemoveAll(UnicodeSet) |
Removes from this set all of its elements that are contained in the specified set. |
RemoveAllStrings() |
Remove all strings from this UnicodeSet |
Retain(ICharSequence) |
Retain the specified string in this set if it is present. |
Retain(Int32, Int32) |
Retain only the elements in this set that are contained in the specified range. |
Retain(Int32) |
Retain the specified character from this set if it is present. |
Retain(String) |
Retain the specified string in this set if it is present. |
RetainAll(ICharSequence) |
Retains EACH of the characters in this string. |
RetainAll(IIterable) | |
RetainAll(String) |
Retains EACH of the characters in this string. |
RetainAll(UnicodeSet) |
Retains only the elements in this set that are contained in the specified set. |
Set(Int32, Int32) |
Make this object represent the range |
Set(UnicodeSet) |
Make this object represent the same set as |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
Size() |
Returns the number of elements in this set (its cardinality) Note than the elements of a set may include both individual codepoints and strings. |
Span(ICharSequence, Int32, UnicodeSet+SpanCondition) | |
Span(ICharSequence, UnicodeSet+SpanCondition) | |
Span(String, Int32, UnicodeSet+SpanCondition) | |
Span(String, UnicodeSet+SpanCondition) | |
SpanBack(ICharSequence, Int32, UnicodeSet+SpanCondition) | |
SpanBack(ICharSequence, UnicodeSet+SpanCondition) | |
SpanBack(String, Int32, UnicodeSet+SpanCondition) | |
SpanBack(String, UnicodeSet+SpanCondition) | |
Strings() |
For iterating through the strings in the set. |
ToArray<T>() | (Inherited from Object) |
ToPattern(Boolean) |
Returns a string representation of this set. |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (Inherited from Object) |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
IComparable.CompareTo(Object) | |
IFreezable.CloneAsThawed() | |
IFreezable.Freeze() | |
IIterable.Iterator() | |
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |
Gets the JNI name of the type of the instance |
JavaAs<TResult>(IJavaPeerable) |
Try to coerce |
TryJavaCast<TResult>(IJavaPeerable, TResult) |
Try to coerce |
ToEnumerable(IIterable) | |
ToEnumerable<T>(IIterable) |