intl/icu/source/common/unicode/uniset.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial