1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ***************************************************************************
5 * Copyright (C) 1999-2016, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 ***************************************************************************
8 * Date Name Description
9 * 10/20/99 alan Creation.
10 ***************************************************************************
16 #include "unicode/unifilt.h"
17 #include "unicode/unistr.h"
18 #include "unicode/uset.h"
22 * \brief C++ API: Unicode Set
25 #if U_SHOW_CPLUSPLUS_API
28 // Forward Declarations.
29 void U_CALLCONV
UnicodeSet_initInclusion(int32_t src
, UErrorCode
&status
); /**< @internal */
33 class RBBIRuleScanner
;
35 class UnicodeSetStringSpan
;
37 class RuleCharacterIterator
;
40 * A mutable set of Unicode characters and multicharacter strings. Objects of this class
41 * represent <em>character classes</em> used in regular expressions.
42 * A character specifies a subset of Unicode code points. Legal
43 * code points are U+0000 to U+10FFFF, inclusive.
45 * <p>The UnicodeSet class is not designed to be subclassed.
47 * <p><code>UnicodeSet</code> supports two APIs. The first is the
48 * <em>operand</em> API that allows the caller to modify the value of
49 * a <code>UnicodeSet</code> object. It conforms to Java 2's
50 * <code>java.util.Set</code> interface, although
51 * <code>UnicodeSet</code> does not actually implement that
52 * interface. All methods of <code>Set</code> are supported, with the
53 * modification that they take a character range or single character
54 * instead of an <code>Object</code>, and they take a
55 * <code>UnicodeSet</code> instead of a <code>Collection</code>. The
56 * operand API may be thought of in terms of boolean logic: a boolean
57 * OR is implemented by <code>add</code>, a boolean AND is implemented
58 * by <code>retain</code>, a boolean XOR is implemented by
59 * <code>complement</code> taking an argument, and a boolean NOT is
60 * implemented by <code>complement</code> with no argument. In terms
61 * of traditional set theory function names, <code>add</code> is a
62 * union, <code>retain</code> is an intersection, <code>remove</code>
63 * is an asymmetric difference, and <code>complement</code> with no
64 * argument is a set complement with respect to the superset range
65 * <code>MIN_VALUE-MAX_VALUE</code>
67 * <p>The second API is the
68 * <code>applyPattern()</code>/<code>toPattern()</code> API from the
69 * <code>java.text.Format</code>-derived classes. Unlike the
70 * methods that add characters, add categories, and control the logic
71 * of the set, the method <code>applyPattern()</code> sets all
72 * attributes of a <code>UnicodeSet</code> at once, based on a
75 * <p><b>Pattern syntax</b></p>
77 * Patterns are accepted by the constructors and the
78 * <code>applyPattern()</code> methods and returned by the
79 * <code>toPattern()</code> method. These patterns follow a syntax
80 * similar to that employed by version 8 regular expression character
81 * classes. Here are some simple examples:
83 * \htmlonly<blockquote>\endhtmlonly
86 * <td nowrap valign="top" align="left"><code>[]</code></td>
87 * <td valign="top">No characters</td>
88 * </tr><tr align="top">
89 * <td nowrap valign="top" align="left"><code>[a]</code></td>
90 * <td valign="top">The character 'a'</td>
91 * </tr><tr align="top">
92 * <td nowrap valign="top" align="left"><code>[ae]</code></td>
93 * <td valign="top">The characters 'a' and 'e'</td>
96 * <td nowrap valign="top" align="left"><code>[a-e]</code></td>
97 * <td valign="top">The characters 'a' through 'e' inclusive, in Unicode code
101 * <td nowrap valign="top" align="left"><code>[\\u4E01]</code></td>
102 * <td valign="top">The character U+4E01</td>
105 * <td nowrap valign="top" align="left"><code>[a{ab}{ac}]</code></td>
106 * <td valign="top">The character 'a' and the multicharacter strings "ab" and
107 * "ac"</td>
110 * <td nowrap valign="top" align="left"><code>[\\p{Lu}]</code></td>
111 * <td valign="top">All characters in the general category Uppercase Letter</td>
114 * \htmlonly</blockquote>\endhtmlonly
116 * Any character may be preceded by a backslash in order to remove any special
117 * meaning. White space characters, as defined by UCharacter.isWhitespace(), are
118 * ignored, unless they are escaped.
120 * <p>Property patterns specify a set of characters having a certain
121 * property as defined by the Unicode standard. Both the POSIX-like
122 * "[:Lu:]" and the Perl-like syntax "\\p{Lu}" are recognized. For a
123 * complete list of supported property patterns, see the User's Guide
125 * <a href="http://icu-project.org/userguide/unicodeSet.html">
126 * http://icu-project.org/userguide/unicodeSet.html</a>.
127 * Actual determination of property data is defined by the underlying
128 * Unicode database as implemented by UCharacter.
130 * <p>Patterns specify individual characters, ranges of characters, and
131 * Unicode property sets. When elements are concatenated, they
132 * specify their union. To complement a set, place a '^' immediately
133 * after the opening '['. Property patterns are inverted by modifying
134 * their delimiters; "[:^foo]" and "\\P{foo}". In any other location,
135 * '^' has no special meaning.
137 * <p>Ranges are indicated by placing two a '-' between two
138 * characters, as in "a-z". This specifies the range of all
139 * characters from the left to the right, in Unicode order. If the
140 * left character is greater than or equal to the
141 * right character it is a syntax error. If a '-' occurs as the first
142 * character after the opening '[' or '[^', or if it occurs as the
143 * last character before the closing ']', then it is taken as a
144 * literal. Thus "[a\-b]", "[-ab]", and "[ab-]" all indicate the same
145 * set of three characters, 'a', 'b', and '-'.
147 * <p>Sets may be intersected using the '&' operator or the asymmetric
148 * set difference may be taken using the '-' operator, for example,
149 * "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters
150 * with values less than 4096. Operators ('&' and '|') have equal
151 * precedence and bind left-to-right. Thus
152 * "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to
153 * "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]". This only really matters for
154 * difference; intersection is commutative.
157 * <tr valign=top><td nowrap><code>[a]</code><td>The set containing 'a'
158 * <tr valign=top><td nowrap><code>[a-z]</code><td>The set containing 'a'
159 * through 'z' and all letters in between, in Unicode order
160 * <tr valign=top><td nowrap><code>[^a-z]</code><td>The set containing
161 * all characters but 'a' through 'z',
162 * that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF
163 * <tr valign=top><td nowrap><code>[[<em>pat1</em>][<em>pat2</em>]]</code>
164 * <td>The union of sets specified by <em>pat1</em> and <em>pat2</em>
165 * <tr valign=top><td nowrap><code>[[<em>pat1</em>]&[<em>pat2</em>]]</code>
166 * <td>The intersection of sets specified by <em>pat1</em> and <em>pat2</em>
167 * <tr valign=top><td nowrap><code>[[<em>pat1</em>]-[<em>pat2</em>]]</code>
168 * <td>The asymmetric difference of sets specified by <em>pat1</em> and
170 * <tr valign=top><td nowrap><code>[:Lu:] or \\p{Lu}</code>
171 * <td>The set of characters having the specified
172 * Unicode property; in
173 * this case, Unicode uppercase letters
174 * <tr valign=top><td nowrap><code>[:^Lu:] or \\P{Lu}</code>
175 * <td>The set of characters <em>not</em> having the given
179 * <p><b>Warning</b>: you cannot add an empty string ("") to a UnicodeSet.</p>
181 * <p><b>Formal syntax</b></p>
183 * \htmlonly<blockquote>\endhtmlonly
186 * <td nowrap valign="top" align="right"><code>pattern := </code></td>
187 * <td valign="top"><code>('[' '^'? item* ']') |
188 * property</code></td>
191 * <td nowrap valign="top" align="right"><code>item := </code></td>
192 * <td valign="top"><code>char | (char '-' char) | pattern-expr<br>
196 * <td nowrap valign="top" align="right"><code>pattern-expr := </code></td>
197 * <td valign="top"><code>pattern | pattern-expr pattern |
198 * pattern-expr op pattern<br>
202 * <td nowrap valign="top" align="right"><code>op := </code></td>
203 * <td valign="top"><code>'&' | '-'<br>
207 * <td nowrap valign="top" align="right"><code>special := </code></td>
208 * <td valign="top"><code>'[' | ']' | '-'<br>
212 * <td nowrap valign="top" align="right"><code>char := </code></td>
213 * <td valign="top"><em>any character that is not</em><code> special<br>
214 * | ('\' </code><em>any character</em><code>)<br>
215 * | ('\\u' hex hex hex hex)<br>
219 * <td nowrap valign="top" align="right"><code>hex := </code></td>
220 * <td valign="top"><em>any character for which
221 * </em><code>Character.digit(c, 16)</code><em>
222 * returns a non-negative result</em></td>
225 * <td nowrap valign="top" align="right"><code>property := </code></td>
226 * <td valign="top"><em>a Unicode property set pattern</em></td>
232 * <td>Legend: <table>
234 * <td nowrap valign="top"><code>a := b</code></td>
235 * <td width="20" valign="top"> </td>
236 * <td valign="top"><code>a</code> may be replaced by <code>b</code> </td>
239 * <td nowrap valign="top"><code>a?</code></td>
240 * <td valign="top"></td>
241 * <td valign="top">zero or one instance of <code>a</code><br>
245 * <td nowrap valign="top"><code>a*</code></td>
246 * <td valign="top"></td>
247 * <td valign="top">one or more instances of <code>a</code><br>
251 * <td nowrap valign="top"><code>a | b</code></td>
252 * <td valign="top"></td>
253 * <td valign="top">either <code>a</code> or <code>b</code><br>
257 * <td nowrap valign="top"><code>'a'</code></td>
258 * <td valign="top"></td>
259 * <td valign="top">the literal string between the quotes </td>
265 * \htmlonly</blockquote>\endhtmlonly
268 * - Most UnicodeSet methods do not take a UErrorCode parameter because
269 * there are usually very few opportunities for failure other than a shortage
270 * of memory, error codes in low-level C++ string methods would be inconvenient,
271 * and the error code as the last parameter (ICU convention) would prevent
272 * the use of default parameter values.
273 * Instead, such methods set the UnicodeSet into a "bogus" state
274 * (see isBogus()) if an error occurs.
279 class U_COMMON_API UnicodeSet U_FINAL
: public UnicodeFilter
{
281 int32_t len
; // length of list used; 0 <= len <= capacity
282 int32_t capacity
; // capacity of list
283 UChar32
* list
; // MUST be terminated with HIGH
284 BMPSet
*bmpSet
; // The set is frozen iff either bmpSet or stringSpan is not NULL.
285 UChar32
* buffer
; // internal buffer, may be NULL
286 int32_t bufferCapacity
; // capacity of buffer
290 * The pattern representation of this set. This may not be the
291 * most economical pattern. It is the pattern supplied to
292 * applyPattern(), with variables substituted and whitespace
293 * removed. For sets constructed without applyPattern(), or
294 * modified using the non-pattern API, this string will be empty,
295 * indicating that toPattern() must generate a pattern
296 * representation from the inversion list.
299 UVector
* strings
; // maintained in sorted order
300 UnicodeSetStringSpan
*stringSpan
;
304 kIsBogus
= 1 // This set is bogus (i.e. not valid)
306 uint8_t fFlags
; // Bit flag (see constants above)
309 * Determine if this object contains a valid set.
310 * A bogus set has no value. It is different from an empty set.
311 * It can be used to indicate that no set value is available.
313 * @return TRUE if the set is bogus/invalid, FALSE otherwise
317 inline UBool
isBogus(void) const;
320 * Make this UnicodeSet object invalid.
321 * The string will test TRUE with isBogus().
323 * A bogus set has no value. It is different from an empty set.
324 * It can be used to indicate that no set value is available.
326 * This utility function is used throughout the UnicodeSet
327 * implementation to indicate that a UnicodeSet operation failed,
328 * and may be used in other functions,
329 * especially but not exclusively when such functions do not
330 * take a UErrorCode for simplicity.
341 * Minimum value that can be stored in a UnicodeSet.
347 * Maximum value that can be stored in a UnicodeSet.
353 //----------------------------------------------------------------
355 //----------------------------------------------------------------
360 * Constructs an empty set.
366 * Constructs a set containing the given range. If <code>end <
367 * start</code> then an empty set is created.
369 * @param start first character, inclusive, of range
370 * @param end last character, inclusive, of range
373 UnicodeSet(UChar32 start
, UChar32 end
);
375 #ifndef U_HIDE_INTERNAL_API
379 enum ESerialization
{
380 kSerialized
/* result of serialize() */
384 * Constructs a set from the output of serialize().
386 * @param buffer the 16 bit array
387 * @param bufferLen the original length returned from serialize()
388 * @param serialization the value 'kSerialized'
389 * @param status error code
393 UnicodeSet(const uint16_t buffer
[], int32_t bufferLen
,
394 ESerialization serialization
, UErrorCode
&status
);
395 #endif /* U_HIDE_INTERNAL_API */
398 * Constructs a set from the given pattern. See the class
399 * description for the syntax of the pattern language.
400 * @param pattern a string specifying what characters are in the set
401 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
402 * contains a syntax error.
405 UnicodeSet(const UnicodeString
& pattern
,
408 #ifndef U_HIDE_INTERNAL_API
410 * Constructs a set from the given pattern. See the class
411 * description for the syntax of the pattern language.
412 * @param pattern a string specifying what characters are in the set
413 * @param options bitmask for options to apply to the pattern.
414 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
415 * @param symbols a symbol table mapping variable names to values
416 * and stand-in characters to UnicodeSets; may be NULL
417 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
418 * contains a syntax error.
421 UnicodeSet(const UnicodeString
& pattern
,
423 const SymbolTable
* symbols
,
425 #endif /* U_HIDE_INTERNAL_API */
428 * Constructs a set from the given pattern. See the class description
429 * for the syntax of the pattern language.
430 * @param pattern a string specifying what characters are in the set
431 * @param pos on input, the position in pattern at which to start parsing.
432 * On output, the position after the last character parsed.
433 * @param options bitmask for options to apply to the pattern.
434 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
435 * @param symbols a symbol table mapping variable names to values
436 * and stand-in characters to UnicodeSets; may be NULL
437 * @param status input-output error code
440 UnicodeSet(const UnicodeString
& pattern
, ParsePosition
& pos
,
442 const SymbolTable
* symbols
,
446 * Constructs a set that is identical to the given UnicodeSet.
449 UnicodeSet(const UnicodeSet
& o
);
455 virtual ~UnicodeSet();
458 * Assigns this object to be a copy of another.
459 * A frozen set will not be modified.
462 UnicodeSet
& operator=(const UnicodeSet
& o
);
465 * Compares the specified object with this set for equality. Returns
466 * <tt>true</tt> if the two sets
467 * have the same size, and every member of the specified set is
468 * contained in this set (or equivalently, every member of this set is
469 * contained in the specified set).
471 * @param o set to be compared for equality with this set.
472 * @return <tt>true</tt> if the specified set is equal to this set.
475 virtual UBool
operator==(const UnicodeSet
& o
) const;
478 * Compares the specified object with this set for equality. Returns
479 * <tt>true</tt> if the specified set is not equal to this set.
482 UBool
operator!=(const UnicodeSet
& o
) const;
485 * Returns a copy of this object. All UnicodeFunctor objects have
486 * to support cloning in order to allow classes using
487 * UnicodeFunctors, such as Transliterator, to implement cloning.
488 * If this set is frozen, then the clone will be frozen as well.
489 * Use cloneAsThawed() for a mutable clone of a frozen set.
493 virtual UnicodeFunctor
* clone() const;
496 * Returns the hash code value for this set.
498 * @return the hash code value for this set.
499 * @see Object#hashCode()
502 virtual int32_t hashCode(void) const;
505 * Get a UnicodeSet pointer from a USet
507 * @param uset a USet (the ICU plain C type for UnicodeSet)
508 * @return the corresponding UnicodeSet pointer.
512 inline static UnicodeSet
*fromUSet(USet
*uset
);
515 * Get a UnicodeSet pointer from a const USet
517 * @param uset a const USet (the ICU plain C type for UnicodeSet)
518 * @return the corresponding UnicodeSet pointer.
522 inline static const UnicodeSet
*fromUSet(const USet
*uset
);
525 * Produce a USet * pointer for this UnicodeSet.
526 * USet is the plain C type for UnicodeSet
528 * @return a USet pointer for this UnicodeSet
531 inline USet
*toUSet();
535 * Produce a const USet * pointer for this UnicodeSet.
536 * USet is the plain C type for UnicodeSet
538 * @return a const USet pointer for this UnicodeSet
541 inline const USet
* toUSet() const;
544 //----------------------------------------------------------------
546 //----------------------------------------------------------------
549 * Determines whether the set has been frozen (made immutable) or not.
550 * See the ICU4J Freezable interface for details.
551 * @return TRUE/FALSE for whether the set has been frozen
556 inline UBool
isFrozen() const;
559 * Freeze the set (make it immutable).
560 * Once frozen, it cannot be unfrozen and is therefore thread-safe
561 * until it is deleted.
562 * See the ICU4J Freezable interface for details.
563 * Freezing the set may also make some operations faster, for example
564 * contains() and span().
565 * A frozen set will not be modified. (It remains frozen.)
571 UnicodeFunctor
*freeze();
574 * Clone the set and make the clone mutable.
575 * See the ICU4J Freezable interface for details.
576 * @return the mutable clone
581 UnicodeFunctor
*cloneAsThawed() const;
583 //----------------------------------------------------------------
585 //----------------------------------------------------------------
588 * Make this object represent the range <code>start - end</code>.
589 * If <code>end > start</code> then this object is set to an
591 * A frozen set will not be modified.
593 * @param start first character in the set, inclusive
594 * @param end last character in the set, inclusive
597 UnicodeSet
& set(UChar32 start
, UChar32 end
);
600 * Return true if the given position, in the given pattern, appears
601 * to be the start of a UnicodeSet pattern.
604 static UBool
resemblesPattern(const UnicodeString
& pattern
,
608 * Modifies this set to represent the set specified by the given
609 * pattern, ignoring Unicode Pattern_White_Space characters.
610 * See the class description for the syntax of the pattern language.
611 * A frozen set will not be modified.
612 * @param pattern a string specifying what characters are in the set
613 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
614 * contains a syntax error.
615 * <em> Empties the set passed before applying the pattern.</em>
616 * @return a reference to this
619 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
622 #ifndef U_HIDE_INTERNAL_API
624 * Modifies this set to represent the set specified by the given
625 * pattern, optionally ignoring Unicode Pattern_White_Space characters.
626 * See the class description for the syntax of the pattern language.
627 * A frozen set will not be modified.
628 * @param pattern a string specifying what characters are in the set
629 * @param options bitmask for options to apply to the pattern.
630 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
631 * @param symbols a symbol table mapping variable names to
632 * values and stand-ins to UnicodeSets; may be NULL
633 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
634 * contains a syntax error.
635 *<em> Empties the set passed before applying the pattern.</em>
636 * @return a reference to this
639 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
641 const SymbolTable
* symbols
,
643 #endif /* U_HIDE_INTERNAL_API */
646 * Parses the given pattern, starting at the given position. The
647 * character at pattern.charAt(pos.getIndex()) must be '[', or the
648 * parse fails. Parsing continues until the corresponding closing
649 * ']'. If a syntax error is encountered between the opening and
650 * closing brace, the parse fails. Upon return from a successful
651 * parse, the ParsePosition is updated to point to the character
652 * following the closing ']', and a StringBuffer containing a
653 * pairs list for the parsed pattern is returned. This method calls
654 * itself recursively to parse embedded subpatterns.
655 *<em> Empties the set passed before applying the pattern.</em>
656 * A frozen set will not be modified.
658 * @param pattern the string containing the pattern to be parsed.
659 * The portion of the string from pos.getIndex(), which must be a
660 * '[', to the corresponding closing ']', is parsed.
661 * @param pos upon entry, the position at which to being parsing.
662 * The character at pattern.charAt(pos.getIndex()) must be a '['.
663 * Upon return from a successful parse, pos.getIndex() is either
664 * the character after the closing ']' of the parsed pattern, or
665 * pattern.length() if the closing ']' is the last character of
666 * the pattern string.
667 * @param options bitmask for options to apply to the pattern.
668 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
669 * @param symbols a symbol table mapping variable names to
670 * values and stand-ins to UnicodeSets; may be NULL
671 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
672 * contains a syntax error.
673 * @return a reference to this
676 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
679 const SymbolTable
* symbols
,
683 * Returns a string representation of this set. If the result of
684 * calling this function is passed to a UnicodeSet constructor, it
685 * will produce another set that is equal to this one.
686 * A frozen set will not be modified.
687 * @param result the string to receive the rules. Previous
688 * contents will be deleted.
689 * @param escapeUnprintable if TRUE then convert unprintable
690 * character to their hex escape representations, \\uxxxx or
691 * \\Uxxxxxxxx. Unprintable characters are those other than
692 * U+000A, U+0020..U+007E.
695 virtual UnicodeString
& toPattern(UnicodeString
& result
,
696 UBool escapeUnprintable
= FALSE
) const;
699 * Modifies this set to contain those code points which have the given value
700 * for the given binary or enumerated property, as returned by
701 * u_getIntPropertyValue. Prior contents of this set are lost.
702 * A frozen set will not be modified.
704 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
705 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
706 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
708 * @param value a value in the range u_getIntPropertyMinValue(prop)..
709 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
710 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
711 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
712 * categories such as [:L:] to be represented.
714 * @param ec error code input/output parameter
716 * @return a reference to this set
720 UnicodeSet
& applyIntPropertyValue(UProperty prop
,
725 * Modifies this set to contain those code points which have the
726 * given value for the given property. Prior contents of this
728 * A frozen set will not be modified.
730 * @param prop a property alias, either short or long. The name is matched
731 * loosely. See PropertyAliases.txt for names and a description of loose
732 * matching. If the value string is empty, then this string is interpreted
733 * as either a General_Category value alias, a Script value alias, a binary
734 * property alias, or a special ID. Special IDs are matched loosely and
735 * correspond to the following sets:
737 * "ANY" = [\\u0000-\\U0010FFFF],
738 * "ASCII" = [\\u0000-\\u007F],
739 * "Assigned" = [:^Cn:].
741 * @param value a value alias, either short or long. The name is matched
742 * loosely. See PropertyValueAliases.txt for names and a description of
743 * loose matching. In addition to aliases listed, numeric values and
744 * canonical combining classes may be expressed numerically, e.g., ("nv",
745 * "0.5") or ("ccc", "220"). The value string may also be empty.
747 * @param ec error code input/output parameter
749 * @return a reference to this set
753 UnicodeSet
& applyPropertyAlias(const UnicodeString
& prop
,
754 const UnicodeString
& value
,
758 * Returns the number of elements in this set (its cardinality).
759 * Note than the elements of a set may include both individual
760 * codepoints and strings.
762 * @return the number of elements in this set (its cardinality).
765 virtual int32_t size(void) const;
768 * Returns <tt>true</tt> if this set contains no elements.
770 * @return <tt>true</tt> if this set contains no elements.
773 virtual UBool
isEmpty(void) const;
776 * Returns true if this set contains the given character.
777 * This function works faster with a frozen set.
778 * @param c character to be checked for containment
779 * @return true if the test condition is met
782 virtual UBool
contains(UChar32 c
) const;
785 * Returns true if this set contains every character
786 * of the given range.
787 * @param start first character, inclusive, of the range
788 * @param end last character, inclusive, of the range
789 * @return true if the test condition is met
792 virtual UBool
contains(UChar32 start
, UChar32 end
) const;
795 * Returns <tt>true</tt> if this set contains the given
796 * multicharacter string.
797 * @param s string to be checked for containment
798 * @return <tt>true</tt> if this set contains the specified string
801 UBool
contains(const UnicodeString
& s
) const;
804 * Returns true if this set contains all the characters and strings
806 * @param c set to be checked for containment
807 * @return true if the test condition is met
810 virtual UBool
containsAll(const UnicodeSet
& c
) const;
813 * Returns true if this set contains all 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
containsAll(const UnicodeString
& s
) const;
822 * Returns true if this set contains none of the characters
823 * of 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 test condition is met
829 UBool
containsNone(UChar32 start
, UChar32 end
) const;
832 * Returns true if this set contains none of the characters and strings
834 * @param c set to be checked for containment
835 * @return true if the test condition is met
838 UBool
containsNone(const UnicodeSet
& c
) const;
841 * Returns true if this set contains none of the characters
842 * of the given string.
843 * @param s string containing characters to be checked for containment
844 * @return true if the test condition is met
847 UBool
containsNone(const UnicodeString
& s
) const;
850 * Returns true if this set contains one or more of the characters
851 * in the given range.
852 * @param start first character, inclusive, of the range
853 * @param end last character, inclusive, of the range
854 * @return true if the condition is met
857 inline UBool
containsSome(UChar32 start
, UChar32 end
) const;
860 * Returns true if this set contains one or more of the characters
861 * and strings of the given set.
862 * @param s The set to be checked for containment
863 * @return true if the condition is met
866 inline UBool
containsSome(const UnicodeSet
& s
) const;
869 * Returns true if this set contains one or more of the characters
870 * of the given string.
871 * @param s string containing characters to be checked for containment
872 * @return true if the condition is met
875 inline UBool
containsSome(const UnicodeString
& s
) const;
878 * Returns the length of the initial substring of the input string which
879 * consists only of characters and strings that are contained in this set
880 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
881 * or only of characters and strings that are not contained
882 * in this set (USET_SPAN_NOT_CONTAINED).
883 * See USetSpanCondition for details.
884 * Similar to the strspn() C library function.
885 * Unpaired surrogates are treated according to contains() of their surrogate code points.
886 * This function works faster with a frozen set and with a non-negative string length argument.
887 * @param s start of the string
888 * @param length of the string; can be -1 for NUL-terminated
889 * @param spanCondition specifies the containment condition
890 * @return the length of the initial substring according to the spanCondition;
891 * 0 if the start of the string does not fit the spanCondition
893 * @see USetSpanCondition
895 int32_t span(const char16_t *s
, int32_t length
, USetSpanCondition spanCondition
) const;
898 * Returns the end of the substring of the input string according to the USetSpanCondition.
899 * Same as <code>start+span(s.getBuffer()+start, s.length()-start, spanCondition)</code>
900 * after pinning start to 0<=start<=s.length().
901 * @param s the string
902 * @param start the start index in the string for the span operation
903 * @param spanCondition specifies the containment condition
904 * @return the exclusive end of the substring according to the spanCondition;
905 * the substring s.tempSubStringBetween(start, end) fulfills the spanCondition
907 * @see USetSpanCondition
909 inline int32_t span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const;
912 * Returns the start of the trailing substring of the input string which
913 * consists only of characters and strings that are contained in this set
914 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
915 * or only of characters and strings that are not contained
916 * in this set (USET_SPAN_NOT_CONTAINED).
917 * See USetSpanCondition for details.
918 * Unpaired surrogates are treated according to contains() of their surrogate code points.
919 * This function works faster with a frozen set and with a non-negative string length argument.
920 * @param s start of the string
921 * @param length of the string; can be -1 for NUL-terminated
922 * @param spanCondition specifies the containment condition
923 * @return the start of the trailing substring according to the spanCondition;
924 * the string length if the end of the string does not fit the spanCondition
926 * @see USetSpanCondition
928 int32_t spanBack(const char16_t *s
, int32_t length
, USetSpanCondition spanCondition
) const;
931 * Returns the start of the substring of the input string according to the USetSpanCondition.
932 * Same as <code>spanBack(s.getBuffer(), limit, spanCondition)</code>
933 * after pinning limit to 0<=end<=s.length().
934 * @param s the string
935 * @param limit the exclusive-end index in the string for the span operation
936 * (use s.length() or INT32_MAX for spanning back from the end of the string)
937 * @param spanCondition specifies the containment condition
938 * @return the start of the substring according to the spanCondition;
939 * the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition
941 * @see USetSpanCondition
943 inline int32_t spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const;
946 * Returns the length of the initial substring of the input string which
947 * consists only of characters and strings that are contained in this set
948 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
949 * or only of characters and strings that are not contained
950 * in this set (USET_SPAN_NOT_CONTAINED).
951 * See USetSpanCondition for details.
952 * Similar to the strspn() C library function.
953 * Malformed byte sequences are treated according to contains(0xfffd).
954 * This function works faster with a frozen set and with a non-negative string length argument.
955 * @param s start of the string (UTF-8)
956 * @param length of the string; can be -1 for NUL-terminated
957 * @param spanCondition specifies the containment condition
958 * @return the length of the initial substring according to the spanCondition;
959 * 0 if the start of the string does not fit the spanCondition
961 * @see USetSpanCondition
963 int32_t spanUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
966 * Returns the start of the trailing substring of the input string which
967 * consists only of characters and strings that are contained in this set
968 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
969 * or only of characters and strings that are not contained
970 * in this set (USET_SPAN_NOT_CONTAINED).
971 * See USetSpanCondition for details.
972 * Malformed byte sequences are treated according to contains(0xfffd).
973 * This function works faster with a frozen set and with a non-negative string length argument.
974 * @param s start of the string (UTF-8)
975 * @param length of the string; can be -1 for NUL-terminated
976 * @param spanCondition specifies the containment condition
977 * @return the start of the trailing substring according to the spanCondition;
978 * the string length if the end of the string does not fit the spanCondition
980 * @see USetSpanCondition
982 int32_t spanBackUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
985 * Implement UnicodeMatcher::matches()
988 virtual UMatchDegree
matches(const Replaceable
& text
,
995 * Returns the longest match for s in text at the given position.
996 * If limit > start then match forward from start+1 to limit
997 * matching all characters except s.charAt(0). If limit < start,
998 * go backward starting from start-1 matching all characters
999 * except s.charAt(s.length()-1). This method assumes that the
1000 * first character, text.charAt(start), matches s, so it does not
1002 * @param text the text to match
1003 * @param start the first character to match. In the forward
1004 * direction, text.charAt(start) is matched against s.charAt(0).
1005 * In the reverse direction, it is matched against
1006 * s.charAt(s.length()-1).
1007 * @param limit the limit offset for matching, either last+1 in
1008 * the forward direction, or last-1 in the reverse direction,
1009 * where last is the index of the last character to match.
1011 * @return If part of s matches up to the limit, return |limit -
1012 * start|. If all of s matches before reaching the limit, return
1013 * s.length(). If there is a mismatch between s and text, return
1016 static int32_t matchRest(const Replaceable
& text
,
1017 int32_t start
, int32_t limit
,
1018 const UnicodeString
& s
);
1021 * Returns the smallest value i such that c < list[i]. Caller
1022 * must ensure that c is a legal value or this method will enter
1023 * an infinite loop. This method performs a binary search.
1024 * @param c a character in the range MIN_VALUE..MAX_VALUE
1026 * @return the smallest integer i in the range 0..len-1,
1027 * inclusive, such that c < list[i]
1029 int32_t findCodePoint(UChar32 c
) const;
1034 * Implementation of UnicodeMatcher API. Union the set of all
1035 * characters that may be matched by this object into the given
1037 * @param toUnionTo the set into which to union the source characters
1040 virtual void addMatchSetTo(UnicodeSet
& toUnionTo
) const;
1043 * Returns the index of the given character within this set, where
1044 * the set is ordered by ascending code point. If the character
1045 * is not in this set, return -1. The inverse of this method is
1046 * <code>charAt()</code>.
1047 * @return an index from 0..size()-1, or -1
1050 int32_t indexOf(UChar32 c
) const;
1053 * Returns the character at the given index within this set, where
1054 * the set is ordered by ascending code point. If the index is
1055 * out of range, return (UChar32)-1. The inverse of this method is
1056 * <code>indexOf()</code>.
1057 * @param index an index from 0..size()-1
1058 * @return the character at the given index, or (UChar32)-1.
1061 UChar32
charAt(int32_t index
) const;
1064 * Adds the specified range to this set if it is not already
1065 * present. If this set already contains the specified range,
1066 * the call leaves this set unchanged. If <code>end > start</code>
1067 * then an empty range is added, leaving the set unchanged.
1068 * This is equivalent to a boolean logic OR, or a set UNION.
1069 * A frozen set will not be modified.
1071 * @param start first character, inclusive, of range to be added
1073 * @param end last character, inclusive, of range to be added
1077 virtual UnicodeSet
& add(UChar32 start
, UChar32 end
);
1080 * Adds the specified character to this set if it is not already
1081 * present. If this set already contains the specified character,
1082 * the call leaves this set unchanged.
1083 * A frozen set will not be modified.
1086 UnicodeSet
& add(UChar32 c
);
1089 * Adds the specified multicharacter to this set if it is not already
1090 * present. If this set already contains the multicharacter,
1091 * the call leaves this set unchanged.
1092 * Thus "ch" => {"ch"}
1093 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1094 * A frozen set will not be modified.
1095 * @param s the source string
1096 * @return this object, for chaining
1099 UnicodeSet
& add(const UnicodeString
& s
);
1103 * @return a code point IF the string consists of a single one.
1104 * otherwise returns -1.
1105 * @param s string to test
1107 static int32_t getSingleCP(const UnicodeString
& s
);
1109 void _add(const UnicodeString
& s
);
1113 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
1114 * If this set already any particular character, it has no effect on that character.
1115 * A frozen set will not be modified.
1116 * @param s the source string
1117 * @return this object, for chaining
1120 UnicodeSet
& addAll(const UnicodeString
& s
);
1123 * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
1124 * If this set already any particular character, it has no effect on that character.
1125 * A frozen set will not be modified.
1126 * @param s the source string
1127 * @return this object, for chaining
1130 UnicodeSet
& retainAll(const UnicodeString
& s
);
1133 * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
1134 * If this set already any particular character, it has no effect on that character.
1135 * A frozen set will not be modified.
1136 * @param s the source string
1137 * @return this object, for chaining
1140 UnicodeSet
& complementAll(const UnicodeString
& s
);
1143 * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
1144 * If this set already any particular character, it has no effect on that character.
1145 * A frozen set will not be modified.
1146 * @param s the source string
1147 * @return this object, for chaining
1150 UnicodeSet
& removeAll(const UnicodeString
& s
);
1153 * Makes a set from a multicharacter string. Thus "ch" => {"ch"}
1154 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1155 * @param s the source string
1156 * @return a newly created set containing the given string.
1157 * The caller owns the return object and is responsible for deleting it.
1160 static UnicodeSet
* U_EXPORT2
createFrom(const UnicodeString
& s
);
1164 * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
1165 * @param s the source string
1166 * @return a newly created set containing the given characters
1167 * The caller owns the return object and is responsible for deleting it.
1170 static UnicodeSet
* U_EXPORT2
createFromAll(const UnicodeString
& s
);
1173 * Retain only the elements in this set that are contained in the
1174 * specified range. If <code>end > start</code> then an empty range is
1175 * retained, leaving the set empty. This is equivalent to
1176 * a boolean logic AND, or a set INTERSECTION.
1177 * A frozen set will not be modified.
1179 * @param start first character, inclusive, of range to be retained
1181 * @param end last character, inclusive, of range to be retained
1185 virtual UnicodeSet
& retain(UChar32 start
, UChar32 end
);
1189 * Retain the specified character from this set if it is present.
1190 * A frozen set will not be modified.
1193 UnicodeSet
& retain(UChar32 c
);
1196 * Removes the specified range from this set if it is present.
1197 * The set will not contain the specified range once the call
1198 * returns. If <code>end > start</code> then an empty range is
1199 * removed, leaving the set unchanged.
1200 * A frozen set will not be modified.
1202 * @param start first character, inclusive, of range to be removed
1204 * @param end last character, inclusive, of range to be removed
1208 virtual UnicodeSet
& remove(UChar32 start
, UChar32 end
);
1211 * Removes the specified character from this set if it is present.
1212 * The set will not contain the specified range once the call
1214 * A frozen set will not be modified.
1217 UnicodeSet
& remove(UChar32 c
);
1220 * Removes the specified string from this set if it is present.
1221 * The set will not contain the specified character once the call
1223 * A frozen set will not be modified.
1224 * @param s the source string
1225 * @return this object, for chaining
1228 UnicodeSet
& remove(const UnicodeString
& s
);
1231 * Inverts this set. This operation modifies this set so that
1232 * its value is its complement. This is equivalent to
1233 * <code>complement(MIN_VALUE, MAX_VALUE)</code>.
1234 * A frozen set will not be modified.
1237 virtual UnicodeSet
& complement(void);
1240 * Complements the specified range in this set. Any character in
1241 * the range will be removed if it is in this set, or will be
1242 * added if it is not in this set. If <code>end > start</code>
1243 * then an empty range is complemented, leaving the set unchanged.
1244 * This is equivalent to a boolean logic XOR.
1245 * A frozen set will not be modified.
1247 * @param start first character, inclusive, of range to be removed
1249 * @param end last character, inclusive, of range to be removed
1253 virtual UnicodeSet
& complement(UChar32 start
, UChar32 end
);
1256 * Complements the specified character in this set. The character
1257 * will be removed if it is in this set, or will be added if it is
1259 * A frozen set will not be modified.
1262 UnicodeSet
& complement(UChar32 c
);
1265 * Complement the specified string in this set.
1266 * The set will not contain the specified string once the call
1268 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1269 * A frozen set will not be modified.
1270 * @param s the string to complement
1271 * @return this object, for chaining
1274 UnicodeSet
& complement(const UnicodeString
& s
);
1277 * Adds all of the elements in the specified set to this set if
1278 * they're not already present. This operation effectively
1279 * modifies this set so that its value is the <i>union</i> of the two
1280 * sets. The behavior of this operation is unspecified if the specified
1281 * collection is modified while the operation is in progress.
1282 * A frozen set will not be modified.
1284 * @param c set whose elements are to be added to this set.
1285 * @see #add(UChar32, UChar32)
1288 virtual UnicodeSet
& addAll(const UnicodeSet
& c
);
1291 * Retains only the elements in this set that are contained in the
1292 * specified set. In other words, removes from this set all of
1293 * its elements that are not contained in the specified set. This
1294 * operation effectively modifies this set so that its value is
1295 * the <i>intersection</i> of the two sets.
1296 * A frozen set will not be modified.
1298 * @param c set that defines which elements this set will retain.
1301 virtual UnicodeSet
& retainAll(const UnicodeSet
& c
);
1304 * Removes from this set all of its elements that are contained in the
1305 * specified set. This operation effectively modifies this
1306 * set so that its value is the <i>asymmetric set difference</i> of
1308 * A frozen set will not be modified.
1310 * @param c set that defines which elements will be removed from
1314 virtual UnicodeSet
& removeAll(const UnicodeSet
& c
);
1317 * Complements in this set all elements contained in the specified
1318 * set. Any character in the other set will be removed if it is
1319 * in this set, or will be added if it is not in this set.
1320 * A frozen set will not be modified.
1322 * @param c set that defines which elements will be xor'ed from
1326 virtual UnicodeSet
& complementAll(const UnicodeSet
& c
);
1329 * Removes all of the elements from this set. This set will be
1330 * empty after this call returns.
1331 * A frozen set will not be modified.
1334 virtual UnicodeSet
& clear(void);
1337 * Close this set over the given attribute. For the attribute
1338 * USET_CASE, the result is to modify this set so that:
1340 * 1. For each character or string 'a' in this set, all strings or
1341 * characters 'b' such that foldCase(a) == foldCase(b) are added
1344 * 2. For each string 'e' in the resulting set, if e !=
1345 * foldCase(e), 'e' will be removed.
1347 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
1349 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
1350 * == b denotes that the contents are the same, not pointer
1353 * A frozen set will not be modified.
1355 * @param attribute bitmask for attributes to close over.
1356 * Currently only the USET_CASE bit is supported. Any undefined bits
1358 * @return a reference to this set.
1361 UnicodeSet
& closeOver(int32_t attribute
);
1364 * Remove all strings from this set.
1366 * @return a reference to this set.
1369 virtual UnicodeSet
&removeAllStrings();
1372 * Iteration method that returns the number of ranges contained in
1374 * @see #getRangeStart
1378 virtual int32_t getRangeCount(void) const;
1381 * Iteration method that returns the first character in the
1382 * specified range of this set.
1383 * @see #getRangeCount
1387 virtual UChar32
getRangeStart(int32_t index
) const;
1390 * Iteration method that returns the last character in the
1391 * specified range of this set.
1392 * @see #getRangeStart
1396 virtual UChar32
getRangeEnd(int32_t index
) const;
1399 * Serializes this set into an array of 16-bit integers. Serialization
1400 * (currently) only records the characters in the set; multicharacter
1401 * strings are ignored.
1403 * The array has following format (each line is one 16-bit
1406 * length = (n+2*m) | (m!=0?0x8000:0)
1407 * bmpLength = n; present if m!=0
1420 * The array starts with a header. After the header are n bmp
1421 * code points, then m supplementary code points. Either n or m
1422 * or both may be zero. n+2*m is always <= 0x7FFF.
1424 * If there are no supplementary characters (if m==0) then the
1425 * header is one 16-bit integer, 'length', with value n.
1427 * If there are supplementary characters (if m!=0) then the header
1428 * is two 16-bit integers. The first, 'length', has value
1429 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
1431 * After the header the code points are stored in ascending order.
1432 * Supplementary code points are stored as most significant 16
1433 * bits followed by least significant 16 bits.
1435 * @param dest pointer to buffer of destCapacity 16-bit integers.
1436 * May be NULL only if destCapacity is zero.
1437 * @param destCapacity size of dest, or zero. Must not be negative.
1438 * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR
1439 * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if
1440 * n+2*m+(m!=0?2:1) > destCapacity.
1441 * @return the total length of the serialized format, including
1442 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1443 * than U_BUFFER_OVERFLOW_ERROR.
1446 int32_t serialize(uint16_t *dest
, int32_t destCapacity
, UErrorCode
& ec
) const;
1449 * Reallocate this objects internal structures to take up the least
1450 * possible space, without changing this object's value.
1451 * A frozen set will not be modified.
1454 virtual UnicodeSet
& compact();
1457 * Return the class ID for this class. This is useful only for
1458 * comparing to a return value from getDynamicClassID(). For example:
1460 * . Base* polymorphic_pointer = createPolymorphicObject();
1461 * . if (polymorphic_pointer->getDynamicClassID() ==
1462 * . Derived::getStaticClassID()) ...
1464 * @return The class ID for all objects of this class.
1467 static UClassID U_EXPORT2
getStaticClassID(void);
1470 * Implement UnicodeFunctor API.
1472 * @return The class ID for this object. All objects of a given
1473 * class have the same class ID. Objects of other classes have
1474 * different class IDs.
1477 virtual UClassID
getDynamicClassID(void) const;
1481 // Private API for the USet API
1483 friend class USetAccess
;
1485 int32_t getStringCount() const;
1487 const UnicodeString
* getString(int32_t index
) const;
1489 //----------------------------------------------------------------
1490 // RuleBasedTransliterator support
1491 //----------------------------------------------------------------
1496 * Returns <tt>true</tt> if this set contains any character whose low byte
1497 * is the given value. This is used by <tt>RuleBasedTransliterator</tt> for
1500 virtual UBool
matchesIndexValue(uint8_t v
) const;
1503 friend class RBBIRuleScanner
;
1505 //----------------------------------------------------------------
1506 // Implementation: Clone as thawed (see ICU4J Freezable)
1507 //----------------------------------------------------------------
1509 UnicodeSet(const UnicodeSet
& o
, UBool
/* asThawed */);
1511 //----------------------------------------------------------------
1512 // Implementation: Pattern parsing
1513 //----------------------------------------------------------------
1515 void applyPatternIgnoreSpace(const UnicodeString
& pattern
,
1517 const SymbolTable
* symbols
,
1518 UErrorCode
& status
);
1520 void applyPattern(RuleCharacterIterator
& chars
,
1521 const SymbolTable
* symbols
,
1522 UnicodeString
& rebuiltPat
,
1524 UnicodeSet
& (UnicodeSet::*caseClosure
)(int32_t attribute
),
1527 //----------------------------------------------------------------
1528 // Implementation: Utility methods
1529 //----------------------------------------------------------------
1531 void ensureCapacity(int32_t newLen
, UErrorCode
& ec
);
1533 void ensureBufferCapacity(int32_t newLen
, UErrorCode
& ec
);
1535 void swapBuffers(void);
1537 UBool
allocateStrings(UErrorCode
&status
);
1539 UnicodeString
& _toPattern(UnicodeString
& result
,
1540 UBool escapeUnprintable
) const;
1542 UnicodeString
& _generatePattern(UnicodeString
& result
,
1543 UBool escapeUnprintable
) const;
1545 static void _appendToPat(UnicodeString
& buf
, const UnicodeString
& s
, UBool escapeUnprintable
);
1547 static void _appendToPat(UnicodeString
& buf
, UChar32 c
, UBool escapeUnprintable
);
1549 //----------------------------------------------------------------
1550 // Implementation: Fundamental operators
1551 //----------------------------------------------------------------
1553 void exclusiveOr(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1555 void add(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1557 void retain(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1560 * Return true if the given position, in the given pattern, appears
1561 * to be the start of a property set pattern [:foo:], \\p{foo}, or
1562 * \\P{foo}, or \\N{name}.
1564 static UBool
resemblesPropertyPattern(const UnicodeString
& pattern
,
1567 static UBool
resemblesPropertyPattern(RuleCharacterIterator
& chars
,
1571 * Parse the given property pattern at the given parse position
1572 * and set this UnicodeSet to the result.
1574 * The original design document is out of date, but still useful.
1575 * Ignore the property and value names:
1576 * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/unicodeset_properties.html
1578 * Recognized syntax:
1580 * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]"
1581 * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P"
1582 * \\N{name} - white space not allowed within "\\N"
1584 * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored.
1585 * Case is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading
1586 * and trailing space is deleted, and internal runs of whitespace
1587 * are collapsed to a single space.
1589 * We support binary properties, enumerated properties, and the
1590 * following non-enumerated properties:
1596 * @param pattern the pattern string
1597 * @param ppos on entry, the position at which to begin parsing.
1598 * This should be one of the locations marked '^':
1600 * [:blah:] \\p{blah} \\P{blah} \\N{name}
1603 * On return, the position after the last character parsed, that is,
1604 * the locations marked '%'. If the parse fails, ppos is returned
1607 * @return a reference to this.
1609 UnicodeSet
& applyPropertyPattern(const UnicodeString
& pattern
,
1610 ParsePosition
& ppos
,
1613 void applyPropertyPattern(RuleCharacterIterator
& chars
,
1614 UnicodeString
& rebuiltPat
,
1617 friend void U_CALLCONV
UnicodeSet_initInclusion(int32_t src
, UErrorCode
&status
);
1618 static const UnicodeSet
* getInclusions(int32_t src
, UErrorCode
&status
);
1621 * A filter that returns TRUE if the given code point should be
1622 * included in the UnicodeSet being constructed.
1624 typedef UBool (*Filter
)(UChar32 codePoint
, void* context
);
1627 * Given a filter, set this UnicodeSet to the code points
1628 * contained by that filter. The filter MUST be
1629 * property-conformant. That is, if it returns value v for one
1630 * code point, then it must return v for all affiliated code
1631 * points, as defined by the inclusions list. See
1633 * src is a UPropertySource value.
1635 void applyFilter(Filter filter
,
1638 UErrorCode
&status
);
1641 * Set the new pattern to cache.
1643 void setPattern(const UnicodeString
& newPat
);
1645 * Release existing cached pattern.
1647 void releasePattern();
1649 friend class UnicodeSetIterator
;
1654 inline UBool
UnicodeSet::operator!=(const UnicodeSet
& o
) const {
1655 return !operator==(o
);
1658 inline UBool
UnicodeSet::isFrozen() const {
1659 return (UBool
)(bmpSet
!=NULL
|| stringSpan
!=NULL
);
1662 inline UBool
UnicodeSet::containsSome(UChar32 start
, UChar32 end
) const {
1663 return !containsNone(start
, end
);
1666 inline UBool
UnicodeSet::containsSome(const UnicodeSet
& s
) const {
1667 return !containsNone(s
);
1670 inline UBool
UnicodeSet::containsSome(const UnicodeString
& s
) const {
1671 return !containsNone(s
);
1674 inline UBool
UnicodeSet::isBogus() const {
1675 return (UBool
)(fFlags
& kIsBogus
);
1678 inline UnicodeSet
*UnicodeSet::fromUSet(USet
*uset
) {
1679 return reinterpret_cast<UnicodeSet
*>(uset
);
1682 inline const UnicodeSet
*UnicodeSet::fromUSet(const USet
*uset
) {
1683 return reinterpret_cast<const UnicodeSet
*>(uset
);
1686 inline USet
*UnicodeSet::toUSet() {
1687 return reinterpret_cast<USet
*>(this);
1690 inline const USet
*UnicodeSet::toUSet() const {
1691 return reinterpret_cast<const USet
*>(this);
1694 inline int32_t UnicodeSet::span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const {
1695 int32_t sLength
=s
.length();
1698 } else if(start
>sLength
) {
1701 return start
+span(s
.getBuffer()+start
, sLength
-start
, spanCondition
);
1704 inline int32_t UnicodeSet::spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const {
1705 int32_t sLength
=s
.length();
1708 } else if(limit
>sLength
) {
1711 return spanBack(s
.getBuffer(), limit
, spanCondition
);
1715 #endif // U_SHOW_CPLUSPLUS_API