|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.text.UnicodeFilter | +--com.ibm.text.UnicodeSet
A mutable set of Unicode characters. Objects of this class represent character classes used in regular expressions. A character specifies a subset of Unicode code points. Legal code points are U+0000 to U+10FFFF, inclusive.
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:
Any character may be preceded by a backslash in order to remove any special meaning. White space characters, as defined by UCharacter.isWhitespace(), are ignored, unless they are escaped.
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 :=
any character for which Character.digit(c, 16)
returns a non-negative resultproperty :=
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
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 http://oss.software.ibm.com/icu/userguide/unicodeset.html. 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.
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 |
Field Summary | |
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. |
Fields inherited from interface com.ibm.text.UnicodeMatcher |
U_MATCH, U_MISMATCH, U_PARTIAL_MATCH |
Constructor Summary | |
UnicodeSet()
Constructs an empty set. |
|
UnicodeSet(int category)
Deprecated. this will be removed Dec-31-2002 |
|
UnicodeSet(int start,
int end)
Constructs a set containing the given range. |
|
UnicodeSet(java.lang.String pattern)
Constructs a set from the given pattern. |
|
UnicodeSet(java.lang.String pattern,
boolean ignoreWhitespace)
Constructs a set from the given pattern. |
|
UnicodeSet(java.lang.String pattern,
java.text.ParsePosition pos,
SymbolTable symbols)
Constructs a set from the given pattern. |
|
UnicodeSet(UnicodeSet other)
Constructs a copy of an existing set. |
Method Summary | |
java.lang.StringBuffer |
_generatePattern(java.lang.StringBuffer result,
boolean escapeUnprintable)
Generate and append a string representation of this set to result. |
void |
add(int c)
Adds the specified character to this set if it is not already present. |
void |
add(int start,
int end)
Adds the specified range to this set if it is not already present. |
void |
addAll(UnicodeSet c)
Adds all of the elements in the specified set to this set if they're not already present. |
void |
applyPattern(java.lang.String pattern)
Modifies this set to represent the set specified by the given pattern. |
void |
applyPattern(java.lang.String pattern,
boolean ignoreWhitespace)
Modifies this set to represent the set specified by the given pattern, optionally ignoring whitespace. |
int |
charAt(int index)
Returns the character at the given index within this set, where the set is ordered by ascending code point. |
void |
clear()
Removes all of the elements from this set. |
java.lang.Object |
clone()
Return a new set that is equivalent to this one. |
void |
compact()
Reallocate this objects internal structures to take up the least possible space, without changing this object's value. |
void |
complement()
Inverts this set. |
void |
complement(int c)
Complements the specified character in this set. |
void |
complement(int start,
int end)
Complements the specified range in this set. |
void |
complementAll(UnicodeSet c)
Complements in this set all elements contained in the specified set. |
boolean |
contains(int c)
Returns true if this set contains the specified char. |
boolean |
contains(int start,
int end)
Returns true if this set contains every character in the specified range of chars. |
boolean |
containsAll(UnicodeSet c)
Returns true if the specified set is a subset of this set. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this set for equality. |
UnicodeSet |
getMatchSet(UnicodeSet toUnionTo)
Implementation of UnicodeMatcher API. |
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. |
int |
hashCode()
Returns the hash code value for this set. |
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. |
int |
matches(Replaceable text,
int[] offset,
int limit,
boolean incremental)
Implementation of UnicodeMatcher.matches(). |
boolean |
matchesIndexValue(int v)
Implementation of UnicodeMatcher API. |
void |
remove(int c)
Removes the specified character from this set if it is present. |
void |
remove(int start,
int end)
Removes the specified range from this set if it is present. |
void |
removeAll(UnicodeSet c)
Removes from this set all of its elements that are contained in the specified set. |
static boolean |
resemblesPattern(java.lang.String pattern,
int pos)
Return true if the given position, in the given pattern, appears to be the start of a UnicodeSet pattern. |
void |
retain(int c)
Retain the specified character from this set if it is present. |
void |
retain(int start,
int end)
Retain only the elements in this set that are contained in the specified range. |
void |
retainAll(UnicodeSet c)
Retains only the elements in this set that are contained in the specified set. |
void |
set(int start,
int end)
Make this object represent the range start - end . |
void |
set(UnicodeSet other)
Make this object represent the same set as other . |
int |
size()
Returns the number of elements in this set (its cardinality), n, where 0 <= n <= 65536 . |
java.lang.String |
toPattern(boolean escapeUnprintable)
Returns a string representation of this set. |
java.lang.String |
toString()
Return a programmer-readable string representation of this object. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int MIN_VALUE
public static final int MAX_VALUE
Constructor Detail |
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(java.lang.String pattern)
pattern
- a string specifying what characters are in the setjava.lang.IllegalArgumentException
- if the pattern contains
a syntax error.public UnicodeSet(java.lang.String pattern, boolean ignoreWhitespace)
pattern
- a string specifying what characters are in the setignoreWhitespace
- if true, ignore characters for which
Character.isWhitespace() returns truejava.lang.IllegalArgumentException
- if the pattern contains
a syntax error.public UnicodeSet(java.lang.String pattern, java.text.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 UnicodeSetsjava.lang.IllegalArgumentException
- if the pattern
contains a syntax error.public UnicodeSet(int category)
category
- an integer indicating the character category as
returned by java.lang.Character.getType()
. Note
that this is different from the UCharacterCategory
codes.java.lang.IllegalArgumentException
- if the given
category is invalid.Method Detail |
public java.lang.Object clone()
clone
in class java.lang.Object
public void set(int start, int end)
start - end
.
If end > start
then this object is set to an
an empty range.start
- first character in the set, inclusivepublic void set(UnicodeSet other)
other
.other
- a UnicodeSet
whose value will be
copied to this objectpublic final void applyPattern(java.lang.String pattern)
pattern
- a string specifying what characters are in the setjava.lang.IllegalArgumentException
- if the pattern
contains a syntax error.public void applyPattern(java.lang.String pattern, boolean ignoreWhitespace)
pattern
- a string specifying what characters are in the setignoreWhitespace
- if true then characters for which
Character.isWhitespace() returns true are ignoredjava.lang.IllegalArgumentException
- if the pattern
contains a syntax error.public static boolean resemblesPattern(java.lang.String pattern, int pos)
public java.lang.String toPattern(boolean escapeUnprintable)
toPattern
in class UnicodeFilter
com.ibm.text.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 java.lang.StringBuffer _generatePattern(java.lang.StringBuffer result, boolean escapeUnprintable)
public int size()
0 <=
n <= 65536
.public boolean isEmpty()
public boolean contains(int start, int end)
end > start
then the results of this method
are undefined.public boolean matchesIndexValue(int v)
matchesIndexValue
in class UnicodeFilter
public int matches(Replaceable text, int[] offset, int limit, boolean incremental)
matches
in class UnicodeFilter
com.ibm.text.UnicodeMatcher
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.public UnicodeSet getMatchSet(UnicodeSet toUnionTo)
getMatchSet
in class UnicodeFilter
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 boolean contains(int c)
contains
in class UnicodeFilter
public void add(int start, int end)
end > start
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 final void add(int c)
public void retain(int start, int end)
end > start
then an empty range is
retained, leaving the set empty.start
- first character, inclusive, of range to be retained
to this set.end
- last character, inclusive, of range to be retained
to this set.public final void retain(int c)
public void remove(int start, int end)
end > start
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 void remove(int c)
public void complement(int start, int end)
end > start
then an empty range is complemented, 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 void complement(int c)
public void complement()
complement(MIN_VALUE, MAX_VALUE)
.public boolean containsAll(UnicodeSet c)
c
- set to be checked for containment in this set.public void addAll(UnicodeSet c)
c
- set whose elements are to be added to this set.public void retainAll(UnicodeSet c)
c
- set that defines which elements this set will retain.public void removeAll(UnicodeSet c)
c
- set that defines which elements will be removed from
this set.public void complementAll(UnicodeSet c)
c
- set that defines which elements will be complemented from
this set.public void 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 void compact()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- Object to be compared for equality with this set.public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |