jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: *************************************************************************** jpayne@69: * Copyright (C) 1999-2016, International Business Machines Corporation jpayne@69: * and others. All Rights Reserved. jpayne@69: *************************************************************************** jpayne@69: * Date Name Description jpayne@69: * 10/20/99 alan Creation. jpayne@69: *************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef UNICODESET_H jpayne@69: #define UNICODESET_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #include "unicode/ucpmap.h" jpayne@69: #include "unicode/unifilt.h" jpayne@69: #include "unicode/unistr.h" jpayne@69: #include "unicode/uset.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Unicode Set jpayne@69: */ jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: // Forward Declarations. jpayne@69: class BMPSet; jpayne@69: class ParsePosition; jpayne@69: class RBBIRuleScanner; jpayne@69: class SymbolTable; jpayne@69: class UnicodeSetStringSpan; jpayne@69: class UVector; jpayne@69: class RuleCharacterIterator; jpayne@69: jpayne@69: /** jpayne@69: * A mutable set of Unicode characters and multicharacter strings. Objects of this class jpayne@69: * represent character classes used in regular expressions. jpayne@69: * A character specifies a subset of Unicode code points. Legal jpayne@69: * code points are U+0000 to U+10FFFF, inclusive. jpayne@69: * jpayne@69: *
The UnicodeSet class is not designed to be subclassed. jpayne@69: * jpayne@69: *
UnicodeSet
supports two APIs. The first is the
jpayne@69: * operand API that allows the caller to modify the value of
jpayne@69: * a UnicodeSet
object. It conforms to Java 2's
jpayne@69: * java.util.Set
interface, although
jpayne@69: * UnicodeSet
does not actually implement that
jpayne@69: * interface. All methods of Set
are supported, with the
jpayne@69: * modification that they take a character range or single character
jpayne@69: * instead of an Object
, and they take a
jpayne@69: * UnicodeSet
instead of a Collection
. The
jpayne@69: * operand API may be thought of in terms of boolean logic: a boolean
jpayne@69: * OR is implemented by add
, a boolean AND is implemented
jpayne@69: * by retain
, a boolean XOR is implemented by
jpayne@69: * complement
taking an argument, and a boolean NOT is
jpayne@69: * implemented by complement
with no argument. In terms
jpayne@69: * of traditional set theory function names, add
is a
jpayne@69: * union, retain
is an intersection, remove
jpayne@69: * is an asymmetric difference, and complement
with no
jpayne@69: * argument is a set complement with respect to the superset range
jpayne@69: * MIN_VALUE-MAX_VALUE
jpayne@69: *
jpayne@69: *
The second API is the
jpayne@69: * applyPattern()
/toPattern()
API from the
jpayne@69: * java.text.Format
-derived classes. Unlike the
jpayne@69: * methods that add characters, add categories, and control the logic
jpayne@69: * of the set, the method applyPattern()
sets all
jpayne@69: * attributes of a UnicodeSet
at once, based on a
jpayne@69: * string pattern.
jpayne@69: *
jpayne@69: *
Pattern syntax
jpayne@69: * jpayne@69: * Patterns are accepted by the constructors and the jpayne@69: *applyPattern()
methods and returned by the
jpayne@69: * toPattern()
method. These patterns follow a syntax
jpayne@69: * similar to that employed by version 8 regular expression character
jpayne@69: * classes. Here are some simple examples:
jpayne@69: *
jpayne@69: * \htmlonly\endhtmlonly jpayne@69: *\endhtmlonly jpayne@69: * jpayne@69: * Any character may be preceded by a backslash in order to remove any special jpayne@69: * meaning. White space characters, as defined by UCharacter.isWhitespace(), are jpayne@69: * ignored, unless they are escaped. jpayne@69: * jpayne@69: *jpayne@69: *
jpayne@69: * \htmlonlyjpayne@69: * jpayne@69: * []
No characters jpayne@69: *jpayne@69: * jpayne@69: * [a]
The character 'a' jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * [ae]
The characters 'a' and 'e' jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * [a-e]
The characters 'a' through 'e' inclusive, in Unicode code jpayne@69: * point order jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * [\\u4E01]
The character U+4E01 jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * [a{ab}{ac}]
The character 'a' and the multicharacter strings "ab" and jpayne@69: * "ac" jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * [\\p{Lu}]
All characters in the general category Uppercase Letter jpayne@69: *
Property patterns specify a set of characters having a certain jpayne@69: * property as defined by the Unicode standard. Both the POSIX-like jpayne@69: * "[:Lu:]" and the Perl-like syntax "\\p{Lu}" are recognized. For a jpayne@69: * complete list of supported property patterns, see the User's Guide jpayne@69: * for UnicodeSet at jpayne@69: * jpayne@69: * http://icu-project.org/userguide/unicodeSet.html. jpayne@69: * Actual determination of property data is defined by the underlying jpayne@69: * Unicode database as implemented by UCharacter. jpayne@69: * jpayne@69: *
Patterns specify individual characters, ranges of characters, and jpayne@69: * Unicode property sets. When elements are concatenated, they jpayne@69: * specify their union. To complement a set, place a '^' immediately jpayne@69: * after the opening '['. Property patterns are inverted by modifying jpayne@69: * their delimiters; "[:^foo]" and "\\P{foo}". In any other location, jpayne@69: * '^' has no special meaning. jpayne@69: * jpayne@69: *
Ranges are indicated by placing two a '-' between two jpayne@69: * characters, as in "a-z". This specifies the range of all jpayne@69: * characters from the left to the right, in Unicode order. If the jpayne@69: * left character is greater than or equal to the jpayne@69: * right character it is a syntax error. If a '-' occurs as the first jpayne@69: * character after the opening '[' or '[^', or if it occurs as the jpayne@69: * last character before the closing ']', then it is taken as a jpayne@69: * literal. Thus "[a\-b]", "[-ab]", and "[ab-]" all indicate the same jpayne@69: * set of three characters, 'a', 'b', and '-'. jpayne@69: * jpayne@69: *
Sets may be intersected using the '&' operator or the asymmetric jpayne@69: * set difference may be taken using the '-' operator, for example, jpayne@69: * "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters jpayne@69: * with values less than 4096. Operators ('&' and '|') have equal jpayne@69: * precedence and bind left-to-right. Thus jpayne@69: * "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to jpayne@69: * "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]". This only really matters for jpayne@69: * difference; intersection is commutative. jpayne@69: * jpayne@69: *
[a] | The set containing 'a' jpayne@69: * |
[a-z] | The set containing 'a' jpayne@69: * through 'z' and all letters in between, in Unicode order jpayne@69: * |
[^a-z] | The set containing jpayne@69: * all characters but 'a' through 'z', jpayne@69: * that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF jpayne@69: * |
[[pat1][pat2]]
jpayne@69: * | The union of sets specified by pat1 and pat2 jpayne@69: * |
[[pat1]&[pat2]]
jpayne@69: * | The intersection of sets specified by pat1 and pat2 jpayne@69: * |
[[pat1]-[pat2]]
jpayne@69: * | The asymmetric difference of sets specified by pat1 and jpayne@69: * pat2 jpayne@69: * |
[:Lu:] or \\p{Lu}
jpayne@69: * | The set of characters having the specified jpayne@69: * Unicode property; in jpayne@69: * this case, Unicode uppercase letters jpayne@69: * |
[:^Lu:] or \\P{Lu}
jpayne@69: * | The set of characters not having the given jpayne@69: * Unicode property jpayne@69: * |
Warning: you cannot add an empty string ("") to a UnicodeSet.
jpayne@69: * jpayne@69: *Formal syntax
jpayne@69: * jpayne@69: * \htmlonly\endhtmlonly jpayne@69: *\endhtmlonly jpayne@69: * jpayne@69: *jpayne@69: *
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * pattern :=
jpayne@69: * ('[' '^'? item* ']') | jpayne@69: * property
jpayne@69: * jpayne@69: *jpayne@69: * item :=
jpayne@69: * char | (char '-' char) | pattern-expr
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * pattern-expr :=
jpayne@69: * pattern | pattern-expr pattern | jpayne@69: * pattern-expr op pattern
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * op :=
jpayne@69: * '&' | '-'
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * special :=
jpayne@69: * '[' | ']' | '-'
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * char :=
any character that is not jpayne@69: *special
any character
jpayne@69: * | ('\')
jpayne@69: * | ('\\u' hex hex hex hex)
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * hex :=
any character for which jpayne@69: * jpayne@69: *Character.digit(c, 16)
jpayne@69: * returns a non-negative resultjpayne@69: * jpayne@69: *jpayne@69: * property :=
a Unicode property set pattern jpayne@69: *
jpayne@69: *jpayne@69: *
jpayne@69: * \htmlonlyjpayne@69: * jpayne@69: *Legend: jpayne@69: *jpayne@69: *
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * a := b
jpayne@69: * jpayne@69: * a
may be replaced byb
jpayne@69: * jpayne@69: *jpayne@69: * a?
jpayne@69: * zero or one instance of jpayne@69: *a
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * a*
jpayne@69: * one or more instances of jpayne@69: *a
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * a | b
jpayne@69: * either jpayne@69: *a
orb
jpayne@69: *jpayne@69: * jpayne@69: *jpayne@69: * 'a'
jpayne@69: * the literal string between the quotes jpayne@69: *
Note:
jpayne@69: * - Most UnicodeSet methods do not take a UErrorCode parameter because
jpayne@69: * there are usually very few opportunities for failure other than a shortage
jpayne@69: * of memory, error codes in low-level C++ string methods would be inconvenient,
jpayne@69: * and the error code as the last parameter (ICU convention) would prevent
jpayne@69: * the use of default parameter values.
jpayne@69: * Instead, such methods set the UnicodeSet into a "bogus" state
jpayne@69: * (see isBogus()) if an error occurs.
jpayne@69: *
jpayne@69: * @author Alan Liu
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: class U_COMMON_API UnicodeSet U_FINAL : public UnicodeFilter {
jpayne@69: private:
jpayne@69: /**
jpayne@69: * Enough for sets with few ranges.
jpayne@69: * For example, White_Space has 10 ranges, list length 21.
jpayne@69: */
jpayne@69: static constexpr int32_t INITIAL_CAPACITY = 25;
jpayne@69: // fFlags constant
jpayne@69: static constexpr uint8_t kIsBogus = 1; // This set is bogus (i.e. not valid)
jpayne@69:
jpayne@69: UChar32* list = stackList; // MUST be terminated with HIGH
jpayne@69: int32_t capacity = INITIAL_CAPACITY; // capacity of list
jpayne@69: int32_t len = 1; // length of list used; 1 <= len <= capacity
jpayne@69: uint8_t fFlags = 0; // Bit flag (see constants above)
jpayne@69:
jpayne@69: BMPSet *bmpSet = nullptr; // The set is frozen iff either bmpSet or stringSpan is not NULL.
jpayne@69: UChar32* buffer = nullptr; // internal buffer, may be NULL
jpayne@69: int32_t bufferCapacity = 0; // capacity of buffer
jpayne@69:
jpayne@69: /**
jpayne@69: * The pattern representation of this set. This may not be the
jpayne@69: * most economical pattern. It is the pattern supplied to
jpayne@69: * applyPattern(), with variables substituted and whitespace
jpayne@69: * removed. For sets constructed without applyPattern(), or
jpayne@69: * modified using the non-pattern API, this string will be empty,
jpayne@69: * indicating that toPattern() must generate a pattern
jpayne@69: * representation from the inversion list.
jpayne@69: */
jpayne@69: char16_t *pat = nullptr;
jpayne@69: int32_t patLen = 0;
jpayne@69:
jpayne@69: UVector* strings = nullptr; // maintained in sorted order
jpayne@69: UnicodeSetStringSpan *stringSpan = nullptr;
jpayne@69:
jpayne@69: /**
jpayne@69: * Initial list array.
jpayne@69: * Avoids some heap allocations, and list is never nullptr.
jpayne@69: * Increases the object size a bit.
jpayne@69: */
jpayne@69: UChar32 stackList[INITIAL_CAPACITY];
jpayne@69:
jpayne@69: public:
jpayne@69: /**
jpayne@69: * Determine if this object contains a valid set.
jpayne@69: * A bogus set has no value. It is different from an empty set.
jpayne@69: * It can be used to indicate that no set value is available.
jpayne@69: *
jpayne@69: * @return TRUE if the set is bogus/invalid, FALSE otherwise
jpayne@69: * @see setToBogus()
jpayne@69: * @stable ICU 4.0
jpayne@69: */
jpayne@69: inline UBool isBogus(void) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Make this UnicodeSet object invalid.
jpayne@69: * The string will test TRUE with isBogus().
jpayne@69: *
jpayne@69: * A bogus set has no value. It is different from an empty set.
jpayne@69: * It can be used to indicate that no set value is available.
jpayne@69: *
jpayne@69: * This utility function is used throughout the UnicodeSet
jpayne@69: * implementation to indicate that a UnicodeSet operation failed,
jpayne@69: * and may be used in other functions,
jpayne@69: * especially but not exclusively when such functions do not
jpayne@69: * take a UErrorCode for simplicity.
jpayne@69: *
jpayne@69: * @see isBogus()
jpayne@69: * @stable ICU 4.0
jpayne@69: */
jpayne@69: void setToBogus();
jpayne@69:
jpayne@69: public:
jpayne@69:
jpayne@69: enum {
jpayne@69: /**
jpayne@69: * Minimum value that can be stored in a UnicodeSet.
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: MIN_VALUE = 0,
jpayne@69:
jpayne@69: /**
jpayne@69: * Maximum value that can be stored in a UnicodeSet.
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: MAX_VALUE = 0x10ffff
jpayne@69: };
jpayne@69:
jpayne@69: //----------------------------------------------------------------
jpayne@69: // Constructors &c
jpayne@69: //----------------------------------------------------------------
jpayne@69:
jpayne@69: public:
jpayne@69:
jpayne@69: /**
jpayne@69: * Constructs an empty set.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: UnicodeSet();
jpayne@69:
jpayne@69: /**
jpayne@69: * Constructs a set containing the given range. If end <
jpayne@69: * start
then an empty set is created.
jpayne@69: *
jpayne@69: * @param start first character, inclusive, of range
jpayne@69: * @param end last character, inclusive, of range
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet(UChar32 start, UChar32 end);
jpayne@69:
jpayne@69: #ifndef U_HIDE_INTERNAL_API
jpayne@69: /**
jpayne@69: * @internal
jpayne@69: */
jpayne@69: enum ESerialization {
jpayne@69: kSerialized /* result of serialize() */
jpayne@69: };
jpayne@69:
jpayne@69: /**
jpayne@69: * Constructs a set from the output of serialize().
jpayne@69: *
jpayne@69: * @param buffer the 16 bit array
jpayne@69: * @param bufferLen the original length returned from serialize()
jpayne@69: * @param serialization the value 'kSerialized'
jpayne@69: * @param status error code
jpayne@69: *
jpayne@69: * @internal
jpayne@69: */
jpayne@69: UnicodeSet(const uint16_t buffer[], int32_t bufferLen,
jpayne@69: ESerialization serialization, UErrorCode &status);
jpayne@69: #endif /* U_HIDE_INTERNAL_API */
jpayne@69:
jpayne@69: /**
jpayne@69: * Constructs a set from the given pattern. See the class
jpayne@69: * description for the syntax of the pattern language.
jpayne@69: * @param pattern a string specifying what characters are in the set
jpayne@69: * @param status returns U_ILLEGAL_ARGUMENT_ERROR
if the pattern
jpayne@69: * contains a syntax error.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: UnicodeSet(const UnicodeString& pattern,
jpayne@69: UErrorCode& status);
jpayne@69:
jpayne@69: #ifndef U_HIDE_INTERNAL_API
jpayne@69: /**
jpayne@69: * Constructs a set from the given pattern. See the class
jpayne@69: * description for the syntax of the pattern language.
jpayne@69: * @param pattern a string specifying what characters are in the set
jpayne@69: * @param options bitmask for options to apply to the pattern.
jpayne@69: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
jpayne@69: * @param symbols a symbol table mapping variable names to values
jpayne@69: * and stand-in characters to UnicodeSets; may be NULL
jpayne@69: * @param status returns U_ILLEGAL_ARGUMENT_ERROR
if the pattern
jpayne@69: * contains a syntax error.
jpayne@69: * @internal
jpayne@69: */
jpayne@69: UnicodeSet(const UnicodeString& pattern,
jpayne@69: uint32_t options,
jpayne@69: const SymbolTable* symbols,
jpayne@69: UErrorCode& status);
jpayne@69: #endif /* U_HIDE_INTERNAL_API */
jpayne@69:
jpayne@69: /**
jpayne@69: * Constructs a set from the given pattern. See the class description
jpayne@69: * for the syntax of the pattern language.
jpayne@69: * @param pattern a string specifying what characters are in the set
jpayne@69: * @param pos on input, the position in pattern at which to start parsing.
jpayne@69: * On output, the position after the last character parsed.
jpayne@69: * @param options bitmask for options to apply to the pattern.
jpayne@69: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
jpayne@69: * @param symbols a symbol table mapping variable names to values
jpayne@69: * and stand-in characters to UnicodeSets; may be NULL
jpayne@69: * @param status input-output error code
jpayne@69: * @stable ICU 2.8
jpayne@69: */
jpayne@69: UnicodeSet(const UnicodeString& pattern, ParsePosition& pos,
jpayne@69: uint32_t options,
jpayne@69: const SymbolTable* symbols,
jpayne@69: UErrorCode& status);
jpayne@69:
jpayne@69: /**
jpayne@69: * Constructs a set that is identical to the given UnicodeSet.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: UnicodeSet(const UnicodeSet& o);
jpayne@69:
jpayne@69: /**
jpayne@69: * Destructs the set.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual ~UnicodeSet();
jpayne@69:
jpayne@69: /**
jpayne@69: * Assigns this object to be a copy of another.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: UnicodeSet& operator=(const UnicodeSet& o);
jpayne@69:
jpayne@69: /**
jpayne@69: * Compares the specified object with this set for equality. Returns
jpayne@69: * true if the two sets
jpayne@69: * have the same size, and every member of the specified set is
jpayne@69: * contained in this set (or equivalently, every member of this set is
jpayne@69: * contained in the specified set).
jpayne@69: *
jpayne@69: * @param o set to be compared for equality with this set.
jpayne@69: * @return true if the specified set is equal to this set.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UBool operator==(const UnicodeSet& o) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Compares the specified object with this set for equality. Returns
jpayne@69: * true if the specified set is not equal to this set.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: inline UBool operator!=(const UnicodeSet& o) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns a copy of this object. All UnicodeFunctor objects have
jpayne@69: * to support cloning in order to allow classes using
jpayne@69: * UnicodeFunctors, such as Transliterator, to implement cloning.
jpayne@69: * If this set is frozen, then the clone will be frozen as well.
jpayne@69: * Use cloneAsThawed() for a mutable clone of a frozen set.
jpayne@69: * @see cloneAsThawed
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet* clone() const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the hash code value for this set.
jpayne@69: *
jpayne@69: * @return the hash code value for this set.
jpayne@69: * @see Object#hashCode()
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual int32_t hashCode(void) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Get a UnicodeSet pointer from a USet
jpayne@69: *
jpayne@69: * @param uset a USet (the ICU plain C type for UnicodeSet)
jpayne@69: * @return the corresponding UnicodeSet pointer.
jpayne@69: *
jpayne@69: * @stable ICU 4.2
jpayne@69: */
jpayne@69: inline static UnicodeSet *fromUSet(USet *uset);
jpayne@69:
jpayne@69: /**
jpayne@69: * Get a UnicodeSet pointer from a const USet
jpayne@69: *
jpayne@69: * @param uset a const USet (the ICU plain C type for UnicodeSet)
jpayne@69: * @return the corresponding UnicodeSet pointer.
jpayne@69: *
jpayne@69: * @stable ICU 4.2
jpayne@69: */
jpayne@69: inline static const UnicodeSet *fromUSet(const USet *uset);
jpayne@69:
jpayne@69: /**
jpayne@69: * Produce a USet * pointer for this UnicodeSet.
jpayne@69: * USet is the plain C type for UnicodeSet
jpayne@69: *
jpayne@69: * @return a USet pointer for this UnicodeSet
jpayne@69: * @stable ICU 4.2
jpayne@69: */
jpayne@69: inline USet *toUSet();
jpayne@69:
jpayne@69:
jpayne@69: /**
jpayne@69: * Produce a const USet * pointer for this UnicodeSet.
jpayne@69: * USet is the plain C type for UnicodeSet
jpayne@69: *
jpayne@69: * @return a const USet pointer for this UnicodeSet
jpayne@69: * @stable ICU 4.2
jpayne@69: */
jpayne@69: inline const USet * toUSet() const;
jpayne@69:
jpayne@69:
jpayne@69: //----------------------------------------------------------------
jpayne@69: // Freezable API
jpayne@69: //----------------------------------------------------------------
jpayne@69:
jpayne@69: /**
jpayne@69: * Determines whether the set has been frozen (made immutable) or not.
jpayne@69: * See the ICU4J Freezable interface for details.
jpayne@69: * @return TRUE/FALSE for whether the set has been frozen
jpayne@69: * @see freeze
jpayne@69: * @see cloneAsThawed
jpayne@69: * @stable ICU 3.8
jpayne@69: */
jpayne@69: inline UBool isFrozen() const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Freeze the set (make it immutable).
jpayne@69: * Once frozen, it cannot be unfrozen and is therefore thread-safe
jpayne@69: * until it is deleted.
jpayne@69: * See the ICU4J Freezable interface for details.
jpayne@69: * Freezing the set may also make some operations faster, for example
jpayne@69: * contains() and span().
jpayne@69: * A frozen set will not be modified. (It remains frozen.)
jpayne@69: * @return this set.
jpayne@69: * @see isFrozen
jpayne@69: * @see cloneAsThawed
jpayne@69: * @stable ICU 3.8
jpayne@69: */
jpayne@69: UnicodeSet *freeze();
jpayne@69:
jpayne@69: /**
jpayne@69: * Clone the set and make the clone mutable.
jpayne@69: * See the ICU4J Freezable interface for details.
jpayne@69: * @return the mutable clone
jpayne@69: * @see freeze
jpayne@69: * @see isFrozen
jpayne@69: * @stable ICU 3.8
jpayne@69: */
jpayne@69: UnicodeSet *cloneAsThawed() const;
jpayne@69:
jpayne@69: //----------------------------------------------------------------
jpayne@69: // Public API
jpayne@69: //----------------------------------------------------------------
jpayne@69:
jpayne@69: /**
jpayne@69: * Make this object represent the range `start - end`.
jpayne@69: * If `end > start` then this object is set to an empty range.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param start first character in the set, inclusive
jpayne@69: * @param end last character in the set, inclusive
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& set(UChar32 start, UChar32 end);
jpayne@69:
jpayne@69: /**
jpayne@69: * Return true if the given position, in the given pattern, appears
jpayne@69: * to be the start of a UnicodeSet pattern.
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: static UBool resemblesPattern(const UnicodeString& pattern,
jpayne@69: int32_t pos);
jpayne@69:
jpayne@69: /**
jpayne@69: * Modifies this set to represent the set specified by the given
jpayne@69: * pattern, ignoring Unicode Pattern_White_Space characters.
jpayne@69: * See the class description for the syntax of the pattern language.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param pattern a string specifying what characters are in the set
jpayne@69: * @param status returns U_ILLEGAL_ARGUMENT_ERROR
if the pattern
jpayne@69: * contains a syntax error.
jpayne@69: * Empties the set passed before applying the pattern.
jpayne@69: * @return a reference to this
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: UnicodeSet& applyPattern(const UnicodeString& pattern,
jpayne@69: UErrorCode& status);
jpayne@69:
jpayne@69: #ifndef U_HIDE_INTERNAL_API
jpayne@69: /**
jpayne@69: * Modifies this set to represent the set specified by the given
jpayne@69: * pattern, optionally ignoring Unicode Pattern_White_Space characters.
jpayne@69: * See the class description for the syntax of the pattern language.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param pattern a string specifying what characters are in the set
jpayne@69: * @param options bitmask for options to apply to the pattern.
jpayne@69: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
jpayne@69: * @param symbols a symbol table mapping variable names to
jpayne@69: * values and stand-ins to UnicodeSets; may be NULL
jpayne@69: * @param status returns U_ILLEGAL_ARGUMENT_ERROR
if the pattern
jpayne@69: * contains a syntax error.
jpayne@69: * Empties the set passed before applying the pattern.
jpayne@69: * @return a reference to this
jpayne@69: * @internal
jpayne@69: */
jpayne@69: UnicodeSet& applyPattern(const UnicodeString& pattern,
jpayne@69: uint32_t options,
jpayne@69: const SymbolTable* symbols,
jpayne@69: UErrorCode& status);
jpayne@69: #endif /* U_HIDE_INTERNAL_API */
jpayne@69:
jpayne@69: /**
jpayne@69: * Parses the given pattern, starting at the given position. The
jpayne@69: * character at pattern.charAt(pos.getIndex()) must be '[', or the
jpayne@69: * parse fails. Parsing continues until the corresponding closing
jpayne@69: * ']'. If a syntax error is encountered between the opening and
jpayne@69: * closing brace, the parse fails. Upon return from a successful
jpayne@69: * parse, the ParsePosition is updated to point to the character
jpayne@69: * following the closing ']', and a StringBuffer containing a
jpayne@69: * pairs list for the parsed pattern is returned. This method calls
jpayne@69: * itself recursively to parse embedded subpatterns.
jpayne@69: * Empties the set passed before applying the pattern.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param pattern the string containing the pattern to be parsed.
jpayne@69: * The portion of the string from pos.getIndex(), which must be a
jpayne@69: * '[', to the corresponding closing ']', is parsed.
jpayne@69: * @param pos upon entry, the position at which to being parsing.
jpayne@69: * The character at pattern.charAt(pos.getIndex()) must be a '['.
jpayne@69: * Upon return from a successful parse, pos.getIndex() is either
jpayne@69: * the character after the closing ']' of the parsed pattern, or
jpayne@69: * pattern.length() if the closing ']' is the last character of
jpayne@69: * the pattern string.
jpayne@69: * @param options bitmask for options to apply to the pattern.
jpayne@69: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
jpayne@69: * @param symbols a symbol table mapping variable names to
jpayne@69: * values and stand-ins to UnicodeSets; may be NULL
jpayne@69: * @param status returns U_ILLEGAL_ARGUMENT_ERROR
if the pattern
jpayne@69: * contains a syntax error.
jpayne@69: * @return a reference to this
jpayne@69: * @stable ICU 2.8
jpayne@69: */
jpayne@69: UnicodeSet& applyPattern(const UnicodeString& pattern,
jpayne@69: ParsePosition& pos,
jpayne@69: uint32_t options,
jpayne@69: const SymbolTable* symbols,
jpayne@69: UErrorCode& status);
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns a string representation of this set. If the result of
jpayne@69: * calling this function is passed to a UnicodeSet constructor, it
jpayne@69: * will produce another set that is equal to this one.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param result the string to receive the rules. Previous
jpayne@69: * contents will be deleted.
jpayne@69: * @param escapeUnprintable if TRUE then convert unprintable
jpayne@69: * character to their hex escape representations, \\uxxxx or
jpayne@69: * \\Uxxxxxxxx. Unprintable characters are those other than
jpayne@69: * U+000A, U+0020..U+007E.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeString& toPattern(UnicodeString& result,
jpayne@69: UBool escapeUnprintable = FALSE) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Modifies this set to contain those code points which have the given value
jpayne@69: * for the given binary or enumerated property, as returned by
jpayne@69: * u_getIntPropertyValue. Prior contents of this set are lost.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
jpayne@69: * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
jpayne@69: * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
jpayne@69: *
jpayne@69: * @param value a value in the range u_getIntPropertyMinValue(prop)..
jpayne@69: * u_getIntPropertyMaxValue(prop), with one exception. If prop is
jpayne@69: * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
jpayne@69: * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
jpayne@69: * categories such as [:L:] to be represented.
jpayne@69: *
jpayne@69: * @param ec error code input/output parameter
jpayne@69: *
jpayne@69: * @return a reference to this set
jpayne@69: *
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& applyIntPropertyValue(UProperty prop,
jpayne@69: int32_t value,
jpayne@69: UErrorCode& ec);
jpayne@69:
jpayne@69: /**
jpayne@69: * Modifies this set to contain those code points which have the
jpayne@69: * given value for the given property. Prior contents of this
jpayne@69: * set are lost.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param prop a property alias, either short or long. The name is matched
jpayne@69: * loosely. See PropertyAliases.txt for names and a description of loose
jpayne@69: * matching. If the value string is empty, then this string is interpreted
jpayne@69: * as either a General_Category value alias, a Script value alias, a binary
jpayne@69: * property alias, or a special ID. Special IDs are matched loosely and
jpayne@69: * correspond to the following sets:
jpayne@69: *
jpayne@69: * "ANY" = [\\u0000-\\U0010FFFF],
jpayne@69: * "ASCII" = [\\u0000-\\u007F],
jpayne@69: * "Assigned" = [:^Cn:].
jpayne@69: *
jpayne@69: * @param value a value alias, either short or long. The name is matched
jpayne@69: * loosely. See PropertyValueAliases.txt for names and a description of
jpayne@69: * loose matching. In addition to aliases listed, numeric values and
jpayne@69: * canonical combining classes may be expressed numerically, e.g., ("nv",
jpayne@69: * "0.5") or ("ccc", "220"). The value string may also be empty.
jpayne@69: *
jpayne@69: * @param ec error code input/output parameter
jpayne@69: *
jpayne@69: * @return a reference to this set
jpayne@69: *
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& applyPropertyAlias(const UnicodeString& prop,
jpayne@69: const UnicodeString& value,
jpayne@69: UErrorCode& ec);
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the number of elements in this set (its cardinality).
jpayne@69: * Note than the elements of a set may include both individual
jpayne@69: * codepoints and strings.
jpayne@69: *
jpayne@69: * @return the number of elements in this set (its cardinality).
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual int32_t size(void) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains no elements.
jpayne@69: *
jpayne@69: * @return true if this set contains no elements.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UBool isEmpty(void) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains the given character.
jpayne@69: * This function works faster with a frozen set.
jpayne@69: * @param c character to be checked for containment
jpayne@69: * @return true if the test condition is met
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UBool contains(UChar32 c) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains every character
jpayne@69: * of the given range.
jpayne@69: * @param start first character, inclusive, of the range
jpayne@69: * @param end last character, inclusive, of the range
jpayne@69: * @return true if the test condition is met
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UBool contains(UChar32 start, UChar32 end) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains the given
jpayne@69: * multicharacter string.
jpayne@69: * @param s string to be checked for containment
jpayne@69: * @return true if this set contains the specified string
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UBool contains(const UnicodeString& s) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains all the characters and strings
jpayne@69: * of the given set.
jpayne@69: * @param c set to be checked for containment
jpayne@69: * @return true if the test condition is met
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: virtual UBool containsAll(const UnicodeSet& c) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains all the characters
jpayne@69: * of the given string.
jpayne@69: * @param s string containing characters to be checked for containment
jpayne@69: * @return true if the test condition is met
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UBool containsAll(const UnicodeString& s) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains none of the characters
jpayne@69: * of the given range.
jpayne@69: * @param start first character, inclusive, of the range
jpayne@69: * @param end last character, inclusive, of the range
jpayne@69: * @return true if the test condition is met
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UBool containsNone(UChar32 start, UChar32 end) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains none of the characters and strings
jpayne@69: * of the given set.
jpayne@69: * @param c set to be checked for containment
jpayne@69: * @return true if the test condition is met
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UBool containsNone(const UnicodeSet& c) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains none of the characters
jpayne@69: * of the given string.
jpayne@69: * @param s string containing characters to be checked for containment
jpayne@69: * @return true if the test condition is met
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UBool containsNone(const UnicodeString& s) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains one or more of the characters
jpayne@69: * in the given range.
jpayne@69: * @param start first character, inclusive, of the range
jpayne@69: * @param end last character, inclusive, of the range
jpayne@69: * @return true if the condition is met
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: inline UBool containsSome(UChar32 start, UChar32 end) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains one or more of the characters
jpayne@69: * and strings of the given set.
jpayne@69: * @param s The set to be checked for containment
jpayne@69: * @return true if the condition is met
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: inline UBool containsSome(const UnicodeSet& s) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if this set contains one or more of the characters
jpayne@69: * of the given string.
jpayne@69: * @param s string containing characters to be checked for containment
jpayne@69: * @return true if the condition is met
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: inline UBool containsSome(const UnicodeString& s) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the length of the initial substring of the input string which
jpayne@69: * consists only of characters and strings that are contained in this set
jpayne@69: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
jpayne@69: * or only of characters and strings that are not contained
jpayne@69: * in this set (USET_SPAN_NOT_CONTAINED).
jpayne@69: * See USetSpanCondition for details.
jpayne@69: * Similar to the strspn() C library function.
jpayne@69: * Unpaired surrogates are treated according to contains() of their surrogate code points.
jpayne@69: * This function works faster with a frozen set and with a non-negative string length argument.
jpayne@69: * @param s start of the string
jpayne@69: * @param length of the string; can be -1 for NUL-terminated
jpayne@69: * @param spanCondition specifies the containment condition
jpayne@69: * @return the length of the initial substring according to the spanCondition;
jpayne@69: * 0 if the start of the string does not fit the spanCondition
jpayne@69: * @stable ICU 3.8
jpayne@69: * @see USetSpanCondition
jpayne@69: */
jpayne@69: int32_t span(const char16_t *s, int32_t length, USetSpanCondition spanCondition) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the end of the substring of the input string according to the USetSpanCondition.
jpayne@69: * Same as start+span(s.getBuffer()+start, s.length()-start, spanCondition)
jpayne@69: * after pinning start to 0<=start<=s.length().
jpayne@69: * @param s the string
jpayne@69: * @param start the start index in the string for the span operation
jpayne@69: * @param spanCondition specifies the containment condition
jpayne@69: * @return the exclusive end of the substring according to the spanCondition;
jpayne@69: * the substring s.tempSubStringBetween(start, end) fulfills the spanCondition
jpayne@69: * @stable ICU 4.4
jpayne@69: * @see USetSpanCondition
jpayne@69: */
jpayne@69: inline int32_t span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the start of the trailing substring of the input string which
jpayne@69: * consists only of characters and strings that are contained in this set
jpayne@69: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
jpayne@69: * or only of characters and strings that are not contained
jpayne@69: * in this set (USET_SPAN_NOT_CONTAINED).
jpayne@69: * See USetSpanCondition for details.
jpayne@69: * Unpaired surrogates are treated according to contains() of their surrogate code points.
jpayne@69: * This function works faster with a frozen set and with a non-negative string length argument.
jpayne@69: * @param s start of the string
jpayne@69: * @param length of the string; can be -1 for NUL-terminated
jpayne@69: * @param spanCondition specifies the containment condition
jpayne@69: * @return the start of the trailing substring according to the spanCondition;
jpayne@69: * the string length if the end of the string does not fit the spanCondition
jpayne@69: * @stable ICU 3.8
jpayne@69: * @see USetSpanCondition
jpayne@69: */
jpayne@69: int32_t spanBack(const char16_t *s, int32_t length, USetSpanCondition spanCondition) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the start of the substring of the input string according to the USetSpanCondition.
jpayne@69: * Same as spanBack(s.getBuffer(), limit, spanCondition)
jpayne@69: * after pinning limit to 0<=end<=s.length().
jpayne@69: * @param s the string
jpayne@69: * @param limit the exclusive-end index in the string for the span operation
jpayne@69: * (use s.length() or INT32_MAX for spanning back from the end of the string)
jpayne@69: * @param spanCondition specifies the containment condition
jpayne@69: * @return the start of the substring according to the spanCondition;
jpayne@69: * the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition
jpayne@69: * @stable ICU 4.4
jpayne@69: * @see USetSpanCondition
jpayne@69: */
jpayne@69: inline int32_t spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the length of the initial substring of the input string which
jpayne@69: * consists only of characters and strings that are contained in this set
jpayne@69: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
jpayne@69: * or only of characters and strings that are not contained
jpayne@69: * in this set (USET_SPAN_NOT_CONTAINED).
jpayne@69: * See USetSpanCondition for details.
jpayne@69: * Similar to the strspn() C library function.
jpayne@69: * Malformed byte sequences are treated according to contains(0xfffd).
jpayne@69: * This function works faster with a frozen set and with a non-negative string length argument.
jpayne@69: * @param s start of the string (UTF-8)
jpayne@69: * @param length of the string; can be -1 for NUL-terminated
jpayne@69: * @param spanCondition specifies the containment condition
jpayne@69: * @return the length of the initial substring according to the spanCondition;
jpayne@69: * 0 if the start of the string does not fit the spanCondition
jpayne@69: * @stable ICU 3.8
jpayne@69: * @see USetSpanCondition
jpayne@69: */
jpayne@69: int32_t spanUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the start of the trailing substring of the input string which
jpayne@69: * consists only of characters and strings that are contained in this set
jpayne@69: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
jpayne@69: * or only of characters and strings that are not contained
jpayne@69: * in this set (USET_SPAN_NOT_CONTAINED).
jpayne@69: * See USetSpanCondition for details.
jpayne@69: * Malformed byte sequences are treated according to contains(0xfffd).
jpayne@69: * This function works faster with a frozen set and with a non-negative string length argument.
jpayne@69: * @param s start of the string (UTF-8)
jpayne@69: * @param length of the string; can be -1 for NUL-terminated
jpayne@69: * @param spanCondition specifies the containment condition
jpayne@69: * @return the start of the trailing substring according to the spanCondition;
jpayne@69: * the string length if the end of the string does not fit the spanCondition
jpayne@69: * @stable ICU 3.8
jpayne@69: * @see USetSpanCondition
jpayne@69: */
jpayne@69: int32_t spanBackUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Implement UnicodeMatcher::matches()
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: virtual UMatchDegree matches(const Replaceable& text,
jpayne@69: int32_t& offset,
jpayne@69: int32_t limit,
jpayne@69: UBool incremental);
jpayne@69:
jpayne@69: private:
jpayne@69: /**
jpayne@69: * Returns the longest match for s in text at the given position.
jpayne@69: * If limit > start then match forward from start+1 to limit
jpayne@69: * matching all characters except s.charAt(0). If limit < start,
jpayne@69: * go backward starting from start-1 matching all characters
jpayne@69: * except s.charAt(s.length()-1). This method assumes that the
jpayne@69: * first character, text.charAt(start), matches s, so it does not
jpayne@69: * check it.
jpayne@69: * @param text the text to match
jpayne@69: * @param start the first character to match. In the forward
jpayne@69: * direction, text.charAt(start) is matched against s.charAt(0).
jpayne@69: * In the reverse direction, it is matched against
jpayne@69: * s.charAt(s.length()-1).
jpayne@69: * @param limit the limit offset for matching, either last+1 in
jpayne@69: * the forward direction, or last-1 in the reverse direction,
jpayne@69: * where last is the index of the last character to match.
jpayne@69: * @param s
jpayne@69: * @return If part of s matches up to the limit, return |limit -
jpayne@69: * start|. If all of s matches before reaching the limit, return
jpayne@69: * s.length(). If there is a mismatch between s and text, return
jpayne@69: * 0
jpayne@69: */
jpayne@69: static int32_t matchRest(const Replaceable& text,
jpayne@69: int32_t start, int32_t limit,
jpayne@69: const UnicodeString& s);
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the smallest value i such that c < list[i]. Caller
jpayne@69: * must ensure that c is a legal value or this method will enter
jpayne@69: * an infinite loop. This method performs a binary search.
jpayne@69: * @param c a character in the range MIN_VALUE..MAX_VALUE
jpayne@69: * inclusive
jpayne@69: * @return the smallest integer i in the range 0..len-1,
jpayne@69: * inclusive, such that c < list[i]
jpayne@69: */
jpayne@69: int32_t findCodePoint(UChar32 c) const;
jpayne@69:
jpayne@69: public:
jpayne@69:
jpayne@69: /**
jpayne@69: * Implementation of UnicodeMatcher API. Union the set of all
jpayne@69: * characters that may be matched by this object into the given
jpayne@69: * set.
jpayne@69: * @param toUnionTo the set into which to union the source characters
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: virtual void addMatchSetTo(UnicodeSet& toUnionTo) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the index of the given character within this set, where
jpayne@69: * the set is ordered by ascending code point. If the character
jpayne@69: * is not in this set, return -1. The inverse of this method is
jpayne@69: * charAt()
.
jpayne@69: * @return an index from 0..size()-1, or -1
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: int32_t indexOf(UChar32 c) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the character at the given index within this set, where
jpayne@69: * the set is ordered by ascending code point. If the index is
jpayne@69: * out of range, return (UChar32)-1. The inverse of this method is
jpayne@69: * indexOf()
.
jpayne@69: * @param index an index from 0..size()-1
jpayne@69: * @return the character at the given index, or (UChar32)-1.
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UChar32 charAt(int32_t index) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Adds the specified range to this set if it is not already
jpayne@69: * present. If this set already contains the specified range,
jpayne@69: * the call leaves this set unchanged. If end > start
jpayne@69: * then an empty range is added, leaving the set unchanged.
jpayne@69: * This is equivalent to a boolean logic OR, or a set UNION.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param start first character, inclusive, of range to be added
jpayne@69: * to this set.
jpayne@69: * @param end last character, inclusive, of range to be added
jpayne@69: * to this set.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet& add(UChar32 start, UChar32 end);
jpayne@69:
jpayne@69: /**
jpayne@69: * Adds the specified character to this set if it is not already
jpayne@69: * present. If this set already contains the specified character,
jpayne@69: * the call leaves this set unchanged.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: UnicodeSet& add(UChar32 c);
jpayne@69:
jpayne@69: /**
jpayne@69: * Adds the specified multicharacter to this set if it is not already
jpayne@69: * present. If this set already contains the multicharacter,
jpayne@69: * the call leaves this set unchanged.
jpayne@69: * Thus "ch" => {"ch"}
jpayne@69: *
Warning: you cannot add an empty string ("") to a UnicodeSet.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param s the source string
jpayne@69: * @return this object, for chaining
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& add(const UnicodeString& s);
jpayne@69:
jpayne@69: private:
jpayne@69: /**
jpayne@69: * @return a code point IF the string consists of a single one.
jpayne@69: * otherwise returns -1.
jpayne@69: * @param s string to test
jpayne@69: */
jpayne@69: static int32_t getSingleCP(const UnicodeString& s);
jpayne@69:
jpayne@69: void _add(const UnicodeString& s);
jpayne@69:
jpayne@69: public:
jpayne@69: /**
jpayne@69: * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
jpayne@69: * If this set already any particular character, it has no effect on that character.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param s the source string
jpayne@69: * @return this object, for chaining
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& addAll(const UnicodeString& s);
jpayne@69:
jpayne@69: /**
jpayne@69: * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
jpayne@69: * If this set already any particular character, it has no effect on that character.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param s the source string
jpayne@69: * @return this object, for chaining
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& retainAll(const UnicodeString& s);
jpayne@69:
jpayne@69: /**
jpayne@69: * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
jpayne@69: * If this set already any particular character, it has no effect on that character.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param s the source string
jpayne@69: * @return this object, for chaining
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& complementAll(const UnicodeString& s);
jpayne@69:
jpayne@69: /**
jpayne@69: * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
jpayne@69: * If this set already any particular character, it has no effect on that character.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param s the source string
jpayne@69: * @return this object, for chaining
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& removeAll(const UnicodeString& s);
jpayne@69:
jpayne@69: /**
jpayne@69: * Makes a set from a multicharacter string. Thus "ch" => {"ch"}
jpayne@69: *
Warning: you cannot add an empty string ("") to a UnicodeSet.
jpayne@69: * @param s the source string
jpayne@69: * @return a newly created set containing the given string.
jpayne@69: * The caller owns the return object and is responsible for deleting it.
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: static UnicodeSet* U_EXPORT2 createFrom(const UnicodeString& s);
jpayne@69:
jpayne@69:
jpayne@69: /**
jpayne@69: * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
jpayne@69: * @param s the source string
jpayne@69: * @return a newly created set containing the given characters
jpayne@69: * The caller owns the return object and is responsible for deleting it.
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: static UnicodeSet* U_EXPORT2 createFromAll(const UnicodeString& s);
jpayne@69:
jpayne@69: /**
jpayne@69: * Retain only the elements in this set that are contained in the
jpayne@69: * specified range. If end > start
then an empty range is
jpayne@69: * retained, leaving the set empty. This is equivalent to
jpayne@69: * a boolean logic AND, or a set INTERSECTION.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param start first character, inclusive, of range to be retained
jpayne@69: * to this set.
jpayne@69: * @param end last character, inclusive, of range to be retained
jpayne@69: * to this set.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet& retain(UChar32 start, UChar32 end);
jpayne@69:
jpayne@69:
jpayne@69: /**
jpayne@69: * Retain the specified character from this set if it is present.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: UnicodeSet& retain(UChar32 c);
jpayne@69:
jpayne@69: /**
jpayne@69: * Removes the specified range from this set if it is present.
jpayne@69: * The set will not contain the specified range once the call
jpayne@69: * returns. If end > start
then an empty range is
jpayne@69: * removed, leaving the set unchanged.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param start first character, inclusive, of range to be removed
jpayne@69: * from this set.
jpayne@69: * @param end last character, inclusive, of range to be removed
jpayne@69: * from this set.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet& remove(UChar32 start, UChar32 end);
jpayne@69:
jpayne@69: /**
jpayne@69: * Removes the specified character from this set if it is present.
jpayne@69: * The set will not contain the specified range once the call
jpayne@69: * returns.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: UnicodeSet& remove(UChar32 c);
jpayne@69:
jpayne@69: /**
jpayne@69: * Removes the specified string from this set if it is present.
jpayne@69: * The set will not contain the specified character once the call
jpayne@69: * returns.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param s the source string
jpayne@69: * @return this object, for chaining
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& remove(const UnicodeString& s);
jpayne@69:
jpayne@69: /**
jpayne@69: * Inverts this set. This operation modifies this set so that
jpayne@69: * its value is its complement. This is equivalent to
jpayne@69: * complement(MIN_VALUE, MAX_VALUE)
.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet& complement(void);
jpayne@69:
jpayne@69: /**
jpayne@69: * Complements the specified range in this set. Any character in
jpayne@69: * the range will be removed if it is in this set, or will be
jpayne@69: * added if it is not in this set. If end > start
jpayne@69: * then an empty range is complemented, leaving the set unchanged.
jpayne@69: * This is equivalent to a boolean logic XOR.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param start first character, inclusive, of range to be removed
jpayne@69: * from this set.
jpayne@69: * @param end last character, inclusive, of range to be removed
jpayne@69: * from this set.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet& complement(UChar32 start, UChar32 end);
jpayne@69:
jpayne@69: /**
jpayne@69: * Complements the specified character in this set. The character
jpayne@69: * will be removed if it is in this set, or will be added if it is
jpayne@69: * not in this set.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: UnicodeSet& complement(UChar32 c);
jpayne@69:
jpayne@69: /**
jpayne@69: * Complement the specified string in this set.
jpayne@69: * The set will not contain the specified string once the call
jpayne@69: * returns.
jpayne@69: *
Warning: you cannot add an empty string ("") to a UnicodeSet.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @param s the string to complement
jpayne@69: * @return this object, for chaining
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: UnicodeSet& complement(const UnicodeString& s);
jpayne@69:
jpayne@69: /**
jpayne@69: * Adds all of the elements in the specified set to this set if
jpayne@69: * they're not already present. This operation effectively
jpayne@69: * modifies this set so that its value is the union of the two
jpayne@69: * sets. The behavior of this operation is unspecified if the specified
jpayne@69: * collection is modified while the operation is in progress.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param c set whose elements are to be added to this set.
jpayne@69: * @see #add(UChar32, UChar32)
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet& addAll(const UnicodeSet& c);
jpayne@69:
jpayne@69: /**
jpayne@69: * Retains only the elements in this set that are contained in the
jpayne@69: * specified set. In other words, removes from this set all of
jpayne@69: * its elements that are not contained in the specified set. This
jpayne@69: * operation effectively modifies this set so that its value is
jpayne@69: * the intersection of the two sets.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param c set that defines which elements this set will retain.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet& retainAll(const UnicodeSet& c);
jpayne@69:
jpayne@69: /**
jpayne@69: * Removes from this set all of its elements that are contained in the
jpayne@69: * specified set. This operation effectively modifies this
jpayne@69: * set so that its value is the asymmetric set difference of
jpayne@69: * the two sets.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param c set that defines which elements will be removed from
jpayne@69: * this set.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet& removeAll(const UnicodeSet& c);
jpayne@69:
jpayne@69: /**
jpayne@69: * Complements in this set all elements contained in the specified
jpayne@69: * set. Any character in the other set will be removed if it is
jpayne@69: * in this set, or will be added if it is not in this set.
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param c set that defines which elements will be xor'ed from
jpayne@69: * this set.
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: virtual UnicodeSet& complementAll(const UnicodeSet& c);
jpayne@69:
jpayne@69: /**
jpayne@69: * Removes all of the elements from this set. This set will be
jpayne@69: * empty after this call returns.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UnicodeSet& clear(void);
jpayne@69:
jpayne@69: /**
jpayne@69: * Close this set over the given attribute. For the attribute
jpayne@69: * USET_CASE, the result is to modify this set so that:
jpayne@69: *
jpayne@69: * 1. For each character or string 'a' in this set, all strings or
jpayne@69: * characters 'b' such that foldCase(a) == foldCase(b) are added
jpayne@69: * to this set.
jpayne@69: *
jpayne@69: * 2. For each string 'e' in the resulting set, if e !=
jpayne@69: * foldCase(e), 'e' will be removed.
jpayne@69: *
jpayne@69: * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
jpayne@69: *
jpayne@69: * (Here foldCase(x) refers to the operation u_strFoldCase, and a
jpayne@69: * == b denotes that the contents are the same, not pointer
jpayne@69: * comparison.)
jpayne@69: *
jpayne@69: * A frozen set will not be modified.
jpayne@69: *
jpayne@69: * @param attribute bitmask for attributes to close over.
jpayne@69: * Currently only the USET_CASE bit is supported. Any undefined bits
jpayne@69: * are ignored.
jpayne@69: * @return a reference to this set.
jpayne@69: * @stable ICU 4.2
jpayne@69: */
jpayne@69: UnicodeSet& closeOver(int32_t attribute);
jpayne@69:
jpayne@69: /**
jpayne@69: * Remove all strings from this set.
jpayne@69: *
jpayne@69: * @return a reference to this set.
jpayne@69: * @stable ICU 4.2
jpayne@69: */
jpayne@69: virtual UnicodeSet &removeAllStrings();
jpayne@69:
jpayne@69: /**
jpayne@69: * Iteration method that returns the number of ranges contained in
jpayne@69: * this set.
jpayne@69: * @see #getRangeStart
jpayne@69: * @see #getRangeEnd
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: virtual int32_t getRangeCount(void) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Iteration method that returns the first character in the
jpayne@69: * specified range of this set.
jpayne@69: * @see #getRangeCount
jpayne@69: * @see #getRangeEnd
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: virtual UChar32 getRangeStart(int32_t index) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Iteration method that returns the last character in the
jpayne@69: * specified range of this set.
jpayne@69: * @see #getRangeStart
jpayne@69: * @see #getRangeEnd
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: virtual UChar32 getRangeEnd(int32_t index) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Serializes this set into an array of 16-bit integers. Serialization
jpayne@69: * (currently) only records the characters in the set; multicharacter
jpayne@69: * strings are ignored.
jpayne@69: *
jpayne@69: * The array has following format (each line is one 16-bit
jpayne@69: * integer):
jpayne@69: *
jpayne@69: * length = (n+2*m) | (m!=0?0x8000:0)
jpayne@69: * bmpLength = n; present if m!=0
jpayne@69: * bmp[0]
jpayne@69: * bmp[1]
jpayne@69: * ...
jpayne@69: * bmp[n-1]
jpayne@69: * supp-high[0]
jpayne@69: * supp-low[0]
jpayne@69: * supp-high[1]
jpayne@69: * supp-low[1]
jpayne@69: * ...
jpayne@69: * supp-high[m-1]
jpayne@69: * supp-low[m-1]
jpayne@69: *
jpayne@69: * The array starts with a header. After the header are n bmp
jpayne@69: * code points, then m supplementary code points. Either n or m
jpayne@69: * or both may be zero. n+2*m is always <= 0x7FFF.
jpayne@69: *
jpayne@69: * If there are no supplementary characters (if m==0) then the
jpayne@69: * header is one 16-bit integer, 'length', with value n.
jpayne@69: *
jpayne@69: * If there are supplementary characters (if m!=0) then the header
jpayne@69: * is two 16-bit integers. The first, 'length', has value
jpayne@69: * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
jpayne@69: *
jpayne@69: * After the header the code points are stored in ascending order.
jpayne@69: * Supplementary code points are stored as most significant 16
jpayne@69: * bits followed by least significant 16 bits.
jpayne@69: *
jpayne@69: * @param dest pointer to buffer of destCapacity 16-bit integers.
jpayne@69: * May be NULL only if destCapacity is zero.
jpayne@69: * @param destCapacity size of dest, or zero. Must not be negative.
jpayne@69: * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR
jpayne@69: * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if
jpayne@69: * n+2*m+(m!=0?2:1) > destCapacity.
jpayne@69: * @return the total length of the serialized format, including
jpayne@69: * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
jpayne@69: * than U_BUFFER_OVERFLOW_ERROR.
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: int32_t serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Reallocate this objects internal structures to take up the least
jpayne@69: * possible space, without changing this object's value.
jpayne@69: * A frozen set will not be modified.
jpayne@69: * @stable ICU 2.4
jpayne@69: */
jpayne@69: virtual UnicodeSet& compact();
jpayne@69:
jpayne@69: /**
jpayne@69: * Return the class ID for this class. This is useful only for
jpayne@69: * comparing to a return value from getDynamicClassID(). For example:
jpayne@69: *
jpayne@69: * . Base* polymorphic_pointer = createPolymorphicObject(); jpayne@69: * . if (polymorphic_pointer->getDynamicClassID() == jpayne@69: * . Derived::getStaticClassID()) ... jpayne@69: *jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: /** jpayne@69: * Implement UnicodeFunctor API. jpayne@69: * jpayne@69: * @return The class ID for this object. All objects of a given jpayne@69: * class have the same class ID. Objects of other classes have jpayne@69: * different class IDs. jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID(void) const; jpayne@69: jpayne@69: private: jpayne@69: jpayne@69: // Private API for the USet API jpayne@69: jpayne@69: friend class USetAccess; jpayne@69: jpayne@69: const UnicodeString* getString(int32_t index) const; jpayne@69: jpayne@69: //---------------------------------------------------------------- jpayne@69: // RuleBasedTransliterator support jpayne@69: //---------------------------------------------------------------- jpayne@69: jpayne@69: private: jpayne@69: jpayne@69: /** jpayne@69: * Returns true if this set contains any character whose low byte jpayne@69: * is the given value. This is used by RuleBasedTransliterator for jpayne@69: * indexing. jpayne@69: */ jpayne@69: virtual UBool matchesIndexValue(uint8_t v) const; jpayne@69: jpayne@69: private: jpayne@69: friend class RBBIRuleScanner; jpayne@69: jpayne@69: //---------------------------------------------------------------- jpayne@69: // Implementation: Clone as thawed (see ICU4J Freezable) jpayne@69: //---------------------------------------------------------------- jpayne@69: jpayne@69: UnicodeSet(const UnicodeSet& o, UBool /* asThawed */); jpayne@69: UnicodeSet& copyFrom(const UnicodeSet& o, UBool asThawed); jpayne@69: jpayne@69: //---------------------------------------------------------------- jpayne@69: // Implementation: Pattern parsing jpayne@69: //---------------------------------------------------------------- jpayne@69: jpayne@69: void applyPatternIgnoreSpace(const UnicodeString& pattern, jpayne@69: ParsePosition& pos, jpayne@69: const SymbolTable* symbols, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: void applyPattern(RuleCharacterIterator& chars, jpayne@69: const SymbolTable* symbols, jpayne@69: UnicodeString& rebuiltPat, jpayne@69: uint32_t options, jpayne@69: UnicodeSet& (UnicodeSet::*caseClosure)(int32_t attribute), jpayne@69: int32_t depth, jpayne@69: UErrorCode& ec); jpayne@69: jpayne@69: //---------------------------------------------------------------- jpayne@69: // Implementation: Utility methods jpayne@69: //---------------------------------------------------------------- jpayne@69: jpayne@69: static int32_t nextCapacity(int32_t minCapacity); jpayne@69: jpayne@69: bool ensureCapacity(int32_t newLen); jpayne@69: jpayne@69: bool ensureBufferCapacity(int32_t newLen); jpayne@69: jpayne@69: void swapBuffers(void); jpayne@69: jpayne@69: UBool allocateStrings(UErrorCode &status); jpayne@69: UBool hasStrings() const; jpayne@69: int32_t stringsSize() const; jpayne@69: UBool stringsContains(const UnicodeString &s) const; jpayne@69: jpayne@69: UnicodeString& _toPattern(UnicodeString& result, jpayne@69: UBool escapeUnprintable) const; jpayne@69: jpayne@69: UnicodeString& _generatePattern(UnicodeString& result, jpayne@69: UBool escapeUnprintable) const; jpayne@69: jpayne@69: static void _appendToPat(UnicodeString& buf, const UnicodeString& s, UBool escapeUnprintable); jpayne@69: jpayne@69: static void _appendToPat(UnicodeString& buf, UChar32 c, UBool escapeUnprintable); jpayne@69: jpayne@69: //---------------------------------------------------------------- jpayne@69: // Implementation: Fundamental operators jpayne@69: //---------------------------------------------------------------- jpayne@69: jpayne@69: void exclusiveOr(const UChar32* other, int32_t otherLen, int8_t polarity); jpayne@69: jpayne@69: void add(const UChar32* other, int32_t otherLen, int8_t polarity); jpayne@69: jpayne@69: void retain(const UChar32* other, int32_t otherLen, int8_t polarity); jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given position, in the given pattern, appears jpayne@69: * to be the start of a property set pattern [:foo:], \\p{foo}, or jpayne@69: * \\P{foo}, or \\N{name}. jpayne@69: */ jpayne@69: static UBool resemblesPropertyPattern(const UnicodeString& pattern, jpayne@69: int32_t pos); jpayne@69: jpayne@69: static UBool resemblesPropertyPattern(RuleCharacterIterator& chars, jpayne@69: int32_t iterOpts); jpayne@69: jpayne@69: /** jpayne@69: * Parse the given property pattern at the given parse position jpayne@69: * and set this UnicodeSet to the result. jpayne@69: * jpayne@69: * The original design document is out of date, but still useful. jpayne@69: * Ignore the property and value names: jpayne@69: * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/unicodeset_properties.html jpayne@69: * jpayne@69: * Recognized syntax: jpayne@69: * jpayne@69: * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]" jpayne@69: * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P" jpayne@69: * \\N{name} - white space not allowed within "\\N" jpayne@69: * jpayne@69: * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored. jpayne@69: * Case is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading jpayne@69: * and trailing space is deleted, and internal runs of whitespace jpayne@69: * are collapsed to a single space. jpayne@69: * jpayne@69: * We support binary properties, enumerated properties, and the jpayne@69: * following non-enumerated properties: jpayne@69: * jpayne@69: * Numeric_Value jpayne@69: * Name jpayne@69: * Unicode_1_Name jpayne@69: * jpayne@69: * @param pattern the pattern string jpayne@69: * @param ppos on entry, the position at which to begin parsing. jpayne@69: * This should be one of the locations marked '^': jpayne@69: * jpayne@69: * [:blah:] \\p{blah} \\P{blah} \\N{name} jpayne@69: * ^ % ^ % ^ % ^ % jpayne@69: * jpayne@69: * On return, the position after the last character parsed, that is, jpayne@69: * the locations marked '%'. If the parse fails, ppos is returned jpayne@69: * unchanged. jpayne@69: * @param ec status jpayne@69: * @return a reference to this. jpayne@69: */ jpayne@69: UnicodeSet& applyPropertyPattern(const UnicodeString& pattern, jpayne@69: ParsePosition& ppos, jpayne@69: UErrorCode &ec); jpayne@69: jpayne@69: void applyPropertyPattern(RuleCharacterIterator& chars, jpayne@69: UnicodeString& rebuiltPat, jpayne@69: UErrorCode& ec); jpayne@69: jpayne@69: static const UnicodeSet* getInclusions(int32_t src, UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * A filter that returns TRUE if the given code point should be jpayne@69: * included in the UnicodeSet being constructed. jpayne@69: */ jpayne@69: typedef UBool (*Filter)(UChar32 codePoint, void* context); jpayne@69: jpayne@69: /** jpayne@69: * Given a filter, set this UnicodeSet to the code points jpayne@69: * contained by that filter. The filter MUST be jpayne@69: * property-conformant. That is, if it returns value v for one jpayne@69: * code point, then it must return v for all affiliated code jpayne@69: * points, as defined by the inclusions list. See jpayne@69: * getInclusions(). jpayne@69: * src is a UPropertySource value. jpayne@69: */ jpayne@69: void applyFilter(Filter filter, jpayne@69: void* context, jpayne@69: const UnicodeSet* inclusions, jpayne@69: UErrorCode &status); jpayne@69: jpayne@69: // UCPMap is now stable ICU 63 jpayne@69: void applyIntPropertyValue(const UCPMap *map, jpayne@69: UCPMapValueFilter *filter, const void *context, jpayne@69: UErrorCode &errorCode); jpayne@69: jpayne@69: /** jpayne@69: * Set the new pattern to cache. jpayne@69: */ jpayne@69: void setPattern(const UnicodeString& newPat) { jpayne@69: setPattern(newPat.getBuffer(), newPat.length()); jpayne@69: } jpayne@69: void setPattern(const char16_t *newPat, int32_t newPatLen); jpayne@69: /** jpayne@69: * Release existing cached pattern. jpayne@69: */ jpayne@69: void releasePattern(); jpayne@69: jpayne@69: friend class UnicodeSetIterator; jpayne@69: }; jpayne@69: jpayne@69: jpayne@69: jpayne@69: inline UBool UnicodeSet::operator!=(const UnicodeSet& o) const { jpayne@69: return !operator==(o); jpayne@69: } jpayne@69: jpayne@69: inline UBool UnicodeSet::isFrozen() const { jpayne@69: return (UBool)(bmpSet!=NULL || stringSpan!=NULL); jpayne@69: } jpayne@69: jpayne@69: inline UBool UnicodeSet::containsSome(UChar32 start, UChar32 end) const { jpayne@69: return !containsNone(start, end); jpayne@69: } jpayne@69: jpayne@69: inline UBool UnicodeSet::containsSome(const UnicodeSet& s) const { jpayne@69: return !containsNone(s); jpayne@69: } jpayne@69: jpayne@69: inline UBool UnicodeSet::containsSome(const UnicodeString& s) const { jpayne@69: return !containsNone(s); jpayne@69: } jpayne@69: jpayne@69: inline UBool UnicodeSet::isBogus() const { jpayne@69: return (UBool)(fFlags & kIsBogus); jpayne@69: } jpayne@69: jpayne@69: inline UnicodeSet *UnicodeSet::fromUSet(USet *uset) { jpayne@69: return reinterpret_cast