sl@0: /* sl@0: *************************************************************************** sl@0: * Copyright (C) 1999-2005, International Business Machines Corporation sl@0: * and others. All Rights Reserved. sl@0: *************************************************************************** sl@0: * Date Name Description sl@0: * 10/20/99 alan Creation. sl@0: *************************************************************************** sl@0: */ sl@0: sl@0: #ifndef UNICODESET_H sl@0: #define UNICODESET_H sl@0: sl@0: #include "unicode/unifilt.h" sl@0: #include "unicode/unistr.h" sl@0: #include "unicode/uset.h" sl@0: sl@0: /** sl@0: * \file sl@0: * \brief C++ API: Unicode Set sl@0: */ sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: class ParsePosition; sl@0: class SymbolTable; sl@0: class UVector; sl@0: class RuleCharacterIterator; sl@0: sl@0: /** sl@0: * A mutable set of Unicode characters and multicharacter strings. Objects of this class sl@0: * represent character classes used in regular expressions. sl@0: * A character specifies a subset of Unicode code points. Legal sl@0: * code points are U+0000 to U+10FFFF, inclusive. sl@0: * sl@0: *

The UnicodeSet class is not designed to be subclassed. sl@0: * sl@0: *

UnicodeSet supports two APIs. The first is the sl@0: * operand API that allows the caller to modify the value of sl@0: * a UnicodeSet object. It conforms to Java 2's sl@0: * java.util.Set interface, although sl@0: * UnicodeSet does not actually implement that sl@0: * interface. All methods of Set are supported, with the sl@0: * modification that they take a character range or single character sl@0: * instead of an Object, and they take a sl@0: * UnicodeSet instead of a Collection. The sl@0: * operand API may be thought of in terms of boolean logic: a boolean sl@0: * OR is implemented by add, a boolean AND is implemented sl@0: * by retain, a boolean XOR is implemented by sl@0: * complement taking an argument, and a boolean NOT is sl@0: * implemented by complement with no argument. In terms sl@0: * of traditional set theory function names, add is a sl@0: * union, retain is an intersection, remove sl@0: * is an asymmetric difference, and complement with no sl@0: * argument is a set complement with respect to the superset range sl@0: * MIN_VALUE-MAX_VALUE sl@0: * sl@0: *

The second API is the sl@0: * applyPattern()/toPattern() API from the sl@0: * java.text.Format-derived classes. Unlike the sl@0: * methods that add characters, add categories, and control the logic sl@0: * of the set, the method applyPattern() sets all sl@0: * attributes of a UnicodeSet at once, based on a sl@0: * string pattern. sl@0: * sl@0: *

Pattern syntax

sl@0: * sl@0: * Patterns are accepted by the constructors and the sl@0: * applyPattern() methods and returned by the sl@0: * toPattern() method. These patterns follow a syntax sl@0: * similar to that employed by version 8 regular expression character sl@0: * classes. Here are some simple examples: sl@0: * sl@0: * \htmlonly
\endhtmlonly sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: *
[]No characters
[a]The character 'a'
[ae]The characters 'a' and 'e'
[a-e]The characters 'a' through 'e' inclusive, in Unicode code sl@0: * point order
[\\u4E01]The character U+4E01
[a{ab}{ac}]The character 'a' and the multicharacter strings "ab" and sl@0: * "ac"
[\\p{Lu}]All characters in the general category Uppercase Letter
sl@0: * \htmlonly
\endhtmlonly sl@0: * sl@0: * Any character may be preceded by a backslash in order to remove any special sl@0: * meaning. White space characters, as defined by UCharacter.isWhitespace(), are sl@0: * ignored, unless they are escaped. sl@0: * sl@0: *

Property patterns specify a set of characters having a certain sl@0: * property as defined by the Unicode standard. Both the POSIX-like sl@0: * "[:Lu:]" and the Perl-like syntax "\\p{Lu}" are recognized. For a sl@0: * complete list of supported property patterns, see the User's Guide sl@0: * for UnicodeSet at sl@0: * sl@0: * http://icu.sourceforge.net/userguide/unicodeSet.html. sl@0: * Actual determination of property data is defined by the underlying sl@0: * Unicode database as implemented by UCharacter. sl@0: * sl@0: *

Patterns specify individual characters, ranges of characters, and sl@0: * Unicode property sets. When elements are concatenated, they sl@0: * specify their union. To complement a set, place a '^' immediately sl@0: * after the opening '['. Property patterns are inverted by modifying sl@0: * their delimiters; "[:^foo]" and "\\P{foo}". In any other location, sl@0: * '^' has no special meaning. sl@0: * sl@0: *

Ranges are indicated by placing two a '-' between two sl@0: * characters, as in "a-z". This specifies the range of all sl@0: * characters from the left to the right, in Unicode order. If the sl@0: * left character is greater than or equal to the sl@0: * right character it is a syntax error. If a '-' occurs as the first sl@0: * character after the opening '[' or '[^', or if it occurs as the sl@0: * last character before the closing ']', then it is taken as a sl@0: * literal. Thus "[a\-b]", "[-ab]", and "[ab-]" all indicate the same sl@0: * set of three characters, 'a', 'b', and '-'. sl@0: * sl@0: *

Sets may be intersected using the '&' operator or the asymmetric sl@0: * set difference may be taken using the '-' operator, for example, sl@0: * "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters sl@0: * with values less than 4096. Operators ('&' and '|') have equal sl@0: * precedence and bind left-to-right. Thus sl@0: * "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to sl@0: * "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]". This only really matters for sl@0: * difference; intersection is commutative. sl@0: * sl@0: * sl@0: *
[a]The set containing 'a' sl@0: *
[a-z]The set containing 'a' sl@0: * through 'z' and all letters in between, in Unicode order sl@0: *
[^a-z]The set containing sl@0: * all characters but 'a' through 'z', sl@0: * that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF sl@0: *
[[pat1][pat2]] sl@0: * The union of sets specified by pat1 and pat2 sl@0: *
[[pat1]&[pat2]] sl@0: * The intersection of sets specified by pat1 and pat2 sl@0: *
[[pat1]-[pat2]] sl@0: * The asymmetric difference of sets specified by pat1 and sl@0: * pat2 sl@0: *
[:Lu:] or \\p{Lu} sl@0: * The set of characters having the specified sl@0: * Unicode property; in sl@0: * this case, Unicode uppercase letters sl@0: *
[:^Lu:] or \\P{Lu} sl@0: * The set of characters not having the given sl@0: * Unicode property sl@0: *
sl@0: * sl@0: *

Warning: you cannot add an empty string ("") to a UnicodeSet.

sl@0: * sl@0: *

Formal syntax

