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/ucpmap.h"
17 #include "unicode/unifilt.h"
18 #include "unicode/unistr.h"
19 #include "unicode/uset.h"
23 * \brief C++ API: Unicode Set
26 #if U_SHOW_CPLUSPLUS_API
29 // Forward Declarations.
32 class RBBIRuleScanner
;
34 class UnicodeSetStringSpan
;
36 class RuleCharacterIterator
;
39 * A mutable set of Unicode characters and multicharacter strings. Objects of this class
40 * represent <em>character classes</em> used in regular expressions.
41 * A character specifies a subset of Unicode code points. Legal
42 * code points are U+0000 to U+10FFFF, inclusive.
44 * <p>The UnicodeSet class is not designed to be subclassed.
46 * <p><code>UnicodeSet</code> supports two APIs. The first is the
47 * <em>operand</em> API that allows the caller to modify the value of
48 * a <code>UnicodeSet</code> object. It conforms to Java 2's
49 * <code>java.util.Set</code> interface, although
50 * <code>UnicodeSet</code> does not actually implement that
51 * interface. All methods of <code>Set</code> are supported, with the
52 * modification that they take a character range or single character
53 * instead of an <code>Object</code>, and they take a
54 * <code>UnicodeSet</code> instead of a <code>Collection</code>. The
55 * operand API may be thought of in terms of boolean logic: a boolean
56 * OR is implemented by <code>add</code>, a boolean AND is implemented
57 * by <code>retain</code>, a boolean XOR is implemented by
58 * <code>complement</code> taking an argument, and a boolean NOT is
59 * implemented by <code>complement</code> with no argument. In terms
60 * of traditional set theory function names, <code>add</code> is a
61 * union, <code>retain</code> is an intersection, <code>remove</code>
62 * is an asymmetric difference, and <code>complement</code> with no
63 * argument is a set complement with respect to the superset range
64 * <code>MIN_VALUE-MAX_VALUE</code>
66 * <p>The second API is the
67 * <code>applyPattern()</code>/<code>toPattern()</code> API from the
68 * <code>java.text.Format</code>-derived classes. Unlike the
69 * methods that add characters, add categories, and control the logic
70 * of the set, the method <code>applyPattern()</code> sets all
71 * attributes of a <code>UnicodeSet</code> at once, based on a
74 * <p><b>Pattern syntax</b></p>
76 * Patterns are accepted by the constructors and the
77 * <code>applyPattern()</code> methods and returned by the
78 * <code>toPattern()</code> method. These patterns follow a syntax
79 * similar to that employed by version 8 regular expression character
80 * classes. Here are some simple examples:
82 * \htmlonly<blockquote>\endhtmlonly
85 * <td nowrap valign="top" align="left"><code>[]</code></td>
86 * <td valign="top">No characters</td>
87 * </tr><tr align="top">
88 * <td nowrap valign="top" align="left"><code>[a]</code></td>
89 * <td valign="top">The character 'a'</td>
90 * </tr><tr align="top">
91 * <td nowrap valign="top" align="left"><code>[ae]</code></td>
92 * <td valign="top">The characters 'a' and 'e'</td>
95 * <td nowrap valign="top" align="left"><code>[a-e]</code></td>
96 * <td valign="top">The characters 'a' through 'e' inclusive, in Unicode code
100 * <td nowrap valign="top" align="left"><code>[\\u4E01]</code></td>
101 * <td valign="top">The character U+4E01</td>
104 * <td nowrap valign="top" align="left"><code>[a{ab}{ac}]</code></td>
105 * <td valign="top">The character 'a' and the multicharacter strings "ab" and
106 * "ac"</td>
109 * <td nowrap valign="top" align="left"><code>[\\p{Lu}]</code></td>
110 * <td valign="top">All characters in the general category Uppercase Letter</td>
113 * \htmlonly</blockquote>\endhtmlonly
115 * Any character may be preceded by a backslash in order to remove any special
116 * meaning. White space characters, as defined by UCharacter.isWhitespace(), are
117 * ignored, unless they are escaped.
119 * <p>Property patterns specify a set of characters having a certain
120 * property as defined by the Unicode standard. Both the POSIX-like
121 * "[:Lu:]" and the Perl-like syntax "\\p{Lu}" are recognized. For a
122 * complete list of supported property patterns, see the User's Guide
124 * <a href="http://icu-project.org/userguide/unicodeSet.html">
125 * http://icu-project.org/userguide/unicodeSet.html</a>.
126 * Actual determination of property data is defined by the underlying
127 * Unicode database as implemented by UCharacter.
129 * <p>Patterns specify individual characters, ranges of characters, and
130 * Unicode property sets. When elements are concatenated, they
131 * specify their union. To complement a set, place a '^' immediately
132 * after the opening '['. Property patterns are inverted by modifying
133 * their delimiters; "[:^foo]" and "\\P{foo}". In any other location,
134 * '^' has no special meaning.
136 * <p>Ranges are indicated by placing two a '-' between two
137 * characters, as in "a-z". This specifies the range of all
138 * characters from the left to the right, in Unicode order. If the
139 * left character is greater than or equal to the
140 * right character it is a syntax error. If a '-' occurs as the first
141 * character after the opening '[' or '[^', or if it occurs as the
142 * last character before the closing ']', then it is taken as a
143 * literal. Thus "[a\-b]", "[-ab]", and "[ab-]" all indicate the same
144 * set of three characters, 'a', 'b', and '-'.
146 * <p>Sets may be intersected using the '&' operator or the asymmetric
147 * set difference may be taken using the '-' operator, for example,
148 * "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters
149 * with values less than 4096. Operators ('&' and '|') have equal
150 * precedence and bind left-to-right. Thus
151 * "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to
152 * "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]". This only really matters for
153 * difference; intersection is commutative.
156 * <tr valign=top><td nowrap><code>[a]</code><td>The set containing 'a'
157 * <tr valign=top><td nowrap><code>[a-z]</code><td>The set containing 'a'
158 * through 'z' and all letters in between, in Unicode order
159 * <tr valign=top><td nowrap><code>[^a-z]</code><td>The set containing
160 * all characters but 'a' through 'z',
161 * that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF
162 * <tr valign=top><td nowrap><code>[[<em>pat1</em>][<em>pat2</em>]]</code>
163 * <td>The union 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 intersection of sets specified by <em>pat1</em> and <em>pat2</em>
166 * <tr valign=top><td nowrap><code>[[<em>pat1</em>]-[<em>pat2</em>]]</code>
167 * <td>The asymmetric difference of sets specified by <em>pat1</em> and
169 * <tr valign=top><td nowrap><code>[:Lu:] or \\p{Lu}</code>
170 * <td>The set of characters having the specified
171 * Unicode property; in
172 * this case, Unicode uppercase letters
173 * <tr valign=top><td nowrap><code>[:^Lu:] or \\P{Lu}</code>
174 * <td>The set of characters <em>not</em> having the given
178 * <p><b>Warning</b>: you cannot add an empty string ("") to a UnicodeSet.</p>
180 * <p><b>Formal syntax</b></p>
182 * \htmlonly<blockquote>\endhtmlonly
185 * <td nowrap valign="top" align="right"><code>pattern := </code></td>
186 * <td valign="top"><code>('[' '^'? item* ']') |
187 * property</code></td>
190 * <td nowrap valign="top" align="right"><code>item := </code></td>
191 * <td valign="top"><code>char | (char '-' char) | pattern-expr<br>
195 * <td nowrap valign="top" align="right"><code>pattern-expr := </code></td>
196 * <td valign="top"><code>pattern | pattern-expr pattern |
197 * pattern-expr op pattern<br>
201 * <td nowrap valign="top" align="right"><code>op := </code></td>
202 * <td valign="top"><code>'&' | '-'<br>
206 * <td nowrap valign="top" align="right"><code>special := </code></td>
207 * <td valign="top"><code>'[' | ']' | '-'<br>
211 * <td nowrap valign="top" align="right"><code>char := </code></td>
212 * <td valign="top"><em>any character that is not</em><code> special<br>
213 * | ('\' </code><em>any character</em><code>)<br>
214 * | ('\\u' hex hex hex hex)<br>
218 * <td nowrap valign="top" align="right"><code>hex := </code></td>
219 * <td valign="top"><em>any character for which
220 * </em><code>Character.digit(c, 16)</code><em>
221 * returns a non-negative result</em></td>
224 * <td nowrap valign="top" align="right"><code>property := </code></td>
225 * <td valign="top"><em>a Unicode property set pattern</em></td>
231 * <td>Legend: <table>
233 * <td nowrap valign="top"><code>a := b</code></td>
234 * <td width="20" valign="top"> </td>
235 * <td valign="top"><code>a</code> may be replaced by <code>b</code> </td>
238 * <td nowrap valign="top"><code>a?</code></td>
239 * <td valign="top"></td>
240 * <td valign="top">zero or one instance of <code>a</code><br>
244 * <td nowrap valign="top"><code>a*</code></td>
245 * <td valign="top"></td>
246 * <td valign="top">one or more instances of <code>a</code><br>
250 * <td nowrap valign="top"><code>a | b</code></td>
251 * <td valign="top"></td>
252 * <td valign="top">either <code>a</code> or <code>b</code><br>
256 * <td nowrap valign="top"><code>'a'</code></td>
257 * <td valign="top"></td>
258 * <td valign="top">the literal string between the quotes </td>
264 * \htmlonly</blockquote>\endhtmlonly
267 * - Most UnicodeSet methods do not take a UErrorCode parameter because
268 * there are usually very few opportunities for failure other than a shortage
269 * of memory, error codes in low-level C++ string methods would be inconvenient,
270 * and the error code as the last parameter (ICU convention) would prevent
271 * the use of default parameter values.
272 * Instead, such methods set the UnicodeSet into a "bogus" state
273 * (see isBogus()) if an error occurs.
278 class U_COMMON_API UnicodeSet U_FINAL
: public UnicodeFilter
{
281 * Enough for sets with few ranges.
282 * For example, White_Space has 10 ranges, list length 21.
284 static constexpr int32_t INITIAL_CAPACITY
= 25;
286 static constexpr uint8_t kIsBogus
= 1; // This set is bogus (i.e. not valid)
288 UChar32
* list
= stackList
; // MUST be terminated with HIGH
289 int32_t capacity
= INITIAL_CAPACITY
; // capacity of list
290 int32_t len
= 1; // length of list used; 1 <= len <= capacity
291 uint8_t fFlags
= 0; // Bit flag (see constants above)
293 BMPSet
*bmpSet
= nullptr; // The set is frozen iff either bmpSet or stringSpan is not NULL.
294 UChar32
* buffer
= nullptr; // internal buffer, may be NULL
295 int32_t bufferCapacity
= 0; // capacity of buffer
298 * The pattern representation of this set. This may not be the
299 * most economical pattern. It is the pattern supplied to
300 * applyPattern(), with variables substituted and whitespace
301 * removed. For sets constructed without applyPattern(), or
302 * modified using the non-pattern API, this string will be empty,
303 * indicating that toPattern() must generate a pattern
304 * representation from the inversion list.
306 char16_t *pat
= nullptr;
309 UVector
* strings
= nullptr; // maintained in sorted order
310 UnicodeSetStringSpan
*stringSpan
= nullptr;
313 * Initial list array.
314 * Avoids some heap allocations, and list is never nullptr.
315 * Increases the object size a bit.
317 UChar32 stackList
[INITIAL_CAPACITY
];
321 * Determine if this object contains a valid set.
322 * A bogus set has no value. It is different from an empty set.
323 * It can be used to indicate that no set value is available.
325 * @return TRUE if the set is bogus/invalid, FALSE otherwise
329 inline UBool
isBogus(void) const;
332 * Make this UnicodeSet object invalid.
333 * The string will test TRUE with isBogus().
335 * A bogus set has no value. It is different from an empty set.
336 * It can be used to indicate that no set value is available.
338 * This utility function is used throughout the UnicodeSet
339 * implementation to indicate that a UnicodeSet operation failed,
340 * and may be used in other functions,
341 * especially but not exclusively when such functions do not
342 * take a UErrorCode for simplicity.
353 * Minimum value that can be stored in a UnicodeSet.
359 * Maximum value that can be stored in a UnicodeSet.
365 //----------------------------------------------------------------
367 //----------------------------------------------------------------
372 * Constructs an empty set.
378 * Constructs a set containing the given range. If <code>end <
379 * start</code> then an empty set is created.
381 * @param start first character, inclusive, of range
382 * @param end last character, inclusive, of range
385 UnicodeSet(UChar32 start
, UChar32 end
);
387 #ifndef U_HIDE_INTERNAL_API
391 enum ESerialization
{
392 kSerialized
/* result of serialize() */
396 * Constructs a set from the output of serialize().
398 * @param buffer the 16 bit array
399 * @param bufferLen the original length returned from serialize()
400 * @param serialization the value 'kSerialized'
401 * @param status error code
405 UnicodeSet(const uint16_t buffer
[], int32_t bufferLen
,
406 ESerialization serialization
, UErrorCode
&status
);
407 #endif /* 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 status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
414 * contains a syntax error.
417 UnicodeSet(const UnicodeString
& pattern
,
420 #ifndef U_HIDE_INTERNAL_API
422 * Constructs a set from the given pattern. See the class
423 * description for the syntax of the pattern language.
424 * @param pattern a string specifying what characters are in the set
425 * @param options bitmask for options to apply to the pattern.
426 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
427 * @param symbols a symbol table mapping variable names to values
428 * and stand-in characters to UnicodeSets; may be NULL
429 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
430 * contains a syntax error.
433 UnicodeSet(const UnicodeString
& pattern
,
435 const SymbolTable
* symbols
,
437 #endif /* U_HIDE_INTERNAL_API */
440 * Constructs a set from the given pattern. See the class description
441 * for the syntax of the pattern language.
442 * @param pattern a string specifying what characters are in the set
443 * @param pos on input, the position in pattern at which to start parsing.
444 * On output, the position after the last character parsed.
445 * @param options bitmask for options to apply to the pattern.
446 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
447 * @param symbols a symbol table mapping variable names to values
448 * and stand-in characters to UnicodeSets; may be NULL
449 * @param status input-output error code
452 UnicodeSet(const UnicodeString
& pattern
, ParsePosition
& pos
,
454 const SymbolTable
* symbols
,
458 * Constructs a set that is identical to the given UnicodeSet.
461 UnicodeSet(const UnicodeSet
& o
);
467 virtual ~UnicodeSet();
470 * Assigns this object to be a copy of another.
471 * A frozen set will not be modified.
474 UnicodeSet
& operator=(const UnicodeSet
& o
);
477 * Compares the specified object with this set for equality. Returns
478 * <tt>true</tt> if the two sets
479 * have the same size, and every member of the specified set is
480 * contained in this set (or equivalently, every member of this set is
481 * contained in the specified set).
483 * @param o set to be compared for equality with this set.
484 * @return <tt>true</tt> if the specified set is equal to this set.
487 virtual UBool
operator==(const UnicodeSet
& o
) const;
490 * Compares the specified object with this set for equality. Returns
491 * <tt>true</tt> if the specified set is not equal to this set.
494 inline UBool
operator!=(const UnicodeSet
& o
) const;
497 * Returns a copy of this object. All UnicodeFunctor objects have
498 * to support cloning in order to allow classes using
499 * UnicodeFunctors, such as Transliterator, to implement cloning.
500 * If this set is frozen, then the clone will be frozen as well.
501 * Use cloneAsThawed() for a mutable clone of a frozen set.
505 virtual UnicodeFunctor
* clone() const;
508 * Returns the hash code value for this set.
510 * @return the hash code value for this set.
511 * @see Object#hashCode()
514 virtual int32_t hashCode(void) const;
517 * Get a UnicodeSet pointer from a USet
519 * @param uset a USet (the ICU plain C type for UnicodeSet)
520 * @return the corresponding UnicodeSet pointer.
524 inline static UnicodeSet
*fromUSet(USet
*uset
);
527 * Get a UnicodeSet pointer from a const USet
529 * @param uset a const USet (the ICU plain C type for UnicodeSet)
530 * @return the corresponding UnicodeSet pointer.
534 inline static const UnicodeSet
*fromUSet(const USet
*uset
);
537 * Produce a USet * pointer for this UnicodeSet.
538 * USet is the plain C type for UnicodeSet
540 * @return a USet pointer for this UnicodeSet
543 inline USet
*toUSet();
547 * Produce a const USet * pointer for this UnicodeSet.
548 * USet is the plain C type for UnicodeSet
550 * @return a const USet pointer for this UnicodeSet
553 inline const USet
* toUSet() const;
556 //----------------------------------------------------------------
558 //----------------------------------------------------------------
561 * Determines whether the set has been frozen (made immutable) or not.
562 * See the ICU4J Freezable interface for details.
563 * @return TRUE/FALSE for whether the set has been frozen
568 inline UBool
isFrozen() const;
571 * Freeze the set (make it immutable).
572 * Once frozen, it cannot be unfrozen and is therefore thread-safe
573 * until it is deleted.
574 * See the ICU4J Freezable interface for details.
575 * Freezing the set may also make some operations faster, for example
576 * contains() and span().
577 * A frozen set will not be modified. (It remains frozen.)
583 UnicodeFunctor
*freeze();
586 * Clone the set and make the clone mutable.
587 * See the ICU4J Freezable interface for details.
588 * @return the mutable clone
593 UnicodeFunctor
*cloneAsThawed() const;
595 //----------------------------------------------------------------
597 //----------------------------------------------------------------
600 * Make this object represent the range `start - end`.
601 * If `end > start` then this object is set to an empty range.
602 * A frozen set will not be modified.
604 * @param start first character in the set, inclusive
605 * @param end last character in the set, inclusive
608 UnicodeSet
& set(UChar32 start
, UChar32 end
);
611 * Return true if the given position, in the given pattern, appears
612 * to be the start of a UnicodeSet pattern.
615 static UBool
resemblesPattern(const UnicodeString
& pattern
,
619 * Modifies this set to represent the set specified by the given
620 * pattern, ignoring Unicode Pattern_White_Space characters.
621 * See the class description for the syntax of the pattern language.
622 * A frozen set will not be modified.
623 * @param pattern a string specifying what characters are in the set
624 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
625 * contains a syntax error.
626 * <em> Empties the set passed before applying the pattern.</em>
627 * @return a reference to this
630 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
633 #ifndef U_HIDE_INTERNAL_API
635 * Modifies this set to represent the set specified by the given
636 * pattern, optionally ignoring Unicode Pattern_White_Space characters.
637 * See the class description for the syntax of the pattern language.
638 * A frozen set will not be modified.
639 * @param pattern a string specifying what characters are in the set
640 * @param options bitmask for options to apply to the pattern.
641 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
642 * @param symbols a symbol table mapping variable names to
643 * values and stand-ins to UnicodeSets; may be NULL
644 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
645 * contains a syntax error.
646 *<em> Empties the set passed before applying the pattern.</em>
647 * @return a reference to this
650 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
652 const SymbolTable
* symbols
,
654 #endif /* U_HIDE_INTERNAL_API */
657 * Parses the given pattern, starting at the given position. The
658 * character at pattern.charAt(pos.getIndex()) must be '[', or the
659 * parse fails. Parsing continues until the corresponding closing
660 * ']'. If a syntax error is encountered between the opening and
661 * closing brace, the parse fails. Upon return from a successful
662 * parse, the ParsePosition is updated to point to the character
663 * following the closing ']', and a StringBuffer containing a
664 * pairs list for the parsed pattern is returned. This method calls
665 * itself recursively to parse embedded subpatterns.
666 *<em> Empties the set passed before applying the pattern.</em>
667 * A frozen set will not be modified.
669 * @param pattern the string containing the pattern to be parsed.
670 * The portion of the string from pos.getIndex(), which must be a
671 * '[', to the corresponding closing ']', is parsed.
672 * @param pos upon entry, the position at which to being parsing.
673 * The character at pattern.charAt(pos.getIndex()) must be a '['.
674 * Upon return from a successful parse, pos.getIndex() is either
675 * the character after the closing ']' of the parsed pattern, or
676 * pattern.length() if the closing ']' is the last character of
677 * the pattern string.
678 * @param options bitmask for options to apply to the pattern.
679 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
680 * @param symbols a symbol table mapping variable names to
681 * values and stand-ins to UnicodeSets; may be NULL
682 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
683 * contains a syntax error.
684 * @return a reference to this
687 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
690 const SymbolTable
* symbols
,
694 * Returns a string representation of this set. If the result of
695 * calling this function is passed to a UnicodeSet constructor, it
696 * will produce another set that is equal to this one.
697 * A frozen set will not be modified.
698 * @param result the string to receive the rules. Previous
699 * contents will be deleted.
700 * @param escapeUnprintable if TRUE then convert unprintable
701 * character to their hex escape representations, \\uxxxx or
702 * \\Uxxxxxxxx. Unprintable characters are those other than
703 * U+000A, U+0020..U+007E.
706 virtual UnicodeString
& toPattern(UnicodeString
& result
,
707 UBool escapeUnprintable
= FALSE
) const;
710 * Modifies this set to contain those code points which have the given value
711 * for the given binary or enumerated property, as returned by
712 * u_getIntPropertyValue. Prior contents of this set are lost.
713 * A frozen set will not be modified.
715 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
716 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
717 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
719 * @param value a value in the range u_getIntPropertyMinValue(prop)..
720 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
721 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
722 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
723 * categories such as [:L:] to be represented.
725 * @param ec error code input/output parameter
727 * @return a reference to this set
731 UnicodeSet
& applyIntPropertyValue(UProperty prop
,
736 * Modifies this set to contain those code points which have the
737 * given value for the given property. Prior contents of this
739 * A frozen set will not be modified.
741 * @param prop a property alias, either short or long. The name is matched
742 * loosely. See PropertyAliases.txt for names and a description of loose
743 * matching. If the value string is empty, then this string is interpreted
744 * as either a General_Category value alias, a Script value alias, a binary
745 * property alias, or a special ID. Special IDs are matched loosely and
746 * correspond to the following sets:
748 * "ANY" = [\\u0000-\\U0010FFFF],
749 * "ASCII" = [\\u0000-\\u007F],
750 * "Assigned" = [:^Cn:].
752 * @param value a value alias, either short or long. The name is matched
753 * loosely. See PropertyValueAliases.txt for names and a description of
754 * loose matching. In addition to aliases listed, numeric values and
755 * canonical combining classes may be expressed numerically, e.g., ("nv",
756 * "0.5") or ("ccc", "220"). The value string may also be empty.
758 * @param ec error code input/output parameter
760 * @return a reference to this set
764 UnicodeSet
& applyPropertyAlias(const UnicodeString
& prop
,
765 const UnicodeString
& value
,
769 * Returns the number of elements in this set (its cardinality).
770 * Note than the elements of a set may include both individual
771 * codepoints and strings.
773 * @return the number of elements in this set (its cardinality).
776 virtual int32_t size(void) const;
779 * Returns <tt>true</tt> if this set contains no elements.
781 * @return <tt>true</tt> if this set contains no elements.
784 virtual UBool
isEmpty(void) const;
787 * Returns true if this set contains the given character.
788 * This function works faster with a frozen set.
789 * @param c character to be checked for containment
790 * @return true if the test condition is met
793 virtual UBool
contains(UChar32 c
) const;
796 * Returns true if this set contains every character
797 * of the given range.
798 * @param start first character, inclusive, of the range
799 * @param end last character, inclusive, of the range
800 * @return true if the test condition is met
803 virtual UBool
contains(UChar32 start
, UChar32 end
) const;
806 * Returns <tt>true</tt> if this set contains the given
807 * multicharacter string.
808 * @param s string to be checked for containment
809 * @return <tt>true</tt> if this set contains the specified string
812 UBool
contains(const UnicodeString
& s
) const;
815 * Returns true if this set contains all the characters and strings
817 * @param c set to be checked for containment
818 * @return true if the test condition is met
821 virtual UBool
containsAll(const UnicodeSet
& c
) const;
824 * Returns true if this set contains all the characters
825 * of the given string.
826 * @param s string containing characters to be checked for containment
827 * @return true if the test condition is met
830 UBool
containsAll(const UnicodeString
& s
) const;
833 * Returns true if this set contains none of the characters
834 * of the given range.
835 * @param start first character, inclusive, of the range
836 * @param end last character, inclusive, of the range
837 * @return true if the test condition is met
840 UBool
containsNone(UChar32 start
, UChar32 end
) const;
843 * Returns true if this set contains none of the characters and strings
845 * @param c set to be checked for containment
846 * @return true if the test condition is met
849 UBool
containsNone(const UnicodeSet
& c
) const;
852 * Returns true if this set contains none of the characters
853 * of the given string.
854 * @param s string containing characters to be checked for containment
855 * @return true if the test condition is met
858 UBool
containsNone(const UnicodeString
& s
) const;
861 * Returns true if this set contains one or more of the characters
862 * in the given range.
863 * @param start first character, inclusive, of the range
864 * @param end last character, inclusive, of the range
865 * @return true if the condition is met
868 inline UBool
containsSome(UChar32 start
, UChar32 end
) const;
871 * Returns true if this set contains one or more of the characters
872 * and strings of the given set.
873 * @param s The set to be checked for containment
874 * @return true if the condition is met
877 inline UBool
containsSome(const UnicodeSet
& s
) const;
880 * Returns true if this set contains one or more of the characters
881 * of the given string.
882 * @param s string containing characters to be checked for containment
883 * @return true if the condition is met
886 inline UBool
containsSome(const UnicodeString
& s
) const;
889 * Returns the length of the initial substring of the input string which
890 * consists only of characters and strings that are contained in this set
891 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
892 * or only of characters and strings that are not contained
893 * in this set (USET_SPAN_NOT_CONTAINED).
894 * See USetSpanCondition for details.
895 * Similar to the strspn() C library function.
896 * Unpaired surrogates are treated according to contains() of their surrogate code points.
897 * This function works faster with a frozen set and with a non-negative string length argument.
898 * @param s start of the string
899 * @param length of the string; can be -1 for NUL-terminated
900 * @param spanCondition specifies the containment condition
901 * @return the length of the initial substring according to the spanCondition;
902 * 0 if the start of the string does not fit the spanCondition
904 * @see USetSpanCondition
906 int32_t span(const char16_t *s
, int32_t length
, USetSpanCondition spanCondition
) const;
909 * Returns the end of the substring of the input string according to the USetSpanCondition.
910 * Same as <code>start+span(s.getBuffer()+start, s.length()-start, spanCondition)</code>
911 * after pinning start to 0<=start<=s.length().
912 * @param s the string
913 * @param start the start index in the string for the span operation
914 * @param spanCondition specifies the containment condition
915 * @return the exclusive end of the substring according to the spanCondition;
916 * the substring s.tempSubStringBetween(start, end) fulfills the spanCondition
918 * @see USetSpanCondition
920 inline int32_t span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const;
923 * Returns the start of the trailing substring of the input string which
924 * consists only of characters and strings that are contained in this set
925 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
926 * or only of characters and strings that are not contained
927 * in this set (USET_SPAN_NOT_CONTAINED).
928 * See USetSpanCondition for details.
929 * Unpaired surrogates are treated according to contains() of their surrogate code points.
930 * This function works faster with a frozen set and with a non-negative string length argument.
931 * @param s start of the string
932 * @param length of the string; can be -1 for NUL-terminated
933 * @param spanCondition specifies the containment condition
934 * @return the start of the trailing substring according to the spanCondition;
935 * the string length if the end of the string does not fit the spanCondition
937 * @see USetSpanCondition
939 int32_t spanBack(const char16_t *s
, int32_t length
, USetSpanCondition spanCondition
) const;
942 * Returns the start of the substring of the input string according to the USetSpanCondition.
943 * Same as <code>spanBack(s.getBuffer(), limit, spanCondition)</code>
944 * after pinning limit to 0<=end<=s.length().
945 * @param s the string
946 * @param limit the exclusive-end index in the string for the span operation
947 * (use s.length() or INT32_MAX for spanning back from the end of the string)
948 * @param spanCondition specifies the containment condition
949 * @return the start of the substring according to the spanCondition;
950 * the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition
952 * @see USetSpanCondition
954 inline int32_t spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const;
957 * Returns the length of the initial substring of the input string which
958 * consists only of characters and strings that are contained in this set
959 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
960 * or only of characters and strings that are not contained
961 * in this set (USET_SPAN_NOT_CONTAINED).
962 * See USetSpanCondition for details.
963 * Similar to the strspn() C library function.
964 * Malformed byte sequences are treated according to contains(0xfffd).
965 * This function works faster with a frozen set and with a non-negative string length argument.
966 * @param s start of the string (UTF-8)
967 * @param length of the string; can be -1 for NUL-terminated
968 * @param spanCondition specifies the containment condition
969 * @return the length of the initial substring according to the spanCondition;
970 * 0 if the start of the string does not fit the spanCondition
972 * @see USetSpanCondition
974 int32_t spanUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
977 * Returns the start of the trailing substring of the input string which
978 * consists only of characters and strings that are contained in this set
979 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
980 * or only of characters and strings that are not contained
981 * in this set (USET_SPAN_NOT_CONTAINED).
982 * See USetSpanCondition for details.
983 * Malformed byte sequences are treated according to contains(0xfffd).
984 * This function works faster with a frozen set and with a non-negative string length argument.
985 * @param s start of the string (UTF-8)
986 * @param length of the string; can be -1 for NUL-terminated
987 * @param spanCondition specifies the containment condition
988 * @return the start of the trailing substring according to the spanCondition;
989 * the string length if the end of the string does not fit the spanCondition
991 * @see USetSpanCondition
993 int32_t spanBackUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
996 * Implement UnicodeMatcher::matches()
999 virtual UMatchDegree
matches(const Replaceable
& text
,
1006 * Returns the longest match for s in text at the given position.
1007 * If limit > start then match forward from start+1 to limit
1008 * matching all characters except s.charAt(0). If limit < start,
1009 * go backward starting from start-1 matching all characters
1010 * except s.charAt(s.length()-1). This method assumes that the
1011 * first character, text.charAt(start), matches s, so it does not
1013 * @param text the text to match
1014 * @param start the first character to match. In the forward
1015 * direction, text.charAt(start) is matched against s.charAt(0).
1016 * In the reverse direction, it is matched against
1017 * s.charAt(s.length()-1).
1018 * @param limit the limit offset for matching, either last+1 in
1019 * the forward direction, or last-1 in the reverse direction,
1020 * where last is the index of the last character to match.
1022 * @return If part of s matches up to the limit, return |limit -
1023 * start|. If all of s matches before reaching the limit, return
1024 * s.length(). If there is a mismatch between s and text, return
1027 static int32_t matchRest(const Replaceable
& text
,
1028 int32_t start
, int32_t limit
,
1029 const UnicodeString
& s
);
1032 * Returns the smallest value i such that c < list[i]. Caller
1033 * must ensure that c is a legal value or this method will enter
1034 * an infinite loop. This method performs a binary search.
1035 * @param c a character in the range MIN_VALUE..MAX_VALUE
1037 * @return the smallest integer i in the range 0..len-1,
1038 * inclusive, such that c < list[i]
1040 int32_t findCodePoint(UChar32 c
) const;
1045 * Implementation of UnicodeMatcher API. Union the set of all
1046 * characters that may be matched by this object into the given
1048 * @param toUnionTo the set into which to union the source characters
1051 virtual void addMatchSetTo(UnicodeSet
& toUnionTo
) const;
1054 * Returns the index of the given character within this set, where
1055 * the set is ordered by ascending code point. If the character
1056 * is not in this set, return -1. The inverse of this method is
1057 * <code>charAt()</code>.
1058 * @return an index from 0..size()-1, or -1
1061 int32_t indexOf(UChar32 c
) const;
1064 * Returns the character at the given index within this set, where
1065 * the set is ordered by ascending code point. If the index is
1066 * out of range, return (UChar32)-1. The inverse of this method is
1067 * <code>indexOf()</code>.
1068 * @param index an index from 0..size()-1
1069 * @return the character at the given index, or (UChar32)-1.
1072 UChar32
charAt(int32_t index
) const;
1075 * Adds the specified range to this set if it is not already
1076 * present. If this set already contains the specified range,
1077 * the call leaves this set unchanged. If <code>end > start</code>
1078 * then an empty range is added, leaving the set unchanged.
1079 * This is equivalent to a boolean logic OR, or a set UNION.
1080 * A frozen set will not be modified.
1082 * @param start first character, inclusive, of range to be added
1084 * @param end last character, inclusive, of range to be added
1088 virtual UnicodeSet
& add(UChar32 start
, UChar32 end
);
1091 * Adds the specified character to this set if it is not already
1092 * present. If this set already contains the specified character,
1093 * the call leaves this set unchanged.
1094 * A frozen set will not be modified.
1097 UnicodeSet
& add(UChar32 c
);
1100 * Adds the specified multicharacter to this set if it is not already
1101 * present. If this set already contains the multicharacter,
1102 * the call leaves this set unchanged.
1103 * Thus "ch" => {"ch"}
1104 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1105 * A frozen set will not be modified.
1106 * @param s the source string
1107 * @return this object, for chaining
1110 UnicodeSet
& add(const UnicodeString
& s
);
1114 * @return a code point IF the string consists of a single one.
1115 * otherwise returns -1.
1116 * @param s string to test
1118 static int32_t getSingleCP(const UnicodeString
& s
);
1120 void _add(const UnicodeString
& s
);
1124 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
1125 * If this set already any particular character, it has no effect on that character.
1126 * A frozen set will not be modified.
1127 * @param s the source string
1128 * @return this object, for chaining
1131 UnicodeSet
& addAll(const UnicodeString
& s
);
1134 * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
1135 * If this set already any particular character, it has no effect on that character.
1136 * A frozen set will not be modified.
1137 * @param s the source string
1138 * @return this object, for chaining
1141 UnicodeSet
& retainAll(const UnicodeString
& s
);
1144 * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
1145 * If this set already any particular character, it has no effect on that character.
1146 * A frozen set will not be modified.
1147 * @param s the source string
1148 * @return this object, for chaining
1151 UnicodeSet
& complementAll(const UnicodeString
& s
);
1154 * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
1155 * If this set already any particular character, it has no effect on that character.
1156 * A frozen set will not be modified.
1157 * @param s the source string
1158 * @return this object, for chaining
1161 UnicodeSet
& removeAll(const UnicodeString
& s
);
1164 * Makes a set from a multicharacter string. Thus "ch" => {"ch"}
1165 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1166 * @param s the source string
1167 * @return a newly created set containing the given string.
1168 * The caller owns the return object and is responsible for deleting it.
1171 static UnicodeSet
* U_EXPORT2
createFrom(const UnicodeString
& s
);
1175 * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
1176 * @param s the source string
1177 * @return a newly created set containing the given characters
1178 * The caller owns the return object and is responsible for deleting it.
1181 static UnicodeSet
* U_EXPORT2
createFromAll(const UnicodeString
& s
);
1184 * Retain only the elements in this set that are contained in the
1185 * specified range. If <code>end > start</code> then an empty range is
1186 * retained, leaving the set empty. This is equivalent to
1187 * a boolean logic AND, or a set INTERSECTION.
1188 * A frozen set will not be modified.
1190 * @param start first character, inclusive, of range to be retained
1192 * @param end last character, inclusive, of range to be retained
1196 virtual UnicodeSet
& retain(UChar32 start
, UChar32 end
);
1200 * Retain the specified character from this set if it is present.
1201 * A frozen set will not be modified.
1204 UnicodeSet
& retain(UChar32 c
);
1207 * Removes the specified range from this set if it is present.
1208 * The set will not contain the specified range once the call
1209 * returns. If <code>end > start</code> then an empty range is
1210 * removed, leaving the set unchanged.
1211 * A frozen set will not be modified.
1213 * @param start first character, inclusive, of range to be removed
1215 * @param end last character, inclusive, of range to be removed
1219 virtual UnicodeSet
& remove(UChar32 start
, UChar32 end
);
1222 * Removes the specified character from this set if it is present.
1223 * The set will not contain the specified range once the call
1225 * A frozen set will not be modified.
1228 UnicodeSet
& remove(UChar32 c
);
1231 * Removes the specified string from this set if it is present.
1232 * The set will not contain the specified character once the call
1234 * A frozen set will not be modified.
1235 * @param s the source string
1236 * @return this object, for chaining
1239 UnicodeSet
& remove(const UnicodeString
& s
);
1242 * Inverts this set. This operation modifies this set so that
1243 * its value is its complement. This is equivalent to
1244 * <code>complement(MIN_VALUE, MAX_VALUE)</code>.
1245 * A frozen set will not be modified.
1248 virtual UnicodeSet
& complement(void);
1251 * Complements the specified range in this set. Any character in
1252 * the range will be removed if it is in this set, or will be
1253 * added if it is not in this set. If <code>end > start</code>
1254 * then an empty range is complemented, leaving the set unchanged.
1255 * This is equivalent to a boolean logic XOR.
1256 * A frozen set will not be modified.
1258 * @param start first character, inclusive, of range to be removed
1260 * @param end last character, inclusive, of range to be removed
1264 virtual UnicodeSet
& complement(UChar32 start
, UChar32 end
);
1267 * Complements the specified character in this set. The character
1268 * will be removed if it is in this set, or will be added if it is
1270 * A frozen set will not be modified.
1273 UnicodeSet
& complement(UChar32 c
);
1276 * Complement the specified string in this set.
1277 * The set will not contain the specified string once the call
1279 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1280 * A frozen set will not be modified.
1281 * @param s the string to complement
1282 * @return this object, for chaining
1285 UnicodeSet
& complement(const UnicodeString
& s
);
1288 * Adds all of the elements in the specified set to this set if
1289 * they're not already present. This operation effectively
1290 * modifies this set so that its value is the <i>union</i> of the two
1291 * sets. The behavior of this operation is unspecified if the specified
1292 * collection is modified while the operation is in progress.
1293 * A frozen set will not be modified.
1295 * @param c set whose elements are to be added to this set.
1296 * @see #add(UChar32, UChar32)
1299 virtual UnicodeSet
& addAll(const UnicodeSet
& c
);
1302 * Retains only the elements in this set that are contained in the
1303 * specified set. In other words, removes from this set all of
1304 * its elements that are not contained in the specified set. This
1305 * operation effectively modifies this set so that its value is
1306 * the <i>intersection</i> of the two sets.
1307 * A frozen set will not be modified.
1309 * @param c set that defines which elements this set will retain.
1312 virtual UnicodeSet
& retainAll(const UnicodeSet
& c
);
1315 * Removes from this set all of its elements that are contained in the
1316 * specified set. This operation effectively modifies this
1317 * set so that its value is the <i>asymmetric set difference</i> of
1319 * A frozen set will not be modified.
1321 * @param c set that defines which elements will be removed from
1325 virtual UnicodeSet
& removeAll(const UnicodeSet
& c
);
1328 * Complements in this set all elements contained in the specified
1329 * set. Any character in the other set will be removed if it is
1330 * in this set, or will be added if it is not in this set.
1331 * A frozen set will not be modified.
1333 * @param c set that defines which elements will be xor'ed from
1337 virtual UnicodeSet
& complementAll(const UnicodeSet
& c
);
1340 * Removes all of the elements from this set. This set will be
1341 * empty after this call returns.
1342 * A frozen set will not be modified.
1345 virtual UnicodeSet
& clear(void);
1348 * Close this set over the given attribute. For the attribute
1349 * USET_CASE, the result is to modify this set so that:
1351 * 1. For each character or string 'a' in this set, all strings or
1352 * characters 'b' such that foldCase(a) == foldCase(b) are added
1355 * 2. For each string 'e' in the resulting set, if e !=
1356 * foldCase(e), 'e' will be removed.
1358 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
1360 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
1361 * == b denotes that the contents are the same, not pointer
1364 * A frozen set will not be modified.
1366 * @param attribute bitmask for attributes to close over.
1367 * Currently only the USET_CASE bit is supported. Any undefined bits
1369 * @return a reference to this set.
1372 UnicodeSet
& closeOver(int32_t attribute
);
1375 * Remove all strings from this set.
1377 * @return a reference to this set.
1380 virtual UnicodeSet
&removeAllStrings();
1383 * Iteration method that returns the number of ranges contained in
1385 * @see #getRangeStart
1389 virtual int32_t getRangeCount(void) const;
1392 * Iteration method that returns the first character in the
1393 * specified range of this set.
1394 * @see #getRangeCount
1398 virtual UChar32
getRangeStart(int32_t index
) const;
1401 * Iteration method that returns the last character in the
1402 * specified range of this set.
1403 * @see #getRangeStart
1407 virtual UChar32
getRangeEnd(int32_t index
) const;
1410 * Serializes this set into an array of 16-bit integers. Serialization
1411 * (currently) only records the characters in the set; multicharacter
1412 * strings are ignored.
1414 * The array has following format (each line is one 16-bit
1417 * length = (n+2*m) | (m!=0?0x8000:0)
1418 * bmpLength = n; present if m!=0
1431 * The array starts with a header. After the header are n bmp
1432 * code points, then m supplementary code points. Either n or m
1433 * or both may be zero. n+2*m is always <= 0x7FFF.
1435 * If there are no supplementary characters (if m==0) then the
1436 * header is one 16-bit integer, 'length', with value n.
1438 * If there are supplementary characters (if m!=0) then the header
1439 * is two 16-bit integers. The first, 'length', has value
1440 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
1442 * After the header the code points are stored in ascending order.
1443 * Supplementary code points are stored as most significant 16
1444 * bits followed by least significant 16 bits.
1446 * @param dest pointer to buffer of destCapacity 16-bit integers.
1447 * May be NULL only if destCapacity is zero.
1448 * @param destCapacity size of dest, or zero. Must not be negative.
1449 * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR
1450 * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if
1451 * n+2*m+(m!=0?2:1) > destCapacity.
1452 * @return the total length of the serialized format, including
1453 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1454 * than U_BUFFER_OVERFLOW_ERROR.
1457 int32_t serialize(uint16_t *dest
, int32_t destCapacity
, UErrorCode
& ec
) const;
1460 * Reallocate this objects internal structures to take up the least
1461 * possible space, without changing this object's value.
1462 * A frozen set will not be modified.
1465 virtual UnicodeSet
& compact();
1468 * Return the class ID for this class. This is useful only for
1469 * comparing to a return value from getDynamicClassID(). For example:
1471 * . Base* polymorphic_pointer = createPolymorphicObject();
1472 * . if (polymorphic_pointer->getDynamicClassID() ==
1473 * . Derived::getStaticClassID()) ...
1475 * @return The class ID for all objects of this class.
1478 static UClassID U_EXPORT2
getStaticClassID(void);
1481 * Implement UnicodeFunctor API.
1483 * @return The class ID for this object. All objects of a given
1484 * class have the same class ID. Objects of other classes have
1485 * different class IDs.
1488 virtual UClassID
getDynamicClassID(void) const;
1492 // Private API for the USet API
1494 friend class USetAccess
;
1496 const UnicodeString
* getString(int32_t index
) const;
1498 //----------------------------------------------------------------
1499 // RuleBasedTransliterator support
1500 //----------------------------------------------------------------
1505 * Returns <tt>true</tt> if this set contains any character whose low byte
1506 * is the given value. This is used by <tt>RuleBasedTransliterator</tt> for
1509 virtual UBool
matchesIndexValue(uint8_t v
) const;
1512 friend class RBBIRuleScanner
;
1513 friend class RBBIRuleScanner57
;
1515 //----------------------------------------------------------------
1516 // Implementation: Clone as thawed (see ICU4J Freezable)
1517 //----------------------------------------------------------------
1519 UnicodeSet(const UnicodeSet
& o
, UBool
/* asThawed */);
1520 UnicodeSet
& copyFrom(const UnicodeSet
& o
, UBool asThawed
);
1522 //----------------------------------------------------------------
1523 // Implementation: Pattern parsing
1524 //----------------------------------------------------------------
1526 void applyPatternIgnoreSpace(const UnicodeString
& pattern
,
1528 const SymbolTable
* symbols
,
1529 UErrorCode
& status
);
1531 void applyPattern(RuleCharacterIterator
& chars
,
1532 const SymbolTable
* symbols
,
1533 UnicodeString
& rebuiltPat
,
1535 UnicodeSet
& (UnicodeSet::*caseClosure
)(int32_t attribute
),
1539 //----------------------------------------------------------------
1540 // Implementation: Utility methods
1541 //----------------------------------------------------------------
1543 static int32_t nextCapacity(int32_t minCapacity
);
1545 bool ensureCapacity(int32_t newLen
);
1547 bool ensureBufferCapacity(int32_t newLen
);
1549 void swapBuffers(void);
1551 UBool
allocateStrings(UErrorCode
&status
);
1552 UBool
hasStrings() const;
1553 int32_t stringsSize() const;
1554 UBool
stringsContains(const UnicodeString
&s
) const;
1556 UnicodeString
& _toPattern(UnicodeString
& result
,
1557 UBool escapeUnprintable
) const;
1559 UnicodeString
& _generatePattern(UnicodeString
& result
,
1560 UBool escapeUnprintable
) const;
1562 static void _appendToPat(UnicodeString
& buf
, const UnicodeString
& s
, UBool escapeUnprintable
);
1564 static void _appendToPat(UnicodeString
& buf
, UChar32 c
, UBool escapeUnprintable
);
1566 //----------------------------------------------------------------
1567 // Implementation: Fundamental operators
1568 //----------------------------------------------------------------
1570 void exclusiveOr(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1572 void add(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1574 void retain(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1577 * Return true if the given position, in the given pattern, appears
1578 * to be the start of a property set pattern [:foo:], \\p{foo}, or
1579 * \\P{foo}, or \\N{name}.
1581 static UBool
resemblesPropertyPattern(const UnicodeString
& pattern
,
1584 static UBool
resemblesPropertyPattern(RuleCharacterIterator
& chars
,
1588 * Parse the given property pattern at the given parse position
1589 * and set this UnicodeSet to the result.
1591 * The original design document is out of date, but still useful.
1592 * Ignore the property and value names:
1593 * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/unicodeset_properties.html
1595 * Recognized syntax:
1597 * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]"
1598 * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P"
1599 * \\N{name} - white space not allowed within "\\N"
1601 * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored.
1602 * Case is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading
1603 * and trailing space is deleted, and internal runs of whitespace
1604 * are collapsed to a single space.
1606 * We support binary properties, enumerated properties, and the
1607 * following non-enumerated properties:
1613 * @param pattern the pattern string
1614 * @param ppos on entry, the position at which to begin parsing.
1615 * This should be one of the locations marked '^':
1617 * [:blah:] \\p{blah} \\P{blah} \\N{name}
1620 * On return, the position after the last character parsed, that is,
1621 * the locations marked '%'. If the parse fails, ppos is returned
1624 * @return a reference to this.
1626 UnicodeSet
& applyPropertyPattern(const UnicodeString
& pattern
,
1627 ParsePosition
& ppos
,
1630 void applyPropertyPattern(RuleCharacterIterator
& chars
,
1631 UnicodeString
& rebuiltPat
,
1634 static const UnicodeSet
* getInclusions(int32_t src
, UErrorCode
&status
);
1637 * A filter that returns TRUE if the given code point should be
1638 * included in the UnicodeSet being constructed.
1640 typedef UBool (*Filter
)(UChar32 codePoint
, void* context
);
1643 * Given a filter, set this UnicodeSet to the code points
1644 * contained by that filter. The filter MUST be
1645 * property-conformant. That is, if it returns value v for one
1646 * code point, then it must return v for all affiliated code
1647 * points, as defined by the inclusions list. See
1649 * src is a UPropertySource value.
1651 void applyFilter(Filter filter
,
1653 const UnicodeSet
* inclusions
,
1654 UErrorCode
&status
);
1656 #ifndef U_HIDE_DRAFT_API // Skipped: ucpmap.h is draft only.
1657 void applyIntPropertyValue(const UCPMap
*map
,
1658 UCPMapValueFilter
*filter
, const void *context
,
1659 UErrorCode
&errorCode
);
1660 #endif /* U_HIDE_DRAFT_API */
1663 * Set the new pattern to cache.
1665 void setPattern(const UnicodeString
& newPat
) {
1666 setPattern(newPat
.getBuffer(), newPat
.length());
1668 void setPattern(const char16_t *newPat
, int32_t newPatLen
);
1670 * Release existing cached pattern.
1672 void releasePattern();
1674 friend class UnicodeSetIterator
;
1679 inline UBool
UnicodeSet::operator!=(const UnicodeSet
& o
) const {
1680 return !operator==(o
);
1683 inline UBool
UnicodeSet::isFrozen() const {
1684 return (UBool
)(bmpSet
!=NULL
|| stringSpan
!=NULL
);
1687 inline UBool
UnicodeSet::containsSome(UChar32 start
, UChar32 end
) const {
1688 return !containsNone(start
, end
);
1691 inline UBool
UnicodeSet::containsSome(const UnicodeSet
& s
) const {
1692 return !containsNone(s
);
1695 inline UBool
UnicodeSet::containsSome(const UnicodeString
& s
) const {
1696 return !containsNone(s
);
1699 inline UBool
UnicodeSet::isBogus() const {
1700 return (UBool
)(fFlags
& kIsBogus
);
1703 inline UnicodeSet
*UnicodeSet::fromUSet(USet
*uset
) {
1704 return reinterpret_cast<UnicodeSet
*>(uset
);
1707 inline const UnicodeSet
*UnicodeSet::fromUSet(const USet
*uset
) {
1708 return reinterpret_cast<const UnicodeSet
*>(uset
);
1711 inline USet
*UnicodeSet::toUSet() {
1712 return reinterpret_cast<USet
*>(this);
1715 inline const USet
*UnicodeSet::toUSet() const {
1716 return reinterpret_cast<const USet
*>(this);
1719 inline int32_t UnicodeSet::span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const {
1720 int32_t sLength
=s
.length();
1723 } else if(start
>sLength
) {
1726 return start
+span(s
.getBuffer()+start
, sLength
-start
, spanCondition
);
1729 inline int32_t UnicodeSet::spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const {
1730 int32_t sLength
=s
.length();
1733 } else if(limit
>sLength
) {
1736 return spanBack(s
.getBuffer(), limit
, spanCondition
);
1740 #endif // U_SHOW_CPLUSPLUS_API