2 ***************************************************************************
3 * Copyright (C) 1999-2011, 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
27 class RBBIRuleScanner
;
29 class UnicodeSetStringSpan
;
31 class RuleCharacterIterator
;
34 * A mutable set of Unicode characters and multicharacter strings. Objects of this class
35 * represent <em>character classes</em> used in regular expressions.
36 * A character specifies a subset of Unicode code points. Legal
37 * code points are U+0000 to U+10FFFF, inclusive.
39 * <p>The UnicodeSet class is not designed to be subclassed.
41 * <p><code>UnicodeSet</code> supports two APIs. The first is the
42 * <em>operand</em> API that allows the caller to modify the value of
43 * a <code>UnicodeSet</code> object. It conforms to Java 2's
44 * <code>java.util.Set</code> interface, although
45 * <code>UnicodeSet</code> does not actually implement that
46 * interface. All methods of <code>Set</code> are supported, with the
47 * modification that they take a character range or single character
48 * instead of an <code>Object</code>, and they take a
49 * <code>UnicodeSet</code> instead of a <code>Collection</code>. The
50 * operand API may be thought of in terms of boolean logic: a boolean
51 * OR is implemented by <code>add</code>, a boolean AND is implemented
52 * by <code>retain</code>, a boolean XOR is implemented by
53 * <code>complement</code> taking an argument, and a boolean NOT is
54 * implemented by <code>complement</code> with no argument. In terms
55 * of traditional set theory function names, <code>add</code> is a
56 * union, <code>retain</code> is an intersection, <code>remove</code>
57 * is an asymmetric difference, and <code>complement</code> with no
58 * argument is a set complement with respect to the superset range
59 * <code>MIN_VALUE-MAX_VALUE</code>
61 * <p>The second API is the
62 * <code>applyPattern()</code>/<code>toPattern()</code> API from the
63 * <code>java.text.Format</code>-derived classes. Unlike the
64 * methods that add characters, add categories, and control the logic
65 * of the set, the method <code>applyPattern()</code> sets all
66 * attributes of a <code>UnicodeSet</code> at once, based on a
69 * <p><b>Pattern syntax</b></p>
71 * Patterns are accepted by the constructors and the
72 * <code>applyPattern()</code> methods and returned by the
73 * <code>toPattern()</code> method. These patterns follow a syntax
74 * similar to that employed by version 8 regular expression character
75 * classes. Here are some simple examples:
77 * \htmlonly<blockquote>\endhtmlonly
80 * <td nowrap valign="top" align="left"><code>[]</code></td>
81 * <td valign="top">No characters</td>
82 * </tr><tr align="top">
83 * <td nowrap valign="top" align="left"><code>[a]</code></td>
84 * <td valign="top">The character 'a'</td>
85 * </tr><tr align="top">
86 * <td nowrap valign="top" align="left"><code>[ae]</code></td>
87 * <td valign="top">The characters 'a' and 'e'</td>
90 * <td nowrap valign="top" align="left"><code>[a-e]</code></td>
91 * <td valign="top">The characters 'a' through 'e' inclusive, in Unicode code
95 * <td nowrap valign="top" align="left"><code>[\\u4E01]</code></td>
96 * <td valign="top">The character U+4E01</td>
99 * <td nowrap valign="top" align="left"><code>[a{ab}{ac}]</code></td>
100 * <td valign="top">The character 'a' and the multicharacter strings "ab" and
101 * "ac"</td>
104 * <td nowrap valign="top" align="left"><code>[\\p{Lu}]</code></td>
105 * <td valign="top">All characters in the general category Uppercase Letter</td>
108 * \htmlonly</blockquote>\endhtmlonly
110 * Any character may be preceded by a backslash in order to remove any special
111 * meaning. White space characters, as defined by UCharacter.isWhitespace(), are
112 * ignored, unless they are escaped.
114 * <p>Property patterns specify a set of characters having a certain
115 * property as defined by the Unicode standard. Both the POSIX-like
116 * "[:Lu:]" and the Perl-like syntax "\\p{Lu}" are recognized. For a
117 * complete list of supported property patterns, see the User's Guide
119 * <a href="http://icu-project.org/userguide/unicodeSet.html">
120 * http://icu-project.org/userguide/unicodeSet.html</a>.
121 * Actual determination of property data is defined by the underlying
122 * Unicode database as implemented by UCharacter.
124 * <p>Patterns specify individual characters, ranges of characters, and
125 * Unicode property sets. When elements are concatenated, they
126 * specify their union. To complement a set, place a '^' immediately
127 * after the opening '['. Property patterns are inverted by modifying
128 * their delimiters; "[:^foo]" and "\\P{foo}". In any other location,
129 * '^' has no special meaning.
131 * <p>Ranges are indicated by placing two a '-' between two
132 * characters, as in "a-z". This specifies the range of all
133 * characters from the left to the right, in Unicode order. If the
134 * left character is greater than or equal to the
135 * right character it is a syntax error. If a '-' occurs as the first
136 * character after the opening '[' or '[^', or if it occurs as the
137 * last character before the closing ']', then it is taken as a
138 * literal. Thus "[a\-b]", "[-ab]", and "[ab-]" all indicate the same
139 * set of three characters, 'a', 'b', and '-'.
141 * <p>Sets may be intersected using the '&' operator or the asymmetric
142 * set difference may be taken using the '-' operator, for example,
143 * "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters
144 * with values less than 4096. Operators ('&' and '|') have equal
145 * precedence and bind left-to-right. Thus
146 * "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to
147 * "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]". This only really matters for
148 * difference; intersection is commutative.
151 * <tr valign=top><td nowrap><code>[a]</code><td>The set containing 'a'
152 * <tr valign=top><td nowrap><code>[a-z]</code><td>The set containing 'a'
153 * through 'z' and all letters in between, in Unicode order
154 * <tr valign=top><td nowrap><code>[^a-z]</code><td>The set containing
155 * all characters but 'a' through 'z',
156 * that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF
157 * <tr valign=top><td nowrap><code>[[<em>pat1</em>][<em>pat2</em>]]</code>
158 * <td>The union of sets specified by <em>pat1</em> and <em>pat2</em>
159 * <tr valign=top><td nowrap><code>[[<em>pat1</em>]&[<em>pat2</em>]]</code>
160 * <td>The intersection of sets specified by <em>pat1</em> and <em>pat2</em>
161 * <tr valign=top><td nowrap><code>[[<em>pat1</em>]-[<em>pat2</em>]]</code>
162 * <td>The asymmetric difference of sets specified by <em>pat1</em> and
164 * <tr valign=top><td nowrap><code>[:Lu:] or \\p{Lu}</code>
165 * <td>The set of characters having the specified
166 * Unicode property; in
167 * this case, Unicode uppercase letters
168 * <tr valign=top><td nowrap><code>[:^Lu:] or \\P{Lu}</code>
169 * <td>The set of characters <em>not</em> having the given
173 * <p><b>Warning</b>: you cannot add an empty string ("") to a UnicodeSet.</p>
175 * <p><b>Formal syntax</b></p>
177 * \htmlonly<blockquote>\endhtmlonly
180 * <td nowrap valign="top" align="right"><code>pattern := </code></td>
181 * <td valign="top"><code>('[' '^'? item* ']') |
182 * property</code></td>
185 * <td nowrap valign="top" align="right"><code>item := </code></td>
186 * <td valign="top"><code>char | (char '-' char) | pattern-expr<br>
190 * <td nowrap valign="top" align="right"><code>pattern-expr := </code></td>
191 * <td valign="top"><code>pattern | pattern-expr pattern |
192 * pattern-expr op pattern<br>
196 * <td nowrap valign="top" align="right"><code>op := </code></td>
197 * <td valign="top"><code>'&' | '-'<br>
201 * <td nowrap valign="top" align="right"><code>special := </code></td>
202 * <td valign="top"><code>'[' | ']' | '-'<br>
206 * <td nowrap valign="top" align="right"><code>char := </code></td>
207 * <td valign="top"><em>any character that is not</em><code> special<br>
208 * | ('\' </code><em>any character</em><code>)<br>
209 * | ('\\u' hex hex hex hex)<br>
213 * <td nowrap valign="top" align="right"><code>hex := </code></td>
214 * <td valign="top"><em>any character for which
215 * </em><code>Character.digit(c, 16)</code><em>
216 * returns a non-negative result</em></td>
219 * <td nowrap valign="top" align="right"><code>property := </code></td>
220 * <td valign="top"><em>a Unicode property set pattern</em></td>
226 * <td>Legend: <table>
228 * <td nowrap valign="top"><code>a := b</code></td>
229 * <td width="20" valign="top"> </td>
230 * <td valign="top"><code>a</code> may be replaced by <code>b</code> </td>
233 * <td nowrap valign="top"><code>a?</code></td>
234 * <td valign="top"></td>
235 * <td valign="top">zero or one instance of <code>a</code><br>
239 * <td nowrap valign="top"><code>a*</code></td>
240 * <td valign="top"></td>
241 * <td valign="top">one or more instances of <code>a</code><br>
245 * <td nowrap valign="top"><code>a | b</code></td>
246 * <td valign="top"></td>
247 * <td valign="top">either <code>a</code> or <code>b</code><br>
251 * <td nowrap valign="top"><code>'a'</code></td>
252 * <td valign="top"></td>
253 * <td valign="top">the literal string between the quotes </td>
259 * \htmlonly</blockquote>\endhtmlonly
262 * - Most UnicodeSet methods do not take a UErrorCode parameter because
263 * there are usually very few opportunities for failure other than a shortage
264 * of memory, error codes in low-level C++ string methods would be inconvenient,
265 * and the error code as the last parameter (ICU convention) would prevent
266 * the use of default parameter values.
267 * Instead, such methods set the UnicodeSet into a "bogus" state
268 * (see isBogus()) if an error occurs.
273 class U_COMMON_API UnicodeSet
: public UnicodeFilter
{
275 int32_t len
; // length of list used; 0 <= len <= capacity
276 int32_t capacity
; // capacity of list
277 UChar32
* list
; // MUST be terminated with HIGH
278 BMPSet
*bmpSet
; // The set is frozen iff either bmpSet or stringSpan is not NULL.
279 UChar32
* buffer
; // internal buffer, may be NULL
280 int32_t bufferCapacity
; // capacity of buffer
284 * The pattern representation of this set. This may not be the
285 * most economical pattern. It is the pattern supplied to
286 * applyPattern(), with variables substituted and whitespace
287 * removed. For sets constructed without applyPattern(), or
288 * modified using the non-pattern API, this string will be empty,
289 * indicating that toPattern() must generate a pattern
290 * representation from the inversion list.
293 UVector
* strings
; // maintained in sorted order
294 UnicodeSetStringSpan
*stringSpan
;
298 kIsBogus
= 1 // This set is bogus (i.e. not valid)
300 uint8_t fFlags
; // Bit flag (see constants above)
303 * Determine if this object contains a valid set.
304 * A bogus set has no value. It is different from an empty set.
305 * It can be used to indicate that no set value is available.
307 * @return TRUE if the set is valid, FALSE otherwise
311 inline UBool
isBogus(void) const;
314 * Make this UnicodeSet object invalid.
315 * The string will test TRUE with isBogus().
317 * A bogus set has no value. It is different from an empty set.
318 * It can be used to indicate that no set value is available.
320 * This utility function is used throughout the UnicodeSet
321 * implementation to indicate that a UnicodeSet operation failed,
322 * and may be used in other functions,
323 * especially but not exclusively when such functions do not
324 * take a UErrorCode for simplicity.
335 * Minimum value that can be stored in a UnicodeSet.
341 * Maximum value that can be stored in a UnicodeSet.
347 //----------------------------------------------------------------
349 //----------------------------------------------------------------
354 * Constructs an empty set.
360 * Constructs a set containing the given range. If <code>end >
361 * start</code> then an empty set is created.
363 * @param start first character, inclusive, of range
364 * @param end last character, inclusive, of range
367 UnicodeSet(UChar32 start
, UChar32 end
);
370 * Constructs a set from the given pattern. See the class
371 * description for the syntax of the pattern language.
372 * @param pattern a string specifying what characters are in the set
373 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
374 * contains a syntax error.
377 UnicodeSet(const UnicodeString
& pattern
,
380 #ifndef U_HIDE_INTERNAL_API
382 * Constructs a set from the given pattern. See the class
383 * description for the syntax of the pattern language.
384 * @param pattern a string specifying what characters are in the set
385 * @param options bitmask for options to apply to the pattern.
386 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
387 * @param symbols a symbol table mapping variable names to values
388 * and stand-in characters to UnicodeSets; may be NULL
389 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
390 * contains a syntax error.
393 UnicodeSet(const UnicodeString
& pattern
,
395 const SymbolTable
* symbols
,
397 #endif /* U_HIDE_INTERNAL_API */
400 * Constructs a set from the given pattern. See the class description
401 * for the syntax of the pattern language.
402 * @param pattern a string specifying what characters are in the set
403 * @param pos on input, the position in pattern at which to start parsing.
404 * On output, the position after the last character parsed.
405 * @param options bitmask for options to apply to the pattern.
406 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
407 * @param symbols a symbol table mapping variable names to values
408 * and stand-in characters to UnicodeSets; may be NULL
409 * @param status input-output error code
412 UnicodeSet(const UnicodeString
& pattern
, ParsePosition
& pos
,
414 const SymbolTable
* symbols
,
418 * Constructs a set that is identical to the given UnicodeSet.
421 UnicodeSet(const UnicodeSet
& o
);
427 virtual ~UnicodeSet();
430 * Assigns this object to be a copy of another.
431 * A frozen set will not be modified.
434 UnicodeSet
& operator=(const UnicodeSet
& o
);
437 * Compares the specified object with this set for equality. Returns
438 * <tt>true</tt> if the two sets
439 * have the same size, and every member of the specified set is
440 * contained in this set (or equivalently, every member of this set is
441 * contained in the specified set).
443 * @param o set to be compared for equality with this set.
444 * @return <tt>true</tt> if the specified set is equal to this set.
447 virtual UBool
operator==(const UnicodeSet
& o
) const;
450 * Compares the specified object with this set for equality. Returns
451 * <tt>true</tt> if the specified set is not equal to this set.
454 UBool
operator!=(const UnicodeSet
& o
) const;
457 * Returns a copy of this object. All UnicodeFunctor objects have
458 * to support cloning in order to allow classes using
459 * UnicodeFunctors, such as Transliterator, to implement cloning.
460 * If this set is frozen, then the clone will be frozen as well.
461 * Use cloneAsThawed() for a mutable clone of a frozen set.
465 virtual UnicodeFunctor
* clone() const;
468 * Returns the hash code value for this set.
470 * @return the hash code value for this set.
471 * @see Object#hashCode()
474 virtual int32_t hashCode(void) const;
477 * Get a UnicodeSet pointer from a USet
479 * @param uset a USet (the ICU plain C type for UnicodeSet)
480 * @return the corresponding UnicodeSet pointer.
484 inline static UnicodeSet
*fromUSet(USet
*uset
);
487 * Get a UnicodeSet pointer from a const USet
489 * @param uset a const USet (the ICU plain C type for UnicodeSet)
490 * @return the corresponding UnicodeSet pointer.
494 inline static const UnicodeSet
*fromUSet(const USet
*uset
);
497 * Produce a USet * pointer for this UnicodeSet.
498 * USet is the plain C type for UnicodeSet
500 * @return a USet pointer for this UnicodeSet
503 inline USet
*toUSet();
507 * Produce a const USet * pointer for this UnicodeSet.
508 * USet is the plain C type for UnicodeSet
510 * @return a const USet pointer for this UnicodeSet
513 inline const USet
* toUSet() const;
516 //----------------------------------------------------------------
518 //----------------------------------------------------------------
521 * Determines whether the set has been frozen (made immutable) or not.
522 * See the ICU4J Freezable interface for details.
523 * @return TRUE/FALSE for whether the set has been frozen
528 inline UBool
isFrozen() const;
531 * Freeze the set (make it immutable).
532 * Once frozen, it cannot be unfrozen and is therefore thread-safe
533 * until it is deleted.
534 * See the ICU4J Freezable interface for details.
535 * Freezing the set may also make some operations faster, for example
536 * contains() and span().
537 * A frozen set will not be modified. (It remains frozen.)
543 UnicodeFunctor
*freeze();
546 * Clone the set and make the clone mutable.
547 * See the ICU4J Freezable interface for details.
548 * @return the mutable clone
553 UnicodeFunctor
*cloneAsThawed() const;
555 //----------------------------------------------------------------
557 //----------------------------------------------------------------
560 * Make this object represent the range <code>start - end</code>.
561 * If <code>end > start</code> then this object is set to an
563 * A frozen set will not be modified.
565 * @param start first character in the set, inclusive
566 * @param end last character in the set, inclusive
569 UnicodeSet
& set(UChar32 start
, UChar32 end
);
572 * Return true if the given position, in the given pattern, appears
573 * to be the start of a UnicodeSet pattern.
576 static UBool
resemblesPattern(const UnicodeString
& pattern
,
580 * Modifies this set to represent the set specified by the given
581 * pattern, ignoring Unicode Pattern_White_Space characters.
582 * See the class description for the syntax of the pattern language.
583 * A frozen set will not be modified.
584 * @param pattern a string specifying what characters are in the set
585 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
586 * contains a syntax error.
587 * <em> Empties the set passed before applying the pattern.</em>
588 * @return a reference to this
591 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
594 #ifndef U_HIDE_INTERNAL_API
596 * Modifies this set to represent the set specified by the given
597 * pattern, optionally ignoring Unicode Pattern_White_Space characters.
598 * See the class description for the syntax of the pattern language.
599 * A frozen set will not be modified.
600 * @param pattern a string specifying what characters are in the set
601 * @param options bitmask for options to apply to the pattern.
602 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
603 * @param symbols a symbol table mapping variable names to
604 * values and stand-ins to UnicodeSets; may be NULL
605 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
606 * contains a syntax error.
607 *<em> Empties the set passed before applying the pattern.</em>
608 * @return a reference to this
611 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
613 const SymbolTable
* symbols
,
615 #endif /* U_HIDE_INTERNAL_API */
618 * Parses the given pattern, starting at the given position. The
619 * character at pattern.charAt(pos.getIndex()) must be '[', or the
620 * parse fails. Parsing continues until the corresponding closing
621 * ']'. If a syntax error is encountered between the opening and
622 * closing brace, the parse fails. Upon return from a successful
623 * parse, the ParsePosition is updated to point to the character
624 * following the closing ']', and a StringBuffer containing a
625 * pairs list for the parsed pattern is returned. This method calls
626 * itself recursively to parse embedded subpatterns.
627 *<em> Empties the set passed before applying the pattern.</em>
628 * A frozen set will not be modified.
630 * @param pattern the string containing the pattern to be parsed.
631 * The portion of the string from pos.getIndex(), which must be a
632 * '[', to the corresponding closing ']', is parsed.
633 * @param pos upon entry, the position at which to being parsing.
634 * The character at pattern.charAt(pos.getIndex()) must be a '['.
635 * Upon return from a successful parse, pos.getIndex() is either
636 * the character after the closing ']' of the parsed pattern, or
637 * pattern.length() if the closing ']' is the last character of
638 * the pattern string.
639 * @param options bitmask for options to apply to the pattern.
640 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
641 * @param symbols a symbol table mapping variable names to
642 * values and stand-ins to UnicodeSets; may be NULL
643 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
644 * contains a syntax error.
645 * @return a reference to this
648 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
651 const SymbolTable
* symbols
,
655 * Returns a string representation of this set. If the result of
656 * calling this function is passed to a UnicodeSet constructor, it
657 * will produce another set that is equal to this one.
658 * A frozen set will not be modified.
659 * @param result the string to receive the rules. Previous
660 * contents will be deleted.
661 * @param escapeUnprintable if TRUE then convert unprintable
662 * character to their hex escape representations, \\uxxxx or
663 * \\Uxxxxxxxx. Unprintable characters are those other than
664 * U+000A, U+0020..U+007E.
667 virtual UnicodeString
& toPattern(UnicodeString
& result
,
668 UBool escapeUnprintable
= FALSE
) const;
671 * Modifies this set to contain those code points which have the given value
672 * for the given binary or enumerated property, as returned by
673 * u_getIntPropertyValue. Prior contents of this set are lost.
674 * A frozen set will not be modified.
676 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
677 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
678 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
680 * @param value a value in the range u_getIntPropertyMinValue(prop)..
681 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
682 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
683 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
684 * categories such as [:L:] to be represented.
686 * @param ec error code input/output parameter
688 * @return a reference to this set
692 UnicodeSet
& applyIntPropertyValue(UProperty prop
,
697 * Modifies this set to contain those code points which have the
698 * given value for the given property. Prior contents of this
700 * A frozen set will not be modified.
702 * @param prop a property alias, either short or long. The name is matched
703 * loosely. See PropertyAliases.txt for names and a description of loose
704 * matching. If the value string is empty, then this string is interpreted
705 * as either a General_Category value alias, a Script value alias, a binary
706 * property alias, or a special ID. Special IDs are matched loosely and
707 * correspond to the following sets:
709 * "ANY" = [\\u0000-\\U0010FFFF],
710 * "ASCII" = [\\u0000-\\u007F],
711 * "Assigned" = [:^Cn:].
713 * @param value a value alias, either short or long. The name is matched
714 * loosely. See PropertyValueAliases.txt for names and a description of
715 * loose matching. In addition to aliases listed, numeric values and
716 * canonical combining classes may be expressed numerically, e.g., ("nv",
717 * "0.5") or ("ccc", "220"). The value string may also be empty.
719 * @param ec error code input/output parameter
721 * @return a reference to this set
725 UnicodeSet
& applyPropertyAlias(const UnicodeString
& prop
,
726 const UnicodeString
& value
,
730 * Returns the number of elements in this set (its cardinality).
731 * Note than the elements of a set may include both individual
732 * codepoints and strings.
734 * @return the number of elements in this set (its cardinality).
737 virtual int32_t size(void) const;
740 * Returns <tt>true</tt> if this set contains no elements.
742 * @return <tt>true</tt> if this set contains no elements.
745 virtual UBool
isEmpty(void) const;
748 * Returns true if this set contains the given character.
749 * This function works faster with a frozen set.
750 * @param c character to be checked for containment
751 * @return true if the test condition is met
754 virtual UBool
contains(UChar32 c
) const;
757 * Returns true if this set contains every character
758 * of the given range.
759 * @param start first character, inclusive, of the range
760 * @param end last character, inclusive, of the range
761 * @return true if the test condition is met
764 virtual UBool
contains(UChar32 start
, UChar32 end
) const;
767 * Returns <tt>true</tt> if this set contains the given
768 * multicharacter string.
769 * @param s string to be checked for containment
770 * @return <tt>true</tt> if this set contains the specified string
773 UBool
contains(const UnicodeString
& s
) const;
776 * Returns true if this set contains all the characters and strings
778 * @param c set to be checked for containment
779 * @return true if the test condition is met
782 virtual UBool
containsAll(const UnicodeSet
& c
) const;
785 * Returns true if this set contains all the characters
786 * of the given string.
787 * @param s string containing characters to be checked for containment
788 * @return true if the test condition is met
791 UBool
containsAll(const UnicodeString
& s
) const;
794 * Returns true if this set contains none of the characters
795 * of the given range.
796 * @param start first character, inclusive, of the range
797 * @param end last character, inclusive, of the range
798 * @return true if the test condition is met
801 UBool
containsNone(UChar32 start
, UChar32 end
) const;
804 * Returns true if this set contains none of the characters and strings
806 * @param c set to be checked for containment
807 * @return true if the test condition is met
810 UBool
containsNone(const UnicodeSet
& c
) const;
813 * Returns true if this set contains none of the characters
814 * of the given string.
815 * @param s string containing characters to be checked for containment
816 * @return true if the test condition is met
819 UBool
containsNone(const UnicodeString
& s
) const;
822 * Returns true if this set contains one or more of the characters
823 * in the given range.
824 * @param start first character, inclusive, of the range
825 * @param end last character, inclusive, of the range
826 * @return true if the condition is met
829 inline UBool
containsSome(UChar32 start
, UChar32 end
) const;
832 * Returns true if this set contains one or more of the characters
833 * and strings of the given set.
834 * @param s The set to be checked for containment
835 * @return true if the condition is met
838 inline UBool
containsSome(const UnicodeSet
& s
) const;
841 * Returns true if this set contains one or more of the characters
842 * of the given string.
843 * @param s string containing characters to be checked for containment
844 * @return true if the condition is met
847 inline UBool
containsSome(const UnicodeString
& s
) const;
850 * Returns the length of the initial substring of the input string which
851 * consists only of characters and strings that are contained in this set
852 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
853 * or only of characters and strings that are not contained
854 * in this set (USET_SPAN_NOT_CONTAINED).
855 * See USetSpanCondition for details.
856 * Similar to the strspn() C library function.
857 * Unpaired surrogates are treated according to contains() of their surrogate code points.
858 * This function works faster with a frozen set and with a non-negative string length argument.
859 * @param s start of the string
860 * @param length of the string; can be -1 for NUL-terminated
861 * @param spanCondition specifies the containment condition
862 * @return the length of the initial substring according to the spanCondition;
863 * 0 if the start of the string does not fit the spanCondition
865 * @see USetSpanCondition
867 int32_t span(const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
) const;
870 * Returns the end of the substring of the input string according to the USetSpanCondition.
871 * Same as <code>start+span(s.getBuffer()+start, s.length()-start, spanCondition)</code>
872 * after pinning start to 0<=start<=s.length().
873 * @param s the string
874 * @param start the start index in the string for the span operation
875 * @param spanCondition specifies the containment condition
876 * @return the exclusive end of the substring according to the spanCondition;
877 * the substring s.tempSubStringBetween(start, end) fulfills the spanCondition
879 * @see USetSpanCondition
881 inline int32_t span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const;
884 * Returns the start of the trailing substring of the input string which
885 * consists only of characters and strings that are contained in this set
886 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
887 * or only of characters and strings that are not contained
888 * in this set (USET_SPAN_NOT_CONTAINED).
889 * See USetSpanCondition for details.
890 * Unpaired surrogates are treated according to contains() of their surrogate code points.
891 * This function works faster with a frozen set and with a non-negative string length argument.
892 * @param s start of the string
893 * @param length of the string; can be -1 for NUL-terminated
894 * @param spanCondition specifies the containment condition
895 * @return the start of the trailing substring according to the spanCondition;
896 * the string length if the end of the string does not fit the spanCondition
898 * @see USetSpanCondition
900 int32_t spanBack(const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
) const;
903 * Returns the start of the substring of the input string according to the USetSpanCondition.
904 * Same as <code>spanBack(s.getBuffer(), limit, spanCondition)</code>
905 * after pinning limit to 0<=end<=s.length().
906 * @param s the string
907 * @param limit the exclusive-end index in the string for the span operation
908 * (use s.length() or INT32_MAX for spanning back from the end of the string)
909 * @param spanCondition specifies the containment condition
910 * @return the start of the substring according to the spanCondition;
911 * the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition
913 * @see USetSpanCondition
915 inline int32_t spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const;
918 * Returns the length of the initial substring of the input string which
919 * consists only of characters and strings that are contained in this set
920 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
921 * or only of characters and strings that are not contained
922 * in this set (USET_SPAN_NOT_CONTAINED).
923 * See USetSpanCondition for details.
924 * Similar to the strspn() C library function.
925 * Malformed byte sequences are treated according to contains(0xfffd).
926 * This function works faster with a frozen set and with a non-negative string length argument.
927 * @param s start of the string (UTF-8)
928 * @param length of the string; can be -1 for NUL-terminated
929 * @param spanCondition specifies the containment condition
930 * @return the length of the initial substring according to the spanCondition;
931 * 0 if the start of the string does not fit the spanCondition
933 * @see USetSpanCondition
935 int32_t spanUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
938 * Returns the start of the trailing substring of the input string which
939 * consists only of characters and strings that are contained in this set
940 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
941 * or only of characters and strings that are not contained
942 * in this set (USET_SPAN_NOT_CONTAINED).
943 * See USetSpanCondition for details.
944 * Malformed byte sequences are treated according to contains(0xfffd).
945 * This function works faster with a frozen set and with a non-negative string length argument.
946 * @param s start of the string (UTF-8)
947 * @param length of the string; can be -1 for NUL-terminated
948 * @param spanCondition specifies the containment condition
949 * @return the start of the trailing substring according to the spanCondition;
950 * the string length if the end of the string does not fit the spanCondition
952 * @see USetSpanCondition
954 int32_t spanBackUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
957 * Implement UnicodeMatcher::matches()
960 virtual UMatchDegree
matches(const Replaceable
& text
,
967 * Returns the longest match for s in text at the given position.
968 * If limit > start then match forward from start+1 to limit
969 * matching all characters except s.charAt(0). If limit < start,
970 * go backward starting from start-1 matching all characters
971 * except s.charAt(s.length()-1). This method assumes that the
972 * first character, text.charAt(start), matches s, so it does not
974 * @param text the text to match
975 * @param start the first character to match. In the forward
976 * direction, text.charAt(start) is matched against s.charAt(0).
977 * In the reverse direction, it is matched against
978 * s.charAt(s.length()-1).
979 * @param limit the limit offset for matching, either last+1 in
980 * the forward direction, or last-1 in the reverse direction,
981 * where last is the index of the last character to match.
983 * @return If part of s matches up to the limit, return |limit -
984 * start|. If all of s matches before reaching the limit, return
985 * s.length(). If there is a mismatch between s and text, return
988 static int32_t matchRest(const Replaceable
& text
,
989 int32_t start
, int32_t limit
,
990 const UnicodeString
& s
);
993 * Returns the smallest value i such that c < list[i]. Caller
994 * must ensure that c is a legal value or this method will enter
995 * an infinite loop. This method performs a binary search.
996 * @param c a character in the range MIN_VALUE..MAX_VALUE
998 * @return the smallest integer i in the range 0..len-1,
999 * inclusive, such that c < list[i]
1001 int32_t findCodePoint(UChar32 c
) const;
1006 * Implementation of UnicodeMatcher API. Union the set of all
1007 * characters that may be matched by this object into the given
1009 * @param toUnionTo the set into which to union the source characters
1012 virtual void addMatchSetTo(UnicodeSet
& toUnionTo
) const;
1015 * Returns the index of the given character within this set, where
1016 * the set is ordered by ascending code point. If the character
1017 * is not in this set, return -1. The inverse of this method is
1018 * <code>charAt()</code>.
1019 * @return an index from 0..size()-1, or -1
1022 int32_t indexOf(UChar32 c
) const;
1025 * Returns the character at the given index within this set, where
1026 * the set is ordered by ascending code point. If the index is
1027 * out of range, return (UChar32)-1. The inverse of this method is
1028 * <code>indexOf()</code>.
1029 * @param index an index from 0..size()-1
1030 * @return the character at the given index, or (UChar32)-1.
1033 UChar32
charAt(int32_t index
) const;
1036 * Adds the specified range to this set if it is not already
1037 * present. If this set already contains the specified range,
1038 * the call leaves this set unchanged. If <code>end > start</code>
1039 * then an empty range is added, leaving the set unchanged.
1040 * This is equivalent to a boolean logic OR, or a set UNION.
1041 * A frozen set will not be modified.
1043 * @param start first character, inclusive, of range to be added
1045 * @param end last character, inclusive, of range to be added
1049 virtual UnicodeSet
& add(UChar32 start
, UChar32 end
);
1052 * Adds the specified character to this set if it is not already
1053 * present. If this set already contains the specified character,
1054 * the call leaves this set unchanged.
1055 * A frozen set will not be modified.
1058 UnicodeSet
& add(UChar32 c
);
1061 * Adds the specified multicharacter to this set if it is not already
1062 * present. If this set already contains the multicharacter,
1063 * the call leaves this set unchanged.
1064 * Thus "ch" => {"ch"}
1065 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1066 * A frozen set will not be modified.
1067 * @param s the source string
1068 * @return this object, for chaining
1071 UnicodeSet
& add(const UnicodeString
& s
);
1075 * @return a code point IF the string consists of a single one.
1076 * otherwise returns -1.
1077 * @param s string to test
1079 static int32_t getSingleCP(const UnicodeString
& s
);
1081 void _add(const UnicodeString
& s
);
1085 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
1086 * If this set already any particular character, it has no effect on that character.
1087 * A frozen set will not be modified.
1088 * @param s the source string
1089 * @return this object, for chaining
1092 UnicodeSet
& addAll(const UnicodeString
& s
);
1095 * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
1096 * If this set already any particular character, it has no effect on that character.
1097 * A frozen set will not be modified.
1098 * @param s the source string
1099 * @return this object, for chaining
1102 UnicodeSet
& retainAll(const UnicodeString
& s
);
1105 * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
1106 * If this set already any particular character, it has no effect on that character.
1107 * A frozen set will not be modified.
1108 * @param s the source string
1109 * @return this object, for chaining
1112 UnicodeSet
& complementAll(const UnicodeString
& s
);
1115 * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
1116 * If this set already any particular character, it has no effect on that character.
1117 * A frozen set will not be modified.
1118 * @param s the source string
1119 * @return this object, for chaining
1122 UnicodeSet
& removeAll(const UnicodeString
& s
);
1125 * Makes a set from a multicharacter string. Thus "ch" => {"ch"}
1126 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1127 * @param s the source string
1128 * @return a newly created set containing the given string.
1129 * The caller owns the return object and is responsible for deleting it.
1132 static UnicodeSet
* U_EXPORT2
createFrom(const UnicodeString
& s
);
1136 * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
1137 * @param s the source string
1138 * @return a newly created set containing the given characters
1139 * The caller owns the return object and is responsible for deleting it.
1142 static UnicodeSet
* U_EXPORT2
createFromAll(const UnicodeString
& s
);
1145 * Retain only the elements in this set that are contained in the
1146 * specified range. If <code>end > start</code> then an empty range is
1147 * retained, leaving the set empty. This is equivalent to
1148 * a boolean logic AND, or a set INTERSECTION.
1149 * A frozen set will not be modified.
1151 * @param start first character, inclusive, of range to be retained
1153 * @param end last character, inclusive, of range to be retained
1157 virtual UnicodeSet
& retain(UChar32 start
, UChar32 end
);
1161 * Retain the specified character from this set if it is present.
1162 * A frozen set will not be modified.
1165 UnicodeSet
& retain(UChar32 c
);
1168 * Removes the specified range from this set if it is present.
1169 * The set will not contain the specified range once the call
1170 * returns. If <code>end > start</code> then an empty range is
1171 * removed, leaving the set unchanged.
1172 * A frozen set will not be modified.
1174 * @param start first character, inclusive, of range to be removed
1176 * @param end last character, inclusive, of range to be removed
1180 virtual UnicodeSet
& remove(UChar32 start
, UChar32 end
);
1183 * Removes the specified character from this set if it is present.
1184 * The set will not contain the specified range once the call
1186 * A frozen set will not be modified.
1189 UnicodeSet
& remove(UChar32 c
);
1192 * Removes the specified string from this set if it is present.
1193 * The set will not contain the specified character once the call
1195 * A frozen set will not be modified.
1196 * @param s the source string
1197 * @return this object, for chaining
1200 UnicodeSet
& remove(const UnicodeString
& s
);
1203 * Inverts this set. This operation modifies this set so that
1204 * its value is its complement. This is equivalent to
1205 * <code>complement(MIN_VALUE, MAX_VALUE)</code>.
1206 * A frozen set will not be modified.
1209 virtual UnicodeSet
& complement(void);
1212 * Complements the specified range in this set. Any character in
1213 * the range will be removed if it is in this set, or will be
1214 * added if it is not in this set. If <code>end > start</code>
1215 * then an empty range is complemented, leaving the set unchanged.
1216 * This is equivalent to a boolean logic XOR.
1217 * A frozen set will not be modified.
1219 * @param start first character, inclusive, of range to be removed
1221 * @param end last character, inclusive, of range to be removed
1225 virtual UnicodeSet
& complement(UChar32 start
, UChar32 end
);
1228 * Complements the specified character in this set. The character
1229 * will be removed if it is in this set, or will be added if it is
1231 * A frozen set will not be modified.
1234 UnicodeSet
& complement(UChar32 c
);
1237 * Complement the specified string in this set.
1238 * The set will not contain the specified string once the call
1240 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1241 * A frozen set will not be modified.
1242 * @param s the string to complement
1243 * @return this object, for chaining
1246 UnicodeSet
& complement(const UnicodeString
& s
);
1249 * Adds all of the elements in the specified set to this set if
1250 * they're not already present. This operation effectively
1251 * modifies this set so that its value is the <i>union</i> of the two
1252 * sets. The behavior of this operation is unspecified if the specified
1253 * collection is modified while the operation is in progress.
1254 * A frozen set will not be modified.
1256 * @param c set whose elements are to be added to this set.
1257 * @see #add(UChar32, UChar32)
1260 virtual UnicodeSet
& addAll(const UnicodeSet
& c
);
1263 * Retains only the elements in this set that are contained in the
1264 * specified set. In other words, removes from this set all of
1265 * its elements that are not contained in the specified set. This
1266 * operation effectively modifies this set so that its value is
1267 * the <i>intersection</i> of the two sets.
1268 * A frozen set will not be modified.
1270 * @param c set that defines which elements this set will retain.
1273 virtual UnicodeSet
& retainAll(const UnicodeSet
& c
);
1276 * Removes from this set all of its elements that are contained in the
1277 * specified set. This operation effectively modifies this
1278 * set so that its value is the <i>asymmetric set difference</i> of
1280 * A frozen set will not be modified.
1282 * @param c set that defines which elements will be removed from
1286 virtual UnicodeSet
& removeAll(const UnicodeSet
& c
);
1289 * Complements in this set all elements contained in the specified
1290 * set. Any character in the other set will be removed if it is
1291 * in this set, or will be added if it is not in this set.
1292 * A frozen set will not be modified.
1294 * @param c set that defines which elements will be xor'ed from
1298 virtual UnicodeSet
& complementAll(const UnicodeSet
& c
);
1301 * Removes all of the elements from this set. This set will be
1302 * empty after this call returns.
1303 * A frozen set will not be modified.
1306 virtual UnicodeSet
& clear(void);
1309 * Close this set over the given attribute. For the attribute
1310 * USET_CASE, the result is to modify this set so that:
1312 * 1. For each character or string 'a' in this set, all strings or
1313 * characters 'b' such that foldCase(a) == foldCase(b) are added
1316 * 2. For each string 'e' in the resulting set, if e !=
1317 * foldCase(e), 'e' will be removed.
1319 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
1321 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
1322 * == b denotes that the contents are the same, not pointer
1325 * A frozen set will not be modified.
1327 * @param attribute bitmask for attributes to close over.
1328 * Currently only the USET_CASE bit is supported. Any undefined bits
1330 * @return a reference to this set.
1333 UnicodeSet
& closeOver(int32_t attribute
);
1336 * Remove all strings from this set.
1338 * @return a reference to this set.
1341 virtual UnicodeSet
&removeAllStrings();
1344 * Iteration method that returns the number of ranges contained in
1346 * @see #getRangeStart
1350 virtual int32_t getRangeCount(void) const;
1353 * Iteration method that returns the first character in the
1354 * specified range of this set.
1355 * @see #getRangeCount
1359 virtual UChar32
getRangeStart(int32_t index
) const;
1362 * Iteration method that returns the last character in the
1363 * specified range of this set.
1364 * @see #getRangeStart
1368 virtual UChar32
getRangeEnd(int32_t index
) const;
1371 * Serializes this set into an array of 16-bit integers. Serialization
1372 * (currently) only records the characters in the set; multicharacter
1373 * strings are ignored.
1375 * The array has following format (each line is one 16-bit
1378 * length = (n+2*m) | (m!=0?0x8000:0)
1379 * bmpLength = n; present if m!=0
1392 * The array starts with a header. After the header are n bmp
1393 * code points, then m supplementary code points. Either n or m
1394 * or both may be zero. n+2*m is always <= 0x7FFF.
1396 * If there are no supplementary characters (if m==0) then the
1397 * header is one 16-bit integer, 'length', with value n.
1399 * If there are supplementary characters (if m!=0) then the header
1400 * is two 16-bit integers. The first, 'length', has value
1401 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
1403 * After the header the code points are stored in ascending order.
1404 * Supplementary code points are stored as most significant 16
1405 * bits followed by least significant 16 bits.
1407 * @param dest pointer to buffer of destCapacity 16-bit integers.
1408 * May be NULL only if destCapacity is zero.
1409 * @param destCapacity size of dest, or zero. Must not be negative.
1410 * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR
1411 * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if
1412 * n+2*m+(m!=0?2:1) > destCapacity.
1413 * @return the total length of the serialized format, including
1414 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1415 * than U_BUFFER_OVERFLOW_ERROR.
1418 int32_t serialize(uint16_t *dest
, int32_t destCapacity
, UErrorCode
& ec
) const;
1421 * Reallocate this objects internal structures to take up the least
1422 * possible space, without changing this object's value.
1423 * A frozen set will not be modified.
1426 virtual UnicodeSet
& compact();
1429 * Return the class ID for this class. This is useful only for
1430 * comparing to a return value from getDynamicClassID(). For example:
1432 * . Base* polymorphic_pointer = createPolymorphicObject();
1433 * . if (polymorphic_pointer->getDynamicClassID() ==
1434 * . Derived::getStaticClassID()) ...
1436 * @return The class ID for all objects of this class.
1439 static UClassID U_EXPORT2
getStaticClassID(void);
1442 * Implement UnicodeFunctor API.
1444 * @return The class ID for this object. All objects of a given
1445 * class have the same class ID. Objects of other classes have
1446 * different class IDs.
1449 virtual UClassID
getDynamicClassID(void) const;
1453 // Private API for the USet API
1455 friend class USetAccess
;
1457 int32_t getStringCount() const;
1459 const UnicodeString
* getString(int32_t index
) const;
1461 //----------------------------------------------------------------
1462 // RuleBasedTransliterator support
1463 //----------------------------------------------------------------
1468 * Returns <tt>true</tt> if this set contains any character whose low byte
1469 * is the given value. This is used by <tt>RuleBasedTransliterator</tt> for
1472 virtual UBool
matchesIndexValue(uint8_t v
) const;
1475 friend class RBBIRuleScanner
;
1477 //----------------------------------------------------------------
1478 // Implementation: Clone as thawed (see ICU4J Freezable)
1479 //----------------------------------------------------------------
1481 UnicodeSet(const UnicodeSet
& o
, UBool
/* asThawed */);
1483 //----------------------------------------------------------------
1484 // Implementation: Pattern parsing
1485 //----------------------------------------------------------------
1487 void applyPatternIgnoreSpace(const UnicodeString
& pattern
,
1489 const SymbolTable
* symbols
,
1490 UErrorCode
& status
);
1492 void applyPattern(RuleCharacterIterator
& chars
,
1493 const SymbolTable
* symbols
,
1494 UnicodeString
& rebuiltPat
,
1496 UnicodeSet
& (UnicodeSet::*caseClosure
)(int32_t attribute
),
1499 //----------------------------------------------------------------
1500 // Implementation: Utility methods
1501 //----------------------------------------------------------------
1503 void ensureCapacity(int32_t newLen
, UErrorCode
& ec
);
1505 void ensureBufferCapacity(int32_t newLen
, UErrorCode
& ec
);
1507 void swapBuffers(void);
1509 UBool
allocateStrings(UErrorCode
&status
);
1511 UnicodeString
& _toPattern(UnicodeString
& result
,
1512 UBool escapeUnprintable
) const;
1514 UnicodeString
& _generatePattern(UnicodeString
& result
,
1515 UBool escapeUnprintable
) const;
1517 static void _appendToPat(UnicodeString
& buf
, const UnicodeString
& s
, UBool escapeUnprintable
);
1519 static void _appendToPat(UnicodeString
& buf
, UChar32 c
, UBool escapeUnprintable
);
1521 //----------------------------------------------------------------
1522 // Implementation: Fundamental operators
1523 //----------------------------------------------------------------
1525 void exclusiveOr(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1527 void add(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1529 void retain(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1532 * Return true if the given position, in the given pattern, appears
1533 * to be the start of a property set pattern [:foo:], \\p{foo}, or
1534 * \\P{foo}, or \\N{name}.
1536 static UBool
resemblesPropertyPattern(const UnicodeString
& pattern
,
1539 static UBool
resemblesPropertyPattern(RuleCharacterIterator
& chars
,
1543 * Parse the given property pattern at the given parse position
1544 * and set this UnicodeSet to the result.
1546 * The original design document is out of date, but still useful.
1547 * Ignore the property and value names:
1548 * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/unicodeset_properties.html
1550 * Recognized syntax:
1552 * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]"
1553 * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P"
1554 * \\N{name} - white space not allowed within "\\N"
1556 * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored.
1557 * Case is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading
1558 * and trailing space is deleted, and internal runs of whitespace
1559 * are collapsed to a single space.
1561 * We support binary properties, enumerated properties, and the
1562 * following non-enumerated properties:
1568 * @param pattern the pattern string
1569 * @param ppos on entry, the position at which to begin parsing.
1570 * This should be one of the locations marked '^':
1572 * [:blah:] \\p{blah} \\P{blah} \\N{name}
1575 * On return, the position after the last character parsed, that is,
1576 * the locations marked '%'. If the parse fails, ppos is returned
1579 * @return a reference to this.
1581 UnicodeSet
& applyPropertyPattern(const UnicodeString
& pattern
,
1582 ParsePosition
& ppos
,
1585 void applyPropertyPattern(RuleCharacterIterator
& chars
,
1586 UnicodeString
& rebuiltPat
,
1589 static const UnicodeSet
* getInclusions(int32_t src
, UErrorCode
&status
);
1592 * A filter that returns TRUE if the given code point should be
1593 * included in the UnicodeSet being constructed.
1595 typedef UBool (*Filter
)(UChar32 codePoint
, void* context
);
1598 * Given a filter, set this UnicodeSet to the code points
1599 * contained by that filter. The filter MUST be
1600 * property-conformant. That is, if it returns value v for one
1601 * code point, then it must return v for all affiliated code
1602 * points, as defined by the inclusions list. See
1604 * src is a UPropertySource value.
1606 void applyFilter(Filter filter
,
1609 UErrorCode
&status
);
1612 * Set the new pattern to cache.
1614 void setPattern(const UnicodeString
& newPat
);
1616 * Release existing cached pattern.
1618 void releasePattern();
1620 friend class UnicodeSetIterator
;
1625 inline UBool
UnicodeSet::operator!=(const UnicodeSet
& o
) const {
1626 return !operator==(o
);
1629 inline UBool
UnicodeSet::isFrozen() const {
1630 return (UBool
)(bmpSet
!=NULL
|| stringSpan
!=NULL
);
1633 inline UBool
UnicodeSet::containsSome(UChar32 start
, UChar32 end
) const {
1634 return !containsNone(start
, end
);
1637 inline UBool
UnicodeSet::containsSome(const UnicodeSet
& s
) const {
1638 return !containsNone(s
);
1641 inline UBool
UnicodeSet::containsSome(const UnicodeString
& s
) const {
1642 return !containsNone(s
);
1645 inline UBool
UnicodeSet::isBogus() const {
1646 return (UBool
)(fFlags
& kIsBogus
);
1649 inline UnicodeSet
*UnicodeSet::fromUSet(USet
*uset
) {
1650 return reinterpret_cast<UnicodeSet
*>(uset
);
1653 inline const UnicodeSet
*UnicodeSet::fromUSet(const USet
*uset
) {
1654 return reinterpret_cast<const UnicodeSet
*>(uset
);
1657 inline USet
*UnicodeSet::toUSet() {
1658 return reinterpret_cast<USet
*>(this);
1661 inline const USet
*UnicodeSet::toUSet() const {
1662 return reinterpret_cast<const USet
*>(this);
1665 inline int32_t UnicodeSet::span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const {
1666 int32_t sLength
=s
.length();
1669 } else if(start
>sLength
) {
1672 return start
+span(s
.getBuffer()+start
, sLength
-start
, spanCondition
);
1675 inline int32_t UnicodeSet::spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const {
1676 int32_t sLength
=s
.length();
1679 } else if(limit
>sLength
) {
1682 return spanBack(s
.getBuffer(), limit
, spanCondition
);