xref: /aosp_15_r20/external/icu/libicu/cts_headers/unicode/uniset.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker ***************************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 1999-2016, International Business Machines Corporation
6*0e209d39SAndroid Build Coastguard Worker * and others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker ***************************************************************************
8*0e209d39SAndroid Build Coastguard Worker *   Date        Name        Description
9*0e209d39SAndroid Build Coastguard Worker *   10/20/99    alan        Creation.
10*0e209d39SAndroid Build Coastguard Worker ***************************************************************************
11*0e209d39SAndroid Build Coastguard Worker */
12*0e209d39SAndroid Build Coastguard Worker 
13*0e209d39SAndroid Build Coastguard Worker #ifndef UNICODESET_H
14*0e209d39SAndroid Build Coastguard Worker #define UNICODESET_H
15*0e209d39SAndroid Build Coastguard Worker 
16*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
17*0e209d39SAndroid Build Coastguard Worker 
18*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
19*0e209d39SAndroid Build Coastguard Worker 
20*0e209d39SAndroid Build Coastguard Worker #include "unicode/ucpmap.h"
21*0e209d39SAndroid Build Coastguard Worker #include "unicode/unifilt.h"
22*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h"
23*0e209d39SAndroid Build Coastguard Worker #include "unicode/uset.h"
24*0e209d39SAndroid Build Coastguard Worker 
25*0e209d39SAndroid Build Coastguard Worker /**
26*0e209d39SAndroid Build Coastguard Worker  * \file
27*0e209d39SAndroid Build Coastguard Worker  * \brief C++ API: Unicode Set
28*0e209d39SAndroid Build Coastguard Worker  */
29*0e209d39SAndroid Build Coastguard Worker 
30*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
31*0e209d39SAndroid Build Coastguard Worker 
32*0e209d39SAndroid Build Coastguard Worker // Forward Declarations.
33*0e209d39SAndroid Build Coastguard Worker class BMPSet;
34*0e209d39SAndroid Build Coastguard Worker class ParsePosition;
35*0e209d39SAndroid Build Coastguard Worker class RBBIRuleScanner;
36*0e209d39SAndroid Build Coastguard Worker class SymbolTable;
37*0e209d39SAndroid Build Coastguard Worker class UnicodeSetStringSpan;
38*0e209d39SAndroid Build Coastguard Worker class UVector;
39*0e209d39SAndroid Build Coastguard Worker class RuleCharacterIterator;
40*0e209d39SAndroid Build Coastguard Worker 
41*0e209d39SAndroid Build Coastguard Worker /**
42*0e209d39SAndroid Build Coastguard Worker  * A mutable set of Unicode characters and multicharacter strings.  Objects of this class
43*0e209d39SAndroid Build Coastguard Worker  * represent <em>character classes</em> used in regular expressions.
44*0e209d39SAndroid Build Coastguard Worker  * A character specifies a subset of Unicode code points.  Legal
45*0e209d39SAndroid Build Coastguard Worker  * code points are U+0000 to U+10FFFF, inclusive.
46*0e209d39SAndroid Build Coastguard Worker  *
47*0e209d39SAndroid Build Coastguard Worker  * <p>The UnicodeSet class is not designed to be subclassed.
48*0e209d39SAndroid Build Coastguard Worker  *
49*0e209d39SAndroid Build Coastguard Worker  * <p><code>UnicodeSet</code> supports two APIs. The first is the
50*0e209d39SAndroid Build Coastguard Worker  * <em>operand</em> API that allows the caller to modify the value of
51*0e209d39SAndroid Build Coastguard Worker  * a <code>UnicodeSet</code> object. It conforms to Java 2's
52*0e209d39SAndroid Build Coastguard Worker  * <code>java.util.Set</code> interface, although
53*0e209d39SAndroid Build Coastguard Worker  * <code>UnicodeSet</code> does not actually implement that
54*0e209d39SAndroid Build Coastguard Worker  * interface. All methods of <code>Set</code> are supported, with the
55*0e209d39SAndroid Build Coastguard Worker  * modification that they take a character range or single character
56*0e209d39SAndroid Build Coastguard Worker  * instead of an <code>Object</code>, and they take a
57*0e209d39SAndroid Build Coastguard Worker  * <code>UnicodeSet</code> instead of a <code>Collection</code>.  The
58*0e209d39SAndroid Build Coastguard Worker  * operand API may be thought of in terms of boolean logic: a boolean
59*0e209d39SAndroid Build Coastguard Worker  * OR is implemented by <code>add</code>, a boolean AND is implemented
60*0e209d39SAndroid Build Coastguard Worker  * by <code>retain</code>, a boolean XOR is implemented by
61*0e209d39SAndroid Build Coastguard Worker  * <code>complement</code> taking an argument, and a boolean NOT is
62*0e209d39SAndroid Build Coastguard Worker  * implemented by <code>complement</code> with no argument.  In terms
63*0e209d39SAndroid Build Coastguard Worker  * of traditional set theory function names, <code>add</code> is a
64*0e209d39SAndroid Build Coastguard Worker  * union, <code>retain</code> is an intersection, <code>remove</code>
65*0e209d39SAndroid Build Coastguard Worker  * is an asymmetric difference, and <code>complement</code> with no
66*0e209d39SAndroid Build Coastguard Worker  * argument is a set complement with respect to the superset range
67*0e209d39SAndroid Build Coastguard Worker  * <code>MIN_VALUE-MAX_VALUE</code>
68*0e209d39SAndroid Build Coastguard Worker  *
69*0e209d39SAndroid Build Coastguard Worker  * <p>The second API is the
70*0e209d39SAndroid Build Coastguard Worker  * <code>applyPattern()</code>/<code>toPattern()</code> API from the
71*0e209d39SAndroid Build Coastguard Worker  * <code>java.text.Format</code>-derived classes.  Unlike the
72*0e209d39SAndroid Build Coastguard Worker  * methods that add characters, add categories, and control the logic
73*0e209d39SAndroid Build Coastguard Worker  * of the set, the method <code>applyPattern()</code> sets all
74*0e209d39SAndroid Build Coastguard Worker  * attributes of a <code>UnicodeSet</code> at once, based on a
75*0e209d39SAndroid Build Coastguard Worker  * string pattern.
76*0e209d39SAndroid Build Coastguard Worker  *
77*0e209d39SAndroid Build Coastguard Worker  * <p><b>Pattern syntax</b></p>
78*0e209d39SAndroid Build Coastguard Worker  *
79*0e209d39SAndroid Build Coastguard Worker  * Patterns are accepted by the constructors and the
80*0e209d39SAndroid Build Coastguard Worker  * <code>applyPattern()</code> methods and returned by the
81*0e209d39SAndroid Build Coastguard Worker  * <code>toPattern()</code> method.  These patterns follow a syntax
82*0e209d39SAndroid Build Coastguard Worker  * similar to that employed by version 8 regular expression character
83*0e209d39SAndroid Build Coastguard Worker  * classes.  Here are some simple examples:
84*0e209d39SAndroid Build Coastguard Worker  *
85*0e209d39SAndroid Build Coastguard Worker  * \htmlonly<blockquote>\endhtmlonly
86*0e209d39SAndroid Build Coastguard Worker  *   <table>
87*0e209d39SAndroid Build Coastguard Worker  *     <tr align="top">
88*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="left"><code>[]</code></td>
89*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top">No characters</td>
90*0e209d39SAndroid Build Coastguard Worker  *     </tr><tr align="top">
91*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="left"><code>[a]</code></td>
92*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top">The character 'a'</td>
93*0e209d39SAndroid Build Coastguard Worker  *     </tr><tr align="top">
94*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="left"><code>[ae]</code></td>
95*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top">The characters 'a' and 'e'</td>
96*0e209d39SAndroid Build Coastguard Worker  *     </tr>
97*0e209d39SAndroid Build Coastguard Worker  *     <tr>
98*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="left"><code>[a-e]</code></td>
99*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top">The characters 'a' through 'e' inclusive, in Unicode code
100*0e209d39SAndroid Build Coastguard Worker  *       point order</td>
101*0e209d39SAndroid Build Coastguard Worker  *     </tr>
102*0e209d39SAndroid Build Coastguard Worker  *     <tr>
103*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="left"><code>[\\u4E01]</code></td>
104*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top">The character U+4E01</td>
105*0e209d39SAndroid Build Coastguard Worker  *     </tr>
106*0e209d39SAndroid Build Coastguard Worker  *     <tr>
107*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="left"><code>[a{ab}{ac}]</code></td>
108*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top">The character 'a' and the multicharacter strings &quot;ab&quot; and
109*0e209d39SAndroid Build Coastguard Worker  *       &quot;ac&quot;</td>
110*0e209d39SAndroid Build Coastguard Worker  *     </tr>
111*0e209d39SAndroid Build Coastguard Worker  *     <tr>
112*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="left"><code>[\\p{Lu}]</code></td>
113*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top">All characters in the general category Uppercase Letter</td>
114*0e209d39SAndroid Build Coastguard Worker  *     </tr>
115*0e209d39SAndroid Build Coastguard Worker  *   </table>
116*0e209d39SAndroid Build Coastguard Worker  * \htmlonly</blockquote>\endhtmlonly
117*0e209d39SAndroid Build Coastguard Worker  *
118*0e209d39SAndroid Build Coastguard Worker  * Any character may be preceded by a backslash in order to remove any special
119*0e209d39SAndroid Build Coastguard Worker  * meaning.  White space characters, as defined by UCharacter.isWhitespace(), are
120*0e209d39SAndroid Build Coastguard Worker  * ignored, unless they are escaped.
121*0e209d39SAndroid Build Coastguard Worker  *
122*0e209d39SAndroid Build Coastguard Worker  * <p>Property patterns specify a set of characters having a certain
123*0e209d39SAndroid Build Coastguard Worker  * property as defined by the Unicode standard.  Both the POSIX-like
124*0e209d39SAndroid Build Coastguard Worker  * "[:Lu:]" and the Perl-like syntax "\\p{Lu}" are recognized.  For a
125*0e209d39SAndroid Build Coastguard Worker  * complete list of supported property patterns, see the User's Guide
126*0e209d39SAndroid Build Coastguard Worker  * for UnicodeSet at
127*0e209d39SAndroid Build Coastguard Worker  * <a href="https://unicode-org.github.io/icu/userguide/strings/unicodeset">
128*0e209d39SAndroid Build Coastguard Worker  * https://unicode-org.github.io/icu/userguide/strings/unicodeset</a>.
129*0e209d39SAndroid Build Coastguard Worker  * Actual determination of property data is defined by the underlying
130*0e209d39SAndroid Build Coastguard Worker  * Unicode database as implemented by UCharacter.
131*0e209d39SAndroid Build Coastguard Worker  *
132*0e209d39SAndroid Build Coastguard Worker  * <p>Patterns specify individual characters, ranges of characters, and
133*0e209d39SAndroid Build Coastguard Worker  * Unicode property sets.  When elements are concatenated, they
134*0e209d39SAndroid Build Coastguard Worker  * specify their union.  To complement a set, place a '^' immediately
135*0e209d39SAndroid Build Coastguard Worker  * after the opening '['.  Property patterns are inverted by modifying
136*0e209d39SAndroid Build Coastguard Worker  * their delimiters; "[:^foo]" and "\\P{foo}".  In any other location,
137*0e209d39SAndroid Build Coastguard Worker  * '^' has no special meaning.
138*0e209d39SAndroid Build Coastguard Worker  *
139*0e209d39SAndroid Build Coastguard Worker  * <p>Since ICU 70, "[^...]", "[:^foo]", "\\P{foo}", and "[:binaryProperty=No:]"
140*0e209d39SAndroid Build Coastguard Worker  * perform a “code point complement” (all code points minus the original set),
141*0e209d39SAndroid Build Coastguard Worker  * removing all multicharacter strings,
142*0e209d39SAndroid Build Coastguard Worker  * equivalent to <code>.complement().removeAllStrings()</code>.
143*0e209d39SAndroid Build Coastguard Worker  * The complement() API function continues to perform a
144*0e209d39SAndroid Build Coastguard Worker  * symmetric difference with all code points and thus retains all multicharacter strings.
145*0e209d39SAndroid Build Coastguard Worker  *
146*0e209d39SAndroid Build Coastguard Worker  * <p>Ranges are indicated by placing two a '-' between two
147*0e209d39SAndroid Build Coastguard Worker  * characters, as in "a-z".  This specifies the range of all
148*0e209d39SAndroid Build Coastguard Worker  * characters from the left to the right, in Unicode order.  If the
149*0e209d39SAndroid Build Coastguard Worker  * left character is greater than or equal to the
150*0e209d39SAndroid Build Coastguard Worker  * right character it is a syntax error.  If a '-' occurs as the first
151*0e209d39SAndroid Build Coastguard Worker  * character after the opening '[' or '[^', or if it occurs as the
152*0e209d39SAndroid Build Coastguard Worker  * last character before the closing ']', then it is taken as a
153*0e209d39SAndroid Build Coastguard Worker  * literal.  Thus "[a\-b]", "[-ab]", and "[ab-]" all indicate the same
154*0e209d39SAndroid Build Coastguard Worker  * set of three characters, 'a', 'b', and '-'.
155*0e209d39SAndroid Build Coastguard Worker  *
156*0e209d39SAndroid Build Coastguard Worker  * <p>Sets may be intersected using the '&' operator or the asymmetric
157*0e209d39SAndroid Build Coastguard Worker  * set difference may be taken using the '-' operator, for example,
158*0e209d39SAndroid Build Coastguard Worker  * "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters
159*0e209d39SAndroid Build Coastguard Worker  * with values less than 4096.  Operators ('&' and '|') have equal
160*0e209d39SAndroid Build Coastguard Worker  * precedence and bind left-to-right.  Thus
161*0e209d39SAndroid Build Coastguard Worker  * "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to
162*0e209d39SAndroid Build Coastguard Worker  * "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]".  This only really matters for
163*0e209d39SAndroid Build Coastguard Worker  * difference; intersection is commutative.
164*0e209d39SAndroid Build Coastguard Worker  *
165*0e209d39SAndroid Build Coastguard Worker  * <table>
166*0e209d39SAndroid Build Coastguard Worker  * <tr valign=top><td nowrap><code>[a]</code><td>The set containing 'a'
167*0e209d39SAndroid Build Coastguard Worker  * <tr valign=top><td nowrap><code>[a-z]</code><td>The set containing 'a'
168*0e209d39SAndroid Build Coastguard Worker  * through 'z' and all letters in between, in Unicode order
169*0e209d39SAndroid Build Coastguard Worker  * <tr valign=top><td nowrap><code>[^a-z]</code><td>The set containing
170*0e209d39SAndroid Build Coastguard Worker  * all characters but 'a' through 'z',
171*0e209d39SAndroid Build Coastguard Worker  * that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF
172*0e209d39SAndroid Build Coastguard Worker  * <tr valign=top><td nowrap><code>[[<em>pat1</em>][<em>pat2</em>]]</code>
173*0e209d39SAndroid Build Coastguard Worker  * <td>The union of sets specified by <em>pat1</em> and <em>pat2</em>
174*0e209d39SAndroid Build Coastguard Worker  * <tr valign=top><td nowrap><code>[[<em>pat1</em>]&[<em>pat2</em>]]</code>
175*0e209d39SAndroid Build Coastguard Worker  * <td>The intersection of sets specified by <em>pat1</em> and <em>pat2</em>
176*0e209d39SAndroid Build Coastguard Worker  * <tr valign=top><td nowrap><code>[[<em>pat1</em>]-[<em>pat2</em>]]</code>
177*0e209d39SAndroid Build Coastguard Worker  * <td>The asymmetric difference of sets specified by <em>pat1</em> and
178*0e209d39SAndroid Build Coastguard Worker  * <em>pat2</em>
179*0e209d39SAndroid Build Coastguard Worker  * <tr valign=top><td nowrap><code>[:Lu:] or \\p{Lu}</code>
180*0e209d39SAndroid Build Coastguard Worker  * <td>The set of characters having the specified
181*0e209d39SAndroid Build Coastguard Worker  * Unicode property; in
182*0e209d39SAndroid Build Coastguard Worker  * this case, Unicode uppercase letters
183*0e209d39SAndroid Build Coastguard Worker  * <tr valign=top><td nowrap><code>[:^Lu:] or \\P{Lu}</code>
184*0e209d39SAndroid Build Coastguard Worker  * <td>The set of characters <em>not</em> having the given
185*0e209d39SAndroid Build Coastguard Worker  * Unicode property
186*0e209d39SAndroid Build Coastguard Worker  * </table>
187*0e209d39SAndroid Build Coastguard Worker  *
188*0e209d39SAndroid Build Coastguard Worker  * <p><b>Formal syntax</b></p>
189*0e209d39SAndroid Build Coastguard Worker  *
190*0e209d39SAndroid Build Coastguard Worker  * \htmlonly<blockquote>\endhtmlonly
191*0e209d39SAndroid Build Coastguard Worker  *   <table>
192*0e209d39SAndroid Build Coastguard Worker  *     <tr align="top">
193*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="right"><code>pattern :=&nbsp; </code></td>
194*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top"><code>('[' '^'? item* ']') |
195*0e209d39SAndroid Build Coastguard Worker  *       property</code></td>
196*0e209d39SAndroid Build Coastguard Worker  *     </tr>
197*0e209d39SAndroid Build Coastguard Worker  *     <tr align="top">
198*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="right"><code>item :=&nbsp; </code></td>
199*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top"><code>char | (char '-' char) | pattern-expr<br>
200*0e209d39SAndroid Build Coastguard Worker  *       </code></td>
201*0e209d39SAndroid Build Coastguard Worker  *     </tr>
202*0e209d39SAndroid Build Coastguard Worker  *     <tr align="top">
203*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="right"><code>pattern-expr :=&nbsp; </code></td>
204*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top"><code>pattern | pattern-expr pattern |
205*0e209d39SAndroid Build Coastguard Worker  *       pattern-expr op pattern<br>
206*0e209d39SAndroid Build Coastguard Worker  *       </code></td>
207*0e209d39SAndroid Build Coastguard Worker  *     </tr>
208*0e209d39SAndroid Build Coastguard Worker  *     <tr align="top">
209*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="right"><code>op :=&nbsp; </code></td>
210*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top"><code>'&amp;' | '-'<br>
211*0e209d39SAndroid Build Coastguard Worker  *       </code></td>
212*0e209d39SAndroid Build Coastguard Worker  *     </tr>
213*0e209d39SAndroid Build Coastguard Worker  *     <tr align="top">
214*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="right"><code>special :=&nbsp; </code></td>
215*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top"><code>'[' | ']' | '-'<br>
216*0e209d39SAndroid Build Coastguard Worker  *       </code></td>
217*0e209d39SAndroid Build Coastguard Worker  *     </tr>
218*0e209d39SAndroid Build Coastguard Worker  *     <tr align="top">
219*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="right"><code>char :=&nbsp; </code></td>
220*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top"><em>any character that is not</em><code> special<br>
221*0e209d39SAndroid Build Coastguard Worker  *       | ('\' </code><em>any character</em><code>)<br>
222*0e209d39SAndroid Build Coastguard Worker  *       | ('\\u' hex hex hex hex)<br>
223*0e209d39SAndroid Build Coastguard Worker  *       </code></td>
224*0e209d39SAndroid Build Coastguard Worker  *     </tr>
225*0e209d39SAndroid Build Coastguard Worker  *     <tr align="top">
226*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="right"><code>hex :=&nbsp; </code></td>
227*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top"><code>'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |<br>
228*0e209d39SAndroid Build Coastguard Worker  *       &nbsp;&nbsp;&nbsp;&nbsp;'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'</code></td>
229*0e209d39SAndroid Build Coastguard Worker  *     </tr>
230*0e209d39SAndroid Build Coastguard Worker  *     <tr>
231*0e209d39SAndroid Build Coastguard Worker  *       <td nowrap valign="top" align="right"><code>property :=&nbsp; </code></td>
232*0e209d39SAndroid Build Coastguard Worker  *       <td valign="top"><em>a Unicode property set pattern</em></td>
233*0e209d39SAndroid Build Coastguard Worker  *     </tr>
234*0e209d39SAndroid Build Coastguard Worker  *   </table>
235*0e209d39SAndroid Build Coastguard Worker  *   <br>
236*0e209d39SAndroid Build Coastguard Worker  *   <table border="1">
237*0e209d39SAndroid Build Coastguard Worker  *     <tr>
238*0e209d39SAndroid Build Coastguard Worker  *       <td>Legend: <table>
239*0e209d39SAndroid Build Coastguard Worker  *         <tr>
240*0e209d39SAndroid Build Coastguard Worker  *           <td nowrap valign="top"><code>a := b</code></td>
241*0e209d39SAndroid Build Coastguard Worker  *           <td width="20" valign="top">&nbsp; </td>
242*0e209d39SAndroid Build Coastguard Worker  *           <td valign="top"><code>a</code> may be replaced by <code>b</code> </td>
243*0e209d39SAndroid Build Coastguard Worker  *         </tr>
244*0e209d39SAndroid Build Coastguard Worker  *         <tr>
245*0e209d39SAndroid Build Coastguard Worker  *           <td nowrap valign="top"><code>a?</code></td>
246*0e209d39SAndroid Build Coastguard Worker  *           <td valign="top"></td>
247*0e209d39SAndroid Build Coastguard Worker  *           <td valign="top">zero or one instance of <code>a</code><br>
248*0e209d39SAndroid Build Coastguard Worker  *           </td>
249*0e209d39SAndroid Build Coastguard Worker  *         </tr>
250*0e209d39SAndroid Build Coastguard Worker  *         <tr>
251*0e209d39SAndroid Build Coastguard Worker  *           <td nowrap valign="top"><code>a*</code></td>
252*0e209d39SAndroid Build Coastguard Worker  *           <td valign="top"></td>
253*0e209d39SAndroid Build Coastguard Worker  *           <td valign="top">one or more instances of <code>a</code><br>
254*0e209d39SAndroid Build Coastguard Worker  *           </td>
255*0e209d39SAndroid Build Coastguard Worker  *         </tr>
256*0e209d39SAndroid Build Coastguard Worker  *         <tr>
257*0e209d39SAndroid Build Coastguard Worker  *           <td nowrap valign="top"><code>a | b</code></td>
258*0e209d39SAndroid Build Coastguard Worker  *           <td valign="top"></td>
259*0e209d39SAndroid Build Coastguard Worker  *           <td valign="top">either <code>a</code> or <code>b</code><br>
260*0e209d39SAndroid Build Coastguard Worker  *           </td>
261*0e209d39SAndroid Build Coastguard Worker  *         </tr>
262*0e209d39SAndroid Build Coastguard Worker  *         <tr>
263*0e209d39SAndroid Build Coastguard Worker  *           <td nowrap valign="top"><code>'a'</code></td>
264*0e209d39SAndroid Build Coastguard Worker  *           <td valign="top"></td>
265*0e209d39SAndroid Build Coastguard Worker  *           <td valign="top">the literal string between the quotes </td>
266*0e209d39SAndroid Build Coastguard Worker  *         </tr>
267*0e209d39SAndroid Build Coastguard Worker  *       </table>
268*0e209d39SAndroid Build Coastguard Worker  *       </td>
269*0e209d39SAndroid Build Coastguard Worker  *     </tr>
270*0e209d39SAndroid Build Coastguard Worker  *   </table>
271*0e209d39SAndroid Build Coastguard Worker  * \htmlonly</blockquote>\endhtmlonly
272*0e209d39SAndroid Build Coastguard Worker  *
273*0e209d39SAndroid Build Coastguard Worker  * <p>Note:
274*0e209d39SAndroid Build Coastguard Worker  *  - Most UnicodeSet methods do not take a UErrorCode parameter because
275*0e209d39SAndroid Build Coastguard Worker  *   there are usually very few opportunities for failure other than a shortage
276*0e209d39SAndroid Build Coastguard Worker  *   of memory, error codes in low-level C++ string methods would be inconvenient,
277*0e209d39SAndroid Build Coastguard Worker  *   and the error code as the last parameter (ICU convention) would prevent
278*0e209d39SAndroid Build Coastguard Worker  *   the use of default parameter values.
279*0e209d39SAndroid Build Coastguard Worker  *   Instead, such methods set the UnicodeSet into a "bogus" state
280*0e209d39SAndroid Build Coastguard Worker  *   (see isBogus()) if an error occurs.
281*0e209d39SAndroid Build Coastguard Worker  *
282*0e209d39SAndroid Build Coastguard Worker  * @author Alan Liu
283*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
284*0e209d39SAndroid Build Coastguard Worker  */
285*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API UnicodeSet final : public UnicodeFilter {
286*0e209d39SAndroid Build Coastguard Worker private:
287*0e209d39SAndroid Build Coastguard Worker     /**
288*0e209d39SAndroid Build Coastguard Worker      * Enough for sets with few ranges.
289*0e209d39SAndroid Build Coastguard Worker      * For example, White_Space has 10 ranges, list length 21.
290*0e209d39SAndroid Build Coastguard Worker      */
291*0e209d39SAndroid Build Coastguard Worker     static constexpr int32_t INITIAL_CAPACITY = 25;
292*0e209d39SAndroid Build Coastguard Worker     // fFlags constant
293*0e209d39SAndroid Build Coastguard Worker     static constexpr uint8_t kIsBogus = 1;  // This set is bogus (i.e. not valid)
294*0e209d39SAndroid Build Coastguard Worker 
295*0e209d39SAndroid Build Coastguard Worker     UChar32* list = stackList; // MUST be terminated with HIGH
296*0e209d39SAndroid Build Coastguard Worker     int32_t capacity = INITIAL_CAPACITY; // capacity of list
297*0e209d39SAndroid Build Coastguard Worker     int32_t len = 1; // length of list used; 1 <= len <= capacity
298*0e209d39SAndroid Build Coastguard Worker     uint8_t fFlags = 0;         // Bit flag (see constants above)
299*0e209d39SAndroid Build Coastguard Worker 
300*0e209d39SAndroid Build Coastguard Worker     BMPSet *bmpSet = nullptr; // The set is frozen iff either bmpSet or stringSpan is not nullptr.
301*0e209d39SAndroid Build Coastguard Worker     UChar32* buffer = nullptr; // internal buffer, may be nullptr
302*0e209d39SAndroid Build Coastguard Worker     int32_t bufferCapacity = 0; // capacity of buffer
303*0e209d39SAndroid Build Coastguard Worker 
304*0e209d39SAndroid Build Coastguard Worker     /**
305*0e209d39SAndroid Build Coastguard Worker      * The pattern representation of this set.  This may not be the
306*0e209d39SAndroid Build Coastguard Worker      * most economical pattern.  It is the pattern supplied to
307*0e209d39SAndroid Build Coastguard Worker      * applyPattern(), with variables substituted and whitespace
308*0e209d39SAndroid Build Coastguard Worker      * removed.  For sets constructed without applyPattern(), or
309*0e209d39SAndroid Build Coastguard Worker      * modified using the non-pattern API, this string will be empty,
310*0e209d39SAndroid Build Coastguard Worker      * indicating that toPattern() must generate a pattern
311*0e209d39SAndroid Build Coastguard Worker      * representation from the inversion list.
312*0e209d39SAndroid Build Coastguard Worker      */
313*0e209d39SAndroid Build Coastguard Worker     char16_t *pat = nullptr;
314*0e209d39SAndroid Build Coastguard Worker     int32_t patLen = 0;
315*0e209d39SAndroid Build Coastguard Worker 
316*0e209d39SAndroid Build Coastguard Worker     UVector* strings = nullptr; // maintained in sorted order
317*0e209d39SAndroid Build Coastguard Worker     UnicodeSetStringSpan *stringSpan = nullptr;
318*0e209d39SAndroid Build Coastguard Worker 
319*0e209d39SAndroid Build Coastguard Worker     /**
320*0e209d39SAndroid Build Coastguard Worker      * Initial list array.
321*0e209d39SAndroid Build Coastguard Worker      * Avoids some heap allocations, and list is never nullptr.
322*0e209d39SAndroid Build Coastguard Worker      * Increases the object size a bit.
323*0e209d39SAndroid Build Coastguard Worker      */
324*0e209d39SAndroid Build Coastguard Worker     UChar32 stackList[INITIAL_CAPACITY];
325*0e209d39SAndroid Build Coastguard Worker 
326*0e209d39SAndroid Build Coastguard Worker public:
327*0e209d39SAndroid Build Coastguard Worker     /**
328*0e209d39SAndroid Build Coastguard Worker      * Determine if this object contains a valid set.
329*0e209d39SAndroid Build Coastguard Worker      * A bogus set has no value. It is different from an empty set.
330*0e209d39SAndroid Build Coastguard Worker      * It can be used to indicate that no set value is available.
331*0e209d39SAndroid Build Coastguard Worker      *
332*0e209d39SAndroid Build Coastguard Worker      * @return true if the set is bogus/invalid, false otherwise
333*0e209d39SAndroid Build Coastguard Worker      * @see setToBogus()
334*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.0
335*0e209d39SAndroid Build Coastguard Worker      */
336*0e209d39SAndroid Build Coastguard Worker     inline UBool isBogus() const;
337*0e209d39SAndroid Build Coastguard Worker 
338*0e209d39SAndroid Build Coastguard Worker     /**
339*0e209d39SAndroid Build Coastguard Worker      * Make this UnicodeSet object invalid.
340*0e209d39SAndroid Build Coastguard Worker      * The string will test true with isBogus().
341*0e209d39SAndroid Build Coastguard Worker      *
342*0e209d39SAndroid Build Coastguard Worker      * A bogus set has no value. It is different from an empty set.
343*0e209d39SAndroid Build Coastguard Worker      * It can be used to indicate that no set value is available.
344*0e209d39SAndroid Build Coastguard Worker      *
345*0e209d39SAndroid Build Coastguard Worker      * This utility function is used throughout the UnicodeSet
346*0e209d39SAndroid Build Coastguard Worker      * implementation to indicate that a UnicodeSet operation failed,
347*0e209d39SAndroid Build Coastguard Worker      * and may be used in other functions,
348*0e209d39SAndroid Build Coastguard Worker      * especially but not exclusively when such functions do not
349*0e209d39SAndroid Build Coastguard Worker      * take a UErrorCode for simplicity.
350*0e209d39SAndroid Build Coastguard Worker      *
351*0e209d39SAndroid Build Coastguard Worker      * @see isBogus()
352*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.0
353*0e209d39SAndroid Build Coastguard Worker      */
354*0e209d39SAndroid Build Coastguard Worker     void setToBogus();
355*0e209d39SAndroid Build Coastguard Worker 
356*0e209d39SAndroid Build Coastguard Worker public:
357*0e209d39SAndroid Build Coastguard Worker 
358*0e209d39SAndroid Build Coastguard Worker     enum {
359*0e209d39SAndroid Build Coastguard Worker         /**
360*0e209d39SAndroid Build Coastguard Worker          * Minimum value that can be stored in a UnicodeSet.
361*0e209d39SAndroid Build Coastguard Worker          * @stable ICU 2.4
362*0e209d39SAndroid Build Coastguard Worker          */
363*0e209d39SAndroid Build Coastguard Worker         MIN_VALUE = 0,
364*0e209d39SAndroid Build Coastguard Worker 
365*0e209d39SAndroid Build Coastguard Worker         /**
366*0e209d39SAndroid Build Coastguard Worker          * Maximum value that can be stored in a UnicodeSet.
367*0e209d39SAndroid Build Coastguard Worker          * @stable ICU 2.4
368*0e209d39SAndroid Build Coastguard Worker          */
369*0e209d39SAndroid Build Coastguard Worker         MAX_VALUE = 0x10ffff
370*0e209d39SAndroid Build Coastguard Worker     };
371*0e209d39SAndroid Build Coastguard Worker 
372*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
373*0e209d39SAndroid Build Coastguard Worker     // Constructors &c
374*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
375*0e209d39SAndroid Build Coastguard Worker 
376*0e209d39SAndroid Build Coastguard Worker public:
377*0e209d39SAndroid Build Coastguard Worker 
378*0e209d39SAndroid Build Coastguard Worker     /**
379*0e209d39SAndroid Build Coastguard Worker      * Constructs an empty set.
380*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
381*0e209d39SAndroid Build Coastguard Worker      */
382*0e209d39SAndroid Build Coastguard Worker     UnicodeSet();
383*0e209d39SAndroid Build Coastguard Worker 
384*0e209d39SAndroid Build Coastguard Worker     /**
385*0e209d39SAndroid Build Coastguard Worker      * Constructs a set containing the given range. If <code>end <
386*0e209d39SAndroid Build Coastguard Worker      * start</code> then an empty set is created.
387*0e209d39SAndroid Build Coastguard Worker      *
388*0e209d39SAndroid Build Coastguard Worker      * @param start first character, inclusive, of range
389*0e209d39SAndroid Build Coastguard Worker      * @param end last character, inclusive, of range
390*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
391*0e209d39SAndroid Build Coastguard Worker      */
392*0e209d39SAndroid Build Coastguard Worker     UnicodeSet(UChar32 start, UChar32 end);
393*0e209d39SAndroid Build Coastguard Worker 
394*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
395*0e209d39SAndroid Build Coastguard Worker     /**
396*0e209d39SAndroid Build Coastguard Worker      * @internal
397*0e209d39SAndroid Build Coastguard Worker      */
398*0e209d39SAndroid Build Coastguard Worker     enum ESerialization {
399*0e209d39SAndroid Build Coastguard Worker       kSerialized  /* result of serialize() */
400*0e209d39SAndroid Build Coastguard Worker     };
401*0e209d39SAndroid Build Coastguard Worker 
402*0e209d39SAndroid Build Coastguard Worker     /**
403*0e209d39SAndroid Build Coastguard Worker      * Constructs a set from the output of serialize().
404*0e209d39SAndroid Build Coastguard Worker      *
405*0e209d39SAndroid Build Coastguard Worker      * @param buffer the 16 bit array
406*0e209d39SAndroid Build Coastguard Worker      * @param bufferLen the original length returned from serialize()
407*0e209d39SAndroid Build Coastguard Worker      * @param serialization the value 'kSerialized'
408*0e209d39SAndroid Build Coastguard Worker      * @param status error code
409*0e209d39SAndroid Build Coastguard Worker      *
410*0e209d39SAndroid Build Coastguard Worker      * @internal
411*0e209d39SAndroid Build Coastguard Worker      */
412*0e209d39SAndroid Build Coastguard Worker     UnicodeSet(const uint16_t buffer[], int32_t bufferLen,
413*0e209d39SAndroid Build Coastguard Worker                ESerialization serialization, UErrorCode &status);
414*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_INTERNAL_API */
415*0e209d39SAndroid Build Coastguard Worker 
416*0e209d39SAndroid Build Coastguard Worker     /**
417*0e209d39SAndroid Build Coastguard Worker      * Constructs a set from the given pattern.  See the class
418*0e209d39SAndroid Build Coastguard Worker      * description for the syntax of the pattern language.
419*0e209d39SAndroid Build Coastguard Worker      * @param pattern a string specifying what characters are in the set
420*0e209d39SAndroid Build Coastguard Worker      * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
421*0e209d39SAndroid Build Coastguard Worker      * contains a syntax error.
422*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
423*0e209d39SAndroid Build Coastguard Worker      */
424*0e209d39SAndroid Build Coastguard Worker     UnicodeSet(const UnicodeString& pattern,
425*0e209d39SAndroid Build Coastguard Worker                UErrorCode& status);
426*0e209d39SAndroid Build Coastguard Worker 
427*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
428*0e209d39SAndroid Build Coastguard Worker     /**
429*0e209d39SAndroid Build Coastguard Worker      * Constructs a set from the given pattern.  See the class
430*0e209d39SAndroid Build Coastguard Worker      * description for the syntax of the pattern language.
431*0e209d39SAndroid Build Coastguard Worker      * @param pattern a string specifying what characters are in the set
432*0e209d39SAndroid Build Coastguard Worker      * @param options bitmask for options to apply to the pattern.
433*0e209d39SAndroid Build Coastguard Worker      * Valid options are USET_IGNORE_SPACE and
434*0e209d39SAndroid Build Coastguard Worker      * at most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
435*0e209d39SAndroid Build Coastguard Worker      * These case options are mutually exclusive.
436*0e209d39SAndroid Build Coastguard Worker      * @param symbols a symbol table mapping variable names to values
437*0e209d39SAndroid Build Coastguard Worker      * and stand-in characters to UnicodeSets; may be nullptr
438*0e209d39SAndroid Build Coastguard Worker      * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
439*0e209d39SAndroid Build Coastguard Worker      * contains a syntax error.
440*0e209d39SAndroid Build Coastguard Worker      * @internal
441*0e209d39SAndroid Build Coastguard Worker      */
442*0e209d39SAndroid Build Coastguard Worker     UnicodeSet(const UnicodeString& pattern,
443*0e209d39SAndroid Build Coastguard Worker                uint32_t options,
444*0e209d39SAndroid Build Coastguard Worker                const SymbolTable* symbols,
445*0e209d39SAndroid Build Coastguard Worker                UErrorCode& status);
446*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_INTERNAL_API */
447*0e209d39SAndroid Build Coastguard Worker 
448*0e209d39SAndroid Build Coastguard Worker     /**
449*0e209d39SAndroid Build Coastguard Worker      * Constructs a set from the given pattern.  See the class description
450*0e209d39SAndroid Build Coastguard Worker      * for the syntax of the pattern language.
451*0e209d39SAndroid Build Coastguard Worker      * @param pattern a string specifying what characters are in the set
452*0e209d39SAndroid Build Coastguard Worker      * @param pos on input, the position in pattern at which to start parsing.
453*0e209d39SAndroid Build Coastguard Worker      * On output, the position after the last character parsed.
454*0e209d39SAndroid Build Coastguard Worker      * @param options bitmask for options to apply to the pattern.
455*0e209d39SAndroid Build Coastguard Worker      * Valid options are USET_IGNORE_SPACE and
456*0e209d39SAndroid Build Coastguard Worker      * at most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
457*0e209d39SAndroid Build Coastguard Worker      * These case options are mutually exclusive.
458*0e209d39SAndroid Build Coastguard Worker      * @param symbols a symbol table mapping variable names to values
459*0e209d39SAndroid Build Coastguard Worker      * and stand-in characters to UnicodeSets; may be nullptr
460*0e209d39SAndroid Build Coastguard Worker      * @param status input-output error code
461*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.8
462*0e209d39SAndroid Build Coastguard Worker      */
463*0e209d39SAndroid Build Coastguard Worker     UnicodeSet(const UnicodeString& pattern, ParsePosition& pos,
464*0e209d39SAndroid Build Coastguard Worker                uint32_t options,
465*0e209d39SAndroid Build Coastguard Worker                const SymbolTable* symbols,
466*0e209d39SAndroid Build Coastguard Worker                UErrorCode& status);
467*0e209d39SAndroid Build Coastguard Worker 
468*0e209d39SAndroid Build Coastguard Worker     /**
469*0e209d39SAndroid Build Coastguard Worker      * Constructs a set that is identical to the given UnicodeSet.
470*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
471*0e209d39SAndroid Build Coastguard Worker      */
472*0e209d39SAndroid Build Coastguard Worker     UnicodeSet(const UnicodeSet& o);
473*0e209d39SAndroid Build Coastguard Worker 
474*0e209d39SAndroid Build Coastguard Worker     /**
475*0e209d39SAndroid Build Coastguard Worker      * Destructs the set.
476*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
477*0e209d39SAndroid Build Coastguard Worker      */
478*0e209d39SAndroid Build Coastguard Worker     virtual ~UnicodeSet();
479*0e209d39SAndroid Build Coastguard Worker 
480*0e209d39SAndroid Build Coastguard Worker     /**
481*0e209d39SAndroid Build Coastguard Worker      * Assigns this object to be a copy of another.
482*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
483*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
484*0e209d39SAndroid Build Coastguard Worker      */
485*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& operator=(const UnicodeSet& o);
486*0e209d39SAndroid Build Coastguard Worker 
487*0e209d39SAndroid Build Coastguard Worker     /**
488*0e209d39SAndroid Build Coastguard Worker      * Compares the specified object with this set for equality.  Returns
489*0e209d39SAndroid Build Coastguard Worker      * <tt>true</tt> if the two sets
490*0e209d39SAndroid Build Coastguard Worker      * have the same size, and every member of the specified set is
491*0e209d39SAndroid Build Coastguard Worker      * contained in this set (or equivalently, every member of this set is
492*0e209d39SAndroid Build Coastguard Worker      * contained in the specified set).
493*0e209d39SAndroid Build Coastguard Worker      *
494*0e209d39SAndroid Build Coastguard Worker      * @param o set to be compared for equality with this set.
495*0e209d39SAndroid Build Coastguard Worker      * @return <tt>true</tt> if the specified set is equal to this set.
496*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
497*0e209d39SAndroid Build Coastguard Worker      */
498*0e209d39SAndroid Build Coastguard Worker     virtual bool operator==(const UnicodeSet& o) const;
499*0e209d39SAndroid Build Coastguard Worker 
500*0e209d39SAndroid Build Coastguard Worker     /**
501*0e209d39SAndroid Build Coastguard Worker      * Compares the specified object with this set for equality.  Returns
502*0e209d39SAndroid Build Coastguard Worker      * <tt>true</tt> if the specified set is not equal to this set.
503*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
504*0e209d39SAndroid Build Coastguard Worker      */
505*0e209d39SAndroid Build Coastguard Worker     inline bool operator!=(const UnicodeSet& o) const;
506*0e209d39SAndroid Build Coastguard Worker 
507*0e209d39SAndroid Build Coastguard Worker     /**
508*0e209d39SAndroid Build Coastguard Worker      * Returns a copy of this object.  All UnicodeFunctor objects have
509*0e209d39SAndroid Build Coastguard Worker      * to support cloning in order to allow classes using
510*0e209d39SAndroid Build Coastguard Worker      * UnicodeFunctors, such as Transliterator, to implement cloning.
511*0e209d39SAndroid Build Coastguard Worker      * If this set is frozen, then the clone will be frozen as well.
512*0e209d39SAndroid Build Coastguard Worker      * Use cloneAsThawed() for a mutable clone of a frozen set.
513*0e209d39SAndroid Build Coastguard Worker      * @see cloneAsThawed
514*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
515*0e209d39SAndroid Build Coastguard Worker      */
516*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet* clone() const override;
517*0e209d39SAndroid Build Coastguard Worker 
518*0e209d39SAndroid Build Coastguard Worker     /**
519*0e209d39SAndroid Build Coastguard Worker      * Returns the hash code value for this set.
520*0e209d39SAndroid Build Coastguard Worker      *
521*0e209d39SAndroid Build Coastguard Worker      * @return the hash code value for this set.
522*0e209d39SAndroid Build Coastguard Worker      * @see Object#hashCode()
523*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
524*0e209d39SAndroid Build Coastguard Worker      */
525*0e209d39SAndroid Build Coastguard Worker     virtual int32_t hashCode() const;
526*0e209d39SAndroid Build Coastguard Worker 
527*0e209d39SAndroid Build Coastguard Worker     /**
528*0e209d39SAndroid Build Coastguard Worker      * Get a UnicodeSet pointer from a USet
529*0e209d39SAndroid Build Coastguard Worker      *
530*0e209d39SAndroid Build Coastguard Worker      * @param uset a USet (the ICU plain C type for UnicodeSet)
531*0e209d39SAndroid Build Coastguard Worker      * @return the corresponding UnicodeSet pointer.
532*0e209d39SAndroid Build Coastguard Worker      *
533*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.2
534*0e209d39SAndroid Build Coastguard Worker      */
535*0e209d39SAndroid Build Coastguard Worker     inline static UnicodeSet *fromUSet(USet *uset);
536*0e209d39SAndroid Build Coastguard Worker 
537*0e209d39SAndroid Build Coastguard Worker     /**
538*0e209d39SAndroid Build Coastguard Worker      * Get a UnicodeSet pointer from a const USet
539*0e209d39SAndroid Build Coastguard Worker      *
540*0e209d39SAndroid Build Coastguard Worker      * @param uset a const USet (the ICU plain C type for UnicodeSet)
541*0e209d39SAndroid Build Coastguard Worker      * @return the corresponding UnicodeSet pointer.
542*0e209d39SAndroid Build Coastguard Worker      *
543*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.2
544*0e209d39SAndroid Build Coastguard Worker      */
545*0e209d39SAndroid Build Coastguard Worker     inline static const UnicodeSet *fromUSet(const USet *uset);
546*0e209d39SAndroid Build Coastguard Worker 
547*0e209d39SAndroid Build Coastguard Worker     /**
548*0e209d39SAndroid Build Coastguard Worker      * Produce a USet * pointer for this UnicodeSet.
549*0e209d39SAndroid Build Coastguard Worker      * USet is the plain C type for UnicodeSet
550*0e209d39SAndroid Build Coastguard Worker      *
551*0e209d39SAndroid Build Coastguard Worker      * @return a USet pointer for this UnicodeSet
552*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.2
553*0e209d39SAndroid Build Coastguard Worker      */
554*0e209d39SAndroid Build Coastguard Worker     inline USet *toUSet();
555*0e209d39SAndroid Build Coastguard Worker 
556*0e209d39SAndroid Build Coastguard Worker 
557*0e209d39SAndroid Build Coastguard Worker     /**
558*0e209d39SAndroid Build Coastguard Worker      * Produce a const USet * pointer for this UnicodeSet.
559*0e209d39SAndroid Build Coastguard Worker      * USet is the plain C type for UnicodeSet
560*0e209d39SAndroid Build Coastguard Worker      *
561*0e209d39SAndroid Build Coastguard Worker      * @return a const USet pointer for this UnicodeSet
562*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.2
563*0e209d39SAndroid Build Coastguard Worker      */
564*0e209d39SAndroid Build Coastguard Worker     inline const USet * toUSet() const;
565*0e209d39SAndroid Build Coastguard Worker 
566*0e209d39SAndroid Build Coastguard Worker 
567*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
568*0e209d39SAndroid Build Coastguard Worker     // Freezable API
569*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
570*0e209d39SAndroid Build Coastguard Worker 
571*0e209d39SAndroid Build Coastguard Worker     /**
572*0e209d39SAndroid Build Coastguard Worker      * Determines whether the set has been frozen (made immutable) or not.
573*0e209d39SAndroid Build Coastguard Worker      * See the ICU4J Freezable interface for details.
574*0e209d39SAndroid Build Coastguard Worker      * @return true/false for whether the set has been frozen
575*0e209d39SAndroid Build Coastguard Worker      * @see freeze
576*0e209d39SAndroid Build Coastguard Worker      * @see cloneAsThawed
577*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.8
578*0e209d39SAndroid Build Coastguard Worker      */
579*0e209d39SAndroid Build Coastguard Worker     inline UBool isFrozen() const;
580*0e209d39SAndroid Build Coastguard Worker 
581*0e209d39SAndroid Build Coastguard Worker     /**
582*0e209d39SAndroid Build Coastguard Worker      * Freeze the set (make it immutable).
583*0e209d39SAndroid Build Coastguard Worker      * Once frozen, it cannot be unfrozen and is therefore thread-safe
584*0e209d39SAndroid Build Coastguard Worker      * until it is deleted.
585*0e209d39SAndroid Build Coastguard Worker      * See the ICU4J Freezable interface for details.
586*0e209d39SAndroid Build Coastguard Worker      * Freezing the set may also make some operations faster, for example
587*0e209d39SAndroid Build Coastguard Worker      * contains() and span().
588*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified. (It remains frozen.)
589*0e209d39SAndroid Build Coastguard Worker      * @return this set.
590*0e209d39SAndroid Build Coastguard Worker      * @see isFrozen
591*0e209d39SAndroid Build Coastguard Worker      * @see cloneAsThawed
592*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.8
593*0e209d39SAndroid Build Coastguard Worker      */
594*0e209d39SAndroid Build Coastguard Worker     UnicodeSet *freeze();
595*0e209d39SAndroid Build Coastguard Worker 
596*0e209d39SAndroid Build Coastguard Worker     /**
597*0e209d39SAndroid Build Coastguard Worker      * Clone the set and make the clone mutable.
598*0e209d39SAndroid Build Coastguard Worker      * See the ICU4J Freezable interface for details.
599*0e209d39SAndroid Build Coastguard Worker      * @return the mutable clone
600*0e209d39SAndroid Build Coastguard Worker      * @see freeze
601*0e209d39SAndroid Build Coastguard Worker      * @see isFrozen
602*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.8
603*0e209d39SAndroid Build Coastguard Worker      */
604*0e209d39SAndroid Build Coastguard Worker     UnicodeSet *cloneAsThawed() const;
605*0e209d39SAndroid Build Coastguard Worker 
606*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
607*0e209d39SAndroid Build Coastguard Worker     // Public API
608*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
609*0e209d39SAndroid Build Coastguard Worker 
610*0e209d39SAndroid Build Coastguard Worker     /**
611*0e209d39SAndroid Build Coastguard Worker      * Make this object represent the range `start - end`.
612*0e209d39SAndroid Build Coastguard Worker      * If `start > end` then this object is set to an empty range.
613*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
614*0e209d39SAndroid Build Coastguard Worker      *
615*0e209d39SAndroid Build Coastguard Worker      * @param start first character in the set, inclusive
616*0e209d39SAndroid Build Coastguard Worker      * @param end last character in the set, inclusive
617*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
618*0e209d39SAndroid Build Coastguard Worker      */
619*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& set(UChar32 start, UChar32 end);
620*0e209d39SAndroid Build Coastguard Worker 
621*0e209d39SAndroid Build Coastguard Worker     /**
622*0e209d39SAndroid Build Coastguard Worker      * Return true if the given position, in the given pattern, appears
623*0e209d39SAndroid Build Coastguard Worker      * to be the start of a UnicodeSet pattern.
624*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
625*0e209d39SAndroid Build Coastguard Worker      */
626*0e209d39SAndroid Build Coastguard Worker     static UBool resemblesPattern(const UnicodeString& pattern,
627*0e209d39SAndroid Build Coastguard Worker                                   int32_t pos);
628*0e209d39SAndroid Build Coastguard Worker 
629*0e209d39SAndroid Build Coastguard Worker     /**
630*0e209d39SAndroid Build Coastguard Worker      * Modifies this set to represent the set specified by the given
631*0e209d39SAndroid Build Coastguard Worker      * pattern, ignoring Unicode Pattern_White_Space characters.
632*0e209d39SAndroid Build Coastguard Worker      * See the class description for the syntax of the pattern language.
633*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
634*0e209d39SAndroid Build Coastguard Worker      * @param pattern a string specifying what characters are in the set
635*0e209d39SAndroid Build Coastguard Worker      * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
636*0e209d39SAndroid Build Coastguard Worker      * contains a syntax error.
637*0e209d39SAndroid Build Coastguard Worker      * <em> Empties the set passed before applying the pattern.</em>
638*0e209d39SAndroid Build Coastguard Worker      * @return a reference to this
639*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
640*0e209d39SAndroid Build Coastguard Worker      */
641*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& applyPattern(const UnicodeString& pattern,
642*0e209d39SAndroid Build Coastguard Worker                              UErrorCode& status);
643*0e209d39SAndroid Build Coastguard Worker 
644*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
645*0e209d39SAndroid Build Coastguard Worker     /**
646*0e209d39SAndroid Build Coastguard Worker      * Modifies this set to represent the set specified by the given
647*0e209d39SAndroid Build Coastguard Worker      * pattern, optionally ignoring Unicode Pattern_White_Space characters.
648*0e209d39SAndroid Build Coastguard Worker      * See the class description for the syntax of the pattern language.
649*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
650*0e209d39SAndroid Build Coastguard Worker      * @param pattern a string specifying what characters are in the set
651*0e209d39SAndroid Build Coastguard Worker      * @param options bitmask for options to apply to the pattern.
652*0e209d39SAndroid Build Coastguard Worker      * Valid options are USET_IGNORE_SPACE and
653*0e209d39SAndroid Build Coastguard Worker      * at most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
654*0e209d39SAndroid Build Coastguard Worker      * These case options are mutually exclusive.
655*0e209d39SAndroid Build Coastguard Worker      * @param symbols a symbol table mapping variable names to
656*0e209d39SAndroid Build Coastguard Worker      * values and stand-ins to UnicodeSets; may be nullptr
657*0e209d39SAndroid Build Coastguard Worker      * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
658*0e209d39SAndroid Build Coastguard Worker      * contains a syntax error.
659*0e209d39SAndroid Build Coastguard Worker      *<em> Empties the set passed before applying the pattern.</em>
660*0e209d39SAndroid Build Coastguard Worker      * @return a reference to this
661*0e209d39SAndroid Build Coastguard Worker      * @internal
662*0e209d39SAndroid Build Coastguard Worker      */
663*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& applyPattern(const UnicodeString& pattern,
664*0e209d39SAndroid Build Coastguard Worker                              uint32_t options,
665*0e209d39SAndroid Build Coastguard Worker                              const SymbolTable* symbols,
666*0e209d39SAndroid Build Coastguard Worker                              UErrorCode& status);
667*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_INTERNAL_API */
668*0e209d39SAndroid Build Coastguard Worker 
669*0e209d39SAndroid Build Coastguard Worker     /**
670*0e209d39SAndroid Build Coastguard Worker      * Parses the given pattern, starting at the given position.  The
671*0e209d39SAndroid Build Coastguard Worker      * character at pattern.charAt(pos.getIndex()) must be '[', or the
672*0e209d39SAndroid Build Coastguard Worker      * parse fails.  Parsing continues until the corresponding closing
673*0e209d39SAndroid Build Coastguard Worker      * ']'.  If a syntax error is encountered between the opening and
674*0e209d39SAndroid Build Coastguard Worker      * closing brace, the parse fails.  Upon return from a successful
675*0e209d39SAndroid Build Coastguard Worker      * parse, the ParsePosition is updated to point to the character
676*0e209d39SAndroid Build Coastguard Worker      * following the closing ']', and a StringBuffer containing a
677*0e209d39SAndroid Build Coastguard Worker      * pairs list for the parsed pattern is returned.  This method calls
678*0e209d39SAndroid Build Coastguard Worker      * itself recursively to parse embedded subpatterns.
679*0e209d39SAndroid Build Coastguard Worker      *<em> Empties the set passed before applying the pattern.</em>
680*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
681*0e209d39SAndroid Build Coastguard Worker      *
682*0e209d39SAndroid Build Coastguard Worker      * @param pattern the string containing the pattern to be parsed.
683*0e209d39SAndroid Build Coastguard Worker      * The portion of the string from pos.getIndex(), which must be a
684*0e209d39SAndroid Build Coastguard Worker      * '[', to the corresponding closing ']', is parsed.
685*0e209d39SAndroid Build Coastguard Worker      * @param pos upon entry, the position at which to being parsing.
686*0e209d39SAndroid Build Coastguard Worker      * The character at pattern.charAt(pos.getIndex()) must be a '['.
687*0e209d39SAndroid Build Coastguard Worker      * Upon return from a successful parse, pos.getIndex() is either
688*0e209d39SAndroid Build Coastguard Worker      * the character after the closing ']' of the parsed pattern, or
689*0e209d39SAndroid Build Coastguard Worker      * pattern.length() if the closing ']' is the last character of
690*0e209d39SAndroid Build Coastguard Worker      * the pattern string.
691*0e209d39SAndroid Build Coastguard Worker      * @param options bitmask for options to apply to the pattern.
692*0e209d39SAndroid Build Coastguard Worker      * Valid options are USET_IGNORE_SPACE and
693*0e209d39SAndroid Build Coastguard Worker      * at most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
694*0e209d39SAndroid Build Coastguard Worker      * These case options are mutually exclusive.
695*0e209d39SAndroid Build Coastguard Worker      * @param symbols a symbol table mapping variable names to
696*0e209d39SAndroid Build Coastguard Worker      * values and stand-ins to UnicodeSets; may be nullptr
697*0e209d39SAndroid Build Coastguard Worker      * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
698*0e209d39SAndroid Build Coastguard Worker      * contains a syntax error.
699*0e209d39SAndroid Build Coastguard Worker      * @return a reference to this
700*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.8
701*0e209d39SAndroid Build Coastguard Worker      */
702*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& applyPattern(const UnicodeString& pattern,
703*0e209d39SAndroid Build Coastguard Worker                              ParsePosition& pos,
704*0e209d39SAndroid Build Coastguard Worker                              uint32_t options,
705*0e209d39SAndroid Build Coastguard Worker                              const SymbolTable* symbols,
706*0e209d39SAndroid Build Coastguard Worker                              UErrorCode& status);
707*0e209d39SAndroid Build Coastguard Worker 
708*0e209d39SAndroid Build Coastguard Worker     /**
709*0e209d39SAndroid Build Coastguard Worker      * Returns a string representation of this set.  If the result of
710*0e209d39SAndroid Build Coastguard Worker      * calling this function is passed to a UnicodeSet constructor, it
711*0e209d39SAndroid Build Coastguard Worker      * will produce another set that is equal to this one.
712*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
713*0e209d39SAndroid Build Coastguard Worker      * @param result the string to receive the rules.  Previous
714*0e209d39SAndroid Build Coastguard Worker      * contents will be deleted.
715*0e209d39SAndroid Build Coastguard Worker      * @param escapeUnprintable if true then convert unprintable
716*0e209d39SAndroid Build Coastguard Worker      * character to their hex escape representations, \\uxxxx or
717*0e209d39SAndroid Build Coastguard Worker      * \\Uxxxxxxxx.  Unprintable characters are those other than
718*0e209d39SAndroid Build Coastguard Worker      * U+000A, U+0020..U+007E.
719*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
720*0e209d39SAndroid Build Coastguard Worker      */
721*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeString& toPattern(UnicodeString& result,
722*0e209d39SAndroid Build Coastguard Worker                                      UBool escapeUnprintable = false) const override;
723*0e209d39SAndroid Build Coastguard Worker 
724*0e209d39SAndroid Build Coastguard Worker     /**
725*0e209d39SAndroid Build Coastguard Worker      * Modifies this set to contain those code points which have the given value
726*0e209d39SAndroid Build Coastguard Worker      * for the given binary or enumerated property, as returned by
727*0e209d39SAndroid Build Coastguard Worker      * u_getIntPropertyValue.  Prior contents of this set are lost.
728*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
729*0e209d39SAndroid Build Coastguard Worker      *
730*0e209d39SAndroid Build Coastguard Worker      * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
731*0e209d39SAndroid Build Coastguard Worker      * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
732*0e209d39SAndroid Build Coastguard Worker      * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
733*0e209d39SAndroid Build Coastguard Worker      *
734*0e209d39SAndroid Build Coastguard Worker      * @param value a value in the range u_getIntPropertyMinValue(prop)..
735*0e209d39SAndroid Build Coastguard Worker      * u_getIntPropertyMaxValue(prop), with one exception.  If prop is
736*0e209d39SAndroid Build Coastguard Worker      * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
737*0e209d39SAndroid Build Coastguard Worker      * rather a mask value produced by U_GET_GC_MASK().  This allows grouped
738*0e209d39SAndroid Build Coastguard Worker      * categories such as [:L:] to be represented.
739*0e209d39SAndroid Build Coastguard Worker      *
740*0e209d39SAndroid Build Coastguard Worker      * @param ec error code input/output parameter
741*0e209d39SAndroid Build Coastguard Worker      *
742*0e209d39SAndroid Build Coastguard Worker      * @return a reference to this set
743*0e209d39SAndroid Build Coastguard Worker      *
744*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
745*0e209d39SAndroid Build Coastguard Worker      */
746*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& applyIntPropertyValue(UProperty prop,
747*0e209d39SAndroid Build Coastguard Worker                                       int32_t value,
748*0e209d39SAndroid Build Coastguard Worker                                       UErrorCode& ec);
749*0e209d39SAndroid Build Coastguard Worker 
750*0e209d39SAndroid Build Coastguard Worker     /**
751*0e209d39SAndroid Build Coastguard Worker      * Modifies this set to contain those code points which have the
752*0e209d39SAndroid Build Coastguard Worker      * given value for the given property.  Prior contents of this
753*0e209d39SAndroid Build Coastguard Worker      * set are lost.
754*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
755*0e209d39SAndroid Build Coastguard Worker      *
756*0e209d39SAndroid Build Coastguard Worker      * @param prop a property alias, either short or long.  The name is matched
757*0e209d39SAndroid Build Coastguard Worker      * loosely.  See PropertyAliases.txt for names and a description of loose
758*0e209d39SAndroid Build Coastguard Worker      * matching.  If the value string is empty, then this string is interpreted
759*0e209d39SAndroid Build Coastguard Worker      * as either a General_Category value alias, a Script value alias, a binary
760*0e209d39SAndroid Build Coastguard Worker      * property alias, or a special ID.  Special IDs are matched loosely and
761*0e209d39SAndroid Build Coastguard Worker      * correspond to the following sets:
762*0e209d39SAndroid Build Coastguard Worker      *
763*0e209d39SAndroid Build Coastguard Worker      * "ANY" = [\\u0000-\\U0010FFFF],
764*0e209d39SAndroid Build Coastguard Worker      * "ASCII" = [\\u0000-\\u007F],
765*0e209d39SAndroid Build Coastguard Worker      * "Assigned" = [:^Cn:].
766*0e209d39SAndroid Build Coastguard Worker      *
767*0e209d39SAndroid Build Coastguard Worker      * @param value a value alias, either short or long.  The name is matched
768*0e209d39SAndroid Build Coastguard Worker      * loosely.  See PropertyValueAliases.txt for names and a description of
769*0e209d39SAndroid Build Coastguard Worker      * loose matching.  In addition to aliases listed, numeric values and
770*0e209d39SAndroid Build Coastguard Worker      * canonical combining classes may be expressed numerically, e.g., ("nv",
771*0e209d39SAndroid Build Coastguard Worker      * "0.5") or ("ccc", "220").  The value string may also be empty.
772*0e209d39SAndroid Build Coastguard Worker      *
773*0e209d39SAndroid Build Coastguard Worker      * @param ec error code input/output parameter
774*0e209d39SAndroid Build Coastguard Worker      *
775*0e209d39SAndroid Build Coastguard Worker      * @return a reference to this set
776*0e209d39SAndroid Build Coastguard Worker      *
777*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
778*0e209d39SAndroid Build Coastguard Worker      */
779*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& applyPropertyAlias(const UnicodeString& prop,
780*0e209d39SAndroid Build Coastguard Worker                                    const UnicodeString& value,
781*0e209d39SAndroid Build Coastguard Worker                                    UErrorCode& ec);
782*0e209d39SAndroid Build Coastguard Worker 
783*0e209d39SAndroid Build Coastguard Worker     /**
784*0e209d39SAndroid Build Coastguard Worker      * Returns the number of elements in this set (its cardinality).
785*0e209d39SAndroid Build Coastguard Worker      * Note than the elements of a set may include both individual
786*0e209d39SAndroid Build Coastguard Worker      * codepoints and strings.
787*0e209d39SAndroid Build Coastguard Worker      *
788*0e209d39SAndroid Build Coastguard Worker      * This is slower than getRangeCount() because
789*0e209d39SAndroid Build Coastguard Worker      * it counts the code points of all ranges.
790*0e209d39SAndroid Build Coastguard Worker      *
791*0e209d39SAndroid Build Coastguard Worker      * @return the number of elements in this set (its cardinality).
792*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
793*0e209d39SAndroid Build Coastguard Worker      * @see getRangeCount
794*0e209d39SAndroid Build Coastguard Worker      */
795*0e209d39SAndroid Build Coastguard Worker     virtual int32_t size() const;
796*0e209d39SAndroid Build Coastguard Worker 
797*0e209d39SAndroid Build Coastguard Worker     /**
798*0e209d39SAndroid Build Coastguard Worker      * Returns <tt>true</tt> if this set contains no elements.
799*0e209d39SAndroid Build Coastguard Worker      *
800*0e209d39SAndroid Build Coastguard Worker      * @return <tt>true</tt> if this set contains no elements.
801*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
802*0e209d39SAndroid Build Coastguard Worker      */
803*0e209d39SAndroid Build Coastguard Worker     virtual UBool isEmpty() const;
804*0e209d39SAndroid Build Coastguard Worker 
805*0e209d39SAndroid Build Coastguard Worker     /**
806*0e209d39SAndroid Build Coastguard Worker      * @return true if this set contains multi-character strings or the empty string.
807*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 70
808*0e209d39SAndroid Build Coastguard Worker      */
809*0e209d39SAndroid Build Coastguard Worker     UBool hasStrings() const;
810*0e209d39SAndroid Build Coastguard Worker 
811*0e209d39SAndroid Build Coastguard Worker     /**
812*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains the given character.
813*0e209d39SAndroid Build Coastguard Worker      * This function works faster with a frozen set.
814*0e209d39SAndroid Build Coastguard Worker      * @param c character to be checked for containment
815*0e209d39SAndroid Build Coastguard Worker      * @return true if the test condition is met
816*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
817*0e209d39SAndroid Build Coastguard Worker      */
818*0e209d39SAndroid Build Coastguard Worker     virtual UBool contains(UChar32 c) const override;
819*0e209d39SAndroid Build Coastguard Worker 
820*0e209d39SAndroid Build Coastguard Worker     /**
821*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains every character
822*0e209d39SAndroid Build Coastguard Worker      * of the given range.
823*0e209d39SAndroid Build Coastguard Worker      * @param start first character, inclusive, of the range
824*0e209d39SAndroid Build Coastguard Worker      * @param end last character, inclusive, of the range
825*0e209d39SAndroid Build Coastguard Worker      * @return true if the test condition is met
826*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
827*0e209d39SAndroid Build Coastguard Worker      */
828*0e209d39SAndroid Build Coastguard Worker     virtual UBool contains(UChar32 start, UChar32 end) const;
829*0e209d39SAndroid Build Coastguard Worker 
830*0e209d39SAndroid Build Coastguard Worker     /**
831*0e209d39SAndroid Build Coastguard Worker      * Returns <tt>true</tt> if this set contains the given
832*0e209d39SAndroid Build Coastguard Worker      * multicharacter string.
833*0e209d39SAndroid Build Coastguard Worker      * @param s string to be checked for containment
834*0e209d39SAndroid Build Coastguard Worker      * @return <tt>true</tt> if this set contains the specified string
835*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
836*0e209d39SAndroid Build Coastguard Worker      */
837*0e209d39SAndroid Build Coastguard Worker     UBool contains(const UnicodeString& s) const;
838*0e209d39SAndroid Build Coastguard Worker 
839*0e209d39SAndroid Build Coastguard Worker     /**
840*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains all the characters and strings
841*0e209d39SAndroid Build Coastguard Worker      * of the given set.
842*0e209d39SAndroid Build Coastguard Worker      * @param c set to be checked for containment
843*0e209d39SAndroid Build Coastguard Worker      * @return true if the test condition is met
844*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
845*0e209d39SAndroid Build Coastguard Worker      */
846*0e209d39SAndroid Build Coastguard Worker     virtual UBool containsAll(const UnicodeSet& c) const;
847*0e209d39SAndroid Build Coastguard Worker 
848*0e209d39SAndroid Build Coastguard Worker     /**
849*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains all the characters
850*0e209d39SAndroid Build Coastguard Worker      * of the given string.
851*0e209d39SAndroid Build Coastguard Worker      * @param s string containing characters to be checked for containment
852*0e209d39SAndroid Build Coastguard Worker      * @return true if the test condition is met
853*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
854*0e209d39SAndroid Build Coastguard Worker      */
855*0e209d39SAndroid Build Coastguard Worker     UBool containsAll(const UnicodeString& s) const;
856*0e209d39SAndroid Build Coastguard Worker 
857*0e209d39SAndroid Build Coastguard Worker     /**
858*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains none of the characters
859*0e209d39SAndroid Build Coastguard Worker      * of the given range.
860*0e209d39SAndroid Build Coastguard Worker      * @param start first character, inclusive, of the range
861*0e209d39SAndroid Build Coastguard Worker      * @param end last character, inclusive, of the range
862*0e209d39SAndroid Build Coastguard Worker      * @return true if the test condition is met
863*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
864*0e209d39SAndroid Build Coastguard Worker      */
865*0e209d39SAndroid Build Coastguard Worker     UBool containsNone(UChar32 start, UChar32 end) const;
866*0e209d39SAndroid Build Coastguard Worker 
867*0e209d39SAndroid Build Coastguard Worker     /**
868*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains none of the characters and strings
869*0e209d39SAndroid Build Coastguard Worker      * of the given set.
870*0e209d39SAndroid Build Coastguard Worker      * @param c set to be checked for containment
871*0e209d39SAndroid Build Coastguard Worker      * @return true if the test condition is met
872*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
873*0e209d39SAndroid Build Coastguard Worker      */
874*0e209d39SAndroid Build Coastguard Worker     UBool containsNone(const UnicodeSet& c) const;
875*0e209d39SAndroid Build Coastguard Worker 
876*0e209d39SAndroid Build Coastguard Worker     /**
877*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains none of the characters
878*0e209d39SAndroid Build Coastguard Worker      * of the given string.
879*0e209d39SAndroid Build Coastguard Worker      * @param s string containing characters to be checked for containment
880*0e209d39SAndroid Build Coastguard Worker      * @return true if the test condition is met
881*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
882*0e209d39SAndroid Build Coastguard Worker      */
883*0e209d39SAndroid Build Coastguard Worker     UBool containsNone(const UnicodeString& s) const;
884*0e209d39SAndroid Build Coastguard Worker 
885*0e209d39SAndroid Build Coastguard Worker     /**
886*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains one or more of the characters
887*0e209d39SAndroid Build Coastguard Worker      * in the given range.
888*0e209d39SAndroid Build Coastguard Worker      * @param start first character, inclusive, of the range
889*0e209d39SAndroid Build Coastguard Worker      * @param end last character, inclusive, of the range
890*0e209d39SAndroid Build Coastguard Worker      * @return true if the condition is met
891*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
892*0e209d39SAndroid Build Coastguard Worker      */
893*0e209d39SAndroid Build Coastguard Worker     inline UBool containsSome(UChar32 start, UChar32 end) const;
894*0e209d39SAndroid Build Coastguard Worker 
895*0e209d39SAndroid Build Coastguard Worker     /**
896*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains one or more of the characters
897*0e209d39SAndroid Build Coastguard Worker      * and strings of the given set.
898*0e209d39SAndroid Build Coastguard Worker      * @param s The set to be checked for containment
899*0e209d39SAndroid Build Coastguard Worker      * @return true if the condition is met
900*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
901*0e209d39SAndroid Build Coastguard Worker      */
902*0e209d39SAndroid Build Coastguard Worker     inline UBool containsSome(const UnicodeSet& s) const;
903*0e209d39SAndroid Build Coastguard Worker 
904*0e209d39SAndroid Build Coastguard Worker     /**
905*0e209d39SAndroid Build Coastguard Worker      * Returns true if this set contains one or more of the characters
906*0e209d39SAndroid Build Coastguard Worker      * of the given string.
907*0e209d39SAndroid Build Coastguard Worker      * @param s string containing characters to be checked for containment
908*0e209d39SAndroid Build Coastguard Worker      * @return true if the condition is met
909*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
910*0e209d39SAndroid Build Coastguard Worker      */
911*0e209d39SAndroid Build Coastguard Worker     inline UBool containsSome(const UnicodeString& s) const;
912*0e209d39SAndroid Build Coastguard Worker 
913*0e209d39SAndroid Build Coastguard Worker     /**
914*0e209d39SAndroid Build Coastguard Worker      * Returns the length of the initial substring of the input string which
915*0e209d39SAndroid Build Coastguard Worker      * consists only of characters and strings that are contained in this set
916*0e209d39SAndroid Build Coastguard Worker      * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
917*0e209d39SAndroid Build Coastguard Worker      * or only of characters and strings that are not contained
918*0e209d39SAndroid Build Coastguard Worker      * in this set (USET_SPAN_NOT_CONTAINED).
919*0e209d39SAndroid Build Coastguard Worker      * See USetSpanCondition for details.
920*0e209d39SAndroid Build Coastguard Worker      * Similar to the strspn() C library function.
921*0e209d39SAndroid Build Coastguard Worker      * Unpaired surrogates are treated according to contains() of their surrogate code points.
922*0e209d39SAndroid Build Coastguard Worker      * This function works faster with a frozen set and with a non-negative string length argument.
923*0e209d39SAndroid Build Coastguard Worker      * @param s start of the string
924*0e209d39SAndroid Build Coastguard Worker      * @param length of the string; can be -1 for NUL-terminated
925*0e209d39SAndroid Build Coastguard Worker      * @param spanCondition specifies the containment condition
926*0e209d39SAndroid Build Coastguard Worker      * @return the length of the initial substring according to the spanCondition;
927*0e209d39SAndroid Build Coastguard Worker      *         0 if the start of the string does not fit the spanCondition
928*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.8
929*0e209d39SAndroid Build Coastguard Worker      * @see USetSpanCondition
930*0e209d39SAndroid Build Coastguard Worker      */
931*0e209d39SAndroid Build Coastguard Worker     int32_t span(const char16_t *s, int32_t length, USetSpanCondition spanCondition) const;
932*0e209d39SAndroid Build Coastguard Worker 
933*0e209d39SAndroid Build Coastguard Worker     /**
934*0e209d39SAndroid Build Coastguard Worker      * Returns the end of the substring of the input string according to the USetSpanCondition.
935*0e209d39SAndroid Build Coastguard Worker      * Same as <code>start+span(s.getBuffer()+start, s.length()-start, spanCondition)</code>
936*0e209d39SAndroid Build Coastguard Worker      * after pinning start to 0<=start<=s.length().
937*0e209d39SAndroid Build Coastguard Worker      * @param s the string
938*0e209d39SAndroid Build Coastguard Worker      * @param start the start index in the string for the span operation
939*0e209d39SAndroid Build Coastguard Worker      * @param spanCondition specifies the containment condition
940*0e209d39SAndroid Build Coastguard Worker      * @return the exclusive end of the substring according to the spanCondition;
941*0e209d39SAndroid Build Coastguard Worker      *         the substring s.tempSubStringBetween(start, end) fulfills the spanCondition
942*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.4
943*0e209d39SAndroid Build Coastguard Worker      * @see USetSpanCondition
944*0e209d39SAndroid Build Coastguard Worker      */
945*0e209d39SAndroid Build Coastguard Worker     inline int32_t span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const;
946*0e209d39SAndroid Build Coastguard Worker 
947*0e209d39SAndroid Build Coastguard Worker     /**
948*0e209d39SAndroid Build Coastguard Worker      * Returns the start of the trailing substring of the input string which
949*0e209d39SAndroid Build Coastguard Worker      * consists only of characters and strings that are contained in this set
950*0e209d39SAndroid Build Coastguard Worker      * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
951*0e209d39SAndroid Build Coastguard Worker      * or only of characters and strings that are not contained
952*0e209d39SAndroid Build Coastguard Worker      * in this set (USET_SPAN_NOT_CONTAINED).
953*0e209d39SAndroid Build Coastguard Worker      * See USetSpanCondition for details.
954*0e209d39SAndroid Build Coastguard Worker      * Unpaired surrogates are treated according to contains() of their surrogate code points.
955*0e209d39SAndroid Build Coastguard Worker      * This function works faster with a frozen set and with a non-negative string length argument.
956*0e209d39SAndroid Build Coastguard Worker      * @param s start of the string
957*0e209d39SAndroid Build Coastguard Worker      * @param length of the string; can be -1 for NUL-terminated
958*0e209d39SAndroid Build Coastguard Worker      * @param spanCondition specifies the containment condition
959*0e209d39SAndroid Build Coastguard Worker      * @return the start of the trailing substring according to the spanCondition;
960*0e209d39SAndroid Build Coastguard Worker      *         the string length if the end of the string does not fit the spanCondition
961*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.8
962*0e209d39SAndroid Build Coastguard Worker      * @see USetSpanCondition
963*0e209d39SAndroid Build Coastguard Worker      */
964*0e209d39SAndroid Build Coastguard Worker     int32_t spanBack(const char16_t *s, int32_t length, USetSpanCondition spanCondition) const;
965*0e209d39SAndroid Build Coastguard Worker 
966*0e209d39SAndroid Build Coastguard Worker     /**
967*0e209d39SAndroid Build Coastguard Worker      * Returns the start of the substring of the input string according to the USetSpanCondition.
968*0e209d39SAndroid Build Coastguard Worker      * Same as <code>spanBack(s.getBuffer(), limit, spanCondition)</code>
969*0e209d39SAndroid Build Coastguard Worker      * after pinning limit to 0<=end<=s.length().
970*0e209d39SAndroid Build Coastguard Worker      * @param s the string
971*0e209d39SAndroid Build Coastguard Worker      * @param limit the exclusive-end index in the string for the span operation
972*0e209d39SAndroid Build Coastguard Worker      *              (use s.length() or INT32_MAX for spanning back from the end of the string)
973*0e209d39SAndroid Build Coastguard Worker      * @param spanCondition specifies the containment condition
974*0e209d39SAndroid Build Coastguard Worker      * @return the start of the substring according to the spanCondition;
975*0e209d39SAndroid Build Coastguard Worker      *         the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition
976*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.4
977*0e209d39SAndroid Build Coastguard Worker      * @see USetSpanCondition
978*0e209d39SAndroid Build Coastguard Worker      */
979*0e209d39SAndroid Build Coastguard Worker     inline int32_t spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const;
980*0e209d39SAndroid Build Coastguard Worker 
981*0e209d39SAndroid Build Coastguard Worker     /**
982*0e209d39SAndroid Build Coastguard Worker      * Returns the length of the initial substring of the input string which
983*0e209d39SAndroid Build Coastguard Worker      * consists only of characters and strings that are contained in this set
984*0e209d39SAndroid Build Coastguard Worker      * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
985*0e209d39SAndroid Build Coastguard Worker      * or only of characters and strings that are not contained
986*0e209d39SAndroid Build Coastguard Worker      * in this set (USET_SPAN_NOT_CONTAINED).
987*0e209d39SAndroid Build Coastguard Worker      * See USetSpanCondition for details.
988*0e209d39SAndroid Build Coastguard Worker      * Similar to the strspn() C library function.
989*0e209d39SAndroid Build Coastguard Worker      * Malformed byte sequences are treated according to contains(0xfffd).
990*0e209d39SAndroid Build Coastguard Worker      * This function works faster with a frozen set and with a non-negative string length argument.
991*0e209d39SAndroid Build Coastguard Worker      * @param s start of the string (UTF-8)
992*0e209d39SAndroid Build Coastguard Worker      * @param length of the string; can be -1 for NUL-terminated
993*0e209d39SAndroid Build Coastguard Worker      * @param spanCondition specifies the containment condition
994*0e209d39SAndroid Build Coastguard Worker      * @return the length of the initial substring according to the spanCondition;
995*0e209d39SAndroid Build Coastguard Worker      *         0 if the start of the string does not fit the spanCondition
996*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.8
997*0e209d39SAndroid Build Coastguard Worker      * @see USetSpanCondition
998*0e209d39SAndroid Build Coastguard Worker      */
999*0e209d39SAndroid Build Coastguard Worker     int32_t spanUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
1000*0e209d39SAndroid Build Coastguard Worker 
1001*0e209d39SAndroid Build Coastguard Worker     /**
1002*0e209d39SAndroid Build Coastguard Worker      * Returns the start of the trailing substring of the input string which
1003*0e209d39SAndroid Build Coastguard Worker      * consists only of characters and strings that are contained in this set
1004*0e209d39SAndroid Build Coastguard Worker      * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
1005*0e209d39SAndroid Build Coastguard Worker      * or only of characters and strings that are not contained
1006*0e209d39SAndroid Build Coastguard Worker      * in this set (USET_SPAN_NOT_CONTAINED).
1007*0e209d39SAndroid Build Coastguard Worker      * See USetSpanCondition for details.
1008*0e209d39SAndroid Build Coastguard Worker      * Malformed byte sequences are treated according to contains(0xfffd).
1009*0e209d39SAndroid Build Coastguard Worker      * This function works faster with a frozen set and with a non-negative string length argument.
1010*0e209d39SAndroid Build Coastguard Worker      * @param s start of the string (UTF-8)
1011*0e209d39SAndroid Build Coastguard Worker      * @param length of the string; can be -1 for NUL-terminated
1012*0e209d39SAndroid Build Coastguard Worker      * @param spanCondition specifies the containment condition
1013*0e209d39SAndroid Build Coastguard Worker      * @return the start of the trailing substring according to the spanCondition;
1014*0e209d39SAndroid Build Coastguard Worker      *         the string length if the end of the string does not fit the spanCondition
1015*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.8
1016*0e209d39SAndroid Build Coastguard Worker      * @see USetSpanCondition
1017*0e209d39SAndroid Build Coastguard Worker      */
1018*0e209d39SAndroid Build Coastguard Worker     int32_t spanBackUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
1019*0e209d39SAndroid Build Coastguard Worker 
1020*0e209d39SAndroid Build Coastguard Worker     /**
1021*0e209d39SAndroid Build Coastguard Worker      * Implement UnicodeMatcher::matches()
1022*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1023*0e209d39SAndroid Build Coastguard Worker      */
1024*0e209d39SAndroid Build Coastguard Worker     virtual UMatchDegree matches(const Replaceable& text,
1025*0e209d39SAndroid Build Coastguard Worker                          int32_t& offset,
1026*0e209d39SAndroid Build Coastguard Worker                          int32_t limit,
1027*0e209d39SAndroid Build Coastguard Worker                          UBool incremental) override;
1028*0e209d39SAndroid Build Coastguard Worker 
1029*0e209d39SAndroid Build Coastguard Worker private:
1030*0e209d39SAndroid Build Coastguard Worker     /**
1031*0e209d39SAndroid Build Coastguard Worker      * Returns the longest match for s in text at the given position.
1032*0e209d39SAndroid Build Coastguard Worker      * If limit > start then match forward from start+1 to limit
1033*0e209d39SAndroid Build Coastguard Worker      * matching all characters except s.charAt(0).  If limit < start,
1034*0e209d39SAndroid Build Coastguard Worker      * go backward starting from start-1 matching all characters
1035*0e209d39SAndroid Build Coastguard Worker      * except s.charAt(s.length()-1).  This method assumes that the
1036*0e209d39SAndroid Build Coastguard Worker      * first character, text.charAt(start), matches s, so it does not
1037*0e209d39SAndroid Build Coastguard Worker      * check it.
1038*0e209d39SAndroid Build Coastguard Worker      * @param text the text to match
1039*0e209d39SAndroid Build Coastguard Worker      * @param start the first character to match.  In the forward
1040*0e209d39SAndroid Build Coastguard Worker      * direction, text.charAt(start) is matched against s.charAt(0).
1041*0e209d39SAndroid Build Coastguard Worker      * In the reverse direction, it is matched against
1042*0e209d39SAndroid Build Coastguard Worker      * s.charAt(s.length()-1).
1043*0e209d39SAndroid Build Coastguard Worker      * @param limit the limit offset for matching, either last+1 in
1044*0e209d39SAndroid Build Coastguard Worker      * the forward direction, or last-1 in the reverse direction,
1045*0e209d39SAndroid Build Coastguard Worker      * where last is the index of the last character to match.
1046*0e209d39SAndroid Build Coastguard Worker      * @param s
1047*0e209d39SAndroid Build Coastguard Worker      * @return If part of s matches up to the limit, return |limit -
1048*0e209d39SAndroid Build Coastguard Worker      * start|.  If all of s matches before reaching the limit, return
1049*0e209d39SAndroid Build Coastguard Worker      * s.length().  If there is a mismatch between s and text, return
1050*0e209d39SAndroid Build Coastguard Worker      * 0
1051*0e209d39SAndroid Build Coastguard Worker      */
1052*0e209d39SAndroid Build Coastguard Worker     static int32_t matchRest(const Replaceable& text,
1053*0e209d39SAndroid Build Coastguard Worker                              int32_t start, int32_t limit,
1054*0e209d39SAndroid Build Coastguard Worker                              const UnicodeString& s);
1055*0e209d39SAndroid Build Coastguard Worker 
1056*0e209d39SAndroid Build Coastguard Worker     /**
1057*0e209d39SAndroid Build Coastguard Worker      * Returns the smallest value i such that c < list[i].  Caller
1058*0e209d39SAndroid Build Coastguard Worker      * must ensure that c is a legal value or this method will enter
1059*0e209d39SAndroid Build Coastguard Worker      * an infinite loop.  This method performs a binary search.
1060*0e209d39SAndroid Build Coastguard Worker      * @param c a character in the range MIN_VALUE..MAX_VALUE
1061*0e209d39SAndroid Build Coastguard Worker      * inclusive
1062*0e209d39SAndroid Build Coastguard Worker      * @return the smallest integer i in the range 0..len-1,
1063*0e209d39SAndroid Build Coastguard Worker      * inclusive, such that c < list[i]
1064*0e209d39SAndroid Build Coastguard Worker      */
1065*0e209d39SAndroid Build Coastguard Worker     int32_t findCodePoint(UChar32 c) const;
1066*0e209d39SAndroid Build Coastguard Worker 
1067*0e209d39SAndroid Build Coastguard Worker public:
1068*0e209d39SAndroid Build Coastguard Worker 
1069*0e209d39SAndroid Build Coastguard Worker     /**
1070*0e209d39SAndroid Build Coastguard Worker      * Implementation of UnicodeMatcher API.  Union the set of all
1071*0e209d39SAndroid Build Coastguard Worker      * characters that may be matched by this object into the given
1072*0e209d39SAndroid Build Coastguard Worker      * set.
1073*0e209d39SAndroid Build Coastguard Worker      * @param toUnionTo the set into which to union the source characters
1074*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1075*0e209d39SAndroid Build Coastguard Worker      */
1076*0e209d39SAndroid Build Coastguard Worker     virtual void addMatchSetTo(UnicodeSet& toUnionTo) const override;
1077*0e209d39SAndroid Build Coastguard Worker 
1078*0e209d39SAndroid Build Coastguard Worker     /**
1079*0e209d39SAndroid Build Coastguard Worker      * Returns the index of the given character within this set, where
1080*0e209d39SAndroid Build Coastguard Worker      * the set is ordered by ascending code point.  If the character
1081*0e209d39SAndroid Build Coastguard Worker      * is not in this set, return -1.  The inverse of this method is
1082*0e209d39SAndroid Build Coastguard Worker      * <code>charAt()</code>.
1083*0e209d39SAndroid Build Coastguard Worker      * @return an index from 0..size()-1, or -1
1084*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1085*0e209d39SAndroid Build Coastguard Worker      */
1086*0e209d39SAndroid Build Coastguard Worker     int32_t indexOf(UChar32 c) const;
1087*0e209d39SAndroid Build Coastguard Worker 
1088*0e209d39SAndroid Build Coastguard Worker     /**
1089*0e209d39SAndroid Build Coastguard Worker      * Returns the character at the given index within this set, where
1090*0e209d39SAndroid Build Coastguard Worker      * the set is ordered by ascending code point.  If the index is
1091*0e209d39SAndroid Build Coastguard Worker      * out of range for characters, returns (UChar32)-1.
1092*0e209d39SAndroid Build Coastguard Worker      * The inverse of this method is <code>indexOf()</code>.
1093*0e209d39SAndroid Build Coastguard Worker      *
1094*0e209d39SAndroid Build Coastguard Worker      * For iteration, this is slower than UnicodeSetIterator or
1095*0e209d39SAndroid Build Coastguard Worker      * getRangeCount()/getRangeStart()/getRangeEnd(),
1096*0e209d39SAndroid Build Coastguard Worker      * because for each call it skips linearly over <code>index</code>
1097*0e209d39SAndroid Build Coastguard Worker      * characters in the ranges.
1098*0e209d39SAndroid Build Coastguard Worker      *
1099*0e209d39SAndroid Build Coastguard Worker      * @param index an index from 0..size()-1
1100*0e209d39SAndroid Build Coastguard Worker      * @return the character at the given index, or (UChar32)-1.
1101*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1102*0e209d39SAndroid Build Coastguard Worker      */
1103*0e209d39SAndroid Build Coastguard Worker     UChar32 charAt(int32_t index) const;
1104*0e209d39SAndroid Build Coastguard Worker 
1105*0e209d39SAndroid Build Coastguard Worker     /**
1106*0e209d39SAndroid Build Coastguard Worker      * Adds the specified range to this set if it is not already
1107*0e209d39SAndroid Build Coastguard Worker      * present.  If this set already contains the specified range,
1108*0e209d39SAndroid Build Coastguard Worker      * the call leaves this set unchanged.  If <code>start > end</code>
1109*0e209d39SAndroid Build Coastguard Worker      * then an empty range is added, leaving the set unchanged.
1110*0e209d39SAndroid Build Coastguard Worker      * This is equivalent to a boolean logic OR, or a set UNION.
1111*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1112*0e209d39SAndroid Build Coastguard Worker      *
1113*0e209d39SAndroid Build Coastguard Worker      * @param start first character, inclusive, of range to be added
1114*0e209d39SAndroid Build Coastguard Worker      * to this set.
1115*0e209d39SAndroid Build Coastguard Worker      * @param end last character, inclusive, of range to be added
1116*0e209d39SAndroid Build Coastguard Worker      * to this set.
1117*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1118*0e209d39SAndroid Build Coastguard Worker      */
1119*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& add(UChar32 start, UChar32 end);
1120*0e209d39SAndroid Build Coastguard Worker 
1121*0e209d39SAndroid Build Coastguard Worker     /**
1122*0e209d39SAndroid Build Coastguard Worker      * Adds the specified character to this set if it is not already
1123*0e209d39SAndroid Build Coastguard Worker      * present.  If this set already contains the specified character,
1124*0e209d39SAndroid Build Coastguard Worker      * the call leaves this set unchanged.
1125*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1126*0e209d39SAndroid Build Coastguard Worker      *
1127*0e209d39SAndroid Build Coastguard Worker      * @param c the character (code point)
1128*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1129*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1130*0e209d39SAndroid Build Coastguard Worker      */
1131*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& add(UChar32 c);
1132*0e209d39SAndroid Build Coastguard Worker 
1133*0e209d39SAndroid Build Coastguard Worker     /**
1134*0e209d39SAndroid Build Coastguard Worker      * Adds the specified multicharacter to this set if it is not already
1135*0e209d39SAndroid Build Coastguard Worker      * present.  If this set already contains the multicharacter,
1136*0e209d39SAndroid Build Coastguard Worker      * the call leaves this set unchanged.
1137*0e209d39SAndroid Build Coastguard Worker      * Thus "ch" => {"ch"}
1138*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1139*0e209d39SAndroid Build Coastguard Worker      *
1140*0e209d39SAndroid Build Coastguard Worker      * @param s the source string
1141*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1142*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1143*0e209d39SAndroid Build Coastguard Worker      */
1144*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& add(const UnicodeString& s);
1145*0e209d39SAndroid Build Coastguard Worker 
1146*0e209d39SAndroid Build Coastguard Worker  private:
1147*0e209d39SAndroid Build Coastguard Worker     /**
1148*0e209d39SAndroid Build Coastguard Worker      * @return a code point IF the string consists of a single one.
1149*0e209d39SAndroid Build Coastguard Worker      * otherwise returns -1.
1150*0e209d39SAndroid Build Coastguard Worker      * @param s string to test
1151*0e209d39SAndroid Build Coastguard Worker      */
1152*0e209d39SAndroid Build Coastguard Worker     static int32_t getSingleCP(const UnicodeString& s);
1153*0e209d39SAndroid Build Coastguard Worker 
1154*0e209d39SAndroid Build Coastguard Worker     void _add(const UnicodeString& s);
1155*0e209d39SAndroid Build Coastguard Worker 
1156*0e209d39SAndroid Build Coastguard Worker  public:
1157*0e209d39SAndroid Build Coastguard Worker     /**
1158*0e209d39SAndroid Build Coastguard Worker      * Adds each of the characters in this string to the set. Note: "ch" => {"c", "h"}
1159*0e209d39SAndroid Build Coastguard Worker      * If this set already contains any particular character, it has no effect on that character.
1160*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1161*0e209d39SAndroid Build Coastguard Worker      * @param s the source string
1162*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1163*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1164*0e209d39SAndroid Build Coastguard Worker      */
1165*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& addAll(const UnicodeString& s);
1166*0e209d39SAndroid Build Coastguard Worker 
1167*0e209d39SAndroid Build Coastguard Worker     /**
1168*0e209d39SAndroid Build Coastguard Worker      * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
1169*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1170*0e209d39SAndroid Build Coastguard Worker      * @param s the source string
1171*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1172*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1173*0e209d39SAndroid Build Coastguard Worker      */
1174*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& retainAll(const UnicodeString& s);
1175*0e209d39SAndroid Build Coastguard Worker 
1176*0e209d39SAndroid Build Coastguard Worker     /**
1177*0e209d39SAndroid Build Coastguard Worker      * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
1178*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1179*0e209d39SAndroid Build Coastguard Worker      * @param s the source string
1180*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1181*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1182*0e209d39SAndroid Build Coastguard Worker      */
1183*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& complementAll(const UnicodeString& s);
1184*0e209d39SAndroid Build Coastguard Worker 
1185*0e209d39SAndroid Build Coastguard Worker     /**
1186*0e209d39SAndroid Build Coastguard Worker      * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
1187*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1188*0e209d39SAndroid Build Coastguard Worker      * @param s the source string
1189*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1190*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1191*0e209d39SAndroid Build Coastguard Worker      */
1192*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& removeAll(const UnicodeString& s);
1193*0e209d39SAndroid Build Coastguard Worker 
1194*0e209d39SAndroid Build Coastguard Worker     /**
1195*0e209d39SAndroid Build Coastguard Worker      * Makes a set from a multicharacter string. Thus "ch" => {"ch"}
1196*0e209d39SAndroid Build Coastguard Worker      *
1197*0e209d39SAndroid Build Coastguard Worker      * @param s the source string
1198*0e209d39SAndroid Build Coastguard Worker      * @return a newly created set containing the given string.
1199*0e209d39SAndroid Build Coastguard Worker      * The caller owns the return object and is responsible for deleting it.
1200*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1201*0e209d39SAndroid Build Coastguard Worker      */
1202*0e209d39SAndroid Build Coastguard Worker     static UnicodeSet* U_EXPORT2 createFrom(const UnicodeString& s);
1203*0e209d39SAndroid Build Coastguard Worker 
1204*0e209d39SAndroid Build Coastguard Worker 
1205*0e209d39SAndroid Build Coastguard Worker     /**
1206*0e209d39SAndroid Build Coastguard Worker      * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
1207*0e209d39SAndroid Build Coastguard Worker      * @param s the source string
1208*0e209d39SAndroid Build Coastguard Worker      * @return a newly created set containing the given characters
1209*0e209d39SAndroid Build Coastguard Worker      * The caller owns the return object and is responsible for deleting it.
1210*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1211*0e209d39SAndroid Build Coastguard Worker      */
1212*0e209d39SAndroid Build Coastguard Worker     static UnicodeSet* U_EXPORT2 createFromAll(const UnicodeString& s);
1213*0e209d39SAndroid Build Coastguard Worker 
1214*0e209d39SAndroid Build Coastguard Worker     /**
1215*0e209d39SAndroid Build Coastguard Worker      * Retain only the elements in this set that are contained in the
1216*0e209d39SAndroid Build Coastguard Worker      * specified range.  If <code>start > end</code> then an empty range is
1217*0e209d39SAndroid Build Coastguard Worker      * retained, leaving the set empty.  This is equivalent to
1218*0e209d39SAndroid Build Coastguard Worker      * a boolean logic AND, or a set INTERSECTION.
1219*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1220*0e209d39SAndroid Build Coastguard Worker      *
1221*0e209d39SAndroid Build Coastguard Worker      * @param start first character, inclusive, of range
1222*0e209d39SAndroid Build Coastguard Worker      * @param end last character, inclusive, of range
1223*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1224*0e209d39SAndroid Build Coastguard Worker      */
1225*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& retain(UChar32 start, UChar32 end);
1226*0e209d39SAndroid Build Coastguard Worker 
1227*0e209d39SAndroid Build Coastguard Worker 
1228*0e209d39SAndroid Build Coastguard Worker     /**
1229*0e209d39SAndroid Build Coastguard Worker      * Retain the specified character from this set if it is present.
1230*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1231*0e209d39SAndroid Build Coastguard Worker      *
1232*0e209d39SAndroid Build Coastguard Worker      * @param c the character (code point)
1233*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1234*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1235*0e209d39SAndroid Build Coastguard Worker      */
1236*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& retain(UChar32 c);
1237*0e209d39SAndroid Build Coastguard Worker 
1238*0e209d39SAndroid Build Coastguard Worker     /**
1239*0e209d39SAndroid Build Coastguard Worker      * Retains only the specified string from this set if it is present.
1240*0e209d39SAndroid Build Coastguard Worker      * Upon return this set will be empty if it did not contain s, or
1241*0e209d39SAndroid Build Coastguard Worker      * will only contain s if it did contain s.
1242*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1243*0e209d39SAndroid Build Coastguard Worker      *
1244*0e209d39SAndroid Build Coastguard Worker      * @param s the source string
1245*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1246*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 69
1247*0e209d39SAndroid Build Coastguard Worker      */
1248*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& retain(const UnicodeString &s);
1249*0e209d39SAndroid Build Coastguard Worker 
1250*0e209d39SAndroid Build Coastguard Worker     /**
1251*0e209d39SAndroid Build Coastguard Worker      * Removes the specified range from this set if it is present.
1252*0e209d39SAndroid Build Coastguard Worker      * The set will not contain the specified range once the call
1253*0e209d39SAndroid Build Coastguard Worker      * returns.  If <code>start > end</code> then an empty range is
1254*0e209d39SAndroid Build Coastguard Worker      * removed, leaving the set unchanged.
1255*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1256*0e209d39SAndroid Build Coastguard Worker      *
1257*0e209d39SAndroid Build Coastguard Worker      * @param start first character, inclusive, of range to be removed
1258*0e209d39SAndroid Build Coastguard Worker      * from this set.
1259*0e209d39SAndroid Build Coastguard Worker      * @param end last character, inclusive, of range to be removed
1260*0e209d39SAndroid Build Coastguard Worker      * from this set.
1261*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1262*0e209d39SAndroid Build Coastguard Worker      */
1263*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& remove(UChar32 start, UChar32 end);
1264*0e209d39SAndroid Build Coastguard Worker 
1265*0e209d39SAndroid Build Coastguard Worker     /**
1266*0e209d39SAndroid Build Coastguard Worker      * Removes the specified character from this set if it is present.
1267*0e209d39SAndroid Build Coastguard Worker      * The set will not contain the specified range once the call
1268*0e209d39SAndroid Build Coastguard Worker      * returns.
1269*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1270*0e209d39SAndroid Build Coastguard Worker      *
1271*0e209d39SAndroid Build Coastguard Worker      * @param c the character (code point)
1272*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1273*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1274*0e209d39SAndroid Build Coastguard Worker      */
1275*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& remove(UChar32 c);
1276*0e209d39SAndroid Build Coastguard Worker 
1277*0e209d39SAndroid Build Coastguard Worker     /**
1278*0e209d39SAndroid Build Coastguard Worker      * Removes the specified string from this set if it is present.
1279*0e209d39SAndroid Build Coastguard Worker      * The set will not contain the specified character once the call
1280*0e209d39SAndroid Build Coastguard Worker      * returns.
1281*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1282*0e209d39SAndroid Build Coastguard Worker      * @param s the source string
1283*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1284*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1285*0e209d39SAndroid Build Coastguard Worker      */
1286*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& remove(const UnicodeString& s);
1287*0e209d39SAndroid Build Coastguard Worker 
1288*0e209d39SAndroid Build Coastguard Worker     /**
1289*0e209d39SAndroid Build Coastguard Worker      * This is equivalent to
1290*0e209d39SAndroid Build Coastguard Worker      * <code>complement(MIN_VALUE, MAX_VALUE)</code>.
1291*0e209d39SAndroid Build Coastguard Worker      *
1292*0e209d39SAndroid Build Coastguard Worker      * <strong>Note:</strong> This performs a symmetric difference with all code points
1293*0e209d39SAndroid Build Coastguard Worker      * <em>and thus retains all multicharacter strings</em>.
1294*0e209d39SAndroid Build Coastguard Worker      * In order to achieve a “code point complement” (all code points minus this set),
1295*0e209d39SAndroid Build Coastguard Worker      * the easiest is to <code>.complement().removeAllStrings()</code>.
1296*0e209d39SAndroid Build Coastguard Worker      *
1297*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1298*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1299*0e209d39SAndroid Build Coastguard Worker      */
1300*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& complement();
1301*0e209d39SAndroid Build Coastguard Worker 
1302*0e209d39SAndroid Build Coastguard Worker     /**
1303*0e209d39SAndroid Build Coastguard Worker      * Complements the specified range in this set.  Any character in
1304*0e209d39SAndroid Build Coastguard Worker      * the range will be removed if it is in this set, or will be
1305*0e209d39SAndroid Build Coastguard Worker      * added if it is not in this set.  If <code>start > end</code>
1306*0e209d39SAndroid Build Coastguard Worker      * then an empty range is complemented, leaving the set unchanged.
1307*0e209d39SAndroid Build Coastguard Worker      * This is equivalent to a boolean logic XOR.
1308*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1309*0e209d39SAndroid Build Coastguard Worker      *
1310*0e209d39SAndroid Build Coastguard Worker      * @param start first character, inclusive, of range
1311*0e209d39SAndroid Build Coastguard Worker      * @param end last character, inclusive, of range
1312*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1313*0e209d39SAndroid Build Coastguard Worker      */
1314*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& complement(UChar32 start, UChar32 end);
1315*0e209d39SAndroid Build Coastguard Worker 
1316*0e209d39SAndroid Build Coastguard Worker     /**
1317*0e209d39SAndroid Build Coastguard Worker      * Complements the specified character in this set.  The character
1318*0e209d39SAndroid Build Coastguard Worker      * will be removed if it is in this set, or will be added if it is
1319*0e209d39SAndroid Build Coastguard Worker      * not in this set.
1320*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1321*0e209d39SAndroid Build Coastguard Worker      *
1322*0e209d39SAndroid Build Coastguard Worker      * @param c the character (code point)
1323*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1324*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1325*0e209d39SAndroid Build Coastguard Worker      */
1326*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& complement(UChar32 c);
1327*0e209d39SAndroid Build Coastguard Worker 
1328*0e209d39SAndroid Build Coastguard Worker     /**
1329*0e209d39SAndroid Build Coastguard Worker      * Complement the specified string in this set.
1330*0e209d39SAndroid Build Coastguard Worker      * The string will be removed if it is in this set, or will be added if it is not in this set.
1331*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1332*0e209d39SAndroid Build Coastguard Worker      *
1333*0e209d39SAndroid Build Coastguard Worker      * @param s the string to complement
1334*0e209d39SAndroid Build Coastguard Worker      * @return this object, for chaining
1335*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1336*0e209d39SAndroid Build Coastguard Worker      */
1337*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& complement(const UnicodeString& s);
1338*0e209d39SAndroid Build Coastguard Worker 
1339*0e209d39SAndroid Build Coastguard Worker     /**
1340*0e209d39SAndroid Build Coastguard Worker      * Adds all of the elements in the specified set to this set if
1341*0e209d39SAndroid Build Coastguard Worker      * they're not already present.  This operation effectively
1342*0e209d39SAndroid Build Coastguard Worker      * modifies this set so that its value is the <i>union</i> of the two
1343*0e209d39SAndroid Build Coastguard Worker      * sets.  The behavior of this operation is unspecified if the specified
1344*0e209d39SAndroid Build Coastguard Worker      * collection is modified while the operation is in progress.
1345*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1346*0e209d39SAndroid Build Coastguard Worker      *
1347*0e209d39SAndroid Build Coastguard Worker      * @param c set whose elements are to be added to this set.
1348*0e209d39SAndroid Build Coastguard Worker      * @see #add(UChar32, UChar32)
1349*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1350*0e209d39SAndroid Build Coastguard Worker      */
1351*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& addAll(const UnicodeSet& c);
1352*0e209d39SAndroid Build Coastguard Worker 
1353*0e209d39SAndroid Build Coastguard Worker     /**
1354*0e209d39SAndroid Build Coastguard Worker      * Retains only the elements in this set that are contained in the
1355*0e209d39SAndroid Build Coastguard Worker      * specified set.  In other words, removes from this set all of
1356*0e209d39SAndroid Build Coastguard Worker      * its elements that are not contained in the specified set.  This
1357*0e209d39SAndroid Build Coastguard Worker      * operation effectively modifies this set so that its value is
1358*0e209d39SAndroid Build Coastguard Worker      * the <i>intersection</i> of the two sets.
1359*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1360*0e209d39SAndroid Build Coastguard Worker      *
1361*0e209d39SAndroid Build Coastguard Worker      * @param c set that defines which elements this set will retain.
1362*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1363*0e209d39SAndroid Build Coastguard Worker      */
1364*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& retainAll(const UnicodeSet& c);
1365*0e209d39SAndroid Build Coastguard Worker 
1366*0e209d39SAndroid Build Coastguard Worker     /**
1367*0e209d39SAndroid Build Coastguard Worker      * Removes from this set all of its elements that are contained in the
1368*0e209d39SAndroid Build Coastguard Worker      * specified set.  This operation effectively modifies this
1369*0e209d39SAndroid Build Coastguard Worker      * set so that its value is the <i>asymmetric set difference</i> of
1370*0e209d39SAndroid Build Coastguard Worker      * the two sets.
1371*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1372*0e209d39SAndroid Build Coastguard Worker      *
1373*0e209d39SAndroid Build Coastguard Worker      * @param c set that defines which elements will be removed from
1374*0e209d39SAndroid Build Coastguard Worker      *          this set.
1375*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1376*0e209d39SAndroid Build Coastguard Worker      */
1377*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& removeAll(const UnicodeSet& c);
1378*0e209d39SAndroid Build Coastguard Worker 
1379*0e209d39SAndroid Build Coastguard Worker     /**
1380*0e209d39SAndroid Build Coastguard Worker      * Complements in this set all elements contained in the specified
1381*0e209d39SAndroid Build Coastguard Worker      * set.  Any character in the other set will be removed if it is
1382*0e209d39SAndroid Build Coastguard Worker      * in this set, or will be added if it is not in this set.
1383*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1384*0e209d39SAndroid Build Coastguard Worker      *
1385*0e209d39SAndroid Build Coastguard Worker      * @param c set that defines which elements will be xor'ed from
1386*0e209d39SAndroid Build Coastguard Worker      *          this set.
1387*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1388*0e209d39SAndroid Build Coastguard Worker      */
1389*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& complementAll(const UnicodeSet& c);
1390*0e209d39SAndroid Build Coastguard Worker 
1391*0e209d39SAndroid Build Coastguard Worker     /**
1392*0e209d39SAndroid Build Coastguard Worker      * Removes all of the elements from this set.  This set will be
1393*0e209d39SAndroid Build Coastguard Worker      * empty after this call returns.
1394*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1395*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1396*0e209d39SAndroid Build Coastguard Worker      */
1397*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& clear();
1398*0e209d39SAndroid Build Coastguard Worker 
1399*0e209d39SAndroid Build Coastguard Worker     /**
1400*0e209d39SAndroid Build Coastguard Worker      * Close this set over the given attribute.  For the attribute
1401*0e209d39SAndroid Build Coastguard Worker      * USET_CASE_INSENSITIVE, the result is to modify this set so that:
1402*0e209d39SAndroid Build Coastguard Worker      *
1403*0e209d39SAndroid Build Coastguard Worker      * 1. For each character or string 'a' in this set, all strings or
1404*0e209d39SAndroid Build Coastguard Worker      * characters 'b' such that foldCase(a) == foldCase(b) are added
1405*0e209d39SAndroid Build Coastguard Worker      * to this set.
1406*0e209d39SAndroid Build Coastguard Worker      *
1407*0e209d39SAndroid Build Coastguard Worker      * 2. For each string 'e' in the resulting set, if e !=
1408*0e209d39SAndroid Build Coastguard Worker      * foldCase(e), 'e' will be removed.
1409*0e209d39SAndroid Build Coastguard Worker      *
1410*0e209d39SAndroid Build Coastguard Worker      * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
1411*0e209d39SAndroid Build Coastguard Worker      *
1412*0e209d39SAndroid Build Coastguard Worker      * (Here foldCase(x) refers to the operation u_strFoldCase, and a
1413*0e209d39SAndroid Build Coastguard Worker      * == b denotes that the contents are the same, not pointer
1414*0e209d39SAndroid Build Coastguard Worker      * comparison.)
1415*0e209d39SAndroid Build Coastguard Worker      *
1416*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1417*0e209d39SAndroid Build Coastguard Worker      *
1418*0e209d39SAndroid Build Coastguard Worker      * @param attribute bitmask for attributes to close over.
1419*0e209d39SAndroid Build Coastguard Worker      * Valid options:
1420*0e209d39SAndroid Build Coastguard Worker      * At most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
1421*0e209d39SAndroid Build Coastguard Worker      * These case options are mutually exclusive.
1422*0e209d39SAndroid Build Coastguard Worker      * Unrelated options bits are ignored.
1423*0e209d39SAndroid Build Coastguard Worker      * @return a reference to this set.
1424*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.2
1425*0e209d39SAndroid Build Coastguard Worker      */
1426*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& closeOver(int32_t attribute);
1427*0e209d39SAndroid Build Coastguard Worker 
1428*0e209d39SAndroid Build Coastguard Worker     /**
1429*0e209d39SAndroid Build Coastguard Worker      * Remove all strings from this set.
1430*0e209d39SAndroid Build Coastguard Worker      *
1431*0e209d39SAndroid Build Coastguard Worker      * @return a reference to this set.
1432*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.2
1433*0e209d39SAndroid Build Coastguard Worker      */
1434*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet &removeAllStrings();
1435*0e209d39SAndroid Build Coastguard Worker 
1436*0e209d39SAndroid Build Coastguard Worker     /**
1437*0e209d39SAndroid Build Coastguard Worker      * Iteration method that returns the number of ranges contained in
1438*0e209d39SAndroid Build Coastguard Worker      * this set.
1439*0e209d39SAndroid Build Coastguard Worker      * @see #getRangeStart
1440*0e209d39SAndroid Build Coastguard Worker      * @see #getRangeEnd
1441*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1442*0e209d39SAndroid Build Coastguard Worker      */
1443*0e209d39SAndroid Build Coastguard Worker     virtual int32_t getRangeCount() const;
1444*0e209d39SAndroid Build Coastguard Worker 
1445*0e209d39SAndroid Build Coastguard Worker     /**
1446*0e209d39SAndroid Build Coastguard Worker      * Iteration method that returns the first character in the
1447*0e209d39SAndroid Build Coastguard Worker      * specified range of this set.
1448*0e209d39SAndroid Build Coastguard Worker      * @see #getRangeCount
1449*0e209d39SAndroid Build Coastguard Worker      * @see #getRangeEnd
1450*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1451*0e209d39SAndroid Build Coastguard Worker      */
1452*0e209d39SAndroid Build Coastguard Worker     virtual UChar32 getRangeStart(int32_t index) const;
1453*0e209d39SAndroid Build Coastguard Worker 
1454*0e209d39SAndroid Build Coastguard Worker     /**
1455*0e209d39SAndroid Build Coastguard Worker      * Iteration method that returns the last character in the
1456*0e209d39SAndroid Build Coastguard Worker      * specified range of this set.
1457*0e209d39SAndroid Build Coastguard Worker      * @see #getRangeStart
1458*0e209d39SAndroid Build Coastguard Worker      * @see #getRangeEnd
1459*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1460*0e209d39SAndroid Build Coastguard Worker      */
1461*0e209d39SAndroid Build Coastguard Worker     virtual UChar32 getRangeEnd(int32_t index) const;
1462*0e209d39SAndroid Build Coastguard Worker 
1463*0e209d39SAndroid Build Coastguard Worker     /**
1464*0e209d39SAndroid Build Coastguard Worker      * Serializes this set into an array of 16-bit integers.  Serialization
1465*0e209d39SAndroid Build Coastguard Worker      * (currently) only records the characters in the set; multicharacter
1466*0e209d39SAndroid Build Coastguard Worker      * strings are ignored.
1467*0e209d39SAndroid Build Coastguard Worker      *
1468*0e209d39SAndroid Build Coastguard Worker      * The array has following format (each line is one 16-bit
1469*0e209d39SAndroid Build Coastguard Worker      * integer):
1470*0e209d39SAndroid Build Coastguard Worker      *
1471*0e209d39SAndroid Build Coastguard Worker      *  length     = (n+2*m) | (m!=0?0x8000:0)
1472*0e209d39SAndroid Build Coastguard Worker      *  bmpLength  = n; present if m!=0
1473*0e209d39SAndroid Build Coastguard Worker      *  bmp[0]
1474*0e209d39SAndroid Build Coastguard Worker      *  bmp[1]
1475*0e209d39SAndroid Build Coastguard Worker      *  ...
1476*0e209d39SAndroid Build Coastguard Worker      *  bmp[n-1]
1477*0e209d39SAndroid Build Coastguard Worker      *  supp-high[0]
1478*0e209d39SAndroid Build Coastguard Worker      *  supp-low[0]
1479*0e209d39SAndroid Build Coastguard Worker      *  supp-high[1]
1480*0e209d39SAndroid Build Coastguard Worker      *  supp-low[1]
1481*0e209d39SAndroid Build Coastguard Worker      *  ...
1482*0e209d39SAndroid Build Coastguard Worker      *  supp-high[m-1]
1483*0e209d39SAndroid Build Coastguard Worker      *  supp-low[m-1]
1484*0e209d39SAndroid Build Coastguard Worker      *
1485*0e209d39SAndroid Build Coastguard Worker      * The array starts with a header.  After the header are n bmp
1486*0e209d39SAndroid Build Coastguard Worker      * code points, then m supplementary code points.  Either n or m
1487*0e209d39SAndroid Build Coastguard Worker      * or both may be zero.  n+2*m is always <= 0x7FFF.
1488*0e209d39SAndroid Build Coastguard Worker      *
1489*0e209d39SAndroid Build Coastguard Worker      * If there are no supplementary characters (if m==0) then the
1490*0e209d39SAndroid Build Coastguard Worker      * header is one 16-bit integer, 'length', with value n.
1491*0e209d39SAndroid Build Coastguard Worker      *
1492*0e209d39SAndroid Build Coastguard Worker      * If there are supplementary characters (if m!=0) then the header
1493*0e209d39SAndroid Build Coastguard Worker      * is two 16-bit integers.  The first, 'length', has value
1494*0e209d39SAndroid Build Coastguard Worker      * (n+2*m)|0x8000.  The second, 'bmpLength', has value n.
1495*0e209d39SAndroid Build Coastguard Worker      *
1496*0e209d39SAndroid Build Coastguard Worker      * After the header the code points are stored in ascending order.
1497*0e209d39SAndroid Build Coastguard Worker      * Supplementary code points are stored as most significant 16
1498*0e209d39SAndroid Build Coastguard Worker      * bits followed by least significant 16 bits.
1499*0e209d39SAndroid Build Coastguard Worker      *
1500*0e209d39SAndroid Build Coastguard Worker      * @param dest pointer to buffer of destCapacity 16-bit integers.
1501*0e209d39SAndroid Build Coastguard Worker      * May be nullptr only if destCapacity is zero.
1502*0e209d39SAndroid Build Coastguard Worker      * @param destCapacity size of dest, or zero.  Must not be negative.
1503*0e209d39SAndroid Build Coastguard Worker      * @param ec error code.  Will be set to U_INDEX_OUTOFBOUNDS_ERROR
1504*0e209d39SAndroid Build Coastguard Worker      * if n+2*m > 0x7FFF.  Will be set to U_BUFFER_OVERFLOW_ERROR if
1505*0e209d39SAndroid Build Coastguard Worker      * n+2*m+(m!=0?2:1) > destCapacity.
1506*0e209d39SAndroid Build Coastguard Worker      * @return the total length of the serialized format, including
1507*0e209d39SAndroid Build Coastguard Worker      * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1508*0e209d39SAndroid Build Coastguard Worker      * than U_BUFFER_OVERFLOW_ERROR.
1509*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1510*0e209d39SAndroid Build Coastguard Worker      */
1511*0e209d39SAndroid Build Coastguard Worker     int32_t serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const;
1512*0e209d39SAndroid Build Coastguard Worker 
1513*0e209d39SAndroid Build Coastguard Worker     /**
1514*0e209d39SAndroid Build Coastguard Worker      * Reallocate this objects internal structures to take up the least
1515*0e209d39SAndroid Build Coastguard Worker      * possible space, without changing this object's value.
1516*0e209d39SAndroid Build Coastguard Worker      * A frozen set will not be modified.
1517*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1518*0e209d39SAndroid Build Coastguard Worker      */
1519*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeSet& compact();
1520*0e209d39SAndroid Build Coastguard Worker 
1521*0e209d39SAndroid Build Coastguard Worker     /**
1522*0e209d39SAndroid Build Coastguard Worker      * Return the class ID for this class.  This is useful only for
1523*0e209d39SAndroid Build Coastguard Worker      * comparing to a return value from getDynamicClassID().  For example:
1524*0e209d39SAndroid Build Coastguard Worker      * <pre>
1525*0e209d39SAndroid Build Coastguard Worker      * .      Base* polymorphic_pointer = createPolymorphicObject();
1526*0e209d39SAndroid Build Coastguard Worker      * .      if (polymorphic_pointer->getDynamicClassID() ==
1527*0e209d39SAndroid Build Coastguard Worker      * .          Derived::getStaticClassID()) ...
1528*0e209d39SAndroid Build Coastguard Worker      * </pre>
1529*0e209d39SAndroid Build Coastguard Worker      * @return          The class ID for all objects of this class.
1530*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
1531*0e209d39SAndroid Build Coastguard Worker      */
1532*0e209d39SAndroid Build Coastguard Worker     static UClassID U_EXPORT2 getStaticClassID();
1533*0e209d39SAndroid Build Coastguard Worker 
1534*0e209d39SAndroid Build Coastguard Worker     /**
1535*0e209d39SAndroid Build Coastguard Worker      * Implement UnicodeFunctor API.
1536*0e209d39SAndroid Build Coastguard Worker      *
1537*0e209d39SAndroid Build Coastguard Worker      * @return The class ID for this object. All objects of a given
1538*0e209d39SAndroid Build Coastguard Worker      * class have the same class ID.  Objects of other classes have
1539*0e209d39SAndroid Build Coastguard Worker      * different class IDs.
1540*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.4
1541*0e209d39SAndroid Build Coastguard Worker      */
1542*0e209d39SAndroid Build Coastguard Worker     virtual UClassID getDynamicClassID() const override;
1543*0e209d39SAndroid Build Coastguard Worker 
1544*0e209d39SAndroid Build Coastguard Worker   private:
1545*0e209d39SAndroid Build Coastguard Worker 
1546*0e209d39SAndroid Build Coastguard Worker     // Private API for the USet API
1547*0e209d39SAndroid Build Coastguard Worker 
1548*0e209d39SAndroid Build Coastguard Worker     friend class USetAccess;
1549*0e209d39SAndroid Build Coastguard Worker 
1550*0e209d39SAndroid Build Coastguard Worker     const UnicodeString* getString(int32_t index) const;
1551*0e209d39SAndroid Build Coastguard Worker 
1552*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1553*0e209d39SAndroid Build Coastguard Worker     // RuleBasedTransliterator support
1554*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1555*0e209d39SAndroid Build Coastguard Worker 
1556*0e209d39SAndroid Build Coastguard Worker private:
1557*0e209d39SAndroid Build Coastguard Worker 
1558*0e209d39SAndroid Build Coastguard Worker     /**
1559*0e209d39SAndroid Build Coastguard Worker      * Returns <tt>true</tt> if this set contains any character whose low byte
1560*0e209d39SAndroid Build Coastguard Worker      * is the given value.  This is used by <tt>RuleBasedTransliterator</tt> for
1561*0e209d39SAndroid Build Coastguard Worker      * indexing.
1562*0e209d39SAndroid Build Coastguard Worker      */
1563*0e209d39SAndroid Build Coastguard Worker     virtual UBool matchesIndexValue(uint8_t v) const override;
1564*0e209d39SAndroid Build Coastguard Worker 
1565*0e209d39SAndroid Build Coastguard Worker private:
1566*0e209d39SAndroid Build Coastguard Worker     friend class RBBIRuleScanner;
1567*0e209d39SAndroid Build Coastguard Worker 
1568*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1569*0e209d39SAndroid Build Coastguard Worker     // Implementation: Clone as thawed (see ICU4J Freezable)
1570*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1571*0e209d39SAndroid Build Coastguard Worker 
1572*0e209d39SAndroid Build Coastguard Worker     UnicodeSet(const UnicodeSet& o, UBool /* asThawed */);
1573*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& copyFrom(const UnicodeSet& o, UBool asThawed);
1574*0e209d39SAndroid Build Coastguard Worker 
1575*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1576*0e209d39SAndroid Build Coastguard Worker     // Implementation: Pattern parsing
1577*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1578*0e209d39SAndroid Build Coastguard Worker 
1579*0e209d39SAndroid Build Coastguard Worker     void applyPatternIgnoreSpace(const UnicodeString& pattern,
1580*0e209d39SAndroid Build Coastguard Worker                                  ParsePosition& pos,
1581*0e209d39SAndroid Build Coastguard Worker                                  const SymbolTable* symbols,
1582*0e209d39SAndroid Build Coastguard Worker                                  UErrorCode& status);
1583*0e209d39SAndroid Build Coastguard Worker 
1584*0e209d39SAndroid Build Coastguard Worker     void applyPattern(RuleCharacterIterator& chars,
1585*0e209d39SAndroid Build Coastguard Worker                       const SymbolTable* symbols,
1586*0e209d39SAndroid Build Coastguard Worker                       UnicodeString& rebuiltPat,
1587*0e209d39SAndroid Build Coastguard Worker                       uint32_t options,
1588*0e209d39SAndroid Build Coastguard Worker                       UnicodeSet& (UnicodeSet::*caseClosure)(int32_t attribute),
1589*0e209d39SAndroid Build Coastguard Worker                       int32_t depth,
1590*0e209d39SAndroid Build Coastguard Worker                       UErrorCode& ec);
1591*0e209d39SAndroid Build Coastguard Worker 
1592*0e209d39SAndroid Build Coastguard Worker     void closeOverCaseInsensitive(bool simple);
1593*0e209d39SAndroid Build Coastguard Worker     void closeOverAddCaseMappings();
1594*0e209d39SAndroid Build Coastguard Worker 
1595*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1596*0e209d39SAndroid Build Coastguard Worker     // Implementation: Utility methods
1597*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1598*0e209d39SAndroid Build Coastguard Worker 
1599*0e209d39SAndroid Build Coastguard Worker     static int32_t nextCapacity(int32_t minCapacity);
1600*0e209d39SAndroid Build Coastguard Worker 
1601*0e209d39SAndroid Build Coastguard Worker     bool ensureCapacity(int32_t newLen);
1602*0e209d39SAndroid Build Coastguard Worker 
1603*0e209d39SAndroid Build Coastguard Worker     bool ensureBufferCapacity(int32_t newLen);
1604*0e209d39SAndroid Build Coastguard Worker 
1605*0e209d39SAndroid Build Coastguard Worker     void swapBuffers();
1606*0e209d39SAndroid Build Coastguard Worker 
1607*0e209d39SAndroid Build Coastguard Worker     UBool allocateStrings(UErrorCode &status);
1608*0e209d39SAndroid Build Coastguard Worker     int32_t stringsSize() const;
1609*0e209d39SAndroid Build Coastguard Worker     UBool stringsContains(const UnicodeString &s) const;
1610*0e209d39SAndroid Build Coastguard Worker 
1611*0e209d39SAndroid Build Coastguard Worker     UnicodeString& _toPattern(UnicodeString& result,
1612*0e209d39SAndroid Build Coastguard Worker                               UBool escapeUnprintable) const;
1613*0e209d39SAndroid Build Coastguard Worker 
1614*0e209d39SAndroid Build Coastguard Worker     UnicodeString& _generatePattern(UnicodeString& result,
1615*0e209d39SAndroid Build Coastguard Worker                                     UBool escapeUnprintable) const;
1616*0e209d39SAndroid Build Coastguard Worker 
1617*0e209d39SAndroid Build Coastguard Worker     static void _appendToPat(UnicodeString& buf, const UnicodeString& s, UBool escapeUnprintable);
1618*0e209d39SAndroid Build Coastguard Worker 
1619*0e209d39SAndroid Build Coastguard Worker     static void _appendToPat(UnicodeString& buf, UChar32 c, UBool escapeUnprintable);
1620*0e209d39SAndroid Build Coastguard Worker 
1621*0e209d39SAndroid Build Coastguard Worker     static void _appendToPat(UnicodeString &result, UChar32 start, UChar32 end,
1622*0e209d39SAndroid Build Coastguard Worker                              UBool escapeUnprintable);
1623*0e209d39SAndroid Build Coastguard Worker 
1624*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1625*0e209d39SAndroid Build Coastguard Worker     // Implementation: Fundamental operators
1626*0e209d39SAndroid Build Coastguard Worker     //----------------------------------------------------------------
1627*0e209d39SAndroid Build Coastguard Worker 
1628*0e209d39SAndroid Build Coastguard Worker     void exclusiveOr(const UChar32* other, int32_t otherLen, int8_t polarity);
1629*0e209d39SAndroid Build Coastguard Worker 
1630*0e209d39SAndroid Build Coastguard Worker     void add(const UChar32* other, int32_t otherLen, int8_t polarity);
1631*0e209d39SAndroid Build Coastguard Worker 
1632*0e209d39SAndroid Build Coastguard Worker     void retain(const UChar32* other, int32_t otherLen, int8_t polarity);
1633*0e209d39SAndroid Build Coastguard Worker 
1634*0e209d39SAndroid Build Coastguard Worker     /**
1635*0e209d39SAndroid Build Coastguard Worker      * Return true if the given position, in the given pattern, appears
1636*0e209d39SAndroid Build Coastguard Worker      * to be the start of a property set pattern [:foo:], \\p{foo}, or
1637*0e209d39SAndroid Build Coastguard Worker      * \\P{foo}, or \\N{name}.
1638*0e209d39SAndroid Build Coastguard Worker      */
1639*0e209d39SAndroid Build Coastguard Worker     static UBool resemblesPropertyPattern(const UnicodeString& pattern,
1640*0e209d39SAndroid Build Coastguard Worker                                           int32_t pos);
1641*0e209d39SAndroid Build Coastguard Worker 
1642*0e209d39SAndroid Build Coastguard Worker     static UBool resemblesPropertyPattern(RuleCharacterIterator& chars,
1643*0e209d39SAndroid Build Coastguard Worker                                           int32_t iterOpts);
1644*0e209d39SAndroid Build Coastguard Worker 
1645*0e209d39SAndroid Build Coastguard Worker     /**
1646*0e209d39SAndroid Build Coastguard Worker      * Parse the given property pattern at the given parse position
1647*0e209d39SAndroid Build Coastguard Worker      * and set this UnicodeSet to the result.
1648*0e209d39SAndroid Build Coastguard Worker      *
1649*0e209d39SAndroid Build Coastguard Worker      * The original design document is out of date, but still useful.
1650*0e209d39SAndroid Build Coastguard Worker      * Ignore the property and value names:
1651*0e209d39SAndroid Build Coastguard Worker      * https://htmlpreview.github.io/?https://github.com/unicode-org/icu-docs/blob/main/design/unicodeset_properties.html
1652*0e209d39SAndroid Build Coastguard Worker      *
1653*0e209d39SAndroid Build Coastguard Worker      * Recognized syntax:
1654*0e209d39SAndroid Build Coastguard Worker      *
1655*0e209d39SAndroid Build Coastguard Worker      * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]"
1656*0e209d39SAndroid Build Coastguard Worker      * \\p{foo} \\P{foo}  - white space not allowed within "\\p" or "\\P"
1657*0e209d39SAndroid Build Coastguard Worker      * \\N{name}         - white space not allowed within "\\N"
1658*0e209d39SAndroid Build Coastguard Worker      *
1659*0e209d39SAndroid Build Coastguard Worker      * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored.
1660*0e209d39SAndroid Build Coastguard Worker      * Case is ignored except in "\\p" and "\\P" and "\\N".  In 'name' leading
1661*0e209d39SAndroid Build Coastguard Worker      * and trailing space is deleted, and internal runs of whitespace
1662*0e209d39SAndroid Build Coastguard Worker      * are collapsed to a single space.
1663*0e209d39SAndroid Build Coastguard Worker      *
1664*0e209d39SAndroid Build Coastguard Worker      * We support binary properties, enumerated properties, and the
1665*0e209d39SAndroid Build Coastguard Worker      * following non-enumerated properties:
1666*0e209d39SAndroid Build Coastguard Worker      *
1667*0e209d39SAndroid Build Coastguard Worker      *  Numeric_Value
1668*0e209d39SAndroid Build Coastguard Worker      *  Name
1669*0e209d39SAndroid Build Coastguard Worker      *  Unicode_1_Name
1670*0e209d39SAndroid Build Coastguard Worker      *
1671*0e209d39SAndroid Build Coastguard Worker      * @param pattern the pattern string
1672*0e209d39SAndroid Build Coastguard Worker      * @param ppos on entry, the position at which to begin parsing.
1673*0e209d39SAndroid Build Coastguard Worker      * This should be one of the locations marked '^':
1674*0e209d39SAndroid Build Coastguard Worker      *
1675*0e209d39SAndroid Build Coastguard Worker      *   [:blah:]     \\p{blah}     \\P{blah}     \\N{name}
1676*0e209d39SAndroid Build Coastguard Worker      *   ^       %    ^       %    ^       %    ^       %
1677*0e209d39SAndroid Build Coastguard Worker      *
1678*0e209d39SAndroid Build Coastguard Worker      * On return, the position after the last character parsed, that is,
1679*0e209d39SAndroid Build Coastguard Worker      * the locations marked '%'.  If the parse fails, ppos is returned
1680*0e209d39SAndroid Build Coastguard Worker      * unchanged.
1681*0e209d39SAndroid Build Coastguard Worker      * @param ec status
1682*0e209d39SAndroid Build Coastguard Worker      * @return a reference to this.
1683*0e209d39SAndroid Build Coastguard Worker      */
1684*0e209d39SAndroid Build Coastguard Worker     UnicodeSet& applyPropertyPattern(const UnicodeString& pattern,
1685*0e209d39SAndroid Build Coastguard Worker                                      ParsePosition& ppos,
1686*0e209d39SAndroid Build Coastguard Worker                                      UErrorCode &ec);
1687*0e209d39SAndroid Build Coastguard Worker 
1688*0e209d39SAndroid Build Coastguard Worker     void applyPropertyPattern(RuleCharacterIterator& chars,
1689*0e209d39SAndroid Build Coastguard Worker                               UnicodeString& rebuiltPat,
1690*0e209d39SAndroid Build Coastguard Worker                               UErrorCode& ec);
1691*0e209d39SAndroid Build Coastguard Worker 
1692*0e209d39SAndroid Build Coastguard Worker     /**
1693*0e209d39SAndroid Build Coastguard Worker      * A filter that returns true if the given code point should be
1694*0e209d39SAndroid Build Coastguard Worker      * included in the UnicodeSet being constructed.
1695*0e209d39SAndroid Build Coastguard Worker      */
1696*0e209d39SAndroid Build Coastguard Worker     typedef UBool (*Filter)(UChar32 codePoint, void* context);
1697*0e209d39SAndroid Build Coastguard Worker 
1698*0e209d39SAndroid Build Coastguard Worker     /**
1699*0e209d39SAndroid Build Coastguard Worker      * Given a filter, set this UnicodeSet to the code points
1700*0e209d39SAndroid Build Coastguard Worker      * contained by that filter.  The filter MUST be
1701*0e209d39SAndroid Build Coastguard Worker      * property-conformant.  That is, if it returns value v for one
1702*0e209d39SAndroid Build Coastguard Worker      * code point, then it must return v for all affiliated code
1703*0e209d39SAndroid Build Coastguard Worker      * points, as defined by the inclusions list.  See
1704*0e209d39SAndroid Build Coastguard Worker      * getInclusions().
1705*0e209d39SAndroid Build Coastguard Worker      * src is a UPropertySource value.
1706*0e209d39SAndroid Build Coastguard Worker      */
1707*0e209d39SAndroid Build Coastguard Worker     void applyFilter(Filter filter,
1708*0e209d39SAndroid Build Coastguard Worker                      void* context,
1709*0e209d39SAndroid Build Coastguard Worker                      const UnicodeSet* inclusions,
1710*0e209d39SAndroid Build Coastguard Worker                      UErrorCode &status);
1711*0e209d39SAndroid Build Coastguard Worker 
1712*0e209d39SAndroid Build Coastguard Worker     /**
1713*0e209d39SAndroid Build Coastguard Worker      * Set the new pattern to cache.
1714*0e209d39SAndroid Build Coastguard Worker      */
setPattern(const UnicodeString & newPat)1715*0e209d39SAndroid Build Coastguard Worker     void setPattern(const UnicodeString& newPat) {
1716*0e209d39SAndroid Build Coastguard Worker         setPattern(newPat.getBuffer(), newPat.length());
1717*0e209d39SAndroid Build Coastguard Worker     }
1718*0e209d39SAndroid Build Coastguard Worker     void setPattern(const char16_t *newPat, int32_t newPatLen);
1719*0e209d39SAndroid Build Coastguard Worker     /**
1720*0e209d39SAndroid Build Coastguard Worker      * Release existing cached pattern.
1721*0e209d39SAndroid Build Coastguard Worker      */
1722*0e209d39SAndroid Build Coastguard Worker     void releasePattern();
1723*0e209d39SAndroid Build Coastguard Worker 
1724*0e209d39SAndroid Build Coastguard Worker     friend class UnicodeSetIterator;
1725*0e209d39SAndroid Build Coastguard Worker };
1726*0e209d39SAndroid Build Coastguard Worker 
1727*0e209d39SAndroid Build Coastguard Worker 
1728*0e209d39SAndroid Build Coastguard Worker 
1729*0e209d39SAndroid Build Coastguard Worker inline bool UnicodeSet::operator!=(const UnicodeSet& o) const {
1730*0e209d39SAndroid Build Coastguard Worker     return !operator==(o);
1731*0e209d39SAndroid Build Coastguard Worker }
1732*0e209d39SAndroid Build Coastguard Worker 
isFrozen()1733*0e209d39SAndroid Build Coastguard Worker inline UBool UnicodeSet::isFrozen() const {
1734*0e209d39SAndroid Build Coastguard Worker     return (UBool)(bmpSet!=nullptr || stringSpan!=nullptr);
1735*0e209d39SAndroid Build Coastguard Worker }
1736*0e209d39SAndroid Build Coastguard Worker 
containsSome(UChar32 start,UChar32 end)1737*0e209d39SAndroid Build Coastguard Worker inline UBool UnicodeSet::containsSome(UChar32 start, UChar32 end) const {
1738*0e209d39SAndroid Build Coastguard Worker     return !containsNone(start, end);
1739*0e209d39SAndroid Build Coastguard Worker }
1740*0e209d39SAndroid Build Coastguard Worker 
containsSome(const UnicodeSet & s)1741*0e209d39SAndroid Build Coastguard Worker inline UBool UnicodeSet::containsSome(const UnicodeSet& s) const {
1742*0e209d39SAndroid Build Coastguard Worker     return !containsNone(s);
1743*0e209d39SAndroid Build Coastguard Worker }
1744*0e209d39SAndroid Build Coastguard Worker 
containsSome(const UnicodeString & s)1745*0e209d39SAndroid Build Coastguard Worker inline UBool UnicodeSet::containsSome(const UnicodeString& s) const {
1746*0e209d39SAndroid Build Coastguard Worker     return !containsNone(s);
1747*0e209d39SAndroid Build Coastguard Worker }
1748*0e209d39SAndroid Build Coastguard Worker 
isBogus()1749*0e209d39SAndroid Build Coastguard Worker inline UBool UnicodeSet::isBogus() const {
1750*0e209d39SAndroid Build Coastguard Worker     return (UBool)(fFlags & kIsBogus);
1751*0e209d39SAndroid Build Coastguard Worker }
1752*0e209d39SAndroid Build Coastguard Worker 
fromUSet(USet * uset)1753*0e209d39SAndroid Build Coastguard Worker inline UnicodeSet *UnicodeSet::fromUSet(USet *uset) {
1754*0e209d39SAndroid Build Coastguard Worker     return reinterpret_cast<UnicodeSet *>(uset);
1755*0e209d39SAndroid Build Coastguard Worker }
1756*0e209d39SAndroid Build Coastguard Worker 
fromUSet(const USet * uset)1757*0e209d39SAndroid Build Coastguard Worker inline const UnicodeSet *UnicodeSet::fromUSet(const USet *uset) {
1758*0e209d39SAndroid Build Coastguard Worker     return reinterpret_cast<const UnicodeSet *>(uset);
1759*0e209d39SAndroid Build Coastguard Worker }
1760*0e209d39SAndroid Build Coastguard Worker 
toUSet()1761*0e209d39SAndroid Build Coastguard Worker inline USet *UnicodeSet::toUSet() {
1762*0e209d39SAndroid Build Coastguard Worker     return reinterpret_cast<USet *>(this);
1763*0e209d39SAndroid Build Coastguard Worker }
1764*0e209d39SAndroid Build Coastguard Worker 
toUSet()1765*0e209d39SAndroid Build Coastguard Worker inline const USet *UnicodeSet::toUSet() const {
1766*0e209d39SAndroid Build Coastguard Worker     return reinterpret_cast<const USet *>(this);
1767*0e209d39SAndroid Build Coastguard Worker }
1768*0e209d39SAndroid Build Coastguard Worker 
span(const UnicodeString & s,int32_t start,USetSpanCondition spanCondition)1769*0e209d39SAndroid Build Coastguard Worker inline int32_t UnicodeSet::span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const {
1770*0e209d39SAndroid Build Coastguard Worker     int32_t sLength=s.length();
1771*0e209d39SAndroid Build Coastguard Worker     if(start<0) {
1772*0e209d39SAndroid Build Coastguard Worker         start=0;
1773*0e209d39SAndroid Build Coastguard Worker     } else if(start>sLength) {
1774*0e209d39SAndroid Build Coastguard Worker         start=sLength;
1775*0e209d39SAndroid Build Coastguard Worker     }
1776*0e209d39SAndroid Build Coastguard Worker     return start+span(s.getBuffer()+start, sLength-start, spanCondition);
1777*0e209d39SAndroid Build Coastguard Worker }
1778*0e209d39SAndroid Build Coastguard Worker 
spanBack(const UnicodeString & s,int32_t limit,USetSpanCondition spanCondition)1779*0e209d39SAndroid Build Coastguard Worker inline int32_t UnicodeSet::spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const {
1780*0e209d39SAndroid Build Coastguard Worker     int32_t sLength=s.length();
1781*0e209d39SAndroid Build Coastguard Worker     if(limit<0) {
1782*0e209d39SAndroid Build Coastguard Worker         limit=0;
1783*0e209d39SAndroid Build Coastguard Worker     } else if(limit>sLength) {
1784*0e209d39SAndroid Build Coastguard Worker         limit=sLength;
1785*0e209d39SAndroid Build Coastguard Worker     }
1786*0e209d39SAndroid Build Coastguard Worker     return spanBack(s.getBuffer(), limit, spanCondition);
1787*0e209d39SAndroid Build Coastguard Worker }
1788*0e209d39SAndroid Build Coastguard Worker 
1789*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
1790*0e209d39SAndroid Build Coastguard Worker 
1791*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */
1792*0e209d39SAndroid Build Coastguard Worker 
1793*0e209d39SAndroid Build Coastguard Worker #endif
1794