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

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

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

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

Pattern syntax

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

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

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

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

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

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

michael@0: * michael@0: *

Formal syntax

michael@0: * michael@0: * \htmlonly
\endhtmlonly michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: *
pattern :=  ('[' '^'? item* ']') | michael@0: * property
item :=  char | (char '-' char) | pattern-expr
michael@0: *
pattern-expr :=  pattern | pattern-expr pattern | michael@0: * pattern-expr op pattern
michael@0: *
op :=  '&' | '-'
michael@0: *
special :=  '[' | ']' | '-'
michael@0: *
char :=  any character that is not special
michael@0: * | ('\'
any character)
michael@0: * | ('\\u' hex hex hex hex)
michael@0: *
hex :=  any character for which michael@0: * Character.digit(c, 16) michael@0: * returns a non-negative result
property :=  a Unicode property set pattern
michael@0: *
michael@0: * michael@0: * michael@0: * michael@0: * michael@0: *
Legend: michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: * michael@0: *
a := b  a may be replaced by b
a?zero or one instance of a
michael@0: *
a*one or more instances of a
michael@0: *
a | beither a or b
michael@0: *
'a'the literal string between the quotes
michael@0: *
michael@0: * \htmlonly
\endhtmlonly michael@0: * michael@0: *

Note: michael@0: * - Most UnicodeSet methods do not take a UErrorCode parameter because michael@0: * there are usually very few opportunities for failure other than a shortage michael@0: * of memory, error codes in low-level C++ string methods would be inconvenient, michael@0: * and the error code as the last parameter (ICU convention) would prevent michael@0: * the use of default parameter values. michael@0: * Instead, such methods set the UnicodeSet into a "bogus" state michael@0: * (see isBogus()) if an error occurs. michael@0: * michael@0: * @author Alan Liu michael@0: * @stable ICU 2.0 michael@0: */ michael@0: class U_COMMON_API UnicodeSet : public UnicodeFilter { michael@0: michael@0: int32_t len; // length of list used; 0 <= len <= capacity michael@0: int32_t capacity; // capacity of list michael@0: UChar32* list; // MUST be terminated with HIGH michael@0: BMPSet *bmpSet; // The set is frozen iff either bmpSet or stringSpan is not NULL. michael@0: UChar32* buffer; // internal buffer, may be NULL michael@0: int32_t bufferCapacity; // capacity of buffer michael@0: int32_t patLen; michael@0: michael@0: /** michael@0: * The pattern representation of this set. This may not be the michael@0: * most economical pattern. It is the pattern supplied to michael@0: * applyPattern(), with variables substituted and whitespace michael@0: * removed. For sets constructed without applyPattern(), or michael@0: * modified using the non-pattern API, this string will be empty, michael@0: * indicating that toPattern() must generate a pattern michael@0: * representation from the inversion list. michael@0: */ michael@0: UChar *pat; michael@0: UVector* strings; // maintained in sorted order michael@0: UnicodeSetStringSpan *stringSpan; michael@0: michael@0: private: michael@0: enum { // constants michael@0: kIsBogus = 1 // This set is bogus (i.e. not valid) michael@0: }; michael@0: uint8_t fFlags; // Bit flag (see constants above) michael@0: public: michael@0: /** michael@0: * Determine if this object contains a valid set. michael@0: * A bogus set has no value. It is different from an empty set. michael@0: * It can be used to indicate that no set value is available. michael@0: * michael@0: * @return TRUE if the set is valid, FALSE otherwise michael@0: * @see setToBogus() michael@0: * @stable ICU 4.0 michael@0: */ michael@0: inline UBool isBogus(void) const; michael@0: michael@0: /** michael@0: * Make this UnicodeSet object invalid. michael@0: * The string will test TRUE with isBogus(). michael@0: * michael@0: * A bogus set has no value. It is different from an empty set. michael@0: * It can be used to indicate that no set value is available. michael@0: * michael@0: * This utility function is used throughout the UnicodeSet michael@0: * implementation to indicate that a UnicodeSet operation failed, michael@0: * and may be used in other functions, michael@0: * especially but not exclusively when such functions do not michael@0: * take a UErrorCode for simplicity. michael@0: * michael@0: * @see isBogus() michael@0: * @stable ICU 4.0 michael@0: */ michael@0: void setToBogus(); michael@0: michael@0: public: michael@0: michael@0: enum { michael@0: /** michael@0: * Minimum value that can be stored in a UnicodeSet. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: MIN_VALUE = 0, michael@0: michael@0: /** michael@0: * Maximum value that can be stored in a UnicodeSet. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: MAX_VALUE = 0x10ffff michael@0: }; michael@0: michael@0: //---------------------------------------------------------------- michael@0: // Constructors &c michael@0: //---------------------------------------------------------------- michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Constructs an empty set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeSet(); michael@0: michael@0: /** michael@0: * Constructs a set containing the given range. If end > michael@0: * start then an empty set is created. michael@0: * michael@0: * @param start first character, inclusive, of range michael@0: * @param end last character, inclusive, of range michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet(UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Constructs a set from the given pattern. See the class michael@0: * description for the syntax of the pattern language. michael@0: * @param pattern a string specifying what characters are in the set michael@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern michael@0: * contains a syntax error. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeSet(const UnicodeString& pattern, michael@0: UErrorCode& status); michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Constructs a set from the given pattern. See the class michael@0: * description for the syntax of the pattern language. michael@0: * @param pattern a string specifying what characters are in the set michael@0: * @param options bitmask for options to apply to the pattern. michael@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. michael@0: * @param symbols a symbol table mapping variable names to values michael@0: * and stand-in characters to UnicodeSets; may be NULL michael@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern michael@0: * contains a syntax error. michael@0: * @internal michael@0: */ michael@0: UnicodeSet(const UnicodeString& pattern, michael@0: uint32_t options, michael@0: const SymbolTable* symbols, michael@0: UErrorCode& status); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: /** michael@0: * Constructs a set from the given pattern. See the class description michael@0: * for the syntax of the pattern language. michael@0: * @param pattern a string specifying what characters are in the set michael@0: * @param pos on input, the position in pattern at which to start parsing. michael@0: * On output, the position after the last character parsed. michael@0: * @param options bitmask for options to apply to the pattern. michael@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. michael@0: * @param symbols a symbol table mapping variable names to values michael@0: * and stand-in characters to UnicodeSets; may be NULL michael@0: * @param status input-output error code michael@0: * @stable ICU 2.8 michael@0: */ michael@0: UnicodeSet(const UnicodeString& pattern, ParsePosition& pos, michael@0: uint32_t options, michael@0: const SymbolTable* symbols, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Constructs a set that is identical to the given UnicodeSet. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeSet(const UnicodeSet& o); michael@0: michael@0: /** michael@0: * Destructs the set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual ~UnicodeSet(); michael@0: michael@0: /** michael@0: * Assigns this object to be a copy of another. michael@0: * A frozen set will not be modified. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeSet& operator=(const UnicodeSet& o); michael@0: michael@0: /** michael@0: * Compares the specified object with this set for equality. Returns michael@0: * true if the two sets michael@0: * have the same size, and every member of the specified set is michael@0: * contained in this set (or equivalently, every member of this set is michael@0: * contained in the specified set). michael@0: * michael@0: * @param o set to be compared for equality with this set. michael@0: * @return true if the specified set is equal to this set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool operator==(const UnicodeSet& o) const; michael@0: michael@0: /** michael@0: * Compares the specified object with this set for equality. Returns michael@0: * true if the specified set is not equal to this set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool operator!=(const UnicodeSet& o) const; michael@0: michael@0: /** michael@0: * Returns a copy of this object. All UnicodeFunctor objects have michael@0: * to support cloning in order to allow classes using michael@0: * UnicodeFunctors, such as Transliterator, to implement cloning. michael@0: * If this set is frozen, then the clone will be frozen as well. michael@0: * Use cloneAsThawed() for a mutable clone of a frozen set. michael@0: * @see cloneAsThawed michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeFunctor* clone() const; michael@0: michael@0: /** michael@0: * Returns the hash code value for this set. michael@0: * michael@0: * @return the hash code value for this set. michael@0: * @see Object#hashCode() michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual int32_t hashCode(void) const; michael@0: michael@0: /** michael@0: * Get a UnicodeSet pointer from a USet michael@0: * michael@0: * @param uset a USet (the ICU plain C type for UnicodeSet) michael@0: * @return the corresponding UnicodeSet pointer. michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: inline static UnicodeSet *fromUSet(USet *uset); michael@0: michael@0: /** michael@0: * Get a UnicodeSet pointer from a const USet michael@0: * michael@0: * @param uset a const USet (the ICU plain C type for UnicodeSet) michael@0: * @return the corresponding UnicodeSet pointer. michael@0: * michael@0: * @stable ICU 4.2 michael@0: */ michael@0: inline static const UnicodeSet *fromUSet(const USet *uset); michael@0: michael@0: /** michael@0: * Produce a USet * pointer for this UnicodeSet. michael@0: * USet is the plain C type for UnicodeSet michael@0: * michael@0: * @return a USet pointer for this UnicodeSet michael@0: * @stable ICU 4.2 michael@0: */ michael@0: inline USet *toUSet(); michael@0: michael@0: michael@0: /** michael@0: * Produce a const USet * pointer for this UnicodeSet. michael@0: * USet is the plain C type for UnicodeSet michael@0: * michael@0: * @return a const USet pointer for this UnicodeSet michael@0: * @stable ICU 4.2 michael@0: */ michael@0: inline const USet * toUSet() const; michael@0: michael@0: michael@0: //---------------------------------------------------------------- michael@0: // Freezable API michael@0: //---------------------------------------------------------------- michael@0: michael@0: /** michael@0: * Determines whether the set has been frozen (made immutable) or not. michael@0: * See the ICU4J Freezable interface for details. michael@0: * @return TRUE/FALSE for whether the set has been frozen michael@0: * @see freeze michael@0: * @see cloneAsThawed michael@0: * @stable ICU 3.8 michael@0: */ michael@0: inline UBool isFrozen() const; michael@0: michael@0: /** michael@0: * Freeze the set (make it immutable). michael@0: * Once frozen, it cannot be unfrozen and is therefore thread-safe michael@0: * until it is deleted. michael@0: * See the ICU4J Freezable interface for details. michael@0: * Freezing the set may also make some operations faster, for example michael@0: * contains() and span(). michael@0: * A frozen set will not be modified. (It remains frozen.) michael@0: * @return this set. michael@0: * @see isFrozen michael@0: * @see cloneAsThawed michael@0: * @stable ICU 3.8 michael@0: */ michael@0: UnicodeFunctor *freeze(); michael@0: michael@0: /** michael@0: * Clone the set and make the clone mutable. michael@0: * See the ICU4J Freezable interface for details. michael@0: * @return the mutable clone michael@0: * @see freeze michael@0: * @see isFrozen michael@0: * @stable ICU 3.8 michael@0: */ michael@0: UnicodeFunctor *cloneAsThawed() const; michael@0: michael@0: //---------------------------------------------------------------- michael@0: // Public API michael@0: //---------------------------------------------------------------- michael@0: michael@0: /** michael@0: * Make this object represent the range start - end. michael@0: * If end > start then this object is set to an michael@0: * an empty range. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param start first character in the set, inclusive michael@0: * @param end last character in the set, inclusive michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& set(UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Return true if the given position, in the given pattern, appears michael@0: * to be the start of a UnicodeSet pattern. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static UBool resemblesPattern(const UnicodeString& pattern, michael@0: int32_t pos); michael@0: michael@0: /** michael@0: * Modifies this set to represent the set specified by the given michael@0: * pattern, ignoring Unicode Pattern_White_Space characters. michael@0: * See the class description for the syntax of the pattern language. michael@0: * A frozen set will not be modified. michael@0: * @param pattern a string specifying what characters are in the set michael@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern michael@0: * contains a syntax error. michael@0: * Empties the set passed before applying the pattern. michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeSet& applyPattern(const UnicodeString& pattern, michael@0: UErrorCode& status); michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Modifies this set to represent the set specified by the given michael@0: * pattern, optionally ignoring Unicode Pattern_White_Space characters. michael@0: * See the class description for the syntax of the pattern language. michael@0: * A frozen set will not be modified. michael@0: * @param pattern a string specifying what characters are in the set michael@0: * @param options bitmask for options to apply to the pattern. michael@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. michael@0: * @param symbols a symbol table mapping variable names to michael@0: * values and stand-ins to UnicodeSets; may be NULL michael@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern michael@0: * contains a syntax error. michael@0: * Empties the set passed before applying the pattern. michael@0: * @return a reference to this michael@0: * @internal michael@0: */ michael@0: UnicodeSet& applyPattern(const UnicodeString& pattern, michael@0: uint32_t options, michael@0: const SymbolTable* symbols, michael@0: UErrorCode& status); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: /** michael@0: * Parses the given pattern, starting at the given position. The michael@0: * character at pattern.charAt(pos.getIndex()) must be '[', or the michael@0: * parse fails. Parsing continues until the corresponding closing michael@0: * ']'. If a syntax error is encountered between the opening and michael@0: * closing brace, the parse fails. Upon return from a successful michael@0: * parse, the ParsePosition is updated to point to the character michael@0: * following the closing ']', and a StringBuffer containing a michael@0: * pairs list for the parsed pattern is returned. This method calls michael@0: * itself recursively to parse embedded subpatterns. michael@0: * Empties the set passed before applying the pattern. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param pattern the string containing the pattern to be parsed. michael@0: * The portion of the string from pos.getIndex(), which must be a michael@0: * '[', to the corresponding closing ']', is parsed. michael@0: * @param pos upon entry, the position at which to being parsing. michael@0: * The character at pattern.charAt(pos.getIndex()) must be a '['. michael@0: * Upon return from a successful parse, pos.getIndex() is either michael@0: * the character after the closing ']' of the parsed pattern, or michael@0: * pattern.length() if the closing ']' is the last character of michael@0: * the pattern string. michael@0: * @param options bitmask for options to apply to the pattern. michael@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. michael@0: * @param symbols a symbol table mapping variable names to michael@0: * values and stand-ins to UnicodeSets; may be NULL michael@0: * @param status returns U_ILLEGAL_ARGUMENT_ERROR if the pattern michael@0: * contains a syntax error. michael@0: * @return a reference to this michael@0: * @stable ICU 2.8 michael@0: */ michael@0: UnicodeSet& applyPattern(const UnicodeString& pattern, michael@0: ParsePosition& pos, michael@0: uint32_t options, michael@0: const SymbolTable* symbols, michael@0: UErrorCode& status); michael@0: michael@0: /** michael@0: * Returns a string representation of this set. If the result of michael@0: * calling this function is passed to a UnicodeSet constructor, it michael@0: * will produce another set that is equal to this one. michael@0: * A frozen set will not be modified. michael@0: * @param result the string to receive the rules. Previous michael@0: * contents will be deleted. michael@0: * @param escapeUnprintable if TRUE then convert unprintable michael@0: * character to their hex escape representations, \\uxxxx or michael@0: * \\Uxxxxxxxx. Unprintable characters are those other than michael@0: * U+000A, U+0020..U+007E. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeString& toPattern(UnicodeString& result, michael@0: UBool escapeUnprintable = FALSE) const; michael@0: michael@0: /** michael@0: * Modifies this set to contain those code points which have the given value michael@0: * for the given binary or enumerated property, as returned by michael@0: * u_getIntPropertyValue. Prior contents of this set are lost. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1 michael@0: * or UCHAR_INT_START..UCHAR_INT_LIMIT-1 michael@0: * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1. michael@0: * michael@0: * @param value a value in the range u_getIntPropertyMinValue(prop).. michael@0: * u_getIntPropertyMaxValue(prop), with one exception. If prop is michael@0: * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but michael@0: * rather a mask value produced by U_GET_GC_MASK(). This allows grouped michael@0: * categories such as [:L:] to be represented. michael@0: * michael@0: * @param ec error code input/output parameter michael@0: * michael@0: * @return a reference to this set michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& applyIntPropertyValue(UProperty prop, michael@0: int32_t value, michael@0: UErrorCode& ec); michael@0: michael@0: /** michael@0: * Modifies this set to contain those code points which have the michael@0: * given value for the given property. Prior contents of this michael@0: * set are lost. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param prop a property alias, either short or long. The name is matched michael@0: * loosely. See PropertyAliases.txt for names and a description of loose michael@0: * matching. If the value string is empty, then this string is interpreted michael@0: * as either a General_Category value alias, a Script value alias, a binary michael@0: * property alias, or a special ID. Special IDs are matched loosely and michael@0: * correspond to the following sets: michael@0: * michael@0: * "ANY" = [\\u0000-\\U0010FFFF], michael@0: * "ASCII" = [\\u0000-\\u007F], michael@0: * "Assigned" = [:^Cn:]. michael@0: * michael@0: * @param value a value alias, either short or long. The name is matched michael@0: * loosely. See PropertyValueAliases.txt for names and a description of michael@0: * loose matching. In addition to aliases listed, numeric values and michael@0: * canonical combining classes may be expressed numerically, e.g., ("nv", michael@0: * "0.5") or ("ccc", "220"). The value string may also be empty. michael@0: * michael@0: * @param ec error code input/output parameter michael@0: * michael@0: * @return a reference to this set michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& applyPropertyAlias(const UnicodeString& prop, michael@0: const UnicodeString& value, michael@0: UErrorCode& ec); michael@0: michael@0: /** michael@0: * Returns the number of elements in this set (its cardinality). michael@0: * Note than the elements of a set may include both individual michael@0: * codepoints and strings. michael@0: * michael@0: * @return the number of elements in this set (its cardinality). michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual int32_t size(void) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains no elements. michael@0: * michael@0: * @return true if this set contains no elements. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool isEmpty(void) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains the given character. michael@0: * This function works faster with a frozen set. michael@0: * @param c character to be checked for containment michael@0: * @return true if the test condition is met michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool contains(UChar32 c) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains every character michael@0: * of the given range. michael@0: * @param start first character, inclusive, of the range michael@0: * @param end last character, inclusive, of the range michael@0: * @return true if the test condition is met michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool contains(UChar32 start, UChar32 end) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains the given michael@0: * multicharacter string. michael@0: * @param s string to be checked for containment michael@0: * @return true if this set contains the specified string michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UBool contains(const UnicodeString& s) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains all the characters and strings michael@0: * of the given set. michael@0: * @param c set to be checked for containment michael@0: * @return true if the test condition is met michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UBool containsAll(const UnicodeSet& c) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains all the characters michael@0: * of the given string. michael@0: * @param s string containing characters to be checked for containment michael@0: * @return true if the test condition is met michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UBool containsAll(const UnicodeString& s) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains none of the characters michael@0: * of the given range. michael@0: * @param start first character, inclusive, of the range michael@0: * @param end last character, inclusive, of the range michael@0: * @return true if the test condition is met michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UBool containsNone(UChar32 start, UChar32 end) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains none of the characters and strings michael@0: * of the given set. michael@0: * @param c set to be checked for containment michael@0: * @return true if the test condition is met michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UBool containsNone(const UnicodeSet& c) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains none of the characters michael@0: * of the given string. michael@0: * @param s string containing characters to be checked for containment michael@0: * @return true if the test condition is met michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UBool containsNone(const UnicodeString& s) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains one or more of the characters michael@0: * in the given range. michael@0: * @param start first character, inclusive, of the range michael@0: * @param end last character, inclusive, of the range michael@0: * @return true if the condition is met michael@0: * @stable ICU 2.4 michael@0: */ michael@0: inline UBool containsSome(UChar32 start, UChar32 end) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains one or more of the characters michael@0: * and strings of the given set. michael@0: * @param s The set to be checked for containment michael@0: * @return true if the condition is met michael@0: * @stable ICU 2.4 michael@0: */ michael@0: inline UBool containsSome(const UnicodeSet& s) const; michael@0: michael@0: /** michael@0: * Returns true if this set contains one or more of the characters michael@0: * of the given string. michael@0: * @param s string containing characters to be checked for containment michael@0: * @return true if the condition is met michael@0: * @stable ICU 2.4 michael@0: */ michael@0: inline UBool containsSome(const UnicodeString& s) const; michael@0: michael@0: /** michael@0: * Returns the length of the initial substring of the input string which michael@0: * consists only of characters and strings that are contained in this set michael@0: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), michael@0: * or only of characters and strings that are not contained michael@0: * in this set (USET_SPAN_NOT_CONTAINED). michael@0: * See USetSpanCondition for details. michael@0: * Similar to the strspn() C library function. michael@0: * Unpaired surrogates are treated according to contains() of their surrogate code points. michael@0: * This function works faster with a frozen set and with a non-negative string length argument. michael@0: * @param s start of the string michael@0: * @param length of the string; can be -1 for NUL-terminated michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the length of the initial substring according to the spanCondition; michael@0: * 0 if the start of the string does not fit the spanCondition michael@0: * @stable ICU 3.8 michael@0: * @see USetSpanCondition michael@0: */ michael@0: int32_t span(const UChar *s, int32_t length, USetSpanCondition spanCondition) const; michael@0: michael@0: /** michael@0: * Returns the end of the substring of the input string according to the USetSpanCondition. michael@0: * Same as start+span(s.getBuffer()+start, s.length()-start, spanCondition) michael@0: * after pinning start to 0<=start<=s.length(). michael@0: * @param s the string michael@0: * @param start the start index in the string for the span operation michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the exclusive end of the substring according to the spanCondition; michael@0: * the substring s.tempSubStringBetween(start, end) fulfills the spanCondition michael@0: * @stable ICU 4.4 michael@0: * @see USetSpanCondition michael@0: */ michael@0: inline int32_t span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const; michael@0: michael@0: /** michael@0: * Returns the start of the trailing substring of the input string which michael@0: * consists only of characters and strings that are contained in this set michael@0: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), michael@0: * or only of characters and strings that are not contained michael@0: * in this set (USET_SPAN_NOT_CONTAINED). michael@0: * See USetSpanCondition for details. michael@0: * Unpaired surrogates are treated according to contains() of their surrogate code points. michael@0: * This function works faster with a frozen set and with a non-negative string length argument. michael@0: * @param s start of the string michael@0: * @param length of the string; can be -1 for NUL-terminated michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the start of the trailing substring according to the spanCondition; michael@0: * the string length if the end of the string does not fit the spanCondition michael@0: * @stable ICU 3.8 michael@0: * @see USetSpanCondition michael@0: */ michael@0: int32_t spanBack(const UChar *s, int32_t length, USetSpanCondition spanCondition) const; michael@0: michael@0: /** michael@0: * Returns the start of the substring of the input string according to the USetSpanCondition. michael@0: * Same as spanBack(s.getBuffer(), limit, spanCondition) michael@0: * after pinning limit to 0<=end<=s.length(). michael@0: * @param s the string michael@0: * @param limit the exclusive-end index in the string for the span operation michael@0: * (use s.length() or INT32_MAX for spanning back from the end of the string) michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the start of the substring according to the spanCondition; michael@0: * the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition michael@0: * @stable ICU 4.4 michael@0: * @see USetSpanCondition michael@0: */ michael@0: inline int32_t spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const; michael@0: michael@0: /** michael@0: * Returns the length of the initial substring of the input string which michael@0: * consists only of characters and strings that are contained in this set michael@0: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), michael@0: * or only of characters and strings that are not contained michael@0: * in this set (USET_SPAN_NOT_CONTAINED). michael@0: * See USetSpanCondition for details. michael@0: * Similar to the strspn() C library function. michael@0: * Malformed byte sequences are treated according to contains(0xfffd). michael@0: * This function works faster with a frozen set and with a non-negative string length argument. michael@0: * @param s start of the string (UTF-8) michael@0: * @param length of the string; can be -1 for NUL-terminated michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the length of the initial substring according to the spanCondition; michael@0: * 0 if the start of the string does not fit the spanCondition michael@0: * @stable ICU 3.8 michael@0: * @see USetSpanCondition michael@0: */ michael@0: int32_t spanUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const; michael@0: michael@0: /** michael@0: * Returns the start of the trailing substring of the input string which michael@0: * consists only of characters and strings that are contained in this set michael@0: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), michael@0: * or only of characters and strings that are not contained michael@0: * in this set (USET_SPAN_NOT_CONTAINED). michael@0: * See USetSpanCondition for details. michael@0: * Malformed byte sequences are treated according to contains(0xfffd). michael@0: * This function works faster with a frozen set and with a non-negative string length argument. michael@0: * @param s start of the string (UTF-8) michael@0: * @param length of the string; can be -1 for NUL-terminated michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the start of the trailing substring according to the spanCondition; michael@0: * the string length if the end of the string does not fit the spanCondition michael@0: * @stable ICU 3.8 michael@0: * @see USetSpanCondition michael@0: */ michael@0: int32_t spanBackUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const; michael@0: michael@0: /** michael@0: * Implement UnicodeMatcher::matches() michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UMatchDegree matches(const Replaceable& text, michael@0: int32_t& offset, michael@0: int32_t limit, michael@0: UBool incremental); michael@0: michael@0: private: michael@0: /** michael@0: * Returns the longest match for s in text at the given position. michael@0: * If limit > start then match forward from start+1 to limit michael@0: * matching all characters except s.charAt(0). If limit < start, michael@0: * go backward starting from start-1 matching all characters michael@0: * except s.charAt(s.length()-1). This method assumes that the michael@0: * first character, text.charAt(start), matches s, so it does not michael@0: * check it. michael@0: * @param text the text to match michael@0: * @param start the first character to match. In the forward michael@0: * direction, text.charAt(start) is matched against s.charAt(0). michael@0: * In the reverse direction, it is matched against michael@0: * s.charAt(s.length()-1). michael@0: * @param limit the limit offset for matching, either last+1 in michael@0: * the forward direction, or last-1 in the reverse direction, michael@0: * where last is the index of the last character to match. michael@0: * @param s michael@0: * @return If part of s matches up to the limit, return |limit - michael@0: * start|. If all of s matches before reaching the limit, return michael@0: * s.length(). If there is a mismatch between s and text, return michael@0: * 0 michael@0: */ michael@0: static int32_t matchRest(const Replaceable& text, michael@0: int32_t start, int32_t limit, michael@0: const UnicodeString& s); michael@0: michael@0: /** michael@0: * Returns the smallest value i such that c < list[i]. Caller michael@0: * must ensure that c is a legal value or this method will enter michael@0: * an infinite loop. This method performs a binary search. michael@0: * @param c a character in the range MIN_VALUE..MAX_VALUE michael@0: * inclusive michael@0: * @return the smallest integer i in the range 0..len-1, michael@0: * inclusive, such that c < list[i] michael@0: */ michael@0: int32_t findCodePoint(UChar32 c) const; michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Implementation of UnicodeMatcher API. Union the set of all michael@0: * characters that may be matched by this object into the given michael@0: * set. michael@0: * @param toUnionTo the set into which to union the source characters michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual void addMatchSetTo(UnicodeSet& toUnionTo) const; michael@0: michael@0: /** michael@0: * Returns the index of the given character within this set, where michael@0: * the set is ordered by ascending code point. If the character michael@0: * is not in this set, return -1. The inverse of this method is michael@0: * charAt(). michael@0: * @return an index from 0..size()-1, or -1 michael@0: * @stable ICU 2.4 michael@0: */ michael@0: int32_t indexOf(UChar32 c) const; michael@0: michael@0: /** michael@0: * Returns the character at the given index within this set, where michael@0: * the set is ordered by ascending code point. If the index is michael@0: * out of range, return (UChar32)-1. The inverse of this method is michael@0: * indexOf(). michael@0: * @param index an index from 0..size()-1 michael@0: * @return the character at the given index, or (UChar32)-1. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UChar32 charAt(int32_t index) const; michael@0: michael@0: /** michael@0: * Adds the specified range to this set if it is not already michael@0: * present. If this set already contains the specified range, michael@0: * the call leaves this set unchanged. If end > start michael@0: * then an empty range is added, leaving the set unchanged. michael@0: * This is equivalent to a boolean logic OR, or a set UNION. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param start first character, inclusive, of range to be added michael@0: * to this set. michael@0: * @param end last character, inclusive, of range to be added michael@0: * to this set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeSet& add(UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Adds the specified character to this set if it is not already michael@0: * present. If this set already contains the specified character, michael@0: * the call leaves this set unchanged. michael@0: * A frozen set will not be modified. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeSet& add(UChar32 c); michael@0: michael@0: /** michael@0: * Adds the specified multicharacter to this set if it is not already michael@0: * present. If this set already contains the multicharacter, michael@0: * the call leaves this set unchanged. michael@0: * Thus "ch" => {"ch"} michael@0: *
Warning: you cannot add an empty string ("") to a UnicodeSet. michael@0: * A frozen set will not be modified. michael@0: * @param s the source string michael@0: * @return this object, for chaining michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& add(const UnicodeString& s); michael@0: michael@0: private: michael@0: /** michael@0: * @return a code point IF the string consists of a single one. michael@0: * otherwise returns -1. michael@0: * @param s string to test michael@0: */ michael@0: static int32_t getSingleCP(const UnicodeString& s); michael@0: michael@0: void _add(const UnicodeString& s); michael@0: michael@0: public: michael@0: /** michael@0: * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"} michael@0: * If this set already any particular character, it has no effect on that character. michael@0: * A frozen set will not be modified. michael@0: * @param s the source string michael@0: * @return this object, for chaining michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& addAll(const UnicodeString& s); michael@0: michael@0: /** michael@0: * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"} michael@0: * If this set already any particular character, it has no effect on that character. michael@0: * A frozen set will not be modified. michael@0: * @param s the source string michael@0: * @return this object, for chaining michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& retainAll(const UnicodeString& s); michael@0: michael@0: /** michael@0: * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"} michael@0: * If this set already any particular character, it has no effect on that character. michael@0: * A frozen set will not be modified. michael@0: * @param s the source string michael@0: * @return this object, for chaining michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& complementAll(const UnicodeString& s); michael@0: michael@0: /** michael@0: * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"} michael@0: * If this set already any particular character, it has no effect on that character. michael@0: * A frozen set will not be modified. michael@0: * @param s the source string michael@0: * @return this object, for chaining michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& removeAll(const UnicodeString& s); michael@0: michael@0: /** michael@0: * Makes a set from a multicharacter string. Thus "ch" => {"ch"} michael@0: *
Warning: you cannot add an empty string ("") to a UnicodeSet. michael@0: * @param s the source string michael@0: * @return a newly created set containing the given string. michael@0: * The caller owns the return object and is responsible for deleting it. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static UnicodeSet* U_EXPORT2 createFrom(const UnicodeString& s); michael@0: michael@0: michael@0: /** michael@0: * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"} michael@0: * @param s the source string michael@0: * @return a newly created set containing the given characters michael@0: * The caller owns the return object and is responsible for deleting it. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: static UnicodeSet* U_EXPORT2 createFromAll(const UnicodeString& s); michael@0: michael@0: /** michael@0: * Retain only the elements in this set that are contained in the michael@0: * specified range. If end > start then an empty range is michael@0: * retained, leaving the set empty. This is equivalent to michael@0: * a boolean logic AND, or a set INTERSECTION. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param start first character, inclusive, of range to be retained michael@0: * to this set. michael@0: * @param end last character, inclusive, of range to be retained michael@0: * to this set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeSet& retain(UChar32 start, UChar32 end); michael@0: michael@0: michael@0: /** michael@0: * Retain the specified character from this set if it is present. michael@0: * A frozen set will not be modified. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeSet& retain(UChar32 c); michael@0: michael@0: /** michael@0: * Removes the specified range from this set if it is present. michael@0: * The set will not contain the specified range once the call michael@0: * returns. If end > start then an empty range is michael@0: * removed, leaving the set unchanged. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param start first character, inclusive, of range to be removed michael@0: * from this set. michael@0: * @param end last character, inclusive, of range to be removed michael@0: * from this set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeSet& remove(UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Removes the specified character from this set if it is present. michael@0: * The set will not contain the specified range once the call michael@0: * returns. michael@0: * A frozen set will not be modified. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeSet& remove(UChar32 c); michael@0: michael@0: /** michael@0: * Removes the specified string from this set if it is present. michael@0: * The set will not contain the specified character once the call michael@0: * returns. michael@0: * A frozen set will not be modified. michael@0: * @param s the source string michael@0: * @return this object, for chaining michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& remove(const UnicodeString& s); michael@0: michael@0: /** michael@0: * Inverts this set. This operation modifies this set so that michael@0: * its value is its complement. This is equivalent to michael@0: * complement(MIN_VALUE, MAX_VALUE). michael@0: * A frozen set will not be modified. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeSet& complement(void); michael@0: michael@0: /** michael@0: * Complements the specified range in this set. Any character in michael@0: * the range will be removed if it is in this set, or will be michael@0: * added if it is not in this set. If end > start michael@0: * then an empty range is complemented, leaving the set unchanged. michael@0: * This is equivalent to a boolean logic XOR. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param start first character, inclusive, of range to be removed michael@0: * from this set. michael@0: * @param end last character, inclusive, of range to be removed michael@0: * from this set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeSet& complement(UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Complements the specified character in this set. The character michael@0: * will be removed if it is in this set, or will be added if it is michael@0: * not in this set. michael@0: * A frozen set will not be modified. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeSet& complement(UChar32 c); michael@0: michael@0: /** michael@0: * Complement the specified string in this set. michael@0: * The set will not contain the specified string once the call michael@0: * returns. michael@0: *
Warning: you cannot add an empty string ("") to a UnicodeSet. michael@0: * A frozen set will not be modified. michael@0: * @param s the string to complement michael@0: * @return this object, for chaining michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeSet& complement(const UnicodeString& s); michael@0: michael@0: /** michael@0: * Adds all of the elements in the specified set to this set if michael@0: * they're not already present. This operation effectively michael@0: * modifies this set so that its value is the union of the two michael@0: * sets. The behavior of this operation is unspecified if the specified michael@0: * collection is modified while the operation is in progress. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param c set whose elements are to be added to this set. michael@0: * @see #add(UChar32, UChar32) michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeSet& addAll(const UnicodeSet& c); michael@0: michael@0: /** michael@0: * Retains only the elements in this set that are contained in the michael@0: * specified set. In other words, removes from this set all of michael@0: * its elements that are not contained in the specified set. This michael@0: * operation effectively modifies this set so that its value is michael@0: * the intersection of the two sets. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param c set that defines which elements this set will retain. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeSet& retainAll(const UnicodeSet& c); michael@0: michael@0: /** michael@0: * Removes from this set all of its elements that are contained in the michael@0: * specified set. This operation effectively modifies this michael@0: * set so that its value is the asymmetric set difference of michael@0: * the two sets. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param c set that defines which elements will be removed from michael@0: * this set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeSet& removeAll(const UnicodeSet& c); michael@0: michael@0: /** michael@0: * Complements in this set all elements contained in the specified michael@0: * set. Any character in the other set will be removed if it is michael@0: * in this set, or will be added if it is not in this set. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param c set that defines which elements will be xor'ed from michael@0: * this set. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UnicodeSet& complementAll(const UnicodeSet& c); michael@0: michael@0: /** michael@0: * Removes all of the elements from this set. This set will be michael@0: * empty after this call returns. michael@0: * A frozen set will not be modified. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UnicodeSet& clear(void); michael@0: michael@0: /** michael@0: * Close this set over the given attribute. For the attribute michael@0: * USET_CASE, the result is to modify this set so that: michael@0: * michael@0: * 1. For each character or string 'a' in this set, all strings or michael@0: * characters 'b' such that foldCase(a) == foldCase(b) are added michael@0: * to this set. michael@0: * michael@0: * 2. For each string 'e' in the resulting set, if e != michael@0: * foldCase(e), 'e' will be removed. michael@0: * michael@0: * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}] michael@0: * michael@0: * (Here foldCase(x) refers to the operation u_strFoldCase, and a michael@0: * == b denotes that the contents are the same, not pointer michael@0: * comparison.) michael@0: * michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param attribute bitmask for attributes to close over. michael@0: * Currently only the USET_CASE bit is supported. Any undefined bits michael@0: * are ignored. michael@0: * @return a reference to this set. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: UnicodeSet& closeOver(int32_t attribute); michael@0: michael@0: /** michael@0: * Remove all strings from this set. michael@0: * michael@0: * @return a reference to this set. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: virtual UnicodeSet &removeAllStrings(); michael@0: michael@0: /** michael@0: * Iteration method that returns the number of ranges contained in michael@0: * this set. michael@0: * @see #getRangeStart michael@0: * @see #getRangeEnd michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual int32_t getRangeCount(void) const; michael@0: michael@0: /** michael@0: * Iteration method that returns the first character in the michael@0: * specified range of this set. michael@0: * @see #getRangeCount michael@0: * @see #getRangeEnd michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UChar32 getRangeStart(int32_t index) const; michael@0: michael@0: /** michael@0: * Iteration method that returns the last character in the michael@0: * specified range of this set. michael@0: * @see #getRangeStart michael@0: * @see #getRangeEnd michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UChar32 getRangeEnd(int32_t index) const; michael@0: michael@0: /** michael@0: * Serializes this set into an array of 16-bit integers. Serialization michael@0: * (currently) only records the characters in the set; multicharacter michael@0: * strings are ignored. michael@0: * michael@0: * The array has following format (each line is one 16-bit michael@0: * integer): michael@0: * michael@0: * length = (n+2*m) | (m!=0?0x8000:0) michael@0: * bmpLength = n; present if m!=0 michael@0: * bmp[0] michael@0: * bmp[1] michael@0: * ... michael@0: * bmp[n-1] michael@0: * supp-high[0] michael@0: * supp-low[0] michael@0: * supp-high[1] michael@0: * supp-low[1] michael@0: * ... michael@0: * supp-high[m-1] michael@0: * supp-low[m-1] michael@0: * michael@0: * The array starts with a header. After the header are n bmp michael@0: * code points, then m supplementary code points. Either n or m michael@0: * or both may be zero. n+2*m is always <= 0x7FFF. michael@0: * michael@0: * If there are no supplementary characters (if m==0) then the michael@0: * header is one 16-bit integer, 'length', with value n. michael@0: * michael@0: * If there are supplementary characters (if m!=0) then the header michael@0: * is two 16-bit integers. The first, 'length', has value michael@0: * (n+2*m)|0x8000. The second, 'bmpLength', has value n. michael@0: * michael@0: * After the header the code points are stored in ascending order. michael@0: * Supplementary code points are stored as most significant 16 michael@0: * bits followed by least significant 16 bits. michael@0: * michael@0: * @param dest pointer to buffer of destCapacity 16-bit integers. michael@0: * May be NULL only if destCapacity is zero. michael@0: * @param destCapacity size of dest, or zero. Must not be negative. michael@0: * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR michael@0: * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if michael@0: * n+2*m+(m!=0?2:1) > destCapacity. michael@0: * @return the total length of the serialized format, including michael@0: * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other michael@0: * than U_BUFFER_OVERFLOW_ERROR. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: int32_t serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const; michael@0: michael@0: /** michael@0: * Reallocate this objects internal structures to take up the least michael@0: * possible space, without changing this object's value. michael@0: * A frozen set will not be modified. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UnicodeSet& compact(); michael@0: michael@0: /** michael@0: * Return the class ID for this class. This is useful only for michael@0: * comparing to a return value from getDynamicClassID(). For example: michael@0: *

michael@0:      * .      Base* polymorphic_pointer = createPolymorphicObject();
michael@0:      * .      if (polymorphic_pointer->getDynamicClassID() ==
michael@0:      * .          Derived::getStaticClassID()) ...
michael@0:      * 
michael@0: * @return The class ID for all objects of this class. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: /** michael@0: * Implement UnicodeFunctor API. michael@0: * michael@0: * @return The class ID for this object. All objects of a given michael@0: * class have the same class ID. Objects of other classes have michael@0: * different class IDs. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UClassID getDynamicClassID(void) const; michael@0: michael@0: private: michael@0: michael@0: // Private API for the USet API michael@0: michael@0: friend class USetAccess; michael@0: michael@0: int32_t getStringCount() const; michael@0: michael@0: const UnicodeString* getString(int32_t index) const; michael@0: michael@0: //---------------------------------------------------------------- michael@0: // RuleBasedTransliterator support michael@0: //---------------------------------------------------------------- michael@0: michael@0: private: michael@0: michael@0: /** michael@0: * Returns true if this set contains any character whose low byte michael@0: * is the given value. This is used by RuleBasedTransliterator for michael@0: * indexing. michael@0: */ michael@0: virtual UBool matchesIndexValue(uint8_t v) const; michael@0: michael@0: private: michael@0: friend class RBBIRuleScanner; michael@0: michael@0: //---------------------------------------------------------------- michael@0: // Implementation: Clone as thawed (see ICU4J Freezable) michael@0: //---------------------------------------------------------------- michael@0: michael@0: UnicodeSet(const UnicodeSet& o, UBool /* asThawed */); michael@0: michael@0: //---------------------------------------------------------------- michael@0: // Implementation: Pattern parsing michael@0: //---------------------------------------------------------------- michael@0: michael@0: void applyPatternIgnoreSpace(const UnicodeString& pattern, michael@0: ParsePosition& pos, michael@0: const SymbolTable* symbols, michael@0: UErrorCode& status); michael@0: michael@0: void applyPattern(RuleCharacterIterator& chars, michael@0: const SymbolTable* symbols, michael@0: UnicodeString& rebuiltPat, michael@0: uint32_t options, michael@0: UnicodeSet& (UnicodeSet::*caseClosure)(int32_t attribute), michael@0: UErrorCode& ec); michael@0: michael@0: //---------------------------------------------------------------- michael@0: // Implementation: Utility methods michael@0: //---------------------------------------------------------------- michael@0: michael@0: void ensureCapacity(int32_t newLen, UErrorCode& ec); michael@0: michael@0: void ensureBufferCapacity(int32_t newLen, UErrorCode& ec); michael@0: michael@0: void swapBuffers(void); michael@0: michael@0: UBool allocateStrings(UErrorCode &status); michael@0: michael@0: UnicodeString& _toPattern(UnicodeString& result, michael@0: UBool escapeUnprintable) const; michael@0: michael@0: UnicodeString& _generatePattern(UnicodeString& result, michael@0: UBool escapeUnprintable) const; michael@0: michael@0: static void _appendToPat(UnicodeString& buf, const UnicodeString& s, UBool escapeUnprintable); michael@0: michael@0: static void _appendToPat(UnicodeString& buf, UChar32 c, UBool escapeUnprintable); michael@0: michael@0: //---------------------------------------------------------------- michael@0: // Implementation: Fundamental operators michael@0: //---------------------------------------------------------------- michael@0: michael@0: void exclusiveOr(const UChar32* other, int32_t otherLen, int8_t polarity); michael@0: michael@0: void add(const UChar32* other, int32_t otherLen, int8_t polarity); michael@0: michael@0: void retain(const UChar32* other, int32_t otherLen, int8_t polarity); michael@0: michael@0: /** michael@0: * Return true if the given position, in the given pattern, appears michael@0: * to be the start of a property set pattern [:foo:], \\p{foo}, or michael@0: * \\P{foo}, or \\N{name}. michael@0: */ michael@0: static UBool resemblesPropertyPattern(const UnicodeString& pattern, michael@0: int32_t pos); michael@0: michael@0: static UBool resemblesPropertyPattern(RuleCharacterIterator& chars, michael@0: int32_t iterOpts); michael@0: michael@0: /** michael@0: * Parse the given property pattern at the given parse position michael@0: * and set this UnicodeSet to the result. michael@0: * michael@0: * The original design document is out of date, but still useful. michael@0: * Ignore the property and value names: michael@0: * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/unicodeset_properties.html michael@0: * michael@0: * Recognized syntax: michael@0: * michael@0: * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]" michael@0: * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P" michael@0: * \\N{name} - white space not allowed within "\\N" michael@0: * michael@0: * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored. michael@0: * Case is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading michael@0: * and trailing space is deleted, and internal runs of whitespace michael@0: * are collapsed to a single space. michael@0: * michael@0: * We support binary properties, enumerated properties, and the michael@0: * following non-enumerated properties: michael@0: * michael@0: * Numeric_Value michael@0: * Name michael@0: * Unicode_1_Name michael@0: * michael@0: * @param pattern the pattern string michael@0: * @param ppos on entry, the position at which to begin parsing. michael@0: * This should be one of the locations marked '^': michael@0: * michael@0: * [:blah:] \\p{blah} \\P{blah} \\N{name} michael@0: * ^ % ^ % ^ % ^ % michael@0: * michael@0: * On return, the position after the last character parsed, that is, michael@0: * the locations marked '%'. If the parse fails, ppos is returned michael@0: * unchanged. michael@0: * @param ec status michael@0: * @return a reference to this. michael@0: */ michael@0: UnicodeSet& applyPropertyPattern(const UnicodeString& pattern, michael@0: ParsePosition& ppos, michael@0: UErrorCode &ec); michael@0: michael@0: void applyPropertyPattern(RuleCharacterIterator& chars, michael@0: UnicodeString& rebuiltPat, michael@0: UErrorCode& ec); michael@0: michael@0: friend void UnicodeSet_initInclusion(int32_t src, UErrorCode &status); michael@0: static const UnicodeSet* getInclusions(int32_t src, UErrorCode &status); michael@0: michael@0: /** michael@0: * A filter that returns TRUE if the given code point should be michael@0: * included in the UnicodeSet being constructed. michael@0: */ michael@0: typedef UBool (*Filter)(UChar32 codePoint, void* context); michael@0: michael@0: /** michael@0: * Given a filter, set this UnicodeSet to the code points michael@0: * contained by that filter. The filter MUST be michael@0: * property-conformant. That is, if it returns value v for one michael@0: * code point, then it must return v for all affiliated code michael@0: * points, as defined by the inclusions list. See michael@0: * getInclusions(). michael@0: * src is a UPropertySource value. michael@0: */ michael@0: void applyFilter(Filter filter, michael@0: void* context, michael@0: int32_t src, michael@0: UErrorCode &status); michael@0: michael@0: /** michael@0: * Set the new pattern to cache. michael@0: */ michael@0: void setPattern(const UnicodeString& newPat); michael@0: /** michael@0: * Release existing cached pattern. michael@0: */ michael@0: void releasePattern(); michael@0: michael@0: friend class UnicodeSetIterator; michael@0: }; michael@0: michael@0: michael@0: michael@0: inline UBool UnicodeSet::operator!=(const UnicodeSet& o) const { michael@0: return !operator==(o); michael@0: } michael@0: michael@0: inline UBool UnicodeSet::isFrozen() const { michael@0: return (UBool)(bmpSet!=NULL || stringSpan!=NULL); michael@0: } michael@0: michael@0: inline UBool UnicodeSet::containsSome(UChar32 start, UChar32 end) const { michael@0: return !containsNone(start, end); michael@0: } michael@0: michael@0: inline UBool UnicodeSet::containsSome(const UnicodeSet& s) const { michael@0: return !containsNone(s); michael@0: } michael@0: michael@0: inline UBool UnicodeSet::containsSome(const UnicodeString& s) const { michael@0: return !containsNone(s); michael@0: } michael@0: michael@0: inline UBool UnicodeSet::isBogus() const { michael@0: return (UBool)(fFlags & kIsBogus); michael@0: } michael@0: michael@0: inline UnicodeSet *UnicodeSet::fromUSet(USet *uset) { michael@0: return reinterpret_cast(uset); michael@0: } michael@0: michael@0: inline const UnicodeSet *UnicodeSet::fromUSet(const USet *uset) { michael@0: return reinterpret_cast(uset); michael@0: } michael@0: michael@0: inline USet *UnicodeSet::toUSet() { michael@0: return reinterpret_cast(this); michael@0: } michael@0: michael@0: inline const USet *UnicodeSet::toUSet() const { michael@0: return reinterpret_cast(this); michael@0: } michael@0: michael@0: inline int32_t UnicodeSet::span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const { michael@0: int32_t sLength=s.length(); michael@0: if(start<0) { michael@0: start=0; michael@0: } else if(start>sLength) { michael@0: start=sLength; michael@0: } michael@0: return start+span(s.getBuffer()+start, sLength-start, spanCondition); michael@0: } michael@0: michael@0: inline int32_t UnicodeSet::spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const { michael@0: int32_t sLength=s.length(); michael@0: if(limit<0) { michael@0: limit=0; michael@0: } else if(limit>sLength) { michael@0: limit=sLength; michael@0: } michael@0: return spanBack(s.getBuffer(), limit, spanCondition); michael@0: } michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif