public class UnicodeSet extends UnicodeFilter implements Iterable<String>, Comparable<UnicodeSet>, Freezable<UnicodeSet>
The UnicodeSet class is not designed to be subclassed.
UnicodeSet
supports two APIs. The first is the
operand 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.
Pattern syntax
Patterns are accepted by the constructors and theapplyPattern()
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:
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.
[]
No characters [a]
The character 'a' [ae]
The characters 'a' and 'e' [a-e]
The characters 'a' through 'e' inclusive, in Unicode code point order [\\u4E01]
The character U+4E01 [a{ab}{ac}]
The character 'a' and the multicharacter strings "ab" and "ac" [\p{Lu}]
All characters in the general category Uppercase Letter
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.
[a] | The set containing 'a' |
[a-z] | The set containing 'a' through 'z' and all letters in between, in Unicode order |
[^a-z] | The set containing all characters but 'a' through 'z', that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF |
[[pat1][pat2]]
| The union of sets specified by pat1 and pat2 |
[[pat1]&[pat2]]
| The intersection of sets specified by pat1 and pat2 |
[[pat1]-[pat2]]
| The asymmetric difference of sets specified by pat1 and pat2 |
[:Lu:] or \p{Lu}
| The set of characters having the specified Unicode property; in this case, Unicode uppercase letters |
[:^Lu:] or \P{Lu}
| The set of characters not having the given Unicode property |
Formal syntax
pattern :=
('[' '^'? item* ']') | property
item :=
char | (char '-' char) | pattern-expr
pattern-expr :=
pattern | pattern-expr pattern | pattern-expr op pattern
op :=
'&' | '-'
special :=
'[' | ']' | '-'
char :=
any character that is not special
any character
| ('\\')
| ('\u' hex hex hex hex)
hex :=
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'property :=
a Unicode property set pattern
Legend:
a := b
a
may be replaced byb
a?
zero or one instance of a
a*
one or more instances of a
a | b
either a
orb
'a'
the literal string between the quotes
To iterate over contents of UnicodeSet
, the following are available:
ranges()
, rangeStream()
strings()
, stringStream()
codePoints()
, codePointStream()
Iterable
,
or use stream()
.String
.
The iterators and streams methods work as expected in idiomatic Java usage.
The UnicodeSetIterator
cannot be used in for loops, and it is not very Java-idiomatic, because it is old.
But it might be faster in certain use cases. We recommend that you measure in performance sensitive code.
To replace, count elements, or delete spans, see UnicodeSetSpanner
.
UnicodeSetIterator
,
UnicodeSetSpanner
Modifier and Type | Class and Description |
---|---|
static class |
UnicodeSet.ComparisonStyle
Comparison style enums used by
compareTo(UnicodeSet, ComparisonStyle) . |
static class |
UnicodeSet.EntryRange
A struct-like class used for iteration through ranges, for faster iteration than by String.
|
static class |
UnicodeSet.SpanCondition
Argument values for whether span() and similar functions continue while the current character is contained vs.
|
static class |
UnicodeSet.XSymbolTable
Internal class for customizing UnicodeSet parsing of properties.
|
Modifier and Type | Field and Description |
---|---|
static int |
ADD_CASE_MAPPINGS
Adds all case mappings for each element in the set.
|
static UnicodeSet |
ALL_CODE_POINTS
Constant for the set of all code points.
|
static int |
CASE
Deprecated.
ICU 73 Use
CASE_INSENSITIVE instead. |
static int |
CASE_INSENSITIVE
Enable case insensitive matching.
|
static UnicodeSet |
EMPTY
Constant for the empty set.
|
static int |
IGNORE_SPACE
Bitmask for constructor and applyPattern() indicating that
white space should be ignored.
|
static int |
MAX_VALUE
Maximum value that can be stored in a UnicodeSet.
|
static int |
MIN_VALUE
Minimum value that can be stored in a UnicodeSet.
|
static int |
SIMPLE_CASE_INSENSITIVE
Enable case insensitive matching.
|
ETHER, U_MATCH, U_MISMATCH, U_PARTIAL_MATCH
Constructor and Description |
---|
UnicodeSet()
Constructs an empty set.
|
UnicodeSet(int... pairs)
Quickly constructs a set from a set of ranges <s0, e0, s1, e1, s2, e2, ..., sn, en>.
|
UnicodeSet(int start,
int end)
Constructs a set containing the given range.
|
UnicodeSet(String pattern)
Constructs a set from the given pattern.
|
UnicodeSet(String pattern,
boolean ignoreWhitespace)
Constructs a set from the given pattern.
|
UnicodeSet(String pattern,
int options)
Constructs a set from the given pattern.
|
UnicodeSet(String pattern,
ParsePosition pos,
SymbolTable symbols)
Constructs a set from the given pattern.
|
UnicodeSet(String pattern,
ParsePosition pos,
SymbolTable symbols,
int options)
Constructs a set from the given pattern.
|
UnicodeSet(UnicodeSet other)
Constructs a copy of an existing set.
|
Modifier and Type | Method and Description |
---|---|
StringBuffer |
_generatePattern(StringBuffer result,
boolean escapeUnprintable)
Generate and append a string representation of this set to result.
|
StringBuffer |
_generatePattern(StringBuffer result,
boolean escapeUnprintable,
boolean includeStrings)
Generate and append a string representation of this set to result.
|
UnicodeSet |
add(CharSequence s)
Adds the specified multicharacter to this set if it is not already
present.
|
UnicodeSet |
add(int c)
Adds the specified character to this set if it is not already
present.
|
UnicodeSet |
add(int start,
int end)
Adds the specified range to this set if it is not already
present.
|
UnicodeSet |
add(Iterable<?> source)
Add the contents of the collection (as strings) into this UnicodeSet.
|
UnicodeSet |
addAll(CharSequence s)
Adds each of the characters in this string to the set.
|
UnicodeSet |
addAll(int start,
int end)
Adds all characters in range (uses preferred naming convention).
|
UnicodeSet |
addAll(Iterable<?> source)
Add a collection (as strings) into this UnicodeSet.
|
<T extends CharSequence> |
addAll(T... collection) |
UnicodeSet |
addAll(UnicodeSet c)
Adds all of the elements in the specified set to this set if
they're not already present.
|
static <T> T[] |
addAllTo(Iterable<T> source,
T[] target)
Utility for adding the contents of an iterable to a collection.
|
static <T,U extends Collection<T>> |
addAllTo(Iterable<T> source,
U target)
Utility for adding the contents of an iterable to a collection.
|
String[] |
addAllTo(String[] target)
Add the contents of the UnicodeSet (as strings) into a collection.
|
<T extends Collection<String>> |
addAllTo(T target)
Add the contents of the UnicodeSet (as strings) into a collection.
|
UnicodeSet |
addBridges(UnicodeSet dontCare)
Deprecated.
This API is ICU internal only.
|
void |
addMatchSetTo(UnicodeSet toUnionTo)
Implementation of UnicodeMatcher API.
|
UnicodeSet |
applyIntPropertyValue(int prop,
int value)
Modifies this set to contain those code points which have the
given value for the given binary or enumerated property, as
returned by UCharacter.getIntPropertyValue.
|
UnicodeSet |
applyPattern(String pattern)
Modifies this set to represent the set specified by the given pattern.
|
UnicodeSet |
applyPattern(String pattern,
boolean ignoreWhitespace)
Modifies this set to represent the set specified by the given pattern,
optionally ignoring whitespace.
|
UnicodeSet |
applyPattern(String pattern,
int options)
Modifies this set to represent the set specified by the given pattern,
optionally ignoring whitespace.
|
UnicodeSet |
applyPattern(String pattern,
ParsePosition pos,
SymbolTable symbols,
int options)
Deprecated.
This API is ICU internal only.
|
UnicodeSet |
applyPropertyAlias(String propertyAlias,
String valueAlias)
Modifies this set to contain those code points which have the
given value for the given property.
|
UnicodeSet |
applyPropertyAlias(String propertyAlias,
String valueAlias,
SymbolTable symbols)
Modifies this set to contain those code points which have the
given value for the given property.
|
int |
charAt(int index)
Returns the character at the given index within this set, where
the set is ordered by ascending code point.
|
UnicodeSet |
clear()
Removes all of the elements from this set.
|
Object |
clone()
Return a new set that is equivalent to this one.
|
UnicodeSet |
cloneAsThawed()
Clone a thawed version of this class, according to the Freezable interface.
|
UnicodeSet |
closeOver(int attribute)
Close this set over the given attribute.
|
Iterable<Integer> |
codePoints()
Returns an
Iterable for iteration over all the code points in this set. |
IntStream |
codePointStream()
Returns an
IntStream of Unicode code point values from this UnicodeSet . |
UnicodeSet |
compact()
Reallocate this objects internal structures to take up the least
possible space, without changing this object's value.
|
static int |
compare(CharSequence string,
int codePoint)
Utility to compare a string to a code point.
|
static <T extends Comparable<T>> |
compare(Collection<T> collection1,
Collection<T> collection2,
UnicodeSet.ComparisonStyle style)
Utility to compare two collections, optionally by size, and then lexicographically.
|
static int |
compare(int codePoint,
CharSequence string)
Utility to compare a string to a code point.
|
static <T extends Comparable<T>> |
compare(Iterable<T> collection1,
Iterable<T> collection2)
Utility to compare two iterables.
|
static <T extends Comparable<T>> |
compare(Iterator<T> first,
Iterator<T> other)
Deprecated.
This API is ICU internal only.
|
int |
compareTo(Iterable<String> other) |
int |
compareTo(UnicodeSet o)
Compares UnicodeSets, where shorter come first, and otherwise lexicographically
(according to the comparison of the first characters that differ).
|
int |
compareTo(UnicodeSet o,
UnicodeSet.ComparisonStyle style)
Compares UnicodeSets, in three different ways.
|
UnicodeSet |
complement()
This is equivalent to
complement(MIN_VALUE, MAX_VALUE) . |
UnicodeSet |
complement(CharSequence s)
Complement the specified string in this set.
|
UnicodeSet |
complement(int c)
Complements the specified character in this set.
|
UnicodeSet |
complement(int start,
int end)
Complements the specified range in this set.
|
UnicodeSet |
complementAll(CharSequence s)
Complement EACH of the characters in this string.
|
UnicodeSet |
complementAll(UnicodeSet c)
Complements in this set all elements contained in the specified
set.
|
boolean |
contains(CharSequence s)
Returns true if this set contains the given
multicharacter string.
|
boolean |
contains(int c)
Returns true if this set contains the given character.
|
boolean |
contains(int start,
int end)
Returns true if this set contains every character
of the given range.
|
<T extends CharSequence> |
containsAll(Iterable<T> collection) |
boolean |
containsAll(String s)
Returns true if there is a partition of the string such that this set contains each of the partitioned strings.
|
boolean |
containsAll(UnicodeSet b)
Returns true if this set contains all the characters and strings
of the given set.
|
boolean |
containsNone(CharSequence s)
Returns true if this set contains none of the characters
of the given string.
|
boolean |
containsNone(int start,
int end)
Returns true if this set contains none of the characters
of the given range.
|
<T extends CharSequence> |
containsNone(Iterable<T> collection) |
boolean |
containsNone(UnicodeSet b)
Returns true if none of the characters or strings in this UnicodeSet appears in the string.
|
boolean |
containsSome(CharSequence s)
Returns true if this set contains one or more of the characters
of the given string.
|
boolean |
containsSome(int start,
int end)
Returns true if this set contains one or more of the characters
in the given range.
|
<T extends CharSequence> |
containsSome(Iterable<T> collection) |
boolean |
containsSome(UnicodeSet s)
Returns true if this set contains one or more of the characters
and strings of the given set.
|
boolean |
equals(Object o)
Compares the specified object with this set for equality.
|
int |
findIn(CharSequence value,
int fromIndex,
boolean findNot)
Deprecated.
This API is ICU internal only. Use span instead.
|
int |
findLastIn(CharSequence value,
int fromIndex,
boolean findNot)
Deprecated.
This API is ICU internal only. Use spanBack instead.
|
UnicodeSet |
freeze()
Freeze this class, according to the Freezable interface.
|
static UnicodeSet |
from(CharSequence s)
Makes a set from a multicharacter string.
|
static UnicodeSet |
fromAll(CharSequence s)
Makes a set from each of the characters in the string.
|
static UnicodeSet.XSymbolTable |
getDefaultXSymbolTable()
Deprecated.
This API is ICU internal only.
|
int |
getRangeCount()
Iteration method that returns the number of ranges contained in
this set.
|
int |
getRangeEnd(int index)
Iteration method that returns the last character in the
specified range of this set.
|
int |
getRangeStart(int index)
Iteration method that returns the first character in the
specified range of this set.
|
String |
getRegexEquivalent()
Deprecated.
This API is ICU internal only.
|
static int |
getSingleCodePoint(CharSequence s)
Deprecated.
This API is ICU internal only.
|
int |
hashCode()
Returns the hash code value for this set.
|
boolean |
hasStrings() |
int |
indexOf(int c)
Returns the index of the given character within this set, where
the set is ordered by ascending code point.
|
boolean |
isEmpty()
Returns true if this set contains no elements.
|
boolean |
isFrozen()
Is this frozen, according to the Freezable interface?
|
Iterator<String> |
iterator()
Returns a string iterator.
|
int |
matches(Replaceable text,
int[] offset,
int limit,
boolean incremental)
Implementation of UnicodeMatcher.matches().
|
int |
matchesAt(CharSequence text,
int offset)
Deprecated.
This API is ICU internal only.
|
boolean |
matchesIndexValue(int v)
Implementation of UnicodeMatcher API.
|
Iterable<UnicodeSet.EntryRange> |
ranges()
Provide for faster iteration than by String.
|
Stream<UnicodeSet.EntryRange> |
rangeStream()
|
UnicodeSet |
remove(CharSequence s)
Removes the specified string from this set if it is present.
|
UnicodeSet |
remove(int c)
Removes the specified character from this set if it is present.
|
UnicodeSet |
remove(int start,
int end)
Removes the specified range from this set if it is present.
|
UnicodeSet |
removeAll(CharSequence s)
Remove EACH of the characters in this string.
|
<T extends CharSequence> |
removeAll(Iterable<T> collection) |
UnicodeSet |
removeAll(UnicodeSet c)
Removes from this set all of its elements that are contained in the
specified set.
|
UnicodeSet |
removeAllStrings()
Remove all strings from this UnicodeSet
|
static boolean |
resemblesPattern(String pattern,
int pos)
Return true if the given position, in the given pattern, appears
to be the start of a UnicodeSet pattern.
|
UnicodeSet |
retain(CharSequence cs)
Retain the specified string in this set if it is present.
|
UnicodeSet |
retain(int c)
Retain the specified character from this set if it is present.
|
UnicodeSet |
retain(int start,
int end)
Retain only the elements in this set that are contained in the
specified range.
|
UnicodeSet |
retainAll(CharSequence s)
Retains EACH of the characters in this string.
|
<T extends CharSequence> |
retainAll(Iterable<T> collection) |
UnicodeSet |
retainAll(UnicodeSet c)
Retains only the elements in this set that are contained in the
specified set.
|
UnicodeSet |
set(int start,
int end)
Make this object represent the range
start - end . |
UnicodeSet |
set(UnicodeSet other)
Make this object represent the same set as
other . |
static void |
setDefaultXSymbolTable(UnicodeSet.XSymbolTable xSymbolTable)
Deprecated.
This API is ICU internal only.
|
int |
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.
|
int |
span(CharSequence s,
int start,
UnicodeSet.SpanCondition spanCondition)
Span a string using this UnicodeSet.
|
int |
span(CharSequence s,
UnicodeSet.SpanCondition spanCondition)
Span a string using this UnicodeSet.
|
int |
spanAndCount(CharSequence s,
int start,
UnicodeSet.SpanCondition spanCondition,
OutputInt outCount)
Deprecated.
This API is ICU internal only.
|
int |
spanBack(CharSequence s,
int fromIndex,
UnicodeSet.SpanCondition spanCondition)
Span a string backwards (from the fromIndex) using this UnicodeSet.
|
int |
spanBack(CharSequence s,
UnicodeSet.SpanCondition spanCondition)
Span a string backwards (from the end) using this UnicodeSet.
|
Stream<String> |
stream()
Returns a stream of
String values from this UnicodeSet . |
Collection<String> |
strings()
For iterating through the strings in the set.
|
Stream<String> |
stringStream()
|
String |
stripFrom(CharSequence source,
boolean matches)
Deprecated.
This API is ICU internal only. Use replaceFrom.
|
static String[] |
toArray(UnicodeSet set)
Add the contents of the UnicodeSet (as strings) into an array.
|
String |
toPattern(boolean escapeUnprintable)
Returns a string representation of this set.
|
String |
toString()
Return a programmer-readable string representation of this object.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static final UnicodeSet EMPTY
public static final UnicodeSet ALL_CODE_POINTS
public static final int MIN_VALUE
public static final int MAX_VALUE
public static final int IGNORE_SPACE
@Deprecated public static final int CASE
CASE_INSENSITIVE
instead.CASE_INSENSITIVE
.public static final int CASE_INSENSITIVE
This value is an options bit set value for some constructors, applyPattern(), and closeOver(). It can be ORed together with other, unrelated options.
The resulting set is a superset of the input for the code points but not for the strings. It performs a case mapping closure of the code points and adds full case folding strings for the code points, and reduces strings of the original set to their full case folding equivalents.
This is designed for case-insensitive matches, for example in regular expressions. The full code point case closure allows checking of an input character directly against the closure set. Strings are matched by comparing the case-folded form from the closure set with an incremental case folding of the string in question.
The closure set will also contain single code points if the original set contained case-equivalent strings (like U+00DF for "ss" or "Ss" etc.). This is not necessary (that is, redundant) for the above matching method but results in the same closure sets regardless of whether the original set contained the code point or a string.
public static final int ADD_CASE_MAPPINGS
This value is an options bit set value for some constructors, applyPattern(), and closeOver(). It can be ORed together with other, unrelated options.
Unlike the “case insensitive” options, this does not perform a closure. For example, it does not add 'ſ' (U+017F long s) for 's', 'K' (U+212A Kelvin sign) for 'k', or replace set strings by their case-folded versions.
public static final int SIMPLE_CASE_INSENSITIVE
CASE_INSENSITIVE
but using only Simple_Case_Folding (scf) mappings,
which map each code point to one code point,
not full Case_Folding (cf) mappings, which map some code points to multiple code points.
This is designed for case-insensitive matches, for example in certain regular expression implementations where only Simple_Case_Folding mappings are used, such as in ECMAScript (JavaScript) regular expressions.
This value is an options bit set value for some constructors, applyPattern(), and closeOver(). It can be ORed together with other, unrelated options.
public UnicodeSet()
public UnicodeSet(UnicodeSet other)
public UnicodeSet(int start, int end)
end >
start
then an empty set is created.start
- first character, inclusive, of rangeend
- last character, inclusive, of rangepublic UnicodeSet(int... pairs)
pairs
- pairs of character representing rangespublic UnicodeSet(String pattern)
pattern
- a string specifying what characters are in the setIllegalArgumentException
- if the pattern contains
a syntax error.public UnicodeSet(String pattern, boolean ignoreWhitespace)
pattern
- a string specifying what characters are in the setignoreWhitespace
- if true, ignore Unicode Pattern_White_Space charactersIllegalArgumentException
- if the pattern contains
a syntax error.public UnicodeSet(String pattern, int options)
pattern
- a string specifying what characters are in the setoptions
- a bitmask indicating which options to apply.
Valid options are IGNORE_SPACE
and
at most one of CASE_INSENSITIVE
, ADD_CASE_MAPPINGS
,
SIMPLE_CASE_INSENSITIVE
. These case options are mutually exclusive.IllegalArgumentException
- if the pattern contains
a syntax error.public UnicodeSet(String pattern, ParsePosition pos, SymbolTable symbols)
pattern
- a string specifying what characters are in the setpos
- on input, the position in pattern at which to start parsing.
On output, the position after the last character parsed.symbols
- a symbol table mapping variables to char[] arrays
and chars to UnicodeSetsIllegalArgumentException
- if the pattern
contains a syntax error.public UnicodeSet(String pattern, ParsePosition pos, SymbolTable symbols, int options)
pattern
- a string specifying what characters are in the setpos
- on input, the position in pattern at which to start parsing.
On output, the position after the last character parsed.symbols
- a symbol table mapping variables to char[] arrays
and chars to UnicodeSetsoptions
- a bitmask indicating which options to apply.
Valid options are IGNORE_SPACE
and
at most one of CASE_INSENSITIVE
, ADD_CASE_MAPPINGS
,
SIMPLE_CASE_INSENSITIVE
. These case options are mutually exclusive.IllegalArgumentException
- if the pattern
contains a syntax error.public Object clone()
public UnicodeSet set(int start, int end)
start - end
.
If start > end
then this object is set to an empty range.start
- first character in the set, inclusiveend
- last character in the set, inclusivepublic UnicodeSet set(UnicodeSet other)
other
.other
- a UnicodeSet
whose value will be
copied to this objectpublic final UnicodeSet applyPattern(String pattern)
pattern
- a string specifying what characters are in the setIllegalArgumentException
- if the pattern
contains a syntax error.public UnicodeSet applyPattern(String pattern, boolean ignoreWhitespace)
pattern
- a string specifying what characters are in the setignoreWhitespace
- if true then Unicode Pattern_White_Space characters are ignoredIllegalArgumentException
- if the pattern
contains a syntax error.public UnicodeSet applyPattern(String pattern, int options)
pattern
- a string specifying what characters are in the setoptions
- a bitmask indicating which options to apply.
Valid options are IGNORE_SPACE
and
at most one of CASE_INSENSITIVE
, ADD_CASE_MAPPINGS
,
SIMPLE_CASE_INSENSITIVE
. These case options are mutually exclusive.IllegalArgumentException
- if the pattern
contains a syntax error.public static boolean resemblesPattern(String pattern, int pos)
public String toPattern(boolean escapeUnprintable)
toPattern
in interface UnicodeMatcher
escapeUnprintable
- if true then convert unprintable
character to their hex escape representations, \\uxxxx or
\\Uxxxxxxxx. Unprintable characters are those other than
U+000A, U+0020..U+007E.public StringBuffer _generatePattern(StringBuffer result, boolean escapeUnprintable)
result
- the buffer into which to generate the patternescapeUnprintable
- escape unprintable characters if truepublic StringBuffer _generatePattern(StringBuffer result, boolean escapeUnprintable, boolean includeStrings)
result
- the buffer into which to generate the patternescapeUnprintable
- escape unprintable characters if trueincludeStrings
- if false, doesn't include the strings.public int size()
public boolean isEmpty()
public boolean hasStrings()
public boolean matchesIndexValue(int v)
matchesIndexValue
in interface UnicodeMatcher
public int matches(Replaceable text, int[] offset, int limit, boolean incremental)
matches
in interface UnicodeMatcher
matches
in class UnicodeFilter
text
- the text to be matchedoffset
- on input, the index into text at which to begin
matching. On output, the limit of the matched text. The
number of matched characters is the output value of offset
minus the input value. Offset should always point to the
HIGH SURROGATE (leading code unit) of a pair of surrogates,
both on entry and upon return.limit
- the limit index of text to be matched. Greater
than offset for a forward direction match, less than offset for
a backward direction match. The last character to be
considered for matching will be text.charAt(limit-1) in the
forward direction or text.charAt(limit+1) in the backward
direction.incremental
- if true, then assume further characters may
be inserted at limit and check for partial matching. Otherwise
assume the text as given is complete.@Deprecated public int matchesAt(CharSequence text, int offset)
public void addMatchSetTo(UnicodeSet toUnionTo)
addMatchSetTo
in interface UnicodeMatcher
toUnionTo
- the set into which to union the source characterspublic int indexOf(int c)
charAt()
.public int charAt(int index)
indexOf()
.index
- an index from 0..size()-1public UnicodeSet add(int start, int end)
start > end
then an empty range is added, leaving the set unchanged.start
- first character, inclusive, of range to be added
to this set.end
- last character, inclusive, of range to be added
to this set.public UnicodeSet addAll(int start, int end)
start
- The index of where to start on adding all characters.end
- The index of where to end on adding all characters.public final UnicodeSet add(int c)
public final UnicodeSet add(CharSequence s)
s
- the source stringpublic final UnicodeSet addAll(CharSequence s)
s
- the source stringpublic final UnicodeSet retainAll(CharSequence s)
s
- the source stringpublic final UnicodeSet complementAll(CharSequence s)
s
- the source stringpublic final UnicodeSet removeAll(CharSequence s)
s
- the source stringpublic final UnicodeSet removeAllStrings()
public static UnicodeSet from(CharSequence s)
s
- the source stringpublic static UnicodeSet fromAll(CharSequence s)
s
- the source stringpublic UnicodeSet retain(int start, int end)
start > end
then an empty range is
retained, leaving the set empty.start
- first character, inclusive, of rangeend
- last character, inclusive, of rangepublic final UnicodeSet retain(int c)
c
- the character to be retainedpublic final UnicodeSet retain(CharSequence cs)
cs
- the string to be retainedpublic UnicodeSet remove(int start, int end)
start > end
then an empty range is
removed, leaving the set unchanged.start
- first character, inclusive, of range to be removed
from this set.end
- last character, inclusive, of range to be removed
from this set.public final UnicodeSet remove(int c)
c
- the character to be removedpublic final UnicodeSet remove(CharSequence s)
s
- the string to be removedpublic UnicodeSet complement(int start, int end)
start > end
then an empty range is complemented, leaving the set unchanged.start
- first character, inclusive, of rangeend
- last character, inclusive, of rangepublic final UnicodeSet complement(int c)
public UnicodeSet complement()
complement(MIN_VALUE, MAX_VALUE)
.
Note: This performs a symmetric difference with all code points
and thus retains all multicharacter strings.
In order to achieve a “code point complement” (all code points minus this set),
the easiest is to .complement()
.removeAllStrings()
.
public final UnicodeSet complement(CharSequence s)
s
- the string to complementpublic boolean contains(int c)
contains
in class UnicodeFilter
c
- character to be checked for containmentpublic boolean contains(int start, int end)
start
- first character, inclusive, of the rangeend
- last character, inclusive, of the rangepublic final boolean contains(CharSequence s)
s
- string to be checked for containmentpublic boolean containsAll(UnicodeSet b)
b
- set to be checked for containmentpublic boolean containsAll(String s)
s
- string containing characters to be checked for containment@Deprecated public String getRegexEquivalent()
public boolean containsNone(int start, int end)
start
- first character, inclusive, of the rangeend
- last character, inclusive, of the rangepublic boolean containsNone(UnicodeSet b)
b
- set to be checked for containmentpublic boolean containsNone(CharSequence s)
s
- string containing characters to be checked for containmentpublic final boolean containsSome(int start, int end)
start
- first character, inclusive, of the rangeend
- last character, inclusive, of the rangepublic final boolean containsSome(UnicodeSet s)
s
- set to be checked for containmentpublic final boolean containsSome(CharSequence s)
s
- string containing characters to be checked for containmentpublic UnicodeSet addAll(UnicodeSet c)
c
- set whose elements are to be added to this set.public UnicodeSet retainAll(UnicodeSet c)
c
- set that defines which elements this set will retain.public UnicodeSet removeAll(UnicodeSet c)
c
- set that defines which elements will be removed from
this set.public UnicodeSet complementAll(UnicodeSet c)
c
- set that defines which elements will be complemented from
this set.public UnicodeSet clear()
public int getRangeCount()
getRangeStart(int)
,
getRangeEnd(int)
public int getRangeStart(int index)
ArrayIndexOutOfBoundsException
- if index is outside
the range 0..getRangeCount()-1
getRangeCount()
,
getRangeEnd(int)
public int getRangeEnd(int index)
ArrayIndexOutOfBoundsException
- if index is outside
the range 0..getRangeCount()-1
getRangeStart(int)
,
getRangeEnd(int)
public UnicodeSet compact()
public boolean equals(Object o)
public int hashCode()
hashCode
in class Object
Object.hashCode()
public String toString()
@Deprecated public UnicodeSet applyPattern(String pattern, ParsePosition pos, SymbolTable symbols, int options)
pattern
- the string containing the pattern to be parsed. The
portion of the string from pos.getIndex(), which must be a '[', to the
corresponding closing ']', is parsed.pos
- upon entry, the position at which to being parsing. The
character at pattern.charAt(pos.getIndex()) must be a '['. Upon return
from a successful parse, pos.getIndex() is either the character after the
closing ']' of the parsed pattern, or pattern.length() if the closing ']'
is the last character of the pattern string.pattern
IllegalArgumentException
- if the parse fails.public <T extends Collection<String>> T addAllTo(T target)
target
- collection to add intopublic String[] addAllTo(String[] target)
target
- collection to add intopublic static String[] toArray(UnicodeSet set)
public UnicodeSet add(Iterable<?> source)
source
- the collection to addpublic UnicodeSet addAll(Iterable<?> source)
source
- collection to add intopublic UnicodeSet applyIntPropertyValue(int prop, int value)
prop
- a property in the range
UProperty.BIN_START..UProperty.BIN_LIMIT-1 or
UProperty.INT_START..UProperty.INT_LIMIT-1 or.
UProperty.MASK_START..UProperty.MASK_LIMIT-1.value
- a value in the range
UCharacter.getIntPropertyMinValue(prop)..
UCharacter.getIntPropertyMaxValue(prop), with one exception.
If prop is UProperty.GENERAL_CATEGORY_MASK, then value should not be
a UCharacter.getType() result, but rather a mask value produced
by logically ORing (1 << UCharacter.getType()) values together.
This allows grouped categories such as [:L:] to be represented.public UnicodeSet applyPropertyAlias(String propertyAlias, String valueAlias)
propertyAlias
- a property alias, either short or long.
The name is matched loosely. See PropertyAliases.txt for names
and a description of loose matching. If the value string is
empty, then this string is interpreted as either a
General_Category value alias, a Script value alias, a binary
property alias, or a special ID. Special IDs are matched
loosely and correspond to the following sets:
"ANY" = [\\u0000-\\U0010FFFF],
"ASCII" = [\\u0000-\\u007F].valueAlias
- a value alias, either short or long. The
name is matched loosely. See PropertyValueAliases.txt for
names and a description of loose matching. In addition to
aliases listed, numeric values and canonical combining classes
may be expressed numerically, e.g., ("nv", "0.5") or ("ccc",
"220"). The value string may also be empty.public UnicodeSet applyPropertyAlias(String propertyAlias, String valueAlias, SymbolTable symbols)
propertyAlias
- A string of the property alias.valueAlias
- A string of the value alias.symbols
- if not null, then symbols are first called to see if a property
is available. If true, then everything else is skipped.public UnicodeSet closeOver(int attribute)
CASE_INSENSITIVE
, the result is to modify this set so that:
Example: [aqß{Bc}{bC}{Fi}] => [aAqQßfi{ss}{bc}{fi}]
(Here foldCase(x) refers to the operation UCharacter.foldCase(x, true), and a == b actually denotes a.equals(b), not pointer comparison.)
attribute
- bitmask for attributes to close over.
Valid options:
At most one of CASE_INSENSITIVE
, ADD_CASE_MAPPINGS
,
SIMPLE_CASE_INSENSITIVE
. These case options are mutually exclusive.
Unrelated options bits are ignored.public boolean isFrozen()
isFrozen
in interface Freezable<UnicodeSet>
public UnicodeSet freeze()
freeze
in interface Freezable<UnicodeSet>
public int span(CharSequence s, UnicodeSet.SpanCondition spanCondition)
To replace, count elements, or delete spans, see UnicodeSetSpanner
.
s
- The string to be spannedspanCondition
- The span conditionpublic int span(CharSequence s, int start, UnicodeSet.SpanCondition spanCondition)
To replace, count elements, or delete spans, see UnicodeSetSpanner
.
s
- The string to be spannedstart
- The start index that the span beginsspanCondition
- The span condition@Deprecated public int spanAndCount(CharSequence s, int start, UnicodeSet.SpanCondition spanCondition, OutputInt outCount)
To replace, count elements, or delete spans, see UnicodeSetSpanner
.
outCount
- An output-only object (must not be null) for returning the count.public int spanBack(CharSequence s, UnicodeSet.SpanCondition spanCondition)
To replace, count elements, or delete spans, see UnicodeSetSpanner
.
s
- The string to be spannedspanCondition
- The span conditionpublic int spanBack(CharSequence s, int fromIndex, UnicodeSet.SpanCondition spanCondition)
To replace, count elements, or delete spans, see UnicodeSetSpanner
.
s
- The string to be spannedfromIndex
- The index of the char (exclusive) that the string should be spanned backwardsspanCondition
- The span conditionpublic UnicodeSet cloneAsThawed()
cloneAsThawed
in interface Freezable<UnicodeSet>
public Iterable<UnicodeSet.EntryRange> ranges()
Warning: To iterate over the full contents, you have to also iterate over the strings.
Warning: For speed, UnicodeSet iteration does not check for concurrent modification. Do not alter the UnicodeSet while iterating.
// Sample code for (EntryRange range : us1.ranges()) { // do something with code points between range.codepoint and range.codepointEnd; } for (String s : us1.strings()) { // do something with each string; }
public Iterator<String> iterator()
UnicodeSetIterator
.
Warning: For speed, UnicodeSet iteration does not check for concurrent modification. Do not alter the UnicodeSet while iterating.
iterator
in interface Iterable<String>
Set.iterator()
public <T extends CharSequence> boolean containsAll(Iterable<T> collection)
containsAll(com.ibm.icu.text.UnicodeSet)
public <T extends CharSequence> boolean containsNone(Iterable<T> collection)
containsNone(com.ibm.icu.text.UnicodeSet)
public final <T extends CharSequence> boolean containsSome(Iterable<T> collection)
containsAll(com.ibm.icu.text.UnicodeSet)
public <T extends CharSequence> UnicodeSet addAll(T... collection)
addAll(com.ibm.icu.text.UnicodeSet)
public <T extends CharSequence> UnicodeSet removeAll(Iterable<T> collection)
removeAll(com.ibm.icu.text.UnicodeSet)
public <T extends CharSequence> UnicodeSet retainAll(Iterable<T> collection)
retainAll(com.ibm.icu.text.UnicodeSet)
public int compareTo(UnicodeSet o)
compareTo
in interface Comparable<UnicodeSet>
Comparable.compareTo(java.lang.Object)
public int compareTo(UnicodeSet o, UnicodeSet.ComparisonStyle style)
Comparable.compareTo(java.lang.Object)
public static int compare(CharSequence string, int codePoint)
public static int compare(int codePoint, CharSequence string)
public static <T extends Comparable<T>> int compare(Iterable<T> collection1, Iterable<T> collection2)
@Deprecated public static <T extends Comparable<T>> int compare(Iterator<T> first, Iterator<T> other)
public static <T extends Comparable<T>> int compare(Collection<T> collection1, Collection<T> collection2, UnicodeSet.ComparisonStyle style)
public static <T,U extends Collection<T>> U addAllTo(Iterable<T> source, U target)
public static <T> T[] addAllTo(Iterable<T> source, T[] target)
public Collection<String> strings()
for (String key : myUnicodeSet.strings()) { doSomethingWith(key); }
@Deprecated public static int getSingleCodePoint(CharSequence s)
@Deprecated public UnicodeSet addBridges(UnicodeSet dontCare)
dontCare
- Set with the don't-care characters for spanning@Deprecated public int findIn(CharSequence value, int fromIndex, boolean findNot)
@Deprecated public int findLastIn(CharSequence value, int fromIndex, boolean findNot)
@Deprecated public String stripFrom(CharSequence source, boolean matches)
source
- The source of the CharSequence to strip from.matches
- A boolean to either strip all that matches or don't match with the current UnicodeSet object.@Deprecated public static UnicodeSet.XSymbolTable getDefaultXSymbolTable()
@Deprecated public static void setDefaultXSymbolTable(UnicodeSet.XSymbolTable xSymbolTable)
WARNING: If this function is used with a UnicodeProperty, and the
Unassigned characters (gc=Cn) are different than in ICU, you MUST call
UnicodeProperty.ResetCacheProperties
afterwards. If you then call UnicodeSet.setDefaultXSymbolTable
with null to clear the value, you MUST also call UnicodeProperty.ResetCacheProperties
.
xSymbolTable
- the new default symbol table.public Stream<UnicodeSet.EntryRange> rangeStream()
Stream
of UnicodeSet.EntryRange
values from this UnicodeSet
.
Warnings:
UnicodeSet.EntryRange
instance is the same each time; the contents are just reset.
UnicodeSet
iteration does not check for concurrent modification.UnicodeSet
while iterating.
Stream
of UnicodeSet.EntryRange
public Stream<String> stringStream()
Stream
of String
values from this UnicodeSet
.
Warnings:
UnicodeSet
iteration does not check for concurrent modification.UnicodeSet
while iterating.
Stream
of String
public IntStream codePointStream()
IntStream
of Unicode code point values from this UnicodeSet
.
Warnings:
UnicodeSet
iteration does not check for concurrent modification.UnicodeSet
while iterating.
IntStream
of Unicode code point valuespublic Stream<String> stream()
String
values from this UnicodeSet
.
Warnings:
UnicodeSet
iteration does not check for concurrent modification.UnicodeSet
while iterating.
Stream
of String
public Iterable<Integer> codePoints()
Iterable
for iteration over all the code points in this set.
Warnings:
int
into Integer
.UnicodeSetIterator.next()
.
UnicodeSet
iteration does not check for concurrent modification.UnicodeSet
while iterating.
Iterable
over all the code pointsCopyright © 2016 Unicode, Inc. and others.