2 ***************************************************************************
3 * Copyright (C) 1999-2014, 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 valid, 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
);
373 * Constructs a set from the given pattern. See the class
374 * description for the syntax of the pattern language.
375 * @param pattern a string specifying what characters are in the set
376 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
377 * contains a syntax error.
380 UnicodeSet(const UnicodeString
& pattern
,
383 #ifndef U_HIDE_INTERNAL_API
385 * Constructs a set from the given pattern. See the class
386 * description for the syntax of the pattern language.
387 * @param pattern a string specifying what characters are in the set
388 * @param options bitmask for options to apply to the pattern.
389 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
390 * @param symbols a symbol table mapping variable names to values
391 * and stand-in characters to UnicodeSets; may be NULL
392 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
393 * contains a syntax error.
396 UnicodeSet(const UnicodeString
& pattern
,
398 const SymbolTable
* symbols
,
400 #endif /* U_HIDE_INTERNAL_API */
403 * Constructs a set from the given pattern. See the class description
404 * for the syntax of the pattern language.
405 * @param pattern a string specifying what characters are in the set
406 * @param pos on input, the position in pattern at which to start parsing.
407 * On output, the position after the last character parsed.
408 * @param options bitmask for options to apply to the pattern.
409 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
410 * @param symbols a symbol table mapping variable names to values
411 * and stand-in characters to UnicodeSets; may be NULL
412 * @param status input-output error code
415 UnicodeSet(const UnicodeString
& pattern
, ParsePosition
& pos
,
417 const SymbolTable
* symbols
,
421 * Constructs a set that is identical to the given UnicodeSet.
424 UnicodeSet(const UnicodeSet
& o
);
430 virtual ~UnicodeSet();
433 * Assigns this object to be a copy of another.
434 * A frozen set will not be modified.
437 UnicodeSet
& operator=(const UnicodeSet
& o
);
440 * Compares the specified object with this set for equality. Returns
441 * <tt>true</tt> if the two sets
442 * have the same size, and every member of the specified set is
443 * contained in this set (or equivalently, every member of this set is
444 * contained in the specified set).
446 * @param o set to be compared for equality with this set.
447 * @return <tt>true</tt> if the specified set is equal to this set.
450 virtual UBool
operator==(const UnicodeSet
& o
) const;
453 * Compares the specified object with this set for equality. Returns
454 * <tt>true</tt> if the specified set is not equal to this set.
457 UBool
operator!=(const UnicodeSet
& o
) const;
460 * Returns a copy of this object. All UnicodeFunctor objects have
461 * to support cloning in order to allow classes using
462 * UnicodeFunctors, such as Transliterator, to implement cloning.
463 * If this set is frozen, then the clone will be frozen as well.
464 * Use cloneAsThawed() for a mutable clone of a frozen set.
468 virtual UnicodeFunctor
* clone() const;
471 * Returns the hash code value for this set.
473 * @return the hash code value for this set.
474 * @see Object#hashCode()
477 virtual int32_t hashCode(void) const;
480 * Get a UnicodeSet pointer from a USet
482 * @param uset a USet (the ICU plain C type for UnicodeSet)
483 * @return the corresponding UnicodeSet pointer.
487 inline static UnicodeSet
*fromUSet(USet
*uset
);
490 * Get a UnicodeSet pointer from a const USet
492 * @param uset a const USet (the ICU plain C type for UnicodeSet)
493 * @return the corresponding UnicodeSet pointer.
497 inline static const UnicodeSet
*fromUSet(const USet
*uset
);
500 * Produce a USet * pointer for this UnicodeSet.
501 * USet is the plain C type for UnicodeSet
503 * @return a USet pointer for this UnicodeSet
506 inline USet
*toUSet();
510 * Produce a const USet * pointer for this UnicodeSet.
511 * USet is the plain C type for UnicodeSet
513 * @return a const USet pointer for this UnicodeSet
516 inline const USet
* toUSet() const;
519 //----------------------------------------------------------------
521 //----------------------------------------------------------------
524 * Determines whether the set has been frozen (made immutable) or not.
525 * See the ICU4J Freezable interface for details.
526 * @return TRUE/FALSE for whether the set has been frozen
531 inline UBool
isFrozen() const;
534 * Freeze the set (make it immutable).
535 * Once frozen, it cannot be unfrozen and is therefore thread-safe
536 * until it is deleted.
537 * See the ICU4J Freezable interface for details.
538 * Freezing the set may also make some operations faster, for example
539 * contains() and span().
540 * A frozen set will not be modified. (It remains frozen.)
546 UnicodeFunctor
*freeze();
549 * Clone the set and make the clone mutable.
550 * See the ICU4J Freezable interface for details.
551 * @return the mutable clone
556 UnicodeFunctor
*cloneAsThawed() const;
558 //----------------------------------------------------------------
560 //----------------------------------------------------------------
563 * Make this object represent the range <code>start - end</code>.
564 * If <code>end > start</code> then this object is set to an
566 * A frozen set will not be modified.
568 * @param start first character in the set, inclusive
569 * @param end last character in the set, inclusive
572 UnicodeSet
& set(UChar32 start
, UChar32 end
);
575 * Return true if the given position, in the given pattern, appears
576 * to be the start of a UnicodeSet pattern.
579 static UBool
resemblesPattern(const UnicodeString
& pattern
,
583 * Modifies this set to represent the set specified by the given
584 * pattern, ignoring Unicode Pattern_White_Space characters.
585 * See the class description for the syntax of the pattern language.
586 * A frozen set will not be modified.
587 * @param pattern a string specifying what characters are in the set
588 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
589 * contains a syntax error.
590 * <em> Empties the set passed before applying the pattern.</em>
591 * @return a reference to this
594 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
597 #ifndef U_HIDE_INTERNAL_API
599 * Modifies this set to represent the set specified by the given
600 * pattern, optionally ignoring Unicode Pattern_White_Space characters.
601 * See the class description for the syntax of the pattern language.
602 * A frozen set will not be modified.
603 * @param pattern a string specifying what characters are in the set
604 * @param options bitmask for options to apply to the pattern.
605 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
606 * @param symbols a symbol table mapping variable names to
607 * values and stand-ins to UnicodeSets; may be NULL
608 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
609 * contains a syntax error.
610 *<em> Empties the set passed before applying the pattern.</em>
611 * @return a reference to this
614 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
616 const SymbolTable
* symbols
,
618 #endif /* U_HIDE_INTERNAL_API */
621 * Parses the given pattern, starting at the given position. The
622 * character at pattern.charAt(pos.getIndex()) must be '[', or the
623 * parse fails. Parsing continues until the corresponding closing
624 * ']'. If a syntax error is encountered between the opening and
625 * closing brace, the parse fails. Upon return from a successful
626 * parse, the ParsePosition is updated to point to the character
627 * following the closing ']', and a StringBuffer containing a
628 * pairs list for the parsed pattern is returned. This method calls
629 * itself recursively to parse embedded subpatterns.
630 *<em> Empties the set passed before applying the pattern.</em>
631 * A frozen set will not be modified.
633 * @param pattern the string containing the pattern to be parsed.
634 * The portion of the string from pos.getIndex(), which must be a
635 * '[', to the corresponding closing ']', is parsed.
636 * @param pos upon entry, the position at which to being parsing.
637 * The character at pattern.charAt(pos.getIndex()) must be a '['.
638 * Upon return from a successful parse, pos.getIndex() is either
639 * the character after the closing ']' of the parsed pattern, or
640 * pattern.length() if the closing ']' is the last character of
641 * the pattern string.
642 * @param options bitmask for options to apply to the pattern.
643 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
644 * @param symbols a symbol table mapping variable names to
645 * values and stand-ins to UnicodeSets; may be NULL
646 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
647 * contains a syntax error.
648 * @return a reference to this
651 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
654 const SymbolTable
* symbols
,
658 * Returns a string representation of this set. If the result of
659 * calling this function is passed to a UnicodeSet constructor, it
660 * will produce another set that is equal to this one.
661 * A frozen set will not be modified.
662 * @param result the string to receive the rules. Previous
663 * contents will be deleted.
664 * @param escapeUnprintable if TRUE then convert unprintable
665 * character to their hex escape representations, \\uxxxx or
666 * \\Uxxxxxxxx. Unprintable characters are those other than
667 * U+000A, U+0020..U+007E.
670 virtual UnicodeString
& toPattern(UnicodeString
& result
,
671 UBool escapeUnprintable
= FALSE
) const;
674 * Modifies this set to contain those code points which have the given value
675 * for the given binary or enumerated property, as returned by
676 * u_getIntPropertyValue. Prior contents of this set are lost.
677 * A frozen set will not be modified.
679 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
680 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
681 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
683 * @param value a value in the range u_getIntPropertyMinValue(prop)..
684 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
685 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
686 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
687 * categories such as [:L:] to be represented.
689 * @param ec error code input/output parameter
691 * @return a reference to this set
695 UnicodeSet
& applyIntPropertyValue(UProperty prop
,
700 * Modifies this set to contain those code points which have the
701 * given value for the given property. Prior contents of this
703 * A frozen set will not be modified.
705 * @param prop a property alias, either short or long. The name is matched
706 * loosely. See PropertyAliases.txt for names and a description of loose
707 * matching. If the value string is empty, then this string is interpreted
708 * as either a General_Category value alias, a Script value alias, a binary
709 * property alias, or a special ID. Special IDs are matched loosely and
710 * correspond to the following sets:
712 * "ANY" = [\\u0000-\\U0010FFFF],
713 * "ASCII" = [\\u0000-\\u007F],
714 * "Assigned" = [:^Cn:].
716 * @param value a value alias, either short or long. The name is matched
717 * loosely. See PropertyValueAliases.txt for names and a description of
718 * loose matching. In addition to aliases listed, numeric values and
719 * canonical combining classes may be expressed numerically, e.g., ("nv",
720 * "0.5") or ("ccc", "220"). The value string may also be empty.
722 * @param ec error code input/output parameter
724 * @return a reference to this set
728 UnicodeSet
& applyPropertyAlias(const UnicodeString
& prop
,
729 const UnicodeString
& value
,
733 * Returns the number of elements in this set (its cardinality).
734 * Note than the elements of a set may include both individual
735 * codepoints and strings.
737 * @return the number of elements in this set (its cardinality).
740 virtual int32_t size(void) const;
743 * Returns <tt>true</tt> if this set contains no elements.
745 * @return <tt>true</tt> if this set contains no elements.
748 virtual UBool
isEmpty(void) const;
751 * Returns true if this set contains the given character.
752 * This function works faster with a frozen set.
753 * @param c character to be checked for containment
754 * @return true if the test condition is met
757 virtual UBool
contains(UChar32 c
) const;
760 * Returns true if this set contains every character
761 * of the given range.
762 * @param start first character, inclusive, of the range
763 * @param end last character, inclusive, of the range
764 * @return true if the test condition is met
767 virtual UBool
contains(UChar32 start
, UChar32 end
) const;
770 * Returns <tt>true</tt> if this set contains the given
771 * multicharacter string.
772 * @param s string to be checked for containment
773 * @return <tt>true</tt> if this set contains the specified string
776 UBool
contains(const UnicodeString
& s
) const;
779 * Returns true if this set contains all the characters and strings
781 * @param c set to be checked for containment
782 * @return true if the test condition is met
785 virtual UBool
containsAll(const UnicodeSet
& c
) const;
788 * Returns true if this set contains all the characters
789 * of the given string.
790 * @param s string containing characters to be checked for containment
791 * @return true if the test condition is met
794 UBool
containsAll(const UnicodeString
& s
) const;
797 * Returns true if this set contains none of the characters
798 * of the given range.
799 * @param start first character, inclusive, of the range
800 * @param end last character, inclusive, of the range
801 * @return true if the test condition is met
804 UBool
containsNone(UChar32 start
, UChar32 end
) const;
807 * Returns true if this set contains none of the characters and strings
809 * @param c set to be checked for containment
810 * @return true if the test condition is met
813 UBool
containsNone(const UnicodeSet
& c
) const;
816 * Returns true if this set contains none of the characters
817 * of the given string.
818 * @param s string containing characters to be checked for containment
819 * @return true if the test condition is met
822 UBool
containsNone(const UnicodeString
& s
) const;
825 * Returns true if this set contains one or more of the characters
826 * in the given range.
827 * @param start first character, inclusive, of the range
828 * @param end last character, inclusive, of the range
829 * @return true if the condition is met
832 inline UBool
containsSome(UChar32 start
, UChar32 end
) const;
835 * Returns true if this set contains one or more of the characters
836 * and strings of the given set.
837 * @param s The set to be checked for containment
838 * @return true if the condition is met
841 inline UBool
containsSome(const UnicodeSet
& s
) const;
844 * Returns true if this set contains one or more of the characters
845 * of the given string.
846 * @param s string containing characters to be checked for containment
847 * @return true if the condition is met
850 inline UBool
containsSome(const UnicodeString
& s
) const;
853 * Returns the length of the initial substring of the input string which
854 * consists only of characters and strings that are contained in this set
855 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
856 * or only of characters and strings that are not contained
857 * in this set (USET_SPAN_NOT_CONTAINED).
858 * See USetSpanCondition for details.
859 * Similar to the strspn() C library function.
860 * Unpaired surrogates are treated according to contains() of their surrogate code points.
861 * This function works faster with a frozen set and with a non-negative string length argument.
862 * @param s start of the string
863 * @param length of the string; can be -1 for NUL-terminated
864 * @param spanCondition specifies the containment condition
865 * @return the length of the initial substring according to the spanCondition;
866 * 0 if the start of the string does not fit the spanCondition
868 * @see USetSpanCondition
870 int32_t span(const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
) const;
873 * Returns the end of the substring of the input string according to the USetSpanCondition.
874 * Same as <code>start+span(s.getBuffer()+start, s.length()-start, spanCondition)</code>
875 * after pinning start to 0<=start<=s.length().
876 * @param s the string
877 * @param start the start index in the string for the span operation
878 * @param spanCondition specifies the containment condition
879 * @return the exclusive end of the substring according to the spanCondition;
880 * the substring s.tempSubStringBetween(start, end) fulfills the spanCondition
882 * @see USetSpanCondition
884 inline int32_t span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const;
887 * Returns the start of the trailing substring of the input string which
888 * consists only of characters and strings that are contained in this set
889 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
890 * or only of characters and strings that are not contained
891 * in this set (USET_SPAN_NOT_CONTAINED).
892 * See USetSpanCondition for details.
893 * Unpaired surrogates are treated according to contains() of their surrogate code points.
894 * This function works faster with a frozen set and with a non-negative string length argument.
895 * @param s start of the string
896 * @param length of the string; can be -1 for NUL-terminated
897 * @param spanCondition specifies the containment condition
898 * @return the start of the trailing substring according to the spanCondition;
899 * the string length if the end of the string does not fit the spanCondition
901 * @see USetSpanCondition
903 int32_t spanBack(const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
) const;
906 * Returns the start of the substring of the input string according to the USetSpanCondition.
907 * Same as <code>spanBack(s.getBuffer(), limit, spanCondition)</code>
908 * after pinning limit to 0<=end<=s.length().
909 * @param s the string
910 * @param limit the exclusive-end index in the string for the span operation
911 * (use s.length() or INT32_MAX for spanning back from the end of the string)
912 * @param spanCondition specifies the containment condition
913 * @return the start of the substring according to the spanCondition;
914 * the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition
916 * @see USetSpanCondition
918 inline int32_t spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const;
921 * Returns the length of the initial substring of the input string which
922 * consists only of characters and strings that are contained in this set
923 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
924 * or only of characters and strings that are not contained
925 * in this set (USET_SPAN_NOT_CONTAINED).
926 * See USetSpanCondition for details.
927 * Similar to the strspn() C library function.
928 * Malformed byte sequences are treated according to contains(0xfffd).
929 * This function works faster with a frozen set and with a non-negative string length argument.
930 * @param s start of the string (UTF-8)
931 * @param length of the string; can be -1 for NUL-terminated
932 * @param spanCondition specifies the containment condition
933 * @return the length of the initial substring according to the spanCondition;
934 * 0 if the start of the string does not fit the spanCondition
936 * @see USetSpanCondition
938 int32_t spanUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
941 * Returns the start of the trailing substring of the input string which
942 * consists only of characters and strings that are contained in this set
943 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
944 * or only of characters and strings that are not contained
945 * in this set (USET_SPAN_NOT_CONTAINED).
946 * See USetSpanCondition for details.
947 * Malformed byte sequences are treated according to contains(0xfffd).
948 * This function works faster with a frozen set and with a non-negative string length argument.
949 * @param s start of the string (UTF-8)
950 * @param length of the string; can be -1 for NUL-terminated
951 * @param spanCondition specifies the containment condition
952 * @return the start of the trailing substring according to the spanCondition;
953 * the string length if the end of the string does not fit the spanCondition
955 * @see USetSpanCondition
957 int32_t spanBackUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
960 * Implement UnicodeMatcher::matches()
963 virtual UMatchDegree
matches(const Replaceable
& text
,
970 * Returns the longest match for s in text at the given position.
971 * If limit > start then match forward from start+1 to limit
972 * matching all characters except s.charAt(0). If limit < start,
973 * go backward starting from start-1 matching all characters
974 * except s.charAt(s.length()-1). This method assumes that the
975 * first character, text.charAt(start), matches s, so it does not
977 * @param text the text to match
978 * @param start the first character to match. In the forward
979 * direction, text.charAt(start) is matched against s.charAt(0).
980 * In the reverse direction, it is matched against
981 * s.charAt(s.length()-1).
982 * @param limit the limit offset for matching, either last+1 in
983 * the forward direction, or last-1 in the reverse direction,
984 * where last is the index of the last character to match.
986 * @return If part of s matches up to the limit, return |limit -
987 * start|. If all of s matches before reaching the limit, return
988 * s.length(). If there is a mismatch between s and text, return
991 static int32_t matchRest(const Replaceable
& text
,
992 int32_t start
, int32_t limit
,
993 const UnicodeString
& s
);
996 * Returns the smallest value i such that c < list[i]. Caller
997 * must ensure that c is a legal value or this method will enter
998 * an infinite loop. This method performs a binary search.
999 * @param c a character in the range MIN_VALUE..MAX_VALUE
1001 * @return the smallest integer i in the range 0..len-1,
1002 * inclusive, such that c < list[i]
1004 int32_t findCodePoint(UChar32 c
) const;
1009 * Implementation of UnicodeMatcher API. Union the set of all
1010 * characters that may be matched by this object into the given
1012 * @param toUnionTo the set into which to union the source characters
1015 virtual void addMatchSetTo(UnicodeSet
& toUnionTo
) const;
1018 * Returns the index of the given character within this set, where
1019 * the set is ordered by ascending code point. If the character
1020 * is not in this set, return -1. The inverse of this method is
1021 * <code>charAt()</code>.
1022 * @return an index from 0..size()-1, or -1
1025 int32_t indexOf(UChar32 c
) const;
1028 * Returns the character at the given index within this set, where
1029 * the set is ordered by ascending code point. If the index is
1030 * out of range, return (UChar32)-1. The inverse of this method is
1031 * <code>indexOf()</code>.
1032 * @param index an index from 0..size()-1
1033 * @return the character at the given index, or (UChar32)-1.
1036 UChar32
charAt(int32_t index
) const;
1039 * Adds the specified range to this set if it is not already
1040 * present. If this set already contains the specified range,
1041 * the call leaves this set unchanged. If <code>end > start</code>
1042 * then an empty range is added, leaving the set unchanged.
1043 * This is equivalent to a boolean logic OR, or a set UNION.
1044 * A frozen set will not be modified.
1046 * @param start first character, inclusive, of range to be added
1048 * @param end last character, inclusive, of range to be added
1052 virtual UnicodeSet
& add(UChar32 start
, UChar32 end
);
1055 * Adds the specified character to this set if it is not already
1056 * present. If this set already contains the specified character,
1057 * the call leaves this set unchanged.
1058 * A frozen set will not be modified.
1061 UnicodeSet
& add(UChar32 c
);
1064 * Adds the specified multicharacter to this set if it is not already
1065 * present. If this set already contains the multicharacter,
1066 * the call leaves this set unchanged.
1067 * Thus "ch" => {"ch"}
1068 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1069 * A frozen set will not be modified.
1070 * @param s the source string
1071 * @return this object, for chaining
1074 UnicodeSet
& add(const UnicodeString
& s
);
1078 * @return a code point IF the string consists of a single one.
1079 * otherwise returns -1.
1080 * @param s string to test
1082 static int32_t getSingleCP(const UnicodeString
& s
);
1084 void _add(const UnicodeString
& s
);
1088 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
1089 * If this set already any particular character, it has no effect on that character.
1090 * A frozen set will not be modified.
1091 * @param s the source string
1092 * @return this object, for chaining
1095 UnicodeSet
& addAll(const UnicodeString
& s
);
1098 * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
1099 * If this set already any particular character, it has no effect on that character.
1100 * A frozen set will not be modified.
1101 * @param s the source string
1102 * @return this object, for chaining
1105 UnicodeSet
& retainAll(const UnicodeString
& s
);
1108 * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
1109 * If this set already any particular character, it has no effect on that character.
1110 * A frozen set will not be modified.
1111 * @param s the source string
1112 * @return this object, for chaining
1115 UnicodeSet
& complementAll(const UnicodeString
& s
);
1118 * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
1119 * If this set already any particular character, it has no effect on that character.
1120 * A frozen set will not be modified.
1121 * @param s the source string
1122 * @return this object, for chaining
1125 UnicodeSet
& removeAll(const UnicodeString
& s
);
1128 * Makes a set from a multicharacter string. Thus "ch" => {"ch"}
1129 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1130 * @param s the source string
1131 * @return a newly created set containing the given string.
1132 * The caller owns the return object and is responsible for deleting it.
1135 static UnicodeSet
* U_EXPORT2
createFrom(const UnicodeString
& s
);
1139 * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
1140 * @param s the source string
1141 * @return a newly created set containing the given characters
1142 * The caller owns the return object and is responsible for deleting it.
1145 static UnicodeSet
* U_EXPORT2
createFromAll(const UnicodeString
& s
);
1148 * Retain only the elements in this set that are contained in the
1149 * specified range. If <code>end > start</code> then an empty range is
1150 * retained, leaving the set empty. This is equivalent to
1151 * a boolean logic AND, or a set INTERSECTION.
1152 * A frozen set will not be modified.
1154 * @param start first character, inclusive, of range to be retained
1156 * @param end last character, inclusive, of range to be retained
1160 virtual UnicodeSet
& retain(UChar32 start
, UChar32 end
);
1164 * Retain the specified character from this set if it is present.
1165 * A frozen set will not be modified.
1168 UnicodeSet
& retain(UChar32 c
);
1171 * Removes the specified range from this set if it is present.
1172 * The set will not contain the specified range once the call
1173 * returns. If <code>end > start</code> then an empty range is
1174 * removed, leaving the set unchanged.
1175 * A frozen set will not be modified.
1177 * @param start first character, inclusive, of range to be removed
1179 * @param end last character, inclusive, of range to be removed
1183 virtual UnicodeSet
& remove(UChar32 start
, UChar32 end
);
1186 * Removes the specified character from this set if it is present.
1187 * The set will not contain the specified range once the call
1189 * A frozen set will not be modified.
1192 UnicodeSet
& remove(UChar32 c
);
1195 * Removes the specified string from this set if it is present.
1196 * The set will not contain the specified character once the call
1198 * A frozen set will not be modified.
1199 * @param s the source string
1200 * @return this object, for chaining
1203 UnicodeSet
& remove(const UnicodeString
& s
);
1206 * Inverts this set. This operation modifies this set so that
1207 * its value is its complement. This is equivalent to
1208 * <code>complement(MIN_VALUE, MAX_VALUE)</code>.
1209 * A frozen set will not be modified.
1212 virtual UnicodeSet
& complement(void);
1215 * Complements the specified range in this set. Any character in
1216 * the range will be removed if it is in this set, or will be
1217 * added if it is not in this set. If <code>end > start</code>
1218 * then an empty range is complemented, leaving the set unchanged.
1219 * This is equivalent to a boolean logic XOR.
1220 * A frozen set will not be modified.
1222 * @param start first character, inclusive, of range to be removed
1224 * @param end last character, inclusive, of range to be removed
1228 virtual UnicodeSet
& complement(UChar32 start
, UChar32 end
);
1231 * Complements the specified character in this set. The character
1232 * will be removed if it is in this set, or will be added if it is
1234 * A frozen set will not be modified.
1237 UnicodeSet
& complement(UChar32 c
);
1240 * Complement the specified string in this set.
1241 * The set will not contain the specified string once the call
1243 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1244 * A frozen set will not be modified.
1245 * @param s the string to complement
1246 * @return this object, for chaining
1249 UnicodeSet
& complement(const UnicodeString
& s
);
1252 * Adds all of the elements in the specified set to this set if
1253 * they're not already present. This operation effectively
1254 * modifies this set so that its value is the <i>union</i> of the two
1255 * sets. The behavior of this operation is unspecified if the specified
1256 * collection is modified while the operation is in progress.
1257 * A frozen set will not be modified.
1259 * @param c set whose elements are to be added to this set.
1260 * @see #add(UChar32, UChar32)
1263 virtual UnicodeSet
& addAll(const UnicodeSet
& c
);
1266 * Retains only the elements in this set that are contained in the
1267 * specified set. In other words, removes from this set all of
1268 * its elements that are not contained in the specified set. This
1269 * operation effectively modifies this set so that its value is
1270 * the <i>intersection</i> of the two sets.
1271 * A frozen set will not be modified.
1273 * @param c set that defines which elements this set will retain.
1276 virtual UnicodeSet
& retainAll(const UnicodeSet
& c
);
1279 * Removes from this set all of its elements that are contained in the
1280 * specified set. This operation effectively modifies this
1281 * set so that its value is the <i>asymmetric set difference</i> of
1283 * A frozen set will not be modified.
1285 * @param c set that defines which elements will be removed from
1289 virtual UnicodeSet
& removeAll(const UnicodeSet
& c
);
1292 * Complements in this set all elements contained in the specified
1293 * set. Any character in the other set will be removed if it is
1294 * in this set, or will be added if it is not in this set.
1295 * A frozen set will not be modified.
1297 * @param c set that defines which elements will be xor'ed from
1301 virtual UnicodeSet
& complementAll(const UnicodeSet
& c
);
1304 * Removes all of the elements from this set. This set will be
1305 * empty after this call returns.
1306 * A frozen set will not be modified.
1309 virtual UnicodeSet
& clear(void);
1312 * Close this set over the given attribute. For the attribute
1313 * USET_CASE, the result is to modify this set so that:
1315 * 1. For each character or string 'a' in this set, all strings or
1316 * characters 'b' such that foldCase(a) == foldCase(b) are added
1319 * 2. For each string 'e' in the resulting set, if e !=
1320 * foldCase(e), 'e' will be removed.
1322 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
1324 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
1325 * == b denotes that the contents are the same, not pointer
1328 * A frozen set will not be modified.
1330 * @param attribute bitmask for attributes to close over.
1331 * Currently only the USET_CASE bit is supported. Any undefined bits
1333 * @return a reference to this set.
1336 UnicodeSet
& closeOver(int32_t attribute
);
1339 * Remove all strings from this set.
1341 * @return a reference to this set.
1344 virtual UnicodeSet
&removeAllStrings();
1347 * Iteration method that returns the number of ranges contained in
1349 * @see #getRangeStart
1353 virtual int32_t getRangeCount(void) const;
1356 * Iteration method that returns the first character in the
1357 * specified range of this set.
1358 * @see #getRangeCount
1362 virtual UChar32
getRangeStart(int32_t index
) const;
1365 * Iteration method that returns the last character in the
1366 * specified range of this set.
1367 * @see #getRangeStart
1371 virtual UChar32
getRangeEnd(int32_t index
) const;
1374 * Serializes this set into an array of 16-bit integers. Serialization
1375 * (currently) only records the characters in the set; multicharacter
1376 * strings are ignored.
1378 * The array has following format (each line is one 16-bit
1381 * length = (n+2*m) | (m!=0?0x8000:0)
1382 * bmpLength = n; present if m!=0
1395 * The array starts with a header. After the header are n bmp
1396 * code points, then m supplementary code points. Either n or m
1397 * or both may be zero. n+2*m is always <= 0x7FFF.
1399 * If there are no supplementary characters (if m==0) then the
1400 * header is one 16-bit integer, 'length', with value n.
1402 * If there are supplementary characters (if m!=0) then the header
1403 * is two 16-bit integers. The first, 'length', has value
1404 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
1406 * After the header the code points are stored in ascending order.
1407 * Supplementary code points are stored as most significant 16
1408 * bits followed by least significant 16 bits.
1410 * @param dest pointer to buffer of destCapacity 16-bit integers.
1411 * May be NULL only if destCapacity is zero.
1412 * @param destCapacity size of dest, or zero. Must not be negative.
1413 * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR
1414 * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if
1415 * n+2*m+(m!=0?2:1) > destCapacity.
1416 * @return the total length of the serialized format, including
1417 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1418 * than U_BUFFER_OVERFLOW_ERROR.
1421 int32_t serialize(uint16_t *dest
, int32_t destCapacity
, UErrorCode
& ec
) const;
1424 * Reallocate this objects internal structures to take up the least
1425 * possible space, without changing this object's value.
1426 * A frozen set will not be modified.
1429 virtual UnicodeSet
& compact();
1432 * Return the class ID for this class. This is useful only for
1433 * comparing to a return value from getDynamicClassID(). For example:
1435 * . Base* polymorphic_pointer = createPolymorphicObject();
1436 * . if (polymorphic_pointer->getDynamicClassID() ==
1437 * . Derived::getStaticClassID()) ...
1439 * @return The class ID for all objects of this class.
1442 static UClassID U_EXPORT2
getStaticClassID(void);
1445 * Implement UnicodeFunctor API.
1447 * @return The class ID for this object. All objects of a given
1448 * class have the same class ID. Objects of other classes have
1449 * different class IDs.
1452 virtual UClassID
getDynamicClassID(void) const;
1456 // Private API for the USet API
1458 friend class USetAccess
;
1460 int32_t getStringCount() const;
1462 const UnicodeString
* getString(int32_t index
) const;
1464 //----------------------------------------------------------------
1465 // RuleBasedTransliterator support
1466 //----------------------------------------------------------------
1471 * Returns <tt>true</tt> if this set contains any character whose low byte
1472 * is the given value. This is used by <tt>RuleBasedTransliterator</tt> for
1475 virtual UBool
matchesIndexValue(uint8_t v
) const;
1478 friend class RBBIRuleScanner
;
1480 //----------------------------------------------------------------
1481 // Implementation: Clone as thawed (see ICU4J Freezable)
1482 //----------------------------------------------------------------
1484 UnicodeSet(const UnicodeSet
& o
, UBool
/* asThawed */);
1486 //----------------------------------------------------------------
1487 // Implementation: Pattern parsing
1488 //----------------------------------------------------------------
1490 void applyPatternIgnoreSpace(const UnicodeString
& pattern
,
1492 const SymbolTable
* symbols
,
1493 UErrorCode
& status
);
1495 void applyPattern(RuleCharacterIterator
& chars
,
1496 const SymbolTable
* symbols
,
1497 UnicodeString
& rebuiltPat
,
1499 UnicodeSet
& (UnicodeSet::*caseClosure
)(int32_t attribute
),
1502 //----------------------------------------------------------------
1503 // Implementation: Utility methods
1504 //----------------------------------------------------------------
1506 void ensureCapacity(int32_t newLen
, UErrorCode
& ec
);
1508 void ensureBufferCapacity(int32_t newLen
, UErrorCode
& ec
);
1510 void swapBuffers(void);
1512 UBool
allocateStrings(UErrorCode
&status
);
1514 UnicodeString
& _toPattern(UnicodeString
& result
,
1515 UBool escapeUnprintable
) const;
1517 UnicodeString
& _generatePattern(UnicodeString
& result
,
1518 UBool escapeUnprintable
) const;
1520 static void _appendToPat(UnicodeString
& buf
, const UnicodeString
& s
, UBool escapeUnprintable
);
1522 static void _appendToPat(UnicodeString
& buf
, UChar32 c
, UBool escapeUnprintable
);
1524 //----------------------------------------------------------------
1525 // Implementation: Fundamental operators
1526 //----------------------------------------------------------------
1528 void exclusiveOr(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1530 void add(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1532 void retain(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1535 * Return true if the given position, in the given pattern, appears
1536 * to be the start of a property set pattern [:foo:], \\p{foo}, or
1537 * \\P{foo}, or \\N{name}.
1539 static UBool
resemblesPropertyPattern(const UnicodeString
& pattern
,
1542 static UBool
resemblesPropertyPattern(RuleCharacterIterator
& chars
,
1546 * Parse the given property pattern at the given parse position
1547 * and set this UnicodeSet to the result.
1549 * The original design document is out of date, but still useful.
1550 * Ignore the property and value names:
1551 * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/unicodeset_properties.html
1553 * Recognized syntax:
1555 * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]"
1556 * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P"
1557 * \\N{name} - white space not allowed within "\\N"
1559 * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored.
1560 * Case is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading
1561 * and trailing space is deleted, and internal runs of whitespace
1562 * are collapsed to a single space.
1564 * We support binary properties, enumerated properties, and the
1565 * following non-enumerated properties:
1571 * @param pattern the pattern string
1572 * @param ppos on entry, the position at which to begin parsing.
1573 * This should be one of the locations marked '^':
1575 * [:blah:] \\p{blah} \\P{blah} \\N{name}
1578 * On return, the position after the last character parsed, that is,
1579 * the locations marked '%'. If the parse fails, ppos is returned
1582 * @return a reference to this.
1584 UnicodeSet
& applyPropertyPattern(const UnicodeString
& pattern
,
1585 ParsePosition
& ppos
,
1588 void applyPropertyPattern(RuleCharacterIterator
& chars
,
1589 UnicodeString
& rebuiltPat
,
1592 friend void U_CALLCONV
UnicodeSet_initInclusion(int32_t src
, UErrorCode
&status
);
1593 static const UnicodeSet
* getInclusions(int32_t src
, UErrorCode
&status
);
1596 * A filter that returns TRUE if the given code point should be
1597 * included in the UnicodeSet being constructed.
1599 typedef UBool (*Filter
)(UChar32 codePoint
, void* context
);
1602 * Given a filter, set this UnicodeSet to the code points
1603 * contained by that filter. The filter MUST be
1604 * property-conformant. That is, if it returns value v for one
1605 * code point, then it must return v for all affiliated code
1606 * points, as defined by the inclusions list. See
1608 * src is a UPropertySource value.
1610 void applyFilter(Filter filter
,
1613 UErrorCode
&status
);
1616 * Set the new pattern to cache.
1618 void setPattern(const UnicodeString
& newPat
);
1620 * Release existing cached pattern.
1622 void releasePattern();
1624 friend class UnicodeSetIterator
;
1629 inline UBool
UnicodeSet::operator!=(const UnicodeSet
& o
) const {
1630 return !operator==(o
);
1633 inline UBool
UnicodeSet::isFrozen() const {
1634 return (UBool
)(bmpSet
!=NULL
|| stringSpan
!=NULL
);
1637 inline UBool
UnicodeSet::containsSome(UChar32 start
, UChar32 end
) const {
1638 return !containsNone(start
, end
);
1641 inline UBool
UnicodeSet::containsSome(const UnicodeSet
& s
) const {
1642 return !containsNone(s
);
1645 inline UBool
UnicodeSet::containsSome(const UnicodeString
& s
) const {
1646 return !containsNone(s
);
1649 inline UBool
UnicodeSet::isBogus() const {
1650 return (UBool
)(fFlags
& kIsBogus
);
1653 inline UnicodeSet
*UnicodeSet::fromUSet(USet
*uset
) {
1654 return reinterpret_cast<UnicodeSet
*>(uset
);
1657 inline const UnicodeSet
*UnicodeSet::fromUSet(const USet
*uset
) {
1658 return reinterpret_cast<const UnicodeSet
*>(uset
);
1661 inline USet
*UnicodeSet::toUSet() {
1662 return reinterpret_cast<USet
*>(this);
1665 inline const USet
*UnicodeSet::toUSet() const {
1666 return reinterpret_cast<const USet
*>(this);
1669 inline int32_t UnicodeSet::span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const {
1670 int32_t sLength
=s
.length();
1673 } else if(start
>sLength
) {
1676 return start
+span(s
.getBuffer()+start
, sLength
-start
, spanCondition
);
1679 inline int32_t UnicodeSet::spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const {
1680 int32_t sLength
=s
.length();
1683 } else if(limit
>sLength
) {
1686 return spanBack(s
.getBuffer(), limit
, spanCondition
);