2 ***************************************************************************
3 * Copyright (C) 1999-2016, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 ***************************************************************************
6 * Date Name Description
7 * 10/20/99 alan Creation.
8 ***************************************************************************
14 #include "unicode/unifilt.h"
15 #include "unicode/unistr.h"
16 #include "unicode/uset.h"
20 * \brief C++ API: Unicode Set
25 // Forward Declarations.
26 void U_CALLCONV
UnicodeSet_initInclusion(int32_t src
, UErrorCode
&status
); /**< @internal */
30 class RBBIRuleScanner
;
32 class UnicodeSetStringSpan
;
34 class RuleCharacterIterator
;
37 * A mutable set of Unicode characters and multicharacter strings. Objects of this class
38 * represent <em>character classes</em> used in regular expressions.
39 * A character specifies a subset of Unicode code points. Legal
40 * code points are U+0000 to U+10FFFF, inclusive.
42 * <p>The UnicodeSet class is not designed to be subclassed.
44 * <p><code>UnicodeSet</code> supports two APIs. The first is the
45 * <em>operand</em> API that allows the caller to modify the value of
46 * a <code>UnicodeSet</code> object. It conforms to Java 2's
47 * <code>java.util.Set</code> interface, although
48 * <code>UnicodeSet</code> does not actually implement that
49 * interface. All methods of <code>Set</code> are supported, with the
50 * modification that they take a character range or single character
51 * instead of an <code>Object</code>, and they take a
52 * <code>UnicodeSet</code> instead of a <code>Collection</code>. The
53 * operand API may be thought of in terms of boolean logic: a boolean
54 * OR is implemented by <code>add</code>, a boolean AND is implemented
55 * by <code>retain</code>, a boolean XOR is implemented by
56 * <code>complement</code> taking an argument, and a boolean NOT is
57 * implemented by <code>complement</code> with no argument. In terms
58 * of traditional set theory function names, <code>add</code> is a
59 * union, <code>retain</code> is an intersection, <code>remove</code>
60 * is an asymmetric difference, and <code>complement</code> with no
61 * argument is a set complement with respect to the superset range
62 * <code>MIN_VALUE-MAX_VALUE</code>
64 * <p>The second API is the
65 * <code>applyPattern()</code>/<code>toPattern()</code> API from the
66 * <code>java.text.Format</code>-derived classes. Unlike the
67 * methods that add characters, add categories, and control the logic
68 * of the set, the method <code>applyPattern()</code> sets all
69 * attributes of a <code>UnicodeSet</code> at once, based on a
72 * <p><b>Pattern syntax</b></p>
74 * Patterns are accepted by the constructors and the
75 * <code>applyPattern()</code> methods and returned by the
76 * <code>toPattern()</code> method. These patterns follow a syntax
77 * similar to that employed by version 8 regular expression character
78 * classes. Here are some simple examples:
80 * \htmlonly<blockquote>\endhtmlonly
83 * <td nowrap valign="top" align="left"><code>[]</code></td>
84 * <td valign="top">No characters</td>
85 * </tr><tr align="top">
86 * <td nowrap valign="top" align="left"><code>[a]</code></td>
87 * <td valign="top">The character 'a'</td>
88 * </tr><tr align="top">
89 * <td nowrap valign="top" align="left"><code>[ae]</code></td>
90 * <td valign="top">The characters 'a' and 'e'</td>
93 * <td nowrap valign="top" align="left"><code>[a-e]</code></td>
94 * <td valign="top">The characters 'a' through 'e' inclusive, in Unicode code
98 * <td nowrap valign="top" align="left"><code>[\\u4E01]</code></td>
99 * <td valign="top">The character U+4E01</td>
102 * <td nowrap valign="top" align="left"><code>[a{ab}{ac}]</code></td>
103 * <td valign="top">The character 'a' and the multicharacter strings "ab" and
104 * "ac"</td>
107 * <td nowrap valign="top" align="left"><code>[\\p{Lu}]</code></td>
108 * <td valign="top">All characters in the general category Uppercase Letter</td>
111 * \htmlonly</blockquote>\endhtmlonly
113 * Any character may be preceded by a backslash in order to remove any special
114 * meaning. White space characters, as defined by UCharacter.isWhitespace(), are
115 * ignored, unless they are escaped.
117 * <p>Property patterns specify a set of characters having a certain
118 * property as defined by the Unicode standard. Both the POSIX-like
119 * "[:Lu:]" and the Perl-like syntax "\\p{Lu}" are recognized. For a
120 * complete list of supported property patterns, see the User's Guide
122 * <a href="http://icu-project.org/userguide/unicodeSet.html">
123 * http://icu-project.org/userguide/unicodeSet.html</a>.
124 * Actual determination of property data is defined by the underlying
125 * Unicode database as implemented by UCharacter.
127 * <p>Patterns specify individual characters, ranges of characters, and
128 * Unicode property sets. When elements are concatenated, they
129 * specify their union. To complement a set, place a '^' immediately
130 * after the opening '['. Property patterns are inverted by modifying
131 * their delimiters; "[:^foo]" and "\\P{foo}". In any other location,
132 * '^' has no special meaning.
134 * <p>Ranges are indicated by placing two a '-' between two
135 * characters, as in "a-z". This specifies the range of all
136 * characters from the left to the right, in Unicode order. If the
137 * left character is greater than or equal to the
138 * right character it is a syntax error. If a '-' occurs as the first
139 * character after the opening '[' or '[^', or if it occurs as the
140 * last character before the closing ']', then it is taken as a
141 * literal. Thus "[a\-b]", "[-ab]", and "[ab-]" all indicate the same
142 * set of three characters, 'a', 'b', and '-'.
144 * <p>Sets may be intersected using the '&' operator or the asymmetric
145 * set difference may be taken using the '-' operator, for example,
146 * "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters
147 * with values less than 4096. Operators ('&' and '|') have equal
148 * precedence and bind left-to-right. Thus
149 * "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to
150 * "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]". This only really matters for
151 * difference; intersection is commutative.
154 * <tr valign=top><td nowrap><code>[a]</code><td>The set containing 'a'
155 * <tr valign=top><td nowrap><code>[a-z]</code><td>The set containing 'a'
156 * through 'z' and all letters in between, in Unicode order
157 * <tr valign=top><td nowrap><code>[^a-z]</code><td>The set containing
158 * all characters but 'a' through 'z',
159 * that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF
160 * <tr valign=top><td nowrap><code>[[<em>pat1</em>][<em>pat2</em>]]</code>
161 * <td>The union of sets specified by <em>pat1</em> and <em>pat2</em>
162 * <tr valign=top><td nowrap><code>[[<em>pat1</em>]&[<em>pat2</em>]]</code>
163 * <td>The intersection of sets specified by <em>pat1</em> and <em>pat2</em>
164 * <tr valign=top><td nowrap><code>[[<em>pat1</em>]-[<em>pat2</em>]]</code>
165 * <td>The asymmetric difference of sets specified by <em>pat1</em> and
167 * <tr valign=top><td nowrap><code>[:Lu:] or \\p{Lu}</code>
168 * <td>The set of characters having the specified
169 * Unicode property; in
170 * this case, Unicode uppercase letters
171 * <tr valign=top><td nowrap><code>[:^Lu:] or \\P{Lu}</code>
172 * <td>The set of characters <em>not</em> having the given
176 * <p><b>Warning</b>: you cannot add an empty string ("") to a UnicodeSet.</p>
178 * <p><b>Formal syntax</b></p>
180 * \htmlonly<blockquote>\endhtmlonly
183 * <td nowrap valign="top" align="right"><code>pattern := </code></td>
184 * <td valign="top"><code>('[' '^'? item* ']') |
185 * property</code></td>
188 * <td nowrap valign="top" align="right"><code>item := </code></td>
189 * <td valign="top"><code>char | (char '-' char) | pattern-expr<br>
193 * <td nowrap valign="top" align="right"><code>pattern-expr := </code></td>
194 * <td valign="top"><code>pattern | pattern-expr pattern |
195 * pattern-expr op pattern<br>
199 * <td nowrap valign="top" align="right"><code>op := </code></td>
200 * <td valign="top"><code>'&' | '-'<br>
204 * <td nowrap valign="top" align="right"><code>special := </code></td>
205 * <td valign="top"><code>'[' | ']' | '-'<br>
209 * <td nowrap valign="top" align="right"><code>char := </code></td>
210 * <td valign="top"><em>any character that is not</em><code> special<br>
211 * | ('\' </code><em>any character</em><code>)<br>
212 * | ('\\u' hex hex hex hex)<br>
216 * <td nowrap valign="top" align="right"><code>hex := </code></td>
217 * <td valign="top"><em>any character for which
218 * </em><code>Character.digit(c, 16)</code><em>
219 * returns a non-negative result</em></td>
222 * <td nowrap valign="top" align="right"><code>property := </code></td>
223 * <td valign="top"><em>a Unicode property set pattern</em></td>
229 * <td>Legend: <table>
231 * <td nowrap valign="top"><code>a := b</code></td>
232 * <td width="20" valign="top"> </td>
233 * <td valign="top"><code>a</code> may be replaced by <code>b</code> </td>
236 * <td nowrap valign="top"><code>a?</code></td>
237 * <td valign="top"></td>
238 * <td valign="top">zero or one instance of <code>a</code><br>
242 * <td nowrap valign="top"><code>a*</code></td>
243 * <td valign="top"></td>
244 * <td valign="top">one or more instances of <code>a</code><br>
248 * <td nowrap valign="top"><code>a | b</code></td>
249 * <td valign="top"></td>
250 * <td valign="top">either <code>a</code> or <code>b</code><br>
254 * <td nowrap valign="top"><code>'a'</code></td>
255 * <td valign="top"></td>
256 * <td valign="top">the literal string between the quotes </td>
262 * \htmlonly</blockquote>\endhtmlonly
265 * - Most UnicodeSet methods do not take a UErrorCode parameter because
266 * there are usually very few opportunities for failure other than a shortage
267 * of memory, error codes in low-level C++ string methods would be inconvenient,
268 * and the error code as the last parameter (ICU convention) would prevent
269 * the use of default parameter values.
270 * Instead, such methods set the UnicodeSet into a "bogus" state
271 * (see isBogus()) if an error occurs.
276 class U_COMMON_API UnicodeSet U_FINAL
: public UnicodeFilter
{
278 int32_t len
; // length of list used; 0 <= len <= capacity
279 int32_t capacity
; // capacity of list
280 UChar32
* list
; // MUST be terminated with HIGH
281 BMPSet
*bmpSet
; // The set is frozen iff either bmpSet or stringSpan is not NULL.
282 UChar32
* buffer
; // internal buffer, may be NULL
283 int32_t bufferCapacity
; // capacity of buffer
287 * The pattern representation of this set. This may not be the
288 * most economical pattern. It is the pattern supplied to
289 * applyPattern(), with variables substituted and whitespace
290 * removed. For sets constructed without applyPattern(), or
291 * modified using the non-pattern API, this string will be empty,
292 * indicating that toPattern() must generate a pattern
293 * representation from the inversion list.
296 UVector
* strings
; // maintained in sorted order
297 UnicodeSetStringSpan
*stringSpan
;
301 kIsBogus
= 1 // This set is bogus (i.e. not valid)
303 uint8_t fFlags
; // Bit flag (see constants above)
306 * Determine if this object contains a valid set.
307 * A bogus set has no value. It is different from an empty set.
308 * It can be used to indicate that no set value is available.
310 * @return TRUE if the set is bogus/invalid, FALSE otherwise
314 inline UBool
isBogus(void) const;
317 * Make this UnicodeSet object invalid.
318 * The string will test TRUE with isBogus().
320 * A bogus set has no value. It is different from an empty set.
321 * It can be used to indicate that no set value is available.
323 * This utility function is used throughout the UnicodeSet
324 * implementation to indicate that a UnicodeSet operation failed,
325 * and may be used in other functions,
326 * especially but not exclusively when such functions do not
327 * take a UErrorCode for simplicity.
338 * Minimum value that can be stored in a UnicodeSet.
344 * Maximum value that can be stored in a UnicodeSet.
350 //----------------------------------------------------------------
352 //----------------------------------------------------------------
357 * Constructs an empty set.
363 * Constructs a set containing the given range. If <code>end >
364 * start</code> then an empty set is created.
366 * @param start first character, inclusive, of range
367 * @param end last character, inclusive, of range
370 UnicodeSet(UChar32 start
, UChar32 end
);
372 #ifndef U_HIDE_INTERNAL_API
376 enum ESerialization
{
377 kSerialized
/* result of serialize() */
381 * Constructs a set from the output of serialize().
383 * @param buffer the 16 bit array
384 * @param bufferLen the original length returned from serialize()
385 * @param serialization the value 'kSerialized'
386 * @param status error code
390 UnicodeSet(const uint16_t buffer
[], int32_t bufferLen
,
391 ESerialization serialization
, UErrorCode
&status
);
392 #endif /* U_HIDE_INTERNAL_API */
395 * Constructs a set from the given pattern. See the class
396 * description for the syntax of the pattern language.
397 * @param pattern a string specifying what characters are in the set
398 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
399 * contains a syntax error.
402 UnicodeSet(const UnicodeString
& pattern
,
405 #ifndef U_HIDE_INTERNAL_API
407 * Constructs a set from the given pattern. See the class
408 * description for the syntax of the pattern language.
409 * @param pattern a string specifying what characters are in the set
410 * @param options bitmask for options to apply to the pattern.
411 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
412 * @param symbols a symbol table mapping variable names to values
413 * and stand-in characters to UnicodeSets; may be NULL
414 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
415 * contains a syntax error.
418 UnicodeSet(const UnicodeString
& pattern
,
420 const SymbolTable
* symbols
,
422 #endif /* U_HIDE_INTERNAL_API */
425 * Constructs a set from the given pattern. See the class description
426 * for the syntax of the pattern language.
427 * @param pattern a string specifying what characters are in the set
428 * @param pos on input, the position in pattern at which to start parsing.
429 * On output, the position after the last character parsed.
430 * @param options bitmask for options to apply to the pattern.
431 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
432 * @param symbols a symbol table mapping variable names to values
433 * and stand-in characters to UnicodeSets; may be NULL
434 * @param status input-output error code
437 UnicodeSet(const UnicodeString
& pattern
, ParsePosition
& pos
,
439 const SymbolTable
* symbols
,
443 * Constructs a set that is identical to the given UnicodeSet.
446 UnicodeSet(const UnicodeSet
& o
);
452 virtual ~UnicodeSet();
455 * Assigns this object to be a copy of another.
456 * A frozen set will not be modified.
459 UnicodeSet
& operator=(const UnicodeSet
& o
);
462 * Compares the specified object with this set for equality. Returns
463 * <tt>true</tt> if the two sets
464 * have the same size, and every member of the specified set is
465 * contained in this set (or equivalently, every member of this set is
466 * contained in the specified set).
468 * @param o set to be compared for equality with this set.
469 * @return <tt>true</tt> if the specified set is equal to this set.
472 virtual UBool
operator==(const UnicodeSet
& o
) const;
475 * Compares the specified object with this set for equality. Returns
476 * <tt>true</tt> if the specified set is not equal to this set.
479 UBool
operator!=(const UnicodeSet
& o
) const;
482 * Returns a copy of this object. All UnicodeFunctor objects have
483 * to support cloning in order to allow classes using
484 * UnicodeFunctors, such as Transliterator, to implement cloning.
485 * If this set is frozen, then the clone will be frozen as well.
486 * Use cloneAsThawed() for a mutable clone of a frozen set.
490 virtual UnicodeFunctor
* clone() const;
493 * Returns the hash code value for this set.
495 * @return the hash code value for this set.
496 * @see Object#hashCode()
499 virtual int32_t hashCode(void) const;
502 * Get a UnicodeSet pointer from a USet
504 * @param uset a USet (the ICU plain C type for UnicodeSet)
505 * @return the corresponding UnicodeSet pointer.
509 inline static UnicodeSet
*fromUSet(USet
*uset
);
512 * Get a UnicodeSet pointer from a const USet
514 * @param uset a const USet (the ICU plain C type for UnicodeSet)
515 * @return the corresponding UnicodeSet pointer.
519 inline static const UnicodeSet
*fromUSet(const USet
*uset
);
522 * Produce a USet * pointer for this UnicodeSet.
523 * USet is the plain C type for UnicodeSet
525 * @return a USet pointer for this UnicodeSet
528 inline USet
*toUSet();
532 * Produce a const USet * pointer for this UnicodeSet.
533 * USet is the plain C type for UnicodeSet
535 * @return a const USet pointer for this UnicodeSet
538 inline const USet
* toUSet() const;
541 //----------------------------------------------------------------
543 //----------------------------------------------------------------
546 * Determines whether the set has been frozen (made immutable) or not.
547 * See the ICU4J Freezable interface for details.
548 * @return TRUE/FALSE for whether the set has been frozen
553 inline UBool
isFrozen() const;
556 * Freeze the set (make it immutable).
557 * Once frozen, it cannot be unfrozen and is therefore thread-safe
558 * until it is deleted.
559 * See the ICU4J Freezable interface for details.
560 * Freezing the set may also make some operations faster, for example
561 * contains() and span().
562 * A frozen set will not be modified. (It remains frozen.)
568 UnicodeFunctor
*freeze();
571 * Clone the set and make the clone mutable.
572 * See the ICU4J Freezable interface for details.
573 * @return the mutable clone
578 UnicodeFunctor
*cloneAsThawed() const;
580 //----------------------------------------------------------------
582 //----------------------------------------------------------------
585 * Make this object represent the range <code>start - end</code>.
586 * If <code>end > start</code> then this object is set to an
588 * A frozen set will not be modified.
590 * @param start first character in the set, inclusive
591 * @param end last character in the set, inclusive
594 UnicodeSet
& set(UChar32 start
, UChar32 end
);
597 * Return true if the given position, in the given pattern, appears
598 * to be the start of a UnicodeSet pattern.
601 static UBool
resemblesPattern(const UnicodeString
& pattern
,
605 * Modifies this set to represent the set specified by the given
606 * pattern, ignoring Unicode Pattern_White_Space characters.
607 * See the class description for the syntax of the pattern language.
608 * A frozen set will not be modified.
609 * @param pattern a string specifying what characters are in the set
610 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
611 * contains a syntax error.
612 * <em> Empties the set passed before applying the pattern.</em>
613 * @return a reference to this
616 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
619 #ifndef U_HIDE_INTERNAL_API
621 * Modifies this set to represent the set specified by the given
622 * pattern, optionally ignoring Unicode Pattern_White_Space characters.
623 * See the class description for the syntax of the pattern language.
624 * A frozen set will not be modified.
625 * @param pattern a string specifying what characters are in the set
626 * @param options bitmask for options to apply to the pattern.
627 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
628 * @param symbols a symbol table mapping variable names to
629 * values and stand-ins to UnicodeSets; may be NULL
630 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
631 * contains a syntax error.
632 *<em> Empties the set passed before applying the pattern.</em>
633 * @return a reference to this
636 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
638 const SymbolTable
* symbols
,
640 #endif /* U_HIDE_INTERNAL_API */
643 * Parses the given pattern, starting at the given position. The
644 * character at pattern.charAt(pos.getIndex()) must be '[', or the
645 * parse fails. Parsing continues until the corresponding closing
646 * ']'. If a syntax error is encountered between the opening and
647 * closing brace, the parse fails. Upon return from a successful
648 * parse, the ParsePosition is updated to point to the character
649 * following the closing ']', and a StringBuffer containing a
650 * pairs list for the parsed pattern is returned. This method calls
651 * itself recursively to parse embedded subpatterns.
652 *<em> Empties the set passed before applying the pattern.</em>
653 * A frozen set will not be modified.
655 * @param pattern the string containing the pattern to be parsed.
656 * The portion of the string from pos.getIndex(), which must be a
657 * '[', to the corresponding closing ']', is parsed.
658 * @param pos upon entry, the position at which to being parsing.
659 * The character at pattern.charAt(pos.getIndex()) must be a '['.
660 * Upon return from a successful parse, pos.getIndex() is either
661 * the character after the closing ']' of the parsed pattern, or
662 * pattern.length() if the closing ']' is the last character of
663 * the pattern string.
664 * @param options bitmask for options to apply to the pattern.
665 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
666 * @param symbols a symbol table mapping variable names to
667 * values and stand-ins to UnicodeSets; may be NULL
668 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
669 * contains a syntax error.
670 * @return a reference to this
673 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
676 const SymbolTable
* symbols
,
680 * Returns a string representation of this set. If the result of
681 * calling this function is passed to a UnicodeSet constructor, it
682 * will produce another set that is equal to this one.
683 * A frozen set will not be modified.
684 * @param result the string to receive the rules. Previous
685 * contents will be deleted.
686 * @param escapeUnprintable if TRUE then convert unprintable
687 * character to their hex escape representations, \\uxxxx or
688 * \\Uxxxxxxxx. Unprintable characters are those other than
689 * U+000A, U+0020..U+007E.
692 virtual UnicodeString
& toPattern(UnicodeString
& result
,
693 UBool escapeUnprintable
= FALSE
) const;
696 * Modifies this set to contain those code points which have the given value
697 * for the given binary or enumerated property, as returned by
698 * u_getIntPropertyValue. Prior contents of this set are lost.
699 * A frozen set will not be modified.
701 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
702 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
703 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
705 * @param value a value in the range u_getIntPropertyMinValue(prop)..
706 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
707 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
708 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
709 * categories such as [:L:] to be represented.
711 * @param ec error code input/output parameter
713 * @return a reference to this set
717 UnicodeSet
& applyIntPropertyValue(UProperty prop
,
722 * Modifies this set to contain those code points which have the
723 * given value for the given property. Prior contents of this
725 * A frozen set will not be modified.
727 * @param prop a property alias, either short or long. The name is matched
728 * loosely. See PropertyAliases.txt for names and a description of loose
729 * matching. If the value string is empty, then this string is interpreted
730 * as either a General_Category value alias, a Script value alias, a binary
731 * property alias, or a special ID. Special IDs are matched loosely and
732 * correspond to the following sets:
734 * "ANY" = [\\u0000-\\U0010FFFF],
735 * "ASCII" = [\\u0000-\\u007F],
736 * "Assigned" = [:^Cn:].
738 * @param value a value alias, either short or long. The name is matched
739 * loosely. See PropertyValueAliases.txt for names and a description of
740 * loose matching. In addition to aliases listed, numeric values and
741 * canonical combining classes may be expressed numerically, e.g., ("nv",
742 * "0.5") or ("ccc", "220"). The value string may also be empty.
744 * @param ec error code input/output parameter
746 * @return a reference to this set
750 UnicodeSet
& applyPropertyAlias(const UnicodeString
& prop
,
751 const UnicodeString
& value
,
755 * Returns the number of elements in this set (its cardinality).
756 * Note than the elements of a set may include both individual
757 * codepoints and strings.
759 * @return the number of elements in this set (its cardinality).
762 virtual int32_t size(void) const;
765 * Returns <tt>true</tt> if this set contains no elements.
767 * @return <tt>true</tt> if this set contains no elements.
770 virtual UBool
isEmpty(void) const;
773 * Returns true if this set contains the given character.
774 * This function works faster with a frozen set.
775 * @param c character to be checked for containment
776 * @return true if the test condition is met
779 virtual UBool
contains(UChar32 c
) const;
782 * Returns true if this set contains every character
783 * of the given range.
784 * @param start first character, inclusive, of the range
785 * @param end last character, inclusive, of the range
786 * @return true if the test condition is met
789 virtual UBool
contains(UChar32 start
, UChar32 end
) const;
792 * Returns <tt>true</tt> if this set contains the given
793 * multicharacter string.
794 * @param s string to be checked for containment
795 * @return <tt>true</tt> if this set contains the specified string
798 UBool
contains(const UnicodeString
& s
) const;
801 * Returns true if this set contains all the characters and strings
803 * @param c set to be checked for containment
804 * @return true if the test condition is met
807 virtual UBool
containsAll(const UnicodeSet
& c
) const;
810 * Returns true if this set contains all the characters
811 * of the given string.
812 * @param s string containing characters to be checked for containment
813 * @return true if the test condition is met
816 UBool
containsAll(const UnicodeString
& s
) const;
819 * Returns true if this set contains none of the characters
820 * of the given range.
821 * @param start first character, inclusive, of the range
822 * @param end last character, inclusive, of the range
823 * @return true if the test condition is met
826 UBool
containsNone(UChar32 start
, UChar32 end
) const;
829 * Returns true if this set contains none of the characters and strings
831 * @param c set to be checked for containment
832 * @return true if the test condition is met
835 UBool
containsNone(const UnicodeSet
& c
) const;
838 * Returns true if this set contains none of the characters
839 * of the given string.
840 * @param s string containing characters to be checked for containment
841 * @return true if the test condition is met
844 UBool
containsNone(const UnicodeString
& s
) const;
847 * Returns true if this set contains one or more of the characters
848 * in the given range.
849 * @param start first character, inclusive, of the range
850 * @param end last character, inclusive, of the range
851 * @return true if the condition is met
854 inline UBool
containsSome(UChar32 start
, UChar32 end
) const;
857 * Returns true if this set contains one or more of the characters
858 * and strings of the given set.
859 * @param s The set to be checked for containment
860 * @return true if the condition is met
863 inline UBool
containsSome(const UnicodeSet
& s
) const;
866 * Returns true if this set contains one or more of the characters
867 * of the given string.
868 * @param s string containing characters to be checked for containment
869 * @return true if the condition is met
872 inline UBool
containsSome(const UnicodeString
& s
) const;
875 * Returns the length of the initial substring of the input string which
876 * consists only of characters and strings that are contained in this set
877 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
878 * or only of characters and strings that are not contained
879 * in this set (USET_SPAN_NOT_CONTAINED).
880 * See USetSpanCondition for details.
881 * Similar to the strspn() C library function.
882 * Unpaired surrogates are treated according to contains() of their surrogate code points.
883 * This function works faster with a frozen set and with a non-negative string length argument.
884 * @param s start of the string
885 * @param length of the string; can be -1 for NUL-terminated
886 * @param spanCondition specifies the containment condition
887 * @return the length of the initial substring according to the spanCondition;
888 * 0 if the start of the string does not fit the spanCondition
890 * @see USetSpanCondition
892 int32_t span(const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
) const;
895 * Returns the end of the substring of the input string according to the USetSpanCondition.
896 * Same as <code>start+span(s.getBuffer()+start, s.length()-start, spanCondition)</code>
897 * after pinning start to 0<=start<=s.length().
898 * @param s the string
899 * @param start the start index in the string for the span operation
900 * @param spanCondition specifies the containment condition
901 * @return the exclusive end of the substring according to the spanCondition;
902 * the substring s.tempSubStringBetween(start, end) fulfills the spanCondition
904 * @see USetSpanCondition
906 inline int32_t span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const;
909 * Returns the start of the trailing substring of the input string which
910 * consists only of characters and strings that are contained in this set
911 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
912 * or only of characters and strings that are not contained
913 * in this set (USET_SPAN_NOT_CONTAINED).
914 * See USetSpanCondition for details.
915 * Unpaired surrogates are treated according to contains() of their surrogate code points.
916 * This function works faster with a frozen set and with a non-negative string length argument.
917 * @param s start of the string
918 * @param length of the string; can be -1 for NUL-terminated
919 * @param spanCondition specifies the containment condition
920 * @return the start of the trailing substring according to the spanCondition;
921 * the string length if the end of the string does not fit the spanCondition
923 * @see USetSpanCondition
925 int32_t spanBack(const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
) const;
928 * Returns the start of the substring of the input string according to the USetSpanCondition.
929 * Same as <code>spanBack(s.getBuffer(), limit, spanCondition)</code>
930 * after pinning limit to 0<=end<=s.length().
931 * @param s the string
932 * @param limit the exclusive-end index in the string for the span operation
933 * (use s.length() or INT32_MAX for spanning back from the end of the string)
934 * @param spanCondition specifies the containment condition
935 * @return the start of the substring according to the spanCondition;
936 * the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition
938 * @see USetSpanCondition
940 inline int32_t spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const;
943 * Returns the length of the initial substring of the input string which
944 * consists only of characters and strings that are contained in this set
945 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
946 * or only of characters and strings that are not contained
947 * in this set (USET_SPAN_NOT_CONTAINED).
948 * See USetSpanCondition for details.
949 * Similar to the strspn() C library function.
950 * Malformed byte sequences are treated according to contains(0xfffd).
951 * This function works faster with a frozen set and with a non-negative string length argument.
952 * @param s start of the string (UTF-8)
953 * @param length of the string; can be -1 for NUL-terminated
954 * @param spanCondition specifies the containment condition
955 * @return the length of the initial substring according to the spanCondition;
956 * 0 if the start of the string does not fit the spanCondition
958 * @see USetSpanCondition
960 int32_t spanUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
963 * Returns the start of the trailing substring of the input string which
964 * consists only of characters and strings that are contained in this set
965 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
966 * or only of characters and strings that are not contained
967 * in this set (USET_SPAN_NOT_CONTAINED).
968 * See USetSpanCondition for details.
969 * Malformed byte sequences are treated according to contains(0xfffd).
970 * This function works faster with a frozen set and with a non-negative string length argument.
971 * @param s start of the string (UTF-8)
972 * @param length of the string; can be -1 for NUL-terminated
973 * @param spanCondition specifies the containment condition
974 * @return the start of the trailing substring according to the spanCondition;
975 * the string length if the end of the string does not fit the spanCondition
977 * @see USetSpanCondition
979 int32_t spanBackUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
982 * Implement UnicodeMatcher::matches()
985 virtual UMatchDegree
matches(const Replaceable
& text
,
992 * Returns the longest match for s in text at the given position.
993 * If limit > start then match forward from start+1 to limit
994 * matching all characters except s.charAt(0). If limit < start,
995 * go backward starting from start-1 matching all characters
996 * except s.charAt(s.length()-1). This method assumes that the
997 * first character, text.charAt(start), matches s, so it does not
999 * @param text the text to match
1000 * @param start the first character to match. In the forward
1001 * direction, text.charAt(start) is matched against s.charAt(0).
1002 * In the reverse direction, it is matched against
1003 * s.charAt(s.length()-1).
1004 * @param limit the limit offset for matching, either last+1 in
1005 * the forward direction, or last-1 in the reverse direction,
1006 * where last is the index of the last character to match.
1008 * @return If part of s matches up to the limit, return |limit -
1009 * start|. If all of s matches before reaching the limit, return
1010 * s.length(). If there is a mismatch between s and text, return
1013 static int32_t matchRest(const Replaceable
& text
,
1014 int32_t start
, int32_t limit
,
1015 const UnicodeString
& s
);
1018 * Returns the smallest value i such that c < list[i]. Caller
1019 * must ensure that c is a legal value or this method will enter
1020 * an infinite loop. This method performs a binary search.
1021 * @param c a character in the range MIN_VALUE..MAX_VALUE
1023 * @return the smallest integer i in the range 0..len-1,
1024 * inclusive, such that c < list[i]
1026 int32_t findCodePoint(UChar32 c
) const;
1031 * Implementation of UnicodeMatcher API. Union the set of all
1032 * characters that may be matched by this object into the given
1034 * @param toUnionTo the set into which to union the source characters
1037 virtual void addMatchSetTo(UnicodeSet
& toUnionTo
) const;
1040 * Returns the index of the given character within this set, where
1041 * the set is ordered by ascending code point. If the character
1042 * is not in this set, return -1. The inverse of this method is
1043 * <code>charAt()</code>.
1044 * @return an index from 0..size()-1, or -1
1047 int32_t indexOf(UChar32 c
) const;
1050 * Returns the character at the given index within this set, where
1051 * the set is ordered by ascending code point. If the index is
1052 * out of range, return (UChar32)-1. The inverse of this method is
1053 * <code>indexOf()</code>.
1054 * @param index an index from 0..size()-1
1055 * @return the character at the given index, or (UChar32)-1.
1058 UChar32
charAt(int32_t index
) const;
1061 * Adds the specified range to this set if it is not already
1062 * present. If this set already contains the specified range,
1063 * the call leaves this set unchanged. If <code>end > start</code>
1064 * then an empty range is added, leaving the set unchanged.
1065 * This is equivalent to a boolean logic OR, or a set UNION.
1066 * A frozen set will not be modified.
1068 * @param start first character, inclusive, of range to be added
1070 * @param end last character, inclusive, of range to be added
1074 virtual UnicodeSet
& add(UChar32 start
, UChar32 end
);
1077 * Adds the specified character to this set if it is not already
1078 * present. If this set already contains the specified character,
1079 * the call leaves this set unchanged.
1080 * A frozen set will not be modified.
1083 UnicodeSet
& add(UChar32 c
);
1086 * Adds the specified multicharacter to this set if it is not already
1087 * present. If this set already contains the multicharacter,
1088 * the call leaves this set unchanged.
1089 * Thus "ch" => {"ch"}
1090 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1091 * A frozen set will not be modified.
1092 * @param s the source string
1093 * @return this object, for chaining
1096 UnicodeSet
& add(const UnicodeString
& s
);
1100 * @return a code point IF the string consists of a single one.
1101 * otherwise returns -1.
1102 * @param s string to test
1104 static int32_t getSingleCP(const UnicodeString
& s
);
1106 void _add(const UnicodeString
& s
);
1110 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
1111 * If this set already any particular character, it has no effect on that character.
1112 * A frozen set will not be modified.
1113 * @param s the source string
1114 * @return this object, for chaining
1117 UnicodeSet
& addAll(const UnicodeString
& s
);
1120 * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
1121 * If this set already any particular character, it has no effect on that character.
1122 * A frozen set will not be modified.
1123 * @param s the source string
1124 * @return this object, for chaining
1127 UnicodeSet
& retainAll(const UnicodeString
& s
);
1130 * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
1131 * If this set already any particular character, it has no effect on that character.
1132 * A frozen set will not be modified.
1133 * @param s the source string
1134 * @return this object, for chaining
1137 UnicodeSet
& complementAll(const UnicodeString
& s
);
1140 * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
1141 * If this set already any particular character, it has no effect on that character.
1142 * A frozen set will not be modified.
1143 * @param s the source string
1144 * @return this object, for chaining
1147 UnicodeSet
& removeAll(const UnicodeString
& s
);
1150 * Makes a set from a multicharacter string. Thus "ch" => {"ch"}
1151 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1152 * @param s the source string
1153 * @return a newly created set containing the given string.
1154 * The caller owns the return object and is responsible for deleting it.
1157 static UnicodeSet
* U_EXPORT2
createFrom(const UnicodeString
& s
);
1161 * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
1162 * @param s the source string
1163 * @return a newly created set containing the given characters
1164 * The caller owns the return object and is responsible for deleting it.
1167 static UnicodeSet
* U_EXPORT2
createFromAll(const UnicodeString
& s
);
1170 * Retain only the elements in this set that are contained in the
1171 * specified range. If <code>end > start</code> then an empty range is
1172 * retained, leaving the set empty. This is equivalent to
1173 * a boolean logic AND, or a set INTERSECTION.
1174 * A frozen set will not be modified.
1176 * @param start first character, inclusive, of range to be retained
1178 * @param end last character, inclusive, of range to be retained
1182 virtual UnicodeSet
& retain(UChar32 start
, UChar32 end
);
1186 * Retain the specified character from this set if it is present.
1187 * A frozen set will not be modified.
1190 UnicodeSet
& retain(UChar32 c
);
1193 * Removes the specified range from this set if it is present.
1194 * The set will not contain the specified range once the call
1195 * returns. If <code>end > start</code> then an empty range is
1196 * removed, leaving the set unchanged.
1197 * A frozen set will not be modified.
1199 * @param start first character, inclusive, of range to be removed
1201 * @param end last character, inclusive, of range to be removed
1205 virtual UnicodeSet
& remove(UChar32 start
, UChar32 end
);
1208 * Removes the specified character from this set if it is present.
1209 * The set will not contain the specified range once the call
1211 * A frozen set will not be modified.
1214 UnicodeSet
& remove(UChar32 c
);
1217 * Removes the specified string from this set if it is present.
1218 * The set will not contain the specified character once the call
1220 * A frozen set will not be modified.
1221 * @param s the source string
1222 * @return this object, for chaining
1225 UnicodeSet
& remove(const UnicodeString
& s
);
1228 * Inverts this set. This operation modifies this set so that
1229 * its value is its complement. This is equivalent to
1230 * <code>complement(MIN_VALUE, MAX_VALUE)</code>.
1231 * A frozen set will not be modified.
1234 virtual UnicodeSet
& complement(void);
1237 * Complements the specified range in this set. Any character in
1238 * the range will be removed if it is in this set, or will be
1239 * added if it is not in this set. If <code>end > start</code>
1240 * then an empty range is complemented, leaving the set unchanged.
1241 * This is equivalent to a boolean logic XOR.
1242 * A frozen set will not be modified.
1244 * @param start first character, inclusive, of range to be removed
1246 * @param end last character, inclusive, of range to be removed
1250 virtual UnicodeSet
& complement(UChar32 start
, UChar32 end
);
1253 * Complements the specified character in this set. The character
1254 * will be removed if it is in this set, or will be added if it is
1256 * A frozen set will not be modified.
1259 UnicodeSet
& complement(UChar32 c
);
1262 * Complement the specified string in this set.
1263 * The set will not contain the specified string once the call
1265 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1266 * A frozen set will not be modified.
1267 * @param s the string to complement
1268 * @return this object, for chaining
1271 UnicodeSet
& complement(const UnicodeString
& s
);
1274 * Adds all of the elements in the specified set to this set if
1275 * they're not already present. This operation effectively
1276 * modifies this set so that its value is the <i>union</i> of the two
1277 * sets. The behavior of this operation is unspecified if the specified
1278 * collection is modified while the operation is in progress.
1279 * A frozen set will not be modified.
1281 * @param c set whose elements are to be added to this set.
1282 * @see #add(UChar32, UChar32)
1285 virtual UnicodeSet
& addAll(const UnicodeSet
& c
);
1288 * Retains only the elements in this set that are contained in the
1289 * specified set. In other words, removes from this set all of
1290 * its elements that are not contained in the specified set. This
1291 * operation effectively modifies this set so that its value is
1292 * the <i>intersection</i> of the two sets.
1293 * A frozen set will not be modified.
1295 * @param c set that defines which elements this set will retain.
1298 virtual UnicodeSet
& retainAll(const UnicodeSet
& c
);
1301 * Removes from this set all of its elements that are contained in the
1302 * specified set. This operation effectively modifies this
1303 * set so that its value is the <i>asymmetric set difference</i> of
1305 * A frozen set will not be modified.
1307 * @param c set that defines which elements will be removed from
1311 virtual UnicodeSet
& removeAll(const UnicodeSet
& c
);
1314 * Complements in this set all elements contained in the specified
1315 * set. Any character in the other set will be removed if it is
1316 * in this set, or will be added if it is not in this set.
1317 * A frozen set will not be modified.
1319 * @param c set that defines which elements will be xor'ed from
1323 virtual UnicodeSet
& complementAll(const UnicodeSet
& c
);
1326 * Removes all of the elements from this set. This set will be
1327 * empty after this call returns.
1328 * A frozen set will not be modified.
1331 virtual UnicodeSet
& clear(void);
1334 * Close this set over the given attribute. For the attribute
1335 * USET_CASE, the result is to modify this set so that:
1337 * 1. For each character or string 'a' in this set, all strings or
1338 * characters 'b' such that foldCase(a) == foldCase(b) are added
1341 * 2. For each string 'e' in the resulting set, if e !=
1342 * foldCase(e), 'e' will be removed.
1344 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
1346 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
1347 * == b denotes that the contents are the same, not pointer
1350 * A frozen set will not be modified.
1352 * @param attribute bitmask for attributes to close over.
1353 * Currently only the USET_CASE bit is supported. Any undefined bits
1355 * @return a reference to this set.
1358 UnicodeSet
& closeOver(int32_t attribute
);
1361 * Remove all strings from this set.
1363 * @return a reference to this set.
1366 virtual UnicodeSet
&removeAllStrings();
1369 * Iteration method that returns the number of ranges contained in
1371 * @see #getRangeStart
1375 virtual int32_t getRangeCount(void) const;
1378 * Iteration method that returns the first character in the
1379 * specified range of this set.
1380 * @see #getRangeCount
1384 virtual UChar32
getRangeStart(int32_t index
) const;
1387 * Iteration method that returns the last character in the
1388 * specified range of this set.
1389 * @see #getRangeStart
1393 virtual UChar32
getRangeEnd(int32_t index
) const;
1396 * Serializes this set into an array of 16-bit integers. Serialization
1397 * (currently) only records the characters in the set; multicharacter
1398 * strings are ignored.
1400 * The array has following format (each line is one 16-bit
1403 * length = (n+2*m) | (m!=0?0x8000:0)
1404 * bmpLength = n; present if m!=0
1417 * The array starts with a header. After the header are n bmp
1418 * code points, then m supplementary code points. Either n or m
1419 * or both may be zero. n+2*m is always <= 0x7FFF.
1421 * If there are no supplementary characters (if m==0) then the
1422 * header is one 16-bit integer, 'length', with value n.
1424 * If there are supplementary characters (if m!=0) then the header
1425 * is two 16-bit integers. The first, 'length', has value
1426 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
1428 * After the header the code points are stored in ascending order.
1429 * Supplementary code points are stored as most significant 16
1430 * bits followed by least significant 16 bits.
1432 * @param dest pointer to buffer of destCapacity 16-bit integers.
1433 * May be NULL only if destCapacity is zero.
1434 * @param destCapacity size of dest, or zero. Must not be negative.
1435 * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR
1436 * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if
1437 * n+2*m+(m!=0?2:1) > destCapacity.
1438 * @return the total length of the serialized format, including
1439 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1440 * than U_BUFFER_OVERFLOW_ERROR.
1443 int32_t serialize(uint16_t *dest
, int32_t destCapacity
, UErrorCode
& ec
) const;
1446 * Reallocate this objects internal structures to take up the least
1447 * possible space, without changing this object's value.
1448 * A frozen set will not be modified.
1451 virtual UnicodeSet
& compact();
1454 * Return the class ID for this class. This is useful only for
1455 * comparing to a return value from getDynamicClassID(). For example:
1457 * . Base* polymorphic_pointer = createPolymorphicObject();
1458 * . if (polymorphic_pointer->getDynamicClassID() ==
1459 * . Derived::getStaticClassID()) ...
1461 * @return The class ID for all objects of this class.
1464 static UClassID U_EXPORT2
getStaticClassID(void);
1467 * Implement UnicodeFunctor API.
1469 * @return The class ID for this object. All objects of a given
1470 * class have the same class ID. Objects of other classes have
1471 * different class IDs.
1474 virtual UClassID
getDynamicClassID(void) const;
1478 // Private API for the USet API
1480 friend class USetAccess
;
1482 int32_t getStringCount() const;
1484 const UnicodeString
* getString(int32_t index
) const;
1486 //----------------------------------------------------------------
1487 // RuleBasedTransliterator support
1488 //----------------------------------------------------------------
1493 * Returns <tt>true</tt> if this set contains any character whose low byte
1494 * is the given value. This is used by <tt>RuleBasedTransliterator</tt> for
1497 virtual UBool
matchesIndexValue(uint8_t v
) const;
1500 friend class RBBIRuleScanner
;
1502 //----------------------------------------------------------------
1503 // Implementation: Clone as thawed (see ICU4J Freezable)
1504 //----------------------------------------------------------------
1506 UnicodeSet(const UnicodeSet
& o
, UBool
/* asThawed */);
1508 //----------------------------------------------------------------
1509 // Implementation: Pattern parsing
1510 //----------------------------------------------------------------
1512 void applyPatternIgnoreSpace(const UnicodeString
& pattern
,
1514 const SymbolTable
* symbols
,
1515 UErrorCode
& status
);
1517 void applyPattern(RuleCharacterIterator
& chars
,
1518 const SymbolTable
* symbols
,
1519 UnicodeString
& rebuiltPat
,
1521 UnicodeSet
& (UnicodeSet::*caseClosure
)(int32_t attribute
),
1524 //----------------------------------------------------------------
1525 // Implementation: Utility methods
1526 //----------------------------------------------------------------
1528 void ensureCapacity(int32_t newLen
, UErrorCode
& ec
);
1530 void ensureBufferCapacity(int32_t newLen
, UErrorCode
& ec
);
1532 void swapBuffers(void);
1534 UBool
allocateStrings(UErrorCode
&status
);
1536 UnicodeString
& _toPattern(UnicodeString
& result
,
1537 UBool escapeUnprintable
) const;
1539 UnicodeString
& _generatePattern(UnicodeString
& result
,
1540 UBool escapeUnprintable
) const;
1542 static void _appendToPat(UnicodeString
& buf
, const UnicodeString
& s
, UBool escapeUnprintable
);
1544 static void _appendToPat(UnicodeString
& buf
, UChar32 c
, UBool escapeUnprintable
);
1546 //----------------------------------------------------------------
1547 // Implementation: Fundamental operators
1548 //----------------------------------------------------------------
1550 void exclusiveOr(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1552 void add(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1554 void retain(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1557 * Return true if the given position, in the given pattern, appears
1558 * to be the start of a property set pattern [:foo:], \\p{foo}, or
1559 * \\P{foo}, or \\N{name}.
1561 static UBool
resemblesPropertyPattern(const UnicodeString
& pattern
,
1564 static UBool
resemblesPropertyPattern(RuleCharacterIterator
& chars
,
1568 * Parse the given property pattern at the given parse position
1569 * and set this UnicodeSet to the result.
1571 * The original design document is out of date, but still useful.
1572 * Ignore the property and value names:
1573 * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/unicodeset_properties.html
1575 * Recognized syntax:
1577 * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]"
1578 * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P"
1579 * \\N{name} - white space not allowed within "\\N"
1581 * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored.
1582 * Case is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading
1583 * and trailing space is deleted, and internal runs of whitespace
1584 * are collapsed to a single space.
1586 * We support binary properties, enumerated properties, and the
1587 * following non-enumerated properties:
1593 * @param pattern the pattern string
1594 * @param ppos on entry, the position at which to begin parsing.
1595 * This should be one of the locations marked '^':
1597 * [:blah:] \\p{blah} \\P{blah} \\N{name}
1600 * On return, the position after the last character parsed, that is,
1601 * the locations marked '%'. If the parse fails, ppos is returned
1604 * @return a reference to this.
1606 UnicodeSet
& applyPropertyPattern(const UnicodeString
& pattern
,
1607 ParsePosition
& ppos
,
1610 void applyPropertyPattern(RuleCharacterIterator
& chars
,
1611 UnicodeString
& rebuiltPat
,
1614 friend void U_CALLCONV
UnicodeSet_initInclusion(int32_t src
, UErrorCode
&status
);
1615 static const UnicodeSet
* getInclusions(int32_t src
, UErrorCode
&status
);
1618 * A filter that returns TRUE if the given code point should be
1619 * included in the UnicodeSet being constructed.
1621 typedef UBool (*Filter
)(UChar32 codePoint
, void* context
);
1624 * Given a filter, set this UnicodeSet to the code points
1625 * contained by that filter. The filter MUST be
1626 * property-conformant. That is, if it returns value v for one
1627 * code point, then it must return v for all affiliated code
1628 * points, as defined by the inclusions list. See
1630 * src is a UPropertySource value.
1632 void applyFilter(Filter filter
,
1635 UErrorCode
&status
);
1638 * Set the new pattern to cache.
1640 void setPattern(const UnicodeString
& newPat
);
1642 * Release existing cached pattern.
1644 void releasePattern();
1646 friend class UnicodeSetIterator
;
1651 inline UBool
UnicodeSet::operator!=(const UnicodeSet
& o
) const {
1652 return !operator==(o
);
1655 inline UBool
UnicodeSet::isFrozen() const {
1656 return (UBool
)(bmpSet
!=NULL
|| stringSpan
!=NULL
);
1659 inline UBool
UnicodeSet::containsSome(UChar32 start
, UChar32 end
) const {
1660 return !containsNone(start
, end
);
1663 inline UBool
UnicodeSet::containsSome(const UnicodeSet
& s
) const {
1664 return !containsNone(s
);
1667 inline UBool
UnicodeSet::containsSome(const UnicodeString
& s
) const {
1668 return !containsNone(s
);
1671 inline UBool
UnicodeSet::isBogus() const {
1672 return (UBool
)(fFlags
& kIsBogus
);
1675 inline UnicodeSet
*UnicodeSet::fromUSet(USet
*uset
) {
1676 return reinterpret_cast<UnicodeSet
*>(uset
);
1679 inline const UnicodeSet
*UnicodeSet::fromUSet(const USet
*uset
) {
1680 return reinterpret_cast<const UnicodeSet
*>(uset
);
1683 inline USet
*UnicodeSet::toUSet() {
1684 return reinterpret_cast<USet
*>(this);
1687 inline const USet
*UnicodeSet::toUSet() const {
1688 return reinterpret_cast<const USet
*>(this);
1691 inline int32_t UnicodeSet::span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const {
1692 int32_t sLength
=s
.length();
1695 } else if(start
>sLength
) {
1698 return start
+span(s
.getBuffer()+start
, sLength
-start
, spanCondition
);
1701 inline int32_t UnicodeSet::spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const {
1702 int32_t sLength
=s
.length();
1705 } else if(limit
>sLength
) {
1708 return spanBack(s
.getBuffer(), limit
, spanCondition
);