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/utypes.h"
18 #if U_SHOW_CPLUSPLUS_API
20 #include "unicode/ucpmap.h"
21 #include "unicode/unifilt.h"
22 #include "unicode/unistr.h"
23 #include "unicode/uset.h"
27 * \brief C++ API: Unicode Set
32 // Forward Declarations.
35 class RBBIRuleScanner
;
37 class UnicodeSetStringSpan
;
39 class RuleCharacterIterator
;
42 * A mutable set of Unicode characters and multicharacter strings. Objects of this class
43 * represent <em>character classes</em> used in regular expressions.
44 * A character specifies a subset of Unicode code points. Legal
45 * code points are U+0000 to U+10FFFF, inclusive.
47 * <p>The UnicodeSet class is not designed to be subclassed.
49 * <p><code>UnicodeSet</code> supports two APIs. The first is the
50 * <em>operand</em> API that allows the caller to modify the value of
51 * a <code>UnicodeSet</code> object. It conforms to Java 2's
52 * <code>java.util.Set</code> interface, although
53 * <code>UnicodeSet</code> does not actually implement that
54 * interface. All methods of <code>Set</code> are supported, with the
55 * modification that they take a character range or single character
56 * instead of an <code>Object</code>, and they take a
57 * <code>UnicodeSet</code> instead of a <code>Collection</code>. The
58 * operand API may be thought of in terms of boolean logic: a boolean
59 * OR is implemented by <code>add</code>, a boolean AND is implemented
60 * by <code>retain</code>, a boolean XOR is implemented by
61 * <code>complement</code> taking an argument, and a boolean NOT is
62 * implemented by <code>complement</code> with no argument. In terms
63 * of traditional set theory function names, <code>add</code> is a
64 * union, <code>retain</code> is an intersection, <code>remove</code>
65 * is an asymmetric difference, and <code>complement</code> with no
66 * argument is a set complement with respect to the superset range
67 * <code>MIN_VALUE-MAX_VALUE</code>
69 * <p>The second API is the
70 * <code>applyPattern()</code>/<code>toPattern()</code> API from the
71 * <code>java.text.Format</code>-derived classes. Unlike the
72 * methods that add characters, add categories, and control the logic
73 * of the set, the method <code>applyPattern()</code> sets all
74 * attributes of a <code>UnicodeSet</code> at once, based on a
77 * <p><b>Pattern syntax</b></p>
79 * Patterns are accepted by the constructors and the
80 * <code>applyPattern()</code> methods and returned by the
81 * <code>toPattern()</code> method. These patterns follow a syntax
82 * similar to that employed by version 8 regular expression character
83 * classes. Here are some simple examples:
85 * \htmlonly<blockquote>\endhtmlonly
88 * <td nowrap valign="top" align="left"><code>[]</code></td>
89 * <td valign="top">No characters</td>
90 * </tr><tr align="top">
91 * <td nowrap valign="top" align="left"><code>[a]</code></td>
92 * <td valign="top">The character 'a'</td>
93 * </tr><tr align="top">
94 * <td nowrap valign="top" align="left"><code>[ae]</code></td>
95 * <td valign="top">The characters 'a' and 'e'</td>
98 * <td nowrap valign="top" align="left"><code>[a-e]</code></td>
99 * <td valign="top">The characters 'a' through 'e' inclusive, in Unicode code
103 * <td nowrap valign="top" align="left"><code>[\\u4E01]</code></td>
104 * <td valign="top">The character U+4E01</td>
107 * <td nowrap valign="top" align="left"><code>[a{ab}{ac}]</code></td>
108 * <td valign="top">The character 'a' and the multicharacter strings "ab" and
109 * "ac"</td>
112 * <td nowrap valign="top" align="left"><code>[\\p{Lu}]</code></td>
113 * <td valign="top">All characters in the general category Uppercase Letter</td>
116 * \htmlonly</blockquote>\endhtmlonly
118 * Any character may be preceded by a backslash in order to remove any special
119 * meaning. White space characters, as defined by UCharacter.isWhitespace(), are
120 * ignored, unless they are escaped.
122 * <p>Property patterns specify a set of characters having a certain
123 * property as defined by the Unicode standard. Both the POSIX-like
124 * "[:Lu:]" and the Perl-like syntax "\\p{Lu}" are recognized. For a
125 * complete list of supported property patterns, see the User's Guide
127 * <a href="http://icu-project.org/userguide/unicodeSet.html">
128 * http://icu-project.org/userguide/unicodeSet.html</a>.
129 * Actual determination of property data is defined by the underlying
130 * Unicode database as implemented by UCharacter.
132 * <p>Patterns specify individual characters, ranges of characters, and
133 * Unicode property sets. When elements are concatenated, they
134 * specify their union. To complement a set, place a '^' immediately
135 * after the opening '['. Property patterns are inverted by modifying
136 * their delimiters; "[:^foo]" and "\\P{foo}". In any other location,
137 * '^' has no special meaning.
139 * <p>Ranges are indicated by placing two a '-' between two
140 * characters, as in "a-z". This specifies the range of all
141 * characters from the left to the right, in Unicode order. If the
142 * left character is greater than or equal to the
143 * right character it is a syntax error. If a '-' occurs as the first
144 * character after the opening '[' or '[^', or if it occurs as the
145 * last character before the closing ']', then it is taken as a
146 * literal. Thus "[a\-b]", "[-ab]", and "[ab-]" all indicate the same
147 * set of three characters, 'a', 'b', and '-'.
149 * <p>Sets may be intersected using the '&' operator or the asymmetric
150 * set difference may be taken using the '-' operator, for example,
151 * "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters
152 * with values less than 4096. Operators ('&' and '|') have equal
153 * precedence and bind left-to-right. Thus
154 * "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to
155 * "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]". This only really matters for
156 * difference; intersection is commutative.
159 * <tr valign=top><td nowrap><code>[a]</code><td>The set containing 'a'
160 * <tr valign=top><td nowrap><code>[a-z]</code><td>The set containing 'a'
161 * through 'z' and all letters in between, in Unicode order
162 * <tr valign=top><td nowrap><code>[^a-z]</code><td>The set containing
163 * all characters but 'a' through 'z',
164 * that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF
165 * <tr valign=top><td nowrap><code>[[<em>pat1</em>][<em>pat2</em>]]</code>
166 * <td>The union 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 intersection of sets specified by <em>pat1</em> and <em>pat2</em>
169 * <tr valign=top><td nowrap><code>[[<em>pat1</em>]-[<em>pat2</em>]]</code>
170 * <td>The asymmetric difference of sets specified by <em>pat1</em> and
172 * <tr valign=top><td nowrap><code>[:Lu:] or \\p{Lu}</code>
173 * <td>The set of characters having the specified
174 * Unicode property; in
175 * this case, Unicode uppercase letters
176 * <tr valign=top><td nowrap><code>[:^Lu:] or \\P{Lu}</code>
177 * <td>The set of characters <em>not</em> having the given
181 * <p><b>Warning</b>: you cannot add an empty string ("") to a UnicodeSet.</p>
183 * <p><b>Formal syntax</b></p>
185 * \htmlonly<blockquote>\endhtmlonly
188 * <td nowrap valign="top" align="right"><code>pattern := </code></td>
189 * <td valign="top"><code>('[' '^'? item* ']') |
190 * property</code></td>
193 * <td nowrap valign="top" align="right"><code>item := </code></td>
194 * <td valign="top"><code>char | (char '-' char) | pattern-expr<br>
198 * <td nowrap valign="top" align="right"><code>pattern-expr := </code></td>
199 * <td valign="top"><code>pattern | pattern-expr pattern |
200 * pattern-expr op pattern<br>
204 * <td nowrap valign="top" align="right"><code>op := </code></td>
205 * <td valign="top"><code>'&' | '-'<br>
209 * <td nowrap valign="top" align="right"><code>special := </code></td>
210 * <td valign="top"><code>'[' | ']' | '-'<br>
214 * <td nowrap valign="top" align="right"><code>char := </code></td>
215 * <td valign="top"><em>any character that is not</em><code> special<br>
216 * | ('\' </code><em>any character</em><code>)<br>
217 * | ('\\u' hex hex hex hex)<br>
221 * <td nowrap valign="top" align="right"><code>hex := </code></td>
222 * <td valign="top"><em>any character for which
223 * </em><code>Character.digit(c, 16)</code><em>
224 * returns a non-negative result</em></td>
227 * <td nowrap valign="top" align="right"><code>property := </code></td>
228 * <td valign="top"><em>a Unicode property set pattern</em></td>
234 * <td>Legend: <table>
236 * <td nowrap valign="top"><code>a := b</code></td>
237 * <td width="20" valign="top"> </td>
238 * <td valign="top"><code>a</code> may be replaced by <code>b</code> </td>
241 * <td nowrap valign="top"><code>a?</code></td>
242 * <td valign="top"></td>
243 * <td valign="top">zero or one instance of <code>a</code><br>
247 * <td nowrap valign="top"><code>a*</code></td>
248 * <td valign="top"></td>
249 * <td valign="top">one or more instances of <code>a</code><br>
253 * <td nowrap valign="top"><code>a | b</code></td>
254 * <td valign="top"></td>
255 * <td valign="top">either <code>a</code> or <code>b</code><br>
259 * <td nowrap valign="top"><code>'a'</code></td>
260 * <td valign="top"></td>
261 * <td valign="top">the literal string between the quotes </td>
267 * \htmlonly</blockquote>\endhtmlonly
270 * - Most UnicodeSet methods do not take a UErrorCode parameter because
271 * there are usually very few opportunities for failure other than a shortage
272 * of memory, error codes in low-level C++ string methods would be inconvenient,
273 * and the error code as the last parameter (ICU convention) would prevent
274 * the use of default parameter values.
275 * Instead, such methods set the UnicodeSet into a "bogus" state
276 * (see isBogus()) if an error occurs.
281 class U_COMMON_API UnicodeSet U_FINAL
: public UnicodeFilter
{
284 * Enough for sets with few ranges.
285 * For example, White_Space has 10 ranges, list length 21.
287 static constexpr int32_t INITIAL_CAPACITY
= 25;
289 static constexpr uint8_t kIsBogus
= 1; // This set is bogus (i.e. not valid)
291 UChar32
* list
= stackList
; // MUST be terminated with HIGH
292 int32_t capacity
= INITIAL_CAPACITY
; // capacity of list
293 int32_t len
= 1; // length of list used; 1 <= len <= capacity
294 uint8_t fFlags
= 0; // Bit flag (see constants above)
296 BMPSet
*bmpSet
= nullptr; // The set is frozen iff either bmpSet or stringSpan is not NULL.
297 UChar32
* buffer
= nullptr; // internal buffer, may be NULL
298 int32_t bufferCapacity
= 0; // capacity of buffer
301 * The pattern representation of this set. This may not be the
302 * most economical pattern. It is the pattern supplied to
303 * applyPattern(), with variables substituted and whitespace
304 * removed. For sets constructed without applyPattern(), or
305 * modified using the non-pattern API, this string will be empty,
306 * indicating that toPattern() must generate a pattern
307 * representation from the inversion list.
309 char16_t *pat
= nullptr;
312 UVector
* strings
= nullptr; // maintained in sorted order
313 UnicodeSetStringSpan
*stringSpan
= nullptr;
316 * Initial list array.
317 * Avoids some heap allocations, and list is never nullptr.
318 * Increases the object size a bit.
320 UChar32 stackList
[INITIAL_CAPACITY
];
324 * Determine if this object contains a valid set.
325 * A bogus set has no value. It is different from an empty set.
326 * It can be used to indicate that no set value is available.
328 * @return TRUE if the set is bogus/invalid, FALSE otherwise
332 inline UBool
isBogus(void) const;
335 * Make this UnicodeSet object invalid.
336 * The string will test TRUE with isBogus().
338 * A bogus set has no value. It is different from an empty set.
339 * It can be used to indicate that no set value is available.
341 * This utility function is used throughout the UnicodeSet
342 * implementation to indicate that a UnicodeSet operation failed,
343 * and may be used in other functions,
344 * especially but not exclusively when such functions do not
345 * take a UErrorCode for simplicity.
356 * Minimum value that can be stored in a UnicodeSet.
362 * Maximum value that can be stored in a UnicodeSet.
368 //----------------------------------------------------------------
370 //----------------------------------------------------------------
375 * Constructs an empty set.
381 * Constructs a set containing the given range. If <code>end <
382 * start</code> then an empty set is created.
384 * @param start first character, inclusive, of range
385 * @param end last character, inclusive, of range
388 UnicodeSet(UChar32 start
, UChar32 end
);
390 #ifndef U_HIDE_INTERNAL_API
394 enum ESerialization
{
395 kSerialized
/* result of serialize() */
399 * Constructs a set from the output of serialize().
401 * @param buffer the 16 bit array
402 * @param bufferLen the original length returned from serialize()
403 * @param serialization the value 'kSerialized'
404 * @param status error code
408 UnicodeSet(const uint16_t buffer
[], int32_t bufferLen
,
409 ESerialization serialization
, UErrorCode
&status
);
410 #endif /* U_HIDE_INTERNAL_API */
413 * Constructs a set from the given pattern. See the class
414 * description for the syntax of the pattern language.
415 * @param pattern a string specifying what characters are in the set
416 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
417 * contains a syntax error.
420 UnicodeSet(const UnicodeString
& pattern
,
423 #ifndef U_HIDE_INTERNAL_API
425 * Constructs a set from the given pattern. See the class
426 * description for the syntax of the pattern language.
427 * @param pattern a string specifying what characters are in the set
428 * @param options bitmask for options to apply to the pattern.
429 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
430 * @param symbols a symbol table mapping variable names to values
431 * and stand-in characters to UnicodeSets; may be NULL
432 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
433 * contains a syntax error.
436 UnicodeSet(const UnicodeString
& pattern
,
438 const SymbolTable
* symbols
,
440 #endif /* U_HIDE_INTERNAL_API */
443 * Constructs a set from the given pattern. See the class description
444 * for the syntax of the pattern language.
445 * @param pattern a string specifying what characters are in the set
446 * @param pos on input, the position in pattern at which to start parsing.
447 * On output, the position after the last character parsed.
448 * @param options bitmask for options to apply to the pattern.
449 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
450 * @param symbols a symbol table mapping variable names to values
451 * and stand-in characters to UnicodeSets; may be NULL
452 * @param status input-output error code
455 UnicodeSet(const UnicodeString
& pattern
, ParsePosition
& pos
,
457 const SymbolTable
* symbols
,
461 * Constructs a set that is identical to the given UnicodeSet.
464 UnicodeSet(const UnicodeSet
& o
);
470 virtual ~UnicodeSet();
473 * Assigns this object to be a copy of another.
474 * A frozen set will not be modified.
477 UnicodeSet
& operator=(const UnicodeSet
& o
);
480 * Compares the specified object with this set for equality. Returns
481 * <tt>true</tt> if the two sets
482 * have the same size, and every member of the specified set is
483 * contained in this set (or equivalently, every member of this set is
484 * contained in the specified set).
486 * @param o set to be compared for equality with this set.
487 * @return <tt>true</tt> if the specified set is equal to this set.
490 virtual UBool
operator==(const UnicodeSet
& o
) const;
493 * Compares the specified object with this set for equality. Returns
494 * <tt>true</tt> if the specified set is not equal to this set.
497 inline UBool
operator!=(const UnicodeSet
& o
) const;
500 * Returns a copy of this object. All UnicodeFunctor objects have
501 * to support cloning in order to allow classes using
502 * UnicodeFunctors, such as Transliterator, to implement cloning.
503 * If this set is frozen, then the clone will be frozen as well.
504 * Use cloneAsThawed() for a mutable clone of a frozen set.
508 virtual UnicodeSet
* clone() const;
511 * Returns the hash code value for this set.
513 * @return the hash code value for this set.
514 * @see Object#hashCode()
517 virtual int32_t hashCode(void) const;
520 * Get a UnicodeSet pointer from a USet
522 * @param uset a USet (the ICU plain C type for UnicodeSet)
523 * @return the corresponding UnicodeSet pointer.
527 inline static UnicodeSet
*fromUSet(USet
*uset
);
530 * Get a UnicodeSet pointer from a const USet
532 * @param uset a const USet (the ICU plain C type for UnicodeSet)
533 * @return the corresponding UnicodeSet pointer.
537 inline static const UnicodeSet
*fromUSet(const USet
*uset
);
540 * Produce a USet * pointer for this UnicodeSet.
541 * USet is the plain C type for UnicodeSet
543 * @return a USet pointer for this UnicodeSet
546 inline USet
*toUSet();
550 * Produce a const USet * pointer for this UnicodeSet.
551 * USet is the plain C type for UnicodeSet
553 * @return a const USet pointer for this UnicodeSet
556 inline const USet
* toUSet() const;
559 //----------------------------------------------------------------
561 //----------------------------------------------------------------
564 * Determines whether the set has been frozen (made immutable) or not.
565 * See the ICU4J Freezable interface for details.
566 * @return TRUE/FALSE for whether the set has been frozen
571 inline UBool
isFrozen() const;
574 * Freeze the set (make it immutable).
575 * Once frozen, it cannot be unfrozen and is therefore thread-safe
576 * until it is deleted.
577 * See the ICU4J Freezable interface for details.
578 * Freezing the set may also make some operations faster, for example
579 * contains() and span().
580 * A frozen set will not be modified. (It remains frozen.)
586 UnicodeSet
*freeze();
589 * Clone the set and make the clone mutable.
590 * See the ICU4J Freezable interface for details.
591 * @return the mutable clone
596 UnicodeSet
*cloneAsThawed() const;
598 //----------------------------------------------------------------
600 //----------------------------------------------------------------
603 * Make this object represent the range `start - end`.
604 * If `end > start` then this object is set to an empty range.
605 * A frozen set will not be modified.
607 * @param start first character in the set, inclusive
608 * @param end last character in the set, inclusive
611 UnicodeSet
& set(UChar32 start
, UChar32 end
);
614 * Return true if the given position, in the given pattern, appears
615 * to be the start of a UnicodeSet pattern.
618 static UBool
resemblesPattern(const UnicodeString
& pattern
,
622 * Modifies this set to represent the set specified by the given
623 * pattern, ignoring Unicode Pattern_White_Space characters.
624 * See the class description for the syntax of the pattern language.
625 * A frozen set will not be modified.
626 * @param pattern a string specifying what characters are in the set
627 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
628 * contains a syntax error.
629 * <em> Empties the set passed before applying the pattern.</em>
630 * @return a reference to this
633 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
636 #ifndef U_HIDE_INTERNAL_API
638 * Modifies this set to represent the set specified by the given
639 * pattern, optionally ignoring Unicode Pattern_White_Space characters.
640 * See the class description for the syntax of the pattern language.
641 * A frozen set will not be modified.
642 * @param pattern a string specifying what characters are in the set
643 * @param options bitmask for options to apply to the pattern.
644 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
645 * @param symbols a symbol table mapping variable names to
646 * values and stand-ins to UnicodeSets; may be NULL
647 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
648 * contains a syntax error.
649 *<em> Empties the set passed before applying the pattern.</em>
650 * @return a reference to this
653 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
655 const SymbolTable
* symbols
,
657 #endif /* U_HIDE_INTERNAL_API */
660 * Parses the given pattern, starting at the given position. The
661 * character at pattern.charAt(pos.getIndex()) must be '[', or the
662 * parse fails. Parsing continues until the corresponding closing
663 * ']'. If a syntax error is encountered between the opening and
664 * closing brace, the parse fails. Upon return from a successful
665 * parse, the ParsePosition is updated to point to the character
666 * following the closing ']', and a StringBuffer containing a
667 * pairs list for the parsed pattern is returned. This method calls
668 * itself recursively to parse embedded subpatterns.
669 *<em> Empties the set passed before applying the pattern.</em>
670 * A frozen set will not be modified.
672 * @param pattern the string containing the pattern to be parsed.
673 * The portion of the string from pos.getIndex(), which must be a
674 * '[', to the corresponding closing ']', is parsed.
675 * @param pos upon entry, the position at which to being parsing.
676 * The character at pattern.charAt(pos.getIndex()) must be a '['.
677 * Upon return from a successful parse, pos.getIndex() is either
678 * the character after the closing ']' of the parsed pattern, or
679 * pattern.length() if the closing ']' is the last character of
680 * the pattern string.
681 * @param options bitmask for options to apply to the pattern.
682 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
683 * @param symbols a symbol table mapping variable names to
684 * values and stand-ins to UnicodeSets; may be NULL
685 * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
686 * contains a syntax error.
687 * @return a reference to this
690 UnicodeSet
& applyPattern(const UnicodeString
& pattern
,
693 const SymbolTable
* symbols
,
697 * Returns a string representation of this set. If the result of
698 * calling this function is passed to a UnicodeSet constructor, it
699 * will produce another set that is equal to this one.
700 * A frozen set will not be modified.
701 * @param result the string to receive the rules. Previous
702 * contents will be deleted.
703 * @param escapeUnprintable if TRUE then convert unprintable
704 * character to their hex escape representations, \\uxxxx or
705 * \\Uxxxxxxxx. Unprintable characters are those other than
706 * U+000A, U+0020..U+007E.
709 virtual UnicodeString
& toPattern(UnicodeString
& result
,
710 UBool escapeUnprintable
= FALSE
) const;
713 * Modifies this set to contain those code points which have the given value
714 * for the given binary or enumerated property, as returned by
715 * u_getIntPropertyValue. Prior contents of this set are lost.
716 * A frozen set will not be modified.
718 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
719 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
720 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
722 * @param value a value in the range u_getIntPropertyMinValue(prop)..
723 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
724 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
725 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
726 * categories such as [:L:] to be represented.
728 * @param ec error code input/output parameter
730 * @return a reference to this set
734 UnicodeSet
& applyIntPropertyValue(UProperty prop
,
739 * Modifies this set to contain those code points which have the
740 * given value for the given property. Prior contents of this
742 * A frozen set will not be modified.
744 * @param prop a property alias, either short or long. The name is matched
745 * loosely. See PropertyAliases.txt for names and a description of loose
746 * matching. If the value string is empty, then this string is interpreted
747 * as either a General_Category value alias, a Script value alias, a binary
748 * property alias, or a special ID. Special IDs are matched loosely and
749 * correspond to the following sets:
751 * "ANY" = [\\u0000-\\U0010FFFF],
752 * "ASCII" = [\\u0000-\\u007F],
753 * "Assigned" = [:^Cn:].
755 * @param value a value alias, either short or long. The name is matched
756 * loosely. See PropertyValueAliases.txt for names and a description of
757 * loose matching. In addition to aliases listed, numeric values and
758 * canonical combining classes may be expressed numerically, e.g., ("nv",
759 * "0.5") or ("ccc", "220"). The value string may also be empty.
761 * @param ec error code input/output parameter
763 * @return a reference to this set
767 UnicodeSet
& applyPropertyAlias(const UnicodeString
& prop
,
768 const UnicodeString
& value
,
772 * Returns the number of elements in this set (its cardinality).
773 * Note than the elements of a set may include both individual
774 * codepoints and strings.
776 * @return the number of elements in this set (its cardinality).
779 virtual int32_t size(void) const;
782 * Returns <tt>true</tt> if this set contains no elements.
784 * @return <tt>true</tt> if this set contains no elements.
787 virtual UBool
isEmpty(void) const;
790 * Returns true if this set contains the given character.
791 * This function works faster with a frozen set.
792 * @param c character to be checked for containment
793 * @return true if the test condition is met
796 virtual UBool
contains(UChar32 c
) const;
799 * Returns true if this set contains every character
800 * of the given range.
801 * @param start first character, inclusive, of the range
802 * @param end last character, inclusive, of the range
803 * @return true if the test condition is met
806 virtual UBool
contains(UChar32 start
, UChar32 end
) const;
809 * Returns <tt>true</tt> if this set contains the given
810 * multicharacter string.
811 * @param s string to be checked for containment
812 * @return <tt>true</tt> if this set contains the specified string
815 UBool
contains(const UnicodeString
& s
) const;
818 * Returns true if this set contains all the characters and strings
820 * @param c set to be checked for containment
821 * @return true if the test condition is met
824 virtual UBool
containsAll(const UnicodeSet
& c
) const;
827 * Returns true if this set contains all the characters
828 * of the given string.
829 * @param s string containing characters to be checked for containment
830 * @return true if the test condition is met
833 UBool
containsAll(const UnicodeString
& s
) const;
836 * Returns true if this set contains none of the characters
837 * of the given range.
838 * @param start first character, inclusive, of the range
839 * @param end last character, inclusive, of the range
840 * @return true if the test condition is met
843 UBool
containsNone(UChar32 start
, UChar32 end
) const;
846 * Returns true if this set contains none of the characters and strings
848 * @param c set to be checked for containment
849 * @return true if the test condition is met
852 UBool
containsNone(const UnicodeSet
& c
) const;
855 * Returns true if this set contains none of the characters
856 * of the given string.
857 * @param s string containing characters to be checked for containment
858 * @return true if the test condition is met
861 UBool
containsNone(const UnicodeString
& s
) const;
864 * Returns true if this set contains one or more of the characters
865 * in the given range.
866 * @param start first character, inclusive, of the range
867 * @param end last character, inclusive, of the range
868 * @return true if the condition is met
871 inline UBool
containsSome(UChar32 start
, UChar32 end
) const;
874 * Returns true if this set contains one or more of the characters
875 * and strings of the given set.
876 * @param s The set to be checked for containment
877 * @return true if the condition is met
880 inline UBool
containsSome(const UnicodeSet
& s
) const;
883 * Returns true if this set contains one or more of the characters
884 * of the given string.
885 * @param s string containing characters to be checked for containment
886 * @return true if the condition is met
889 inline UBool
containsSome(const UnicodeString
& s
) const;
892 * Returns the length of the initial substring of the input string which
893 * consists only of characters and strings that are contained in this set
894 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
895 * or only of characters and strings that are not contained
896 * in this set (USET_SPAN_NOT_CONTAINED).
897 * See USetSpanCondition for details.
898 * Similar to the strspn() C library function.
899 * Unpaired surrogates are treated according to contains() of their surrogate code points.
900 * This function works faster with a frozen set and with a non-negative string length argument.
901 * @param s start of the string
902 * @param length of the string; can be -1 for NUL-terminated
903 * @param spanCondition specifies the containment condition
904 * @return the length of the initial substring according to the spanCondition;
905 * 0 if the start of the string does not fit the spanCondition
907 * @see USetSpanCondition
909 int32_t span(const char16_t *s
, int32_t length
, USetSpanCondition spanCondition
) const;
912 * Returns the end of the substring of the input string according to the USetSpanCondition.
913 * Same as <code>start+span(s.getBuffer()+start, s.length()-start, spanCondition)</code>
914 * after pinning start to 0<=start<=s.length().
915 * @param s the string
916 * @param start the start index in the string for the span operation
917 * @param spanCondition specifies the containment condition
918 * @return the exclusive end of the substring according to the spanCondition;
919 * the substring s.tempSubStringBetween(start, end) fulfills the spanCondition
921 * @see USetSpanCondition
923 inline int32_t span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const;
926 * Returns the start of the trailing substring of the input string which
927 * consists only of characters and strings that are contained in this set
928 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
929 * or only of characters and strings that are not contained
930 * in this set (USET_SPAN_NOT_CONTAINED).
931 * See USetSpanCondition for details.
932 * Unpaired surrogates are treated according to contains() of their surrogate code points.
933 * This function works faster with a frozen set and with a non-negative string length argument.
934 * @param s start of the string
935 * @param length of the string; can be -1 for NUL-terminated
936 * @param spanCondition specifies the containment condition
937 * @return the start of the trailing substring according to the spanCondition;
938 * the string length if the end of the string does not fit the spanCondition
940 * @see USetSpanCondition
942 int32_t spanBack(const char16_t *s
, int32_t length
, USetSpanCondition spanCondition
) const;
945 * Returns the start of the substring of the input string according to the USetSpanCondition.
946 * Same as <code>spanBack(s.getBuffer(), limit, spanCondition)</code>
947 * after pinning limit to 0<=end<=s.length().
948 * @param s the string
949 * @param limit the exclusive-end index in the string for the span operation
950 * (use s.length() or INT32_MAX for spanning back from the end of the string)
951 * @param spanCondition specifies the containment condition
952 * @return the start of the substring according to the spanCondition;
953 * the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition
955 * @see USetSpanCondition
957 inline int32_t spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const;
960 * Returns the length of the initial substring of the input string which
961 * consists only of characters and strings that are contained in this set
962 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
963 * or only of characters and strings that are not contained
964 * in this set (USET_SPAN_NOT_CONTAINED).
965 * See USetSpanCondition for details.
966 * Similar to the strspn() C library function.
967 * Malformed byte sequences are treated according to contains(0xfffd).
968 * This function works faster with a frozen set and with a non-negative string length argument.
969 * @param s start of the string (UTF-8)
970 * @param length of the string; can be -1 for NUL-terminated
971 * @param spanCondition specifies the containment condition
972 * @return the length of the initial substring according to the spanCondition;
973 * 0 if the start of the string does not fit the spanCondition
975 * @see USetSpanCondition
977 int32_t spanUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
980 * Returns the start of the trailing substring of the input string which
981 * consists only of characters and strings that are contained in this set
982 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
983 * or only of characters and strings that are not contained
984 * in this set (USET_SPAN_NOT_CONTAINED).
985 * See USetSpanCondition for details.
986 * Malformed byte sequences are treated according to contains(0xfffd).
987 * This function works faster with a frozen set and with a non-negative string length argument.
988 * @param s start of the string (UTF-8)
989 * @param length of the string; can be -1 for NUL-terminated
990 * @param spanCondition specifies the containment condition
991 * @return the start of the trailing substring according to the spanCondition;
992 * the string length if the end of the string does not fit the spanCondition
994 * @see USetSpanCondition
996 int32_t spanBackUTF8(const char *s
, int32_t length
, USetSpanCondition spanCondition
) const;
999 * Implement UnicodeMatcher::matches()
1002 virtual UMatchDegree
matches(const Replaceable
& text
,
1009 * Returns the longest match for s in text at the given position.
1010 * If limit > start then match forward from start+1 to limit
1011 * matching all characters except s.charAt(0). If limit < start,
1012 * go backward starting from start-1 matching all characters
1013 * except s.charAt(s.length()-1). This method assumes that the
1014 * first character, text.charAt(start), matches s, so it does not
1016 * @param text the text to match
1017 * @param start the first character to match. In the forward
1018 * direction, text.charAt(start) is matched against s.charAt(0).
1019 * In the reverse direction, it is matched against
1020 * s.charAt(s.length()-1).
1021 * @param limit the limit offset for matching, either last+1 in
1022 * the forward direction, or last-1 in the reverse direction,
1023 * where last is the index of the last character to match.
1025 * @return If part of s matches up to the limit, return |limit -
1026 * start|. If all of s matches before reaching the limit, return
1027 * s.length(). If there is a mismatch between s and text, return
1030 static int32_t matchRest(const Replaceable
& text
,
1031 int32_t start
, int32_t limit
,
1032 const UnicodeString
& s
);
1035 * Returns the smallest value i such that c < list[i]. Caller
1036 * must ensure that c is a legal value or this method will enter
1037 * an infinite loop. This method performs a binary search.
1038 * @param c a character in the range MIN_VALUE..MAX_VALUE
1040 * @return the smallest integer i in the range 0..len-1,
1041 * inclusive, such that c < list[i]
1043 int32_t findCodePoint(UChar32 c
) const;
1048 * Implementation of UnicodeMatcher API. Union the set of all
1049 * characters that may be matched by this object into the given
1051 * @param toUnionTo the set into which to union the source characters
1054 virtual void addMatchSetTo(UnicodeSet
& toUnionTo
) const;
1057 * Returns the index of the given character within this set, where
1058 * the set is ordered by ascending code point. If the character
1059 * is not in this set, return -1. The inverse of this method is
1060 * <code>charAt()</code>.
1061 * @return an index from 0..size()-1, or -1
1064 int32_t indexOf(UChar32 c
) const;
1067 * Returns the character at the given index within this set, where
1068 * the set is ordered by ascending code point. If the index is
1069 * out of range, return (UChar32)-1. The inverse of this method is
1070 * <code>indexOf()</code>.
1071 * @param index an index from 0..size()-1
1072 * @return the character at the given index, or (UChar32)-1.
1075 UChar32
charAt(int32_t index
) const;
1078 * Adds the specified range to this set if it is not already
1079 * present. If this set already contains the specified range,
1080 * the call leaves this set unchanged. If <code>end > start</code>
1081 * then an empty range is added, leaving the set unchanged.
1082 * This is equivalent to a boolean logic OR, or a set UNION.
1083 * A frozen set will not be modified.
1085 * @param start first character, inclusive, of range to be added
1087 * @param end last character, inclusive, of range to be added
1091 virtual UnicodeSet
& add(UChar32 start
, UChar32 end
);
1094 * Adds the specified character to this set if it is not already
1095 * present. If this set already contains the specified character,
1096 * the call leaves this set unchanged.
1097 * A frozen set will not be modified.
1100 UnicodeSet
& add(UChar32 c
);
1103 * Adds the specified multicharacter to this set if it is not already
1104 * present. If this set already contains the multicharacter,
1105 * the call leaves this set unchanged.
1106 * Thus "ch" => {"ch"}
1107 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1108 * A frozen set will not be modified.
1109 * @param s the source string
1110 * @return this object, for chaining
1113 UnicodeSet
& add(const UnicodeString
& s
);
1117 * @return a code point IF the string consists of a single one.
1118 * otherwise returns -1.
1119 * @param s string to test
1121 static int32_t getSingleCP(const UnicodeString
& s
);
1123 void _add(const UnicodeString
& s
);
1127 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
1128 * If this set already any particular character, it has no effect on that character.
1129 * A frozen set will not be modified.
1130 * @param s the source string
1131 * @return this object, for chaining
1134 UnicodeSet
& addAll(const UnicodeString
& s
);
1137 * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
1138 * If this set already any particular character, it has no effect on that character.
1139 * A frozen set will not be modified.
1140 * @param s the source string
1141 * @return this object, for chaining
1144 UnicodeSet
& retainAll(const UnicodeString
& s
);
1147 * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
1148 * If this set already any particular character, it has no effect on that character.
1149 * A frozen set will not be modified.
1150 * @param s the source string
1151 * @return this object, for chaining
1154 UnicodeSet
& complementAll(const UnicodeString
& s
);
1157 * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
1158 * If this set already any particular character, it has no effect on that character.
1159 * A frozen set will not be modified.
1160 * @param s the source string
1161 * @return this object, for chaining
1164 UnicodeSet
& removeAll(const UnicodeString
& s
);
1167 * Makes a set from a multicharacter string. Thus "ch" => {"ch"}
1168 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1169 * @param s the source string
1170 * @return a newly created set containing the given string.
1171 * The caller owns the return object and is responsible for deleting it.
1174 static UnicodeSet
* U_EXPORT2
createFrom(const UnicodeString
& s
);
1178 * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
1179 * @param s the source string
1180 * @return a newly created set containing the given characters
1181 * The caller owns the return object and is responsible for deleting it.
1184 static UnicodeSet
* U_EXPORT2
createFromAll(const UnicodeString
& s
);
1187 * Retain only the elements in this set that are contained in the
1188 * specified range. If <code>end > start</code> then an empty range is
1189 * retained, leaving the set empty. This is equivalent to
1190 * a boolean logic AND, or a set INTERSECTION.
1191 * A frozen set will not be modified.
1193 * @param start first character, inclusive, of range to be retained
1195 * @param end last character, inclusive, of range to be retained
1199 virtual UnicodeSet
& retain(UChar32 start
, UChar32 end
);
1203 * Retain the specified character from this set if it is present.
1204 * A frozen set will not be modified.
1207 UnicodeSet
& retain(UChar32 c
);
1210 * Removes the specified range from this set if it is present.
1211 * The set will not contain the specified range once the call
1212 * returns. If <code>end > start</code> then an empty range is
1213 * removed, leaving the set unchanged.
1214 * A frozen set will not be modified.
1216 * @param start first character, inclusive, of range to be removed
1218 * @param end last character, inclusive, of range to be removed
1222 virtual UnicodeSet
& remove(UChar32 start
, UChar32 end
);
1225 * Removes the specified character from this set if it is present.
1226 * The set will not contain the specified range once the call
1228 * A frozen set will not be modified.
1231 UnicodeSet
& remove(UChar32 c
);
1234 * Removes the specified string from this set if it is present.
1235 * The set will not contain the specified character once the call
1237 * A frozen set will not be modified.
1238 * @param s the source string
1239 * @return this object, for chaining
1242 UnicodeSet
& remove(const UnicodeString
& s
);
1245 * Inverts this set. This operation modifies this set so that
1246 * its value is its complement. This is equivalent to
1247 * <code>complement(MIN_VALUE, MAX_VALUE)</code>.
1248 * A frozen set will not be modified.
1251 virtual UnicodeSet
& complement(void);
1254 * Complements the specified range in this set. Any character in
1255 * the range will be removed if it is in this set, or will be
1256 * added if it is not in this set. If <code>end > start</code>
1257 * then an empty range is complemented, leaving the set unchanged.
1258 * This is equivalent to a boolean logic XOR.
1259 * A frozen set will not be modified.
1261 * @param start first character, inclusive, of range to be removed
1263 * @param end last character, inclusive, of range to be removed
1267 virtual UnicodeSet
& complement(UChar32 start
, UChar32 end
);
1270 * Complements the specified character in this set. The character
1271 * will be removed if it is in this set, or will be added if it is
1273 * A frozen set will not be modified.
1276 UnicodeSet
& complement(UChar32 c
);
1279 * Complement the specified string in this set.
1280 * The set will not contain the specified string once the call
1282 * <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
1283 * A frozen set will not be modified.
1284 * @param s the string to complement
1285 * @return this object, for chaining
1288 UnicodeSet
& complement(const UnicodeString
& s
);
1291 * Adds all of the elements in the specified set to this set if
1292 * they're not already present. This operation effectively
1293 * modifies this set so that its value is the <i>union</i> of the two
1294 * sets. The behavior of this operation is unspecified if the specified
1295 * collection is modified while the operation is in progress.
1296 * A frozen set will not be modified.
1298 * @param c set whose elements are to be added to this set.
1299 * @see #add(UChar32, UChar32)
1302 virtual UnicodeSet
& addAll(const UnicodeSet
& c
);
1305 * Retains only the elements in this set that are contained in the
1306 * specified set. In other words, removes from this set all of
1307 * its elements that are not contained in the specified set. This
1308 * operation effectively modifies this set so that its value is
1309 * the <i>intersection</i> of the two sets.
1310 * A frozen set will not be modified.
1312 * @param c set that defines which elements this set will retain.
1315 virtual UnicodeSet
& retainAll(const UnicodeSet
& c
);
1318 * Removes from this set all of its elements that are contained in the
1319 * specified set. This operation effectively modifies this
1320 * set so that its value is the <i>asymmetric set difference</i> of
1322 * A frozen set will not be modified.
1324 * @param c set that defines which elements will be removed from
1328 virtual UnicodeSet
& removeAll(const UnicodeSet
& c
);
1331 * Complements in this set all elements contained in the specified
1332 * set. Any character in the other set will be removed if it is
1333 * in this set, or will be added if it is not in this set.
1334 * A frozen set will not be modified.
1336 * @param c set that defines which elements will be xor'ed from
1340 virtual UnicodeSet
& complementAll(const UnicodeSet
& c
);
1343 * Removes all of the elements from this set. This set will be
1344 * empty after this call returns.
1345 * A frozen set will not be modified.
1348 virtual UnicodeSet
& clear(void);
1351 * Close this set over the given attribute. For the attribute
1352 * USET_CASE, the result is to modify this set so that:
1354 * 1. For each character or string 'a' in this set, all strings or
1355 * characters 'b' such that foldCase(a) == foldCase(b) are added
1358 * 2. For each string 'e' in the resulting set, if e !=
1359 * foldCase(e), 'e' will be removed.
1361 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
1363 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
1364 * == b denotes that the contents are the same, not pointer
1367 * A frozen set will not be modified.
1369 * @param attribute bitmask for attributes to close over.
1370 * Currently only the USET_CASE bit is supported. Any undefined bits
1372 * @return a reference to this set.
1375 UnicodeSet
& closeOver(int32_t attribute
);
1378 * Remove all strings from this set.
1380 * @return a reference to this set.
1383 virtual UnicodeSet
&removeAllStrings();
1386 * Iteration method that returns the number of ranges contained in
1388 * @see #getRangeStart
1392 virtual int32_t getRangeCount(void) const;
1395 * Iteration method that returns the first character in the
1396 * specified range of this set.
1397 * @see #getRangeCount
1401 virtual UChar32
getRangeStart(int32_t index
) const;
1404 * Iteration method that returns the last character in the
1405 * specified range of this set.
1406 * @see #getRangeStart
1410 virtual UChar32
getRangeEnd(int32_t index
) const;
1413 * Serializes this set into an array of 16-bit integers. Serialization
1414 * (currently) only records the characters in the set; multicharacter
1415 * strings are ignored.
1417 * The array has following format (each line is one 16-bit
1420 * length = (n+2*m) | (m!=0?0x8000:0)
1421 * bmpLength = n; present if m!=0
1434 * The array starts with a header. After the header are n bmp
1435 * code points, then m supplementary code points. Either n or m
1436 * or both may be zero. n+2*m is always <= 0x7FFF.
1438 * If there are no supplementary characters (if m==0) then the
1439 * header is one 16-bit integer, 'length', with value n.
1441 * If there are supplementary characters (if m!=0) then the header
1442 * is two 16-bit integers. The first, 'length', has value
1443 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
1445 * After the header the code points are stored in ascending order.
1446 * Supplementary code points are stored as most significant 16
1447 * bits followed by least significant 16 bits.
1449 * @param dest pointer to buffer of destCapacity 16-bit integers.
1450 * May be NULL only if destCapacity is zero.
1451 * @param destCapacity size of dest, or zero. Must not be negative.
1452 * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR
1453 * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if
1454 * n+2*m+(m!=0?2:1) > destCapacity.
1455 * @return the total length of the serialized format, including
1456 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1457 * than U_BUFFER_OVERFLOW_ERROR.
1460 int32_t serialize(uint16_t *dest
, int32_t destCapacity
, UErrorCode
& ec
) const;
1463 * Reallocate this objects internal structures to take up the least
1464 * possible space, without changing this object's value.
1465 * A frozen set will not be modified.
1468 virtual UnicodeSet
& compact();
1471 * Return the class ID for this class. This is useful only for
1472 * comparing to a return value from getDynamicClassID(). For example:
1474 * . Base* polymorphic_pointer = createPolymorphicObject();
1475 * . if (polymorphic_pointer->getDynamicClassID() ==
1476 * . Derived::getStaticClassID()) ...
1478 * @return The class ID for all objects of this class.
1481 static UClassID U_EXPORT2
getStaticClassID(void);
1484 * Implement UnicodeFunctor API.
1486 * @return The class ID for this object. All objects of a given
1487 * class have the same class ID. Objects of other classes have
1488 * different class IDs.
1491 virtual UClassID
getDynamicClassID(void) const;
1495 // Private API for the USet API
1497 friend class USetAccess
;
1499 const UnicodeString
* getString(int32_t index
) const;
1501 //----------------------------------------------------------------
1502 // RuleBasedTransliterator support
1503 //----------------------------------------------------------------
1508 * Returns <tt>true</tt> if this set contains any character whose low byte
1509 * is the given value. This is used by <tt>RuleBasedTransliterator</tt> for
1512 virtual UBool
matchesIndexValue(uint8_t v
) const;
1515 friend class RBBIRuleScanner
;
1516 friend class RBBIRuleScanner57
;
1518 //----------------------------------------------------------------
1519 // Implementation: Clone as thawed (see ICU4J Freezable)
1520 //----------------------------------------------------------------
1522 UnicodeSet(const UnicodeSet
& o
, UBool
/* asThawed */);
1523 UnicodeSet
& copyFrom(const UnicodeSet
& o
, UBool asThawed
);
1525 //----------------------------------------------------------------
1526 // Implementation: Pattern parsing
1527 //----------------------------------------------------------------
1529 void applyPatternIgnoreSpace(const UnicodeString
& pattern
,
1531 const SymbolTable
* symbols
,
1532 UErrorCode
& status
);
1534 void applyPattern(RuleCharacterIterator
& chars
,
1535 const SymbolTable
* symbols
,
1536 UnicodeString
& rebuiltPat
,
1538 UnicodeSet
& (UnicodeSet::*caseClosure
)(int32_t attribute
),
1542 //----------------------------------------------------------------
1543 // Implementation: Utility methods
1544 //----------------------------------------------------------------
1546 static int32_t nextCapacity(int32_t minCapacity
);
1548 bool ensureCapacity(int32_t newLen
);
1550 bool ensureBufferCapacity(int32_t newLen
);
1552 void swapBuffers(void);
1554 UBool
allocateStrings(UErrorCode
&status
);
1555 UBool
hasStrings() const;
1556 int32_t stringsSize() const;
1557 UBool
stringsContains(const UnicodeString
&s
) const;
1559 UnicodeString
& _toPattern(UnicodeString
& result
,
1560 UBool escapeUnprintable
) const;
1562 UnicodeString
& _generatePattern(UnicodeString
& result
,
1563 UBool escapeUnprintable
) const;
1565 static void _appendToPat(UnicodeString
& buf
, const UnicodeString
& s
, UBool escapeUnprintable
);
1567 static void _appendToPat(UnicodeString
& buf
, UChar32 c
, UBool escapeUnprintable
);
1569 //----------------------------------------------------------------
1570 // Implementation: Fundamental operators
1571 //----------------------------------------------------------------
1573 void exclusiveOr(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1575 void add(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1577 void retain(const UChar32
* other
, int32_t otherLen
, int8_t polarity
);
1580 * Return true if the given position, in the given pattern, appears
1581 * to be the start of a property set pattern [:foo:], \\p{foo}, or
1582 * \\P{foo}, or \\N{name}.
1584 static UBool
resemblesPropertyPattern(const UnicodeString
& pattern
,
1587 static UBool
resemblesPropertyPattern(RuleCharacterIterator
& chars
,
1591 * Parse the given property pattern at the given parse position
1592 * and set this UnicodeSet to the result.
1594 * The original design document is out of date, but still useful.
1595 * Ignore the property and value names:
1596 * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/unicodeset_properties.html
1598 * Recognized syntax:
1600 * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]"
1601 * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P"
1602 * \\N{name} - white space not allowed within "\\N"
1604 * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored.
1605 * Case is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading
1606 * and trailing space is deleted, and internal runs of whitespace
1607 * are collapsed to a single space.
1609 * We support binary properties, enumerated properties, and the
1610 * following non-enumerated properties:
1616 * @param pattern the pattern string
1617 * @param ppos on entry, the position at which to begin parsing.
1618 * This should be one of the locations marked '^':
1620 * [:blah:] \\p{blah} \\P{blah} \\N{name}
1623 * On return, the position after the last character parsed, that is,
1624 * the locations marked '%'. If the parse fails, ppos is returned
1627 * @return a reference to this.
1629 UnicodeSet
& applyPropertyPattern(const UnicodeString
& pattern
,
1630 ParsePosition
& ppos
,
1633 void applyPropertyPattern(RuleCharacterIterator
& chars
,
1634 UnicodeString
& rebuiltPat
,
1637 static const UnicodeSet
* getInclusions(int32_t src
, UErrorCode
&status
);
1640 * A filter that returns TRUE if the given code point should be
1641 * included in the UnicodeSet being constructed.
1643 typedef UBool (*Filter
)(UChar32 codePoint
, void* context
);
1646 * Given a filter, set this UnicodeSet to the code points
1647 * contained by that filter. The filter MUST be
1648 * property-conformant. That is, if it returns value v for one
1649 * code point, then it must return v for all affiliated code
1650 * points, as defined by the inclusions list. See
1652 * src is a UPropertySource value.
1654 void applyFilter(Filter filter
,
1656 const UnicodeSet
* inclusions
,
1657 UErrorCode
&status
);
1659 // UCPMap is now stable ICU 63
1660 void applyIntPropertyValue(const UCPMap
*map
,
1661 UCPMapValueFilter
*filter
, const void *context
,
1662 UErrorCode
&errorCode
);
1665 * Set the new pattern to cache.
1667 void setPattern(const UnicodeString
& newPat
) {
1668 setPattern(newPat
.getBuffer(), newPat
.length());
1670 void setPattern(const char16_t *newPat
, int32_t newPatLen
);
1672 * Release existing cached pattern.
1674 void releasePattern();
1676 friend class UnicodeSetIterator
;
1681 inline UBool
UnicodeSet::operator!=(const UnicodeSet
& o
) const {
1682 return !operator==(o
);
1685 inline UBool
UnicodeSet::isFrozen() const {
1686 return (UBool
)(bmpSet
!=NULL
|| stringSpan
!=NULL
);
1689 inline UBool
UnicodeSet::containsSome(UChar32 start
, UChar32 end
) const {
1690 return !containsNone(start
, end
);
1693 inline UBool
UnicodeSet::containsSome(const UnicodeSet
& s
) const {
1694 return !containsNone(s
);
1697 inline UBool
UnicodeSet::containsSome(const UnicodeString
& s
) const {
1698 return !containsNone(s
);
1701 inline UBool
UnicodeSet::isBogus() const {
1702 return (UBool
)(fFlags
& kIsBogus
);
1705 inline UnicodeSet
*UnicodeSet::fromUSet(USet
*uset
) {
1706 return reinterpret_cast<UnicodeSet
*>(uset
);
1709 inline const UnicodeSet
*UnicodeSet::fromUSet(const USet
*uset
) {
1710 return reinterpret_cast<const UnicodeSet
*>(uset
);
1713 inline USet
*UnicodeSet::toUSet() {
1714 return reinterpret_cast<USet
*>(this);
1717 inline const USet
*UnicodeSet::toUSet() const {
1718 return reinterpret_cast<const USet
*>(this);
1721 inline int32_t UnicodeSet::span(const UnicodeString
&s
, int32_t start
, USetSpanCondition spanCondition
) const {
1722 int32_t sLength
=s
.length();
1725 } else if(start
>sLength
) {
1728 return start
+span(s
.getBuffer()+start
, sLength
-start
, spanCondition
);
1731 inline int32_t UnicodeSet::spanBack(const UnicodeString
&s
, int32_t limit
, USetSpanCondition spanCondition
) const {
1732 int32_t sLength
=s
.length();
1735 } else if(limit
>sLength
) {
1738 return spanBack(s
.getBuffer(), limit
, spanCondition
);
1743 #endif /* U_SHOW_CPLUSPLUS_API */