sl@0: * sl@0: * \htmlonly
\endhtmlonly sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: *
pattern :=  ('[' '^'? item* ']') | sl@0: * property
item :=  char | (char '-' char) | pattern-expr
sl@0: *
pattern-expr :=  pattern | pattern-expr pattern | sl@0: * pattern-expr op pattern
sl@0: *
op :=  '&' | '-'
sl@0: *
special :=  '[' | ']' | '-'
sl@0: *
char :=  any character that is not special
sl@0: * | ('\'
any character)
sl@0: * | ('\\u' hex hex hex hex)
sl@0: *
hex :=  any character for which sl@0: * Character.digit(c, 16) sl@0: * returns a non-negative result
property :=  a Unicode property set pattern
sl@0: *
sl@0: * sl@0: * sl@0: * sl@0: * sl@0: *
Legend: sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: * sl@0: *
a := b  a may be replaced by b
a?zero or one instance of a
sl@0: *
a*one or more instances of a
sl@0: *
a | beither a or b
sl@0: *
'a'the literal string between the quotes
sl@0: *
sl@0: * \htmlonly
\endhtmlonly sl@0: * sl@0: * @author Alan Liu sl@0: * @stable ICU 2.0 sl@0: */ sl@0: class U_COMMON_API UnicodeSet : public UnicodeFilter { sl@0: sl@0: int32_t len; // length of list used; 0 <= len <= capacity sl@0: int32_t capacity; // capacity of list sl@0: int32_t bufferCapacity; // capacity of buffer sl@0: UChar32* list; // MUST be terminated with HIGH sl@0: UChar32* buffer; // internal buffer, may be NULL sl@0: sl@0: UVector* strings; // maintained in sorted order sl@0: sl@0: /** sl@0: * The pattern representation of this set. This may not be the sl@0: * most economical pattern. It is the pattern supplied to sl@0: * applyPattern(), with variables substituted and whitespace sl@0: * removed. For sets constructed without applyPattern(), or sl@0: * modified using the non-pattern API, this string will be empty, sl@0: * indicating that toPattern() must generate a pattern sl@0: * representation from the inversion list. sl@0: */ sl@0: UnicodeString pat; sl@0: sl@0: public: sl@0: sl@0: enum { sl@0: /** sl@0: * Minimum value that can be stored in a UnicodeSet. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: MIN_VALUE = 0, sl@0: sl@0: /** sl@0: * Maximum value that can be stored in a UnicodeSet. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: MAX_VALUE = 0x10ffff sl@0: }; sl@0: sl@0: //---------------------------------------------------------------- sl@0: // Constructors &c sl@0: //---------------------------------------------------------------- sl@0: sl@0: public: sl@0: sl@0: /** sl@0: * Constructs an empty set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeSet(); sl@0: sl@0: /** sl@0: * Constructs a set containing the given range. If end > sl@0: * start then an empty set is created. sl@0: * sl@0: * @param start first character, inclusive, of range sl@0: * @param end last character, inclusive, of range sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet(UChar32 start, UChar32 end); sl@0: sl@0: /** sl@0: * Constructs a set from the given pattern. See the class sl@0: * description for the syntax of the pattern language. sl@0: * @param pattern a string specifying what characters are in the set sl@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern sl@0: * contains a syntax error. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeSet(const UnicodeString& pattern, sl@0: UErrorCode& status); sl@0: sl@0: /** sl@0: * Constructs a set from the given pattern. See the class sl@0: * description for the syntax of the pattern language. sl@0: * @param pattern a string specifying what characters are in the set sl@0: * @param options bitmask for options to apply to the pattern. sl@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. sl@0: * @param symbols a symbol table mapping variable names to values sl@0: * and stand-in characters to UnicodeSets; may be NULL sl@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern sl@0: * contains a syntax error. sl@0: * @internal sl@0: */ sl@0: UnicodeSet(const UnicodeString& pattern, sl@0: uint32_t options, sl@0: const SymbolTable* symbols, sl@0: UErrorCode& status); sl@0: sl@0: /** sl@0: * Constructs a set from the given pattern. See the class description sl@0: * for the syntax of the pattern language. sl@0: * @param pattern a string specifying what characters are in the set sl@0: * @param pos on input, the position in pattern at which to start parsing. sl@0: * On output, the position after the last character parsed. sl@0: * @param options bitmask for options to apply to the pattern. sl@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. sl@0: * @param symbols a symbol table mapping variable names to values sl@0: * and stand-in characters to UnicodeSets; may be NULL sl@0: * @param status input-output error code sl@0: * @stable ICU 2.8 sl@0: */ sl@0: UnicodeSet(const UnicodeString& pattern, ParsePosition& pos, sl@0: uint32_t options, sl@0: const SymbolTable* symbols, sl@0: UErrorCode& status); sl@0: sl@0: #ifdef U_USE_UNICODESET_DEPRECATES sl@0: /** sl@0: * Obsolete: Constructs a set from the given Unicode character category. sl@0: * @param category an integer indicating the character category as sl@0: * defined in uchar.h. sl@0: * @obsolete ICU 2.6. Use a pattern with the category instead since this API will be removed in that release. sl@0: */ sl@0: UnicodeSet(int8_t category, UErrorCode& status); sl@0: #endif sl@0: sl@0: /** sl@0: * Constructs a set that is identical to the given UnicodeSet. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeSet(const UnicodeSet& o); sl@0: sl@0: /** sl@0: * Destructs the set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual ~UnicodeSet(); sl@0: sl@0: /** sl@0: * Assigns this object to be a copy of another. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeSet& operator=(const UnicodeSet& o); sl@0: sl@0: /** sl@0: * Compares the specified object with this set for equality. Returns sl@0: * true if the two sets sl@0: * have the same size, and every member of the specified set is sl@0: * contained in this set (or equivalently, every member of this set is sl@0: * contained in the specified set). sl@0: * sl@0: * @param o set to be compared for equality with this set. sl@0: * @return true if the specified set is equal to this set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UBool operator==(const UnicodeSet& o) const; sl@0: sl@0: /** sl@0: * Compares the specified object with this set for equality. Returns sl@0: * true if the specified set is not equal to this set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UBool operator!=(const UnicodeSet& o) const; sl@0: sl@0: /** sl@0: * Returns a copy of this object. All UnicodeFunctor objects have sl@0: * to support cloning in order to allow classes using sl@0: * UnicodeFunctors, such as Transliterator, to implement cloning. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeFunctor* clone() const; sl@0: sl@0: /** sl@0: * Returns the hash code value for this set. sl@0: * sl@0: * @return the hash code value for this set. sl@0: * @see Object#hashCode() sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual int32_t hashCode(void) const; sl@0: sl@0: //---------------------------------------------------------------- sl@0: // Public API sl@0: //---------------------------------------------------------------- sl@0: sl@0: /** sl@0: * Make this object represent the range start - end. sl@0: * If end > start then this object is set to an sl@0: * an empty range. sl@0: * sl@0: * @param start first character in the set, inclusive sl@0: * @param end last character in the set, inclusive sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& set(UChar32 start, UChar32 end); sl@0: sl@0: /** sl@0: * Return true if the given position, in the given pattern, appears sl@0: * to be the start of a UnicodeSet pattern. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: static UBool resemblesPattern(const UnicodeString& pattern, sl@0: int32_t pos); sl@0: sl@0: /** sl@0: * Modifies this set to represent the set specified by the given sl@0: * pattern, optionally ignoring white space. See the class sl@0: * description for the syntax of the pattern language. sl@0: * @param pattern a string specifying what characters are in the set sl@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern sl@0: * contains a syntax error. sl@0: * Empties the set passed before applying the pattern. sl@0: * @return a reference to this sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeSet& applyPattern(const UnicodeString& pattern, sl@0: UErrorCode& status); sl@0: sl@0: /** sl@0: * Modifies this set to represent the set specified by the given sl@0: * pattern, optionally ignoring white space. See the class sl@0: * description for the syntax of the pattern language. sl@0: * @param pattern a string specifying what characters are in the set sl@0: * @param options bitmask for options to apply to the pattern. sl@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. sl@0: * @param symbols a symbol table mapping variable names to sl@0: * values and stand-ins to UnicodeSets; may be NULL sl@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern sl@0: * contains a syntax error. sl@0: * Empties the set passed before applying the pattern. sl@0: * @return a reference to this sl@0: * @internal sl@0: */ sl@0: UnicodeSet& applyPattern(const UnicodeString& pattern, sl@0: uint32_t options, sl@0: const SymbolTable* symbols, sl@0: UErrorCode& status); sl@0: sl@0: /** sl@0: * Parses the given pattern, starting at the given position. The sl@0: * character at pattern.charAt(pos.getIndex()) must be '[', or the sl@0: * parse fails. Parsing continues until the corresponding closing sl@0: * ']'. If a syntax error is encountered between the opening and sl@0: * closing brace, the parse fails. Upon return from a successful sl@0: * parse, the ParsePosition is updated to point to the character sl@0: * following the closing ']', and a StringBuffer containing a sl@0: * pairs list for the parsed pattern is returned. This method calls sl@0: * itself recursively to parse embedded subpatterns. sl@0: * Empties the set passed before applying the pattern. sl@0: * sl@0: * @param pattern the string containing the pattern to be parsed. sl@0: * The portion of the string from pos.getIndex(), which must be a sl@0: * '[', to the corresponding closing ']', is parsed. sl@0: * @param pos upon entry, the position at which to being parsing. sl@0: * The character at pattern.charAt(pos.getIndex()) must be a '['. sl@0: * Upon return from a successful parse, pos.getIndex() is either sl@0: * the character after the closing ']' of the parsed pattern, or sl@0: * pattern.length() if the closing ']' is the last character of sl@0: * the pattern string. sl@0: * @param options bitmask for options to apply to the pattern. sl@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. sl@0: * @param symbols a symbol table mapping variable names to sl@0: * values and stand-ins to UnicodeSets; may be NULL sl@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern sl@0: * contains a syntax error. sl@0: * @return a reference to this sl@0: * @stable ICU 2.8 sl@0: */ sl@0: UnicodeSet& applyPattern(const UnicodeString& pattern, sl@0: ParsePosition& pos, sl@0: uint32_t options, sl@0: const SymbolTable* symbols, sl@0: UErrorCode& status); sl@0: sl@0: /** sl@0: * Returns a string representation of this set. If the result of sl@0: * calling this function is passed to a UnicodeSet constructor, it sl@0: * will produce another set that is equal to this one. sl@0: * @param result the string to receive the rules. Previous sl@0: * contents will be deleted. sl@0: * @param escapeUnprintable if TRUE then convert unprintable sl@0: * character to their hex escape representations, \\uxxxx or sl@0: * \\Uxxxxxxxx. Unprintable characters are those other than sl@0: * U+000A, U+0020..U+007E. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeString& toPattern(UnicodeString& result, sl@0: UBool escapeUnprintable = FALSE) const; sl@0: sl@0: /** sl@0: * Modifies this set to contain those code points which have the given value sl@0: * for the given binary or enumerated property, as returned by sl@0: * u_getIntPropertyValue. Prior contents of this set are lost. sl@0: * sl@0: * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1 sl@0: * or UCHAR_INT_START..UCHAR_INT_LIMIT-1 sl@0: * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1. sl@0: * sl@0: * @param value a value in the range u_getIntPropertyMinValue(prop).. sl@0: * u_getIntPropertyMaxValue(prop), with one exception. If prop is sl@0: * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but sl@0: * rather a mask value produced by U_GET_GC_MASK(). This allows grouped sl@0: * categories such as [:L:] to be represented. sl@0: * sl@0: * @param ec error code input/output parameter sl@0: * sl@0: * @return a reference to this set sl@0: * sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& applyIntPropertyValue(UProperty prop, sl@0: int32_t value, sl@0: UErrorCode& ec); sl@0: sl@0: /** sl@0: * Modifies this set to contain those code points which have the sl@0: * given value for the given property. Prior contents of this sl@0: * set are lost. sl@0: * sl@0: * @param prop a property alias, either short or long. The name is matched sl@0: * loosely. See PropertyAliases.txt for names and a description of loose sl@0: * matching. If the value string is empty, then this string is interpreted sl@0: * as either a General_Category value alias, a Script value alias, a binary sl@0: * property alias, or a special ID. Special IDs are matched loosely and sl@0: * correspond to the following sets: sl@0: * sl@0: * "ANY" = [\\u0000-\\U0010FFFF], sl@0: * "ASCII" = [\\u0000-\\u007F], sl@0: * "Assigned" = [:^Cn:]. sl@0: * sl@0: * @param value a value alias, either short or long. The name is matched sl@0: * loosely. See PropertyValueAliases.txt for names and a description of sl@0: * loose matching. In addition to aliases listed, numeric values and sl@0: * canonical combining classes may be expressed numerically, e.g., ("nv", sl@0: * "0.5") or ("ccc", "220"). The value string may also be empty. sl@0: * sl@0: * @param ec error code input/output parameter sl@0: * sl@0: * @return a reference to this set sl@0: * sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& applyPropertyAlias(const UnicodeString& prop, sl@0: const UnicodeString& value, sl@0: UErrorCode& ec); sl@0: sl@0: /** sl@0: * Returns the number of elements in this set (its cardinality). sl@0: * Note than the elements of a set may include both individual sl@0: * codepoints and strings. sl@0: * sl@0: * @return the number of elements in this set (its cardinality). sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual int32_t size(void) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains no elements. sl@0: * sl@0: * @return true if this set contains no elements. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UBool isEmpty(void) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains the given character. sl@0: * @param c character to be checked for containment sl@0: * @return true if the test condition is met sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UBool contains(UChar32 c) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains every character sl@0: * of the given range. sl@0: * @param start first character, inclusive, of the range sl@0: * @param end last character, inclusive, of the range sl@0: * @return true if the test condition is met sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UBool contains(UChar32 start, UChar32 end) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains the given sl@0: * multicharacter string. sl@0: * @param s string to be checked for containment sl@0: * @return true if this set contains the specified string sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UBool contains(const UnicodeString& s) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains all the characters and strings sl@0: * of the given set. sl@0: * @param c set to be checked for containment sl@0: * @return true if the test condition is met sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UBool containsAll(const UnicodeSet& c) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains all the characters sl@0: * of the given string. sl@0: * @param s string containing characters to be checked for containment sl@0: * @return true if the test condition is met sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UBool containsAll(const UnicodeString& s) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains none of the characters sl@0: * of the given range. sl@0: * @param start first character, inclusive, of the range sl@0: * @param end last character, inclusive, of the range sl@0: * @return true if the test condition is met sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UBool containsNone(UChar32 start, UChar32 end) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains none of the characters and strings sl@0: * of the given set. sl@0: * @param c set to be checked for containment sl@0: * @return true if the test condition is met sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UBool containsNone(const UnicodeSet& c) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains none of the characters sl@0: * of the given string. sl@0: * @param s string containing characters to be checked for containment sl@0: * @return true if the test condition is met sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UBool containsNone(const UnicodeString& s) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains one or more of the characters sl@0: * in the given range. sl@0: * @param start first character, inclusive, of the range sl@0: * @param end last character, inclusive, of the range sl@0: * @return true if the condition is met sl@0: * @stable ICU 2.4 sl@0: */ sl@0: inline UBool containsSome(UChar32 start, UChar32 end) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains one or more of the characters sl@0: * and strings of the given set. sl@0: * @param s The set to be checked for containment sl@0: * @return true if the condition is met sl@0: * @stable ICU 2.4 sl@0: */ sl@0: inline UBool containsSome(const UnicodeSet& s) const; sl@0: sl@0: /** sl@0: * Returns true if this set contains one or more of the characters sl@0: * of the given string. sl@0: * @param s string containing characters to be checked for containment sl@0: * @return true if the condition is met sl@0: * @stable ICU 2.4 sl@0: */ sl@0: inline UBool containsSome(const UnicodeString& s) const; sl@0: sl@0: /** sl@0: * Implement UnicodeMatcher::matches() sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UMatchDegree matches(const Replaceable& text, sl@0: int32_t& offset, sl@0: int32_t limit, sl@0: UBool incremental); sl@0: sl@0: private: sl@0: /** sl@0: * Returns the longest match for s in text at the given position. sl@0: * If limit > start then match forward from start+1 to limit sl@0: * matching all characters except s.charAt(0). If limit < start, sl@0: * go backward starting from start-1 matching all characters sl@0: * except s.charAt(s.length()-1). This method assumes that the sl@0: * first character, text.charAt(start), matches s, so it does not sl@0: * check it. sl@0: * @param text the text to match sl@0: * @param start the first character to match. In the forward sl@0: * direction, text.charAt(start) is matched against s.charAt(0). sl@0: * In the reverse direction, it is matched against sl@0: * s.charAt(s.length()-1). sl@0: * @param limit the limit offset for matching, either last+1 in sl@0: * the forward direction, or last-1 in the reverse direction, sl@0: * where last is the index of the last character to match. sl@0: * @return If part of s matches up to the limit, return |limit - sl@0: * start|. If all of s matches before reaching the limit, return sl@0: * s.length(). If there is a mismatch between s and text, return sl@0: * 0 sl@0: */ sl@0: static int32_t matchRest(const Replaceable& text, sl@0: int32_t start, int32_t limit, sl@0: const UnicodeString& s); sl@0: sl@0: /** sl@0: * Returns the smallest value i such that c < list[i]. Caller sl@0: * must ensure that c is a legal value or this method will enter sl@0: * an infinite loop. This method performs a binary search. sl@0: * @param c a character in the range MIN_VALUE..MAX_VALUE sl@0: * inclusive sl@0: * @return the smallest integer i in the range 0..len-1, sl@0: * inclusive, such that c < list[i] sl@0: */ sl@0: int32_t findCodePoint(UChar32 c) const; sl@0: sl@0: public: sl@0: sl@0: /** sl@0: * Implementation of UnicodeMatcher API. Union the set of all sl@0: * characters that may be matched by this object into the given sl@0: * set. sl@0: * @param toUnionTo the set into which to union the source characters sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual void addMatchSetTo(UnicodeSet& toUnionTo) const; sl@0: sl@0: /** sl@0: * Returns the index of the given character within this set, where sl@0: * the set is ordered by ascending code point. If the character sl@0: * is not in this set, return -1. The inverse of this method is sl@0: * charAt(). sl@0: * @return an index from 0..size()-1, or -1 sl@0: * @stable ICU 2.4 sl@0: */ sl@0: int32_t indexOf(UChar32 c) const; sl@0: sl@0: /** sl@0: * Returns the character at the given index within this set, where sl@0: * the set is ordered by ascending code point. If the index is sl@0: * out of range, return (UChar32)-1. The inverse of this method is sl@0: * indexOf(). sl@0: * @param index an index from 0..size()-1 sl@0: * @return the character at the given index, or (UChar32)-1. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UChar32 charAt(int32_t index) const; sl@0: sl@0: /** sl@0: * Adds the specified range to this set if it is not already sl@0: * present. If this set already contains the specified range, sl@0: * the call leaves this set unchanged. If end > start sl@0: * then an empty range is added, leaving the set unchanged. sl@0: * This is equivalent to a boolean logic OR, or a set UNION. sl@0: * sl@0: * @param start first character, inclusive, of range to be added sl@0: * to this set. sl@0: * @param end last character, inclusive, of range to be added sl@0: * to this set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeSet& add(UChar32 start, UChar32 end); sl@0: sl@0: /** sl@0: * Adds the specified character to this set if it is not already sl@0: * present. If this set already contains the specified character, sl@0: * the call leaves this set unchanged. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeSet& add(UChar32 c); sl@0: sl@0: /** sl@0: * Adds the specified multicharacter to this set if it is not already sl@0: * present. If this set already contains the multicharacter, sl@0: * the call leaves this set unchanged. sl@0: * Thus "ch" => {"ch"} sl@0: *
Warning: you cannot add an empty string ("") to a UnicodeSet. sl@0: * @param s the source string sl@0: * @return this object, for chaining sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& add(const UnicodeString& s); sl@0: sl@0: private: sl@0: /** sl@0: * @return a code point IF the string consists of a single one. sl@0: * otherwise returns -1. sl@0: * @param string to test sl@0: */ sl@0: static int32_t getSingleCP(const UnicodeString& s); sl@0: sl@0: void _add(const UnicodeString& s); sl@0: sl@0: public: sl@0: /** sl@0: * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"} sl@0: * If this set already any particular character, it has no effect on that character. sl@0: * @param s the source string sl@0: * @return this object, for chaining sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& addAll(const UnicodeString& s); sl@0: sl@0: /** sl@0: * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"} sl@0: * If this set already any particular character, it has no effect on that character. sl@0: * @param s the source string sl@0: * @return this object, for chaining sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& retainAll(const UnicodeString& s); sl@0: sl@0: /** sl@0: * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"} sl@0: * If this set already any particular character, it has no effect on that character. sl@0: * @param s the source string sl@0: * @return this object, for chaining sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& complementAll(const UnicodeString& s); sl@0: sl@0: /** sl@0: * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"} sl@0: * If this set already any particular character, it has no effect on that character. sl@0: * @param s the source string sl@0: * @return this object, for chaining sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& removeAll(const UnicodeString& s); sl@0: sl@0: /** sl@0: * Makes a set from a multicharacter string. Thus "ch" => {"ch"} sl@0: *
Warning: you cannot add an empty string ("") to a UnicodeSet. sl@0: * @param s the source string sl@0: * @return a newly created set containing the given string. sl@0: * The caller owns the return object and is responsible for deleting it. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: static UnicodeSet* U_EXPORT2 createFrom(const UnicodeString& s); sl@0: sl@0: sl@0: /** sl@0: * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"} sl@0: * @param s the source string sl@0: * @return a newly created set containing the given characters sl@0: * The caller owns the return object and is responsible for deleting it. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: static UnicodeSet* U_EXPORT2 createFromAll(const UnicodeString& s); sl@0: sl@0: /** sl@0: * Retain only the elements in this set that are contained in the sl@0: * specified range. If end > start then an empty range is sl@0: * retained, leaving the set empty. This is equivalent to sl@0: * a boolean logic AND, or a set INTERSECTION. sl@0: * sl@0: * @param start first character, inclusive, of range to be retained sl@0: * to this set. sl@0: * @param end last character, inclusive, of range to be retained sl@0: * to this set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeSet& retain(UChar32 start, UChar32 end); sl@0: sl@0: sl@0: /** sl@0: * Retain the specified character from this set if it is present. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeSet& retain(UChar32 c); sl@0: sl@0: /** sl@0: * Removes the specified range from this set if it is present. sl@0: * The set will not contain the specified range once the call sl@0: * returns. If end > start then an empty range is sl@0: * removed, leaving the set unchanged. sl@0: * sl@0: * @param start first character, inclusive, of range to be removed sl@0: * from this set. sl@0: * @param end last character, inclusive, of range to be removed sl@0: * from this set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeSet& remove(UChar32 start, UChar32 end); sl@0: sl@0: /** sl@0: * Removes the specified character from this set if it is present. sl@0: * The set will not contain the specified range once the call sl@0: * returns. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeSet& remove(UChar32 c); sl@0: sl@0: /** sl@0: * Removes the specified string from this set if it is present. sl@0: * The set will not contain the specified character once the call sl@0: * returns. sl@0: * @param s the source string sl@0: * @return this object, for chaining sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& remove(const UnicodeString& s); sl@0: sl@0: /** sl@0: * Inverts this set. This operation modifies this set so that sl@0: * its value is its complement. This is equivalent to sl@0: * complement(MIN_VALUE, MAX_VALUE). sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeSet& complement(void); sl@0: sl@0: /** sl@0: * Complements the specified range in this set. Any character in sl@0: * the range will be removed if it is in this set, or will be sl@0: * added if it is not in this set. If end > start sl@0: * then an empty range is complemented, leaving the set unchanged. sl@0: * This is equivalent to a boolean logic XOR. sl@0: * sl@0: * @param start first character, inclusive, of range to be removed sl@0: * from this set. sl@0: * @param end last character, inclusive, of range to be removed sl@0: * from this set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeSet& complement(UChar32 start, UChar32 end); sl@0: sl@0: /** sl@0: * Complements the specified character in this set. The character sl@0: * will be removed if it is in this set, or will be added if it is sl@0: * not in this set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: UnicodeSet& complement(UChar32 c); sl@0: sl@0: /** sl@0: * Complement the specified string in this set. sl@0: * The set will not contain the specified string once the call sl@0: * returns. sl@0: *
Warning: you cannot add an empty string ("") to a UnicodeSet. sl@0: * @param s the string to complement sl@0: * @return this object, for chaining sl@0: * @stable ICU 2.4 sl@0: */ sl@0: UnicodeSet& complement(const UnicodeString& s); sl@0: sl@0: /** sl@0: * Adds all of the elements in the specified set to this set if sl@0: * they're not already present. This operation effectively sl@0: * modifies this set so that its value is the union of the two sl@0: * sets. The behavior of this operation is unspecified if the specified sl@0: * collection is modified while the operation is in progress. sl@0: * sl@0: * @param c set whose elements are to be added to this set. sl@0: * @see #add(char, char) sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeSet& addAll(const UnicodeSet& c); sl@0: sl@0: /** sl@0: * Retains only the elements in this set that are contained in the sl@0: * specified set. In other words, removes from this set all of sl@0: * its elements that are not contained in the specified set. This sl@0: * operation effectively modifies this set so that its value is sl@0: * the intersection of the two sets. sl@0: * sl@0: * @param c set that defines which elements this set will retain. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeSet& retainAll(const UnicodeSet& c); sl@0: sl@0: /** sl@0: * Removes from this set all of its elements that are contained in the sl@0: * specified set. This operation effectively modifies this sl@0: * set so that its value is the asymmetric set difference of sl@0: * the two sets. sl@0: * sl@0: * @param c set that defines which elements will be removed from sl@0: * this set. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeSet& removeAll(const UnicodeSet& c); sl@0: sl@0: /** sl@0: * Complements in this set all elements contained in the specified sl@0: * set. Any character in the other set will be removed if it is sl@0: * in this set, or will be added if it is not in this set. sl@0: * sl@0: * @param c set that defines which elements will be xor'ed from sl@0: * this set. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UnicodeSet& complementAll(const UnicodeSet& c); sl@0: sl@0: /** sl@0: * Removes all of the elements from this set. This set will be sl@0: * empty after this call returns. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: virtual UnicodeSet& clear(void); sl@0: sl@0: /** sl@0: * Close this set over the given attribute. For the attribute sl@0: * USET_CASE, the result is to modify this set so that: sl@0: * sl@0: * 1. For each character or string 'a' in this set, all strings or sl@0: * characters 'b' such that foldCase(a) == foldCase(b) are added sl@0: * to this set. sl@0: * sl@0: * 2. For each string 'e' in the resulting set, if e != sl@0: * foldCase(e), 'e' will be removed. sl@0: * sl@0: * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}] sl@0: * sl@0: * (Here foldCase(x) refers to the operation u_strFoldCase, and a sl@0: * == b denotes that the contents are the same, not pointer sl@0: * comparison.) sl@0: * sl@0: * @param attribute bitmask for attributes to close over. sl@0: * Currently only the USET_CASE bit is supported. Any undefined bits sl@0: * are ignored. sl@0: * @return a reference to this set. sl@0: * @internal sl@0: */ sl@0: UnicodeSet& closeOver(int32_t attribute); sl@0: sl@0: /** sl@0: * Iteration method that returns the number of ranges contained in sl@0: * this set. sl@0: * @see #getRangeStart sl@0: * @see #getRangeEnd sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual int32_t getRangeCount(void) const; sl@0: sl@0: /** sl@0: * Iteration method that returns the first character in the sl@0: * specified range of this set. sl@0: * @see #getRangeCount sl@0: * @see #getRangeEnd sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UChar32 getRangeStart(int32_t index) const; sl@0: sl@0: /** sl@0: * Iteration method that returns the last character in the sl@0: * specified range of this set. sl@0: * @see #getRangeStart sl@0: * @see #getRangeEnd sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UChar32 getRangeEnd(int32_t index) const; sl@0: sl@0: /** sl@0: * Serializes this set into an array of 16-bit integers. Serialization sl@0: * (currently) only records the characters in the set; multicharacter sl@0: * strings are ignored. sl@0: * sl@0: * The array has following format (each line is one 16-bit sl@0: * integer): sl@0: * sl@0: * length = (n+2*m) | (m!=0?0x8000:0) sl@0: * bmpLength = n; present if m!=0 sl@0: * bmp[0] sl@0: * bmp[1] sl@0: * ... sl@0: * bmp[n-1] sl@0: * supp-high[0] sl@0: * supp-low[0] sl@0: * supp-high[1] sl@0: * supp-low[1] sl@0: * ... sl@0: * supp-high[m-1] sl@0: * supp-low[m-1] sl@0: * sl@0: * The array starts with a header. After the header are n bmp sl@0: * code points, then m supplementary code points. Either n or m sl@0: * or both may be zero. n+2*m is always <= 0x7FFF. sl@0: * sl@0: * If there are no supplementary characters (if m==0) then the sl@0: * header is one 16-bit integer, 'length', with value n. sl@0: * sl@0: * If there are supplementary characters (if m!=0) then the header sl@0: * is two 16-bit integers. The first, 'length', has value sl@0: * (n+2*m)|0x8000. The second, 'bmpLength', has value n. sl@0: * sl@0: * After the header the code points are stored in ascending order. sl@0: * Supplementary code points are stored as most significant 16 sl@0: * bits followed by least significant 16 bits. sl@0: * sl@0: * @param dest pointer to buffer of destCapacity 16-bit integers. sl@0: * May be NULL only if destCapacity is zero. sl@0: * @param destCapacity size of dest, or zero. Must not be negative. sl@0: * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR sl@0: * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if sl@0: * n+2*m+(m!=0?2:1) > destCapacity. sl@0: * @return the total length of the serialized format, including sl@0: * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other sl@0: * than U_BUFFER_OVERFLOW_ERROR. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: int32_t serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const; sl@0: sl@0: /** sl@0: * Reallocate this objects internal structures to take up the least sl@0: * possible space, without changing this object's value. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UnicodeSet& compact(); sl@0: sl@0: /** sl@0: * Return the class ID for this class. This is useful only for sl@0: * comparing to a return value from getDynamicClassID(). For example: sl@0: *
sl@0:      * .      Base* polymorphic_pointer = createPolymorphicObject();
sl@0:      * .      if (polymorphic_pointer->getDynamicClassID() ==
sl@0:      * .          Derived::getStaticClassID()) ...
sl@0:      * 
sl@0: * @return The class ID for all objects of this class. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: static UClassID U_EXPORT2 getStaticClassID(void); sl@0: sl@0: /** sl@0: * Implement UnicodeFunctor API. sl@0: * sl@0: * @return The class ID for this object. All objects of a given sl@0: * class have the same class ID. Objects of other classes have sl@0: * different class IDs. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UClassID getDynamicClassID(void) const; sl@0: sl@0: private: sl@0: sl@0: // Private API for the USet API sl@0: sl@0: friend class USetAccess; sl@0: sl@0: int32_t getStringCount() const; sl@0: sl@0: const UnicodeString* getString(int32_t index) const; sl@0: sl@0: //---------------------------------------------------------------- sl@0: // RuleBasedTransliterator support sl@0: //---------------------------------------------------------------- sl@0: sl@0: private: sl@0: sl@0: /** sl@0: * Returns true if this set contains any character whose low byte sl@0: * is the given value. This is used by RuleBasedTransliterator for sl@0: * indexing. sl@0: */ sl@0: virtual UBool matchesIndexValue(uint8_t v) const; sl@0: sl@0: private: sl@0: sl@0: //---------------------------------------------------------------- sl@0: // Implementation: Pattern parsing sl@0: //---------------------------------------------------------------- sl@0: sl@0: void applyPattern(RuleCharacterIterator& chars, sl@0: const SymbolTable* symbols, sl@0: UnicodeString& rebuiltPat, sl@0: uint32_t options, sl@0: UErrorCode& ec); sl@0: sl@0: //---------------------------------------------------------------- sl@0: // Implementation: Utility methods sl@0: //---------------------------------------------------------------- sl@0: sl@0: void ensureCapacity(int32_t newLen); sl@0: sl@0: void ensureBufferCapacity(int32_t newLen); sl@0: sl@0: void swapBuffers(void); sl@0: sl@0: UBool allocateStrings(); sl@0: sl@0: UnicodeString& _toPattern(UnicodeString& result, sl@0: UBool escapeUnprintable) const; sl@0: sl@0: UnicodeString& _generatePattern(UnicodeString& result, sl@0: UBool escapeUnprintable) const; sl@0: sl@0: static void _appendToPat(UnicodeString& buf, const UnicodeString& s, UBool escapeUnprintable); sl@0: sl@0: static void _appendToPat(UnicodeString& buf, UChar32 c, UBool escapeUnprintable); sl@0: sl@0: //---------------------------------------------------------------- sl@0: // Implementation: Fundamental operators sl@0: //---------------------------------------------------------------- sl@0: sl@0: void exclusiveOr(const UChar32* other, int32_t otherLen, int8_t polarity); sl@0: sl@0: void add(const UChar32* other, int32_t otherLen, int8_t polarity); sl@0: sl@0: void retain(const UChar32* other, int32_t otherLen, int8_t polarity); sl@0: sl@0: /** sl@0: * Return true if the given position, in the given pattern, appears sl@0: * to be the start of a property set pattern [:foo:], \\p{foo}, or sl@0: * \\P{foo}, or \\N{name}. sl@0: */ sl@0: static UBool resemblesPropertyPattern(const UnicodeString& pattern, sl@0: int32_t pos); sl@0: sl@0: static UBool resemblesPropertyPattern(RuleCharacterIterator& chars, sl@0: int32_t iterOpts); sl@0: sl@0: /** sl@0: * Parse the given property pattern at the given parse position sl@0: * and set this UnicodeSet to the result. sl@0: * sl@0: * The original design document is out of date, but still useful. sl@0: * Ignore the property and value names: sl@0: * http://dev.icu-project.org/cgi-bin/viewcvs.cgi/~checkout~/icuhtml/design/unicodeset_properties.html sl@0: * sl@0: * Recognized syntax: sl@0: * sl@0: * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]" sl@0: * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P" sl@0: * \\N{name} - white space not allowed within "\\N" sl@0: * sl@0: * Other than the above restrictions, white space is ignored. Case sl@0: * is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading sl@0: * and trailing space is deleted, and internal runs of whitespace sl@0: * are collapsed to a single space. sl@0: * sl@0: * We support binary properties, enumerated properties, and the sl@0: * following non-enumerated properties: sl@0: * sl@0: * Numeric_Value sl@0: * Name sl@0: * Unicode_1_Name sl@0: * sl@0: * @param pattern the pattern string sl@0: * @param ppos on entry, the position at which to begin parsing. sl@0: * This should be one of the locations marked '^': sl@0: * sl@0: * [:blah:] \\p{blah} \\P{blah} \\N{name} sl@0: * ^ % ^ % ^ % ^ % sl@0: * sl@0: * On return, the position after the last character parsed, that is, sl@0: * the locations marked '%'. If the parse fails, ppos is returned sl@0: * unchanged. sl@0: * @return a reference to this. sl@0: */ sl@0: UnicodeSet& applyPropertyPattern(const UnicodeString& pattern, sl@0: ParsePosition& ppos, sl@0: UErrorCode &ec); sl@0: sl@0: void applyPropertyPattern(RuleCharacterIterator& chars, sl@0: UnicodeString& rebuiltPat, sl@0: UErrorCode& ec); sl@0: sl@0: /** sl@0: * A filter that returns TRUE if the given code point should be sl@0: * included in the UnicodeSet being constructed. sl@0: */ sl@0: typedef UBool (*Filter)(UChar32 codePoint, void* context); sl@0: sl@0: /** sl@0: * Given a filter, set this UnicodeSet to the code points sl@0: * contained by that filter. The filter MUST be sl@0: * property-conformant. That is, if it returns value v for one sl@0: * code point, then it must return v for all affiliated code sl@0: * points, as defined by the inclusions list. See sl@0: * getInclusions(). sl@0: * src is a UPropertySource value. sl@0: */ sl@0: void applyFilter(Filter filter, sl@0: void* context, sl@0: int32_t src, sl@0: UErrorCode &status); sl@0: sl@0: /** sl@0: * Return a cached copy of the inclusions list for the property source. sl@0: */ sl@0: static const UnicodeSet* getInclusions(int32_t src, UErrorCode &errorCode); sl@0: sl@0: friend class UnicodeSetIterator; sl@0: }; sl@0: sl@0: inline UBool UnicodeSet::operator!=(const UnicodeSet& o) const { sl@0: return !operator==(o); sl@0: } sl@0: sl@0: inline UBool UnicodeSet::containsSome(UChar32 start, UChar32 end) const { sl@0: return !containsNone(start, end); sl@0: } sl@0: sl@0: inline UBool UnicodeSet::containsSome(const UnicodeSet& s) const { sl@0: return !containsNone(s); sl@0: } sl@0: sl@0: inline UBool UnicodeSet::containsSome(const UnicodeString& s) const { sl@0: return !containsNone(s); sl@0: } sl@0: sl@0: U_NAMESPACE_END sl@0: sl@0: #endif