annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/uniset.h @ 69:33d812a61356

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