]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/unicode/uset.h
ICU-66108.tar.gz
[apple/icu.git] / icuSources / common / unicode / uset.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/*
4*******************************************************************************
5*
b331163b 6* Copyright (C) 2002-2014, International Business Machines
b75a7d8f
A
7* Corporation and others. All Rights Reserved.
8*
9*******************************************************************************
10* file name: uset.h
f3c0d7a5 11* encoding: UTF-8
b75a7d8f
A
12* tab size: 8 (not used)
13* indentation:4
14*
15* created on: 2002mar07
16* created by: Markus W. Scherer
17*
18* C version of UnicodeSet.
19*/
20
21
22/**
23 * \file
24 * \brief C API: Unicode Set
25 *
26 * <p>This is a C wrapper around the C++ UnicodeSet class.</p>
27 */
28
29#ifndef __USET_H__
30#define __USET_H__
31
32#include "unicode/utypes.h"
374ca955 33#include "unicode/uchar.h"
729e4ab9 34#include "unicode/localpointer.h"
b75a7d8f 35
3d1f044b
A
36#ifndef USET_DEFINED
37
38#ifndef U_IN_DOXYGEN
39#define USET_DEFINED
40#endif
b75a7d8f 41/**
3d1f044b
A
42 * USet is the C API type corresponding to C++ class UnicodeSet.
43 * Use the uset_* API to manipulate. Create with
b75a7d8f 44 * uset_open*, and destroy with uset_close.
374ca955 45 * @stable ICU 2.4
b75a7d8f
A
46 */
47typedef struct USet USet;
48#endif
49
50/**
374ca955
A
51 * Bitmask values to be passed to uset_openPatternOptions() or
52 * uset_applyPattern() taking an option parameter.
53 * @stable ICU 2.4
b75a7d8f
A
54 */
55enum {
56 /**
57 * Ignore white space within patterns unless quoted or escaped.
374ca955 58 * @stable ICU 2.4
b75a7d8f
A
59 */
60 USET_IGNORE_SPACE = 1,
61
62 /**
63 * Enable case insensitive matching. E.g., "[ab]" with this flag
64 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
374ca955
A
65 * match all except 'a', 'A', 'b', and 'B'. This performs a full
66 * closure over case mappings, e.g. U+017F for s.
73c04bcf
A
67 *
68 * The resulting set is a superset of the input for the code points but
69 * not for the strings.
70 * It performs a case mapping closure of the code points and adds
71 * full case folding strings for the code points, and reduces strings of
72 * the original set to their full case folding equivalents.
73 *
74 * This is designed for case-insensitive matches, for example
75 * in regular expressions. The full code point case closure allows checking of
76 * an input character directly against the closure set.
77 * Strings are matched by comparing the case-folded form from the closure
78 * set with an incremental case folding of the string in question.
79 *
80 * The closure set will also contain single code points if the original
81 * set contained case-equivalent strings (like U+00DF for "ss" or "Ss" etc.).
82 * This is not necessary (that is, redundant) for the above matching method
83 * but results in the same closure sets regardless of whether the original
84 * set contained the code point or a string.
85 *
374ca955 86 * @stable ICU 2.4
b75a7d8f
A
87 */
88 USET_CASE_INSENSITIVE = 2,
89
374ca955
A
90 /**
91 * Enable case insensitive matching. E.g., "[ab]" with this flag
92 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
93 * match all except 'a', 'A', 'b', and 'B'. This adds the lower-,
94 * title-, and uppercase mappings as well as the case folding
95 * of each existing element in the set.
73c04bcf 96 * @stable ICU 3.2
374ca955 97 */
4388f060 98 USET_ADD_CASE_MAPPINGS = 4
b75a7d8f
A
99};
100
46f4442e
A
101/**
102 * Argument values for whether span() and similar functions continue while
103 * the current character is contained vs. not contained in the set.
104 *
105 * The functionality is straightforward for sets with only single code points,
106 * without strings (which is the common case):
b331163b
A
107 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE work the same.
108 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE are inverses of USET_SPAN_NOT_CONTAINED.
46f4442e
A
109 * - span() and spanBack() partition any string the same way when
110 * alternating between span(USET_SPAN_NOT_CONTAINED) and
111 * span(either "contained" condition).
112 * - Using a complemented (inverted) set and the opposite span conditions
113 * yields the same results.
114 *
115 * When a set contains multi-code point strings, then these statements may not
116 * be true, depending on the strings in the set (for example, whether they
117 * overlap with each other) and the string that is processed.
118 * For a set with strings:
119 * - The complement of the set contains the opposite set of code points,
120 * but the same set of strings.
121 * Therefore, complementing both the set and the span conditions
122 * may yield different results.
123 * - When starting spans at different positions in a string
124 * (span(s, ...) vs. span(s+1, ...)) the ends of the spans may be different
125 * because a set string may start before the later position.
126 * - span(USET_SPAN_SIMPLE) may be shorter than
127 * span(USET_SPAN_CONTAINED) because it will not recursively try
128 * all possible paths.
129 * For example, with a set which contains the three strings "xy", "xya" and "ax",
130 * span("xyax", USET_SPAN_CONTAINED) will return 4 but
131 * span("xyax", USET_SPAN_SIMPLE) will return 3.
132 * span(USET_SPAN_SIMPLE) will never be longer than
133 * span(USET_SPAN_CONTAINED).
134 * - With either "contained" condition, span() and spanBack() may partition
135 * a string in different ways.
136 * For example, with a set which contains the two strings "ab" and "ba",
137 * and when processing the string "aba",
138 * span() will yield contained/not-contained boundaries of { 0, 2, 3 }
139 * while spanBack() will yield boundaries of { 0, 1, 3 }.
140 *
141 * Note: If it is important to get the same boundaries whether iterating forward
142 * or backward through a string, then either only span() should be used and
143 * the boundaries cached for backward operation, or an ICU BreakIterator
144 * could be used.
145 *
146 * Note: Unpaired surrogates are treated like surrogate code points.
147 * Similarly, set strings match only on code point boundaries,
148 * never in the middle of a surrogate pair.
149 * Illegal UTF-8 sequences are treated like U+FFFD.
150 * When processing UTF-8 strings, malformed set strings
151 * (strings with unpaired surrogates which cannot be converted to UTF-8)
152 * are ignored.
153 *
729e4ab9 154 * @stable ICU 3.8
46f4442e
A
155 */
156typedef enum USetSpanCondition {
157 /**
b331163b
A
158 * Continues a span() while there is no set element at the current position.
159 * Increments by one code point at a time.
46f4442e
A
160 * Stops before the first set element (character or string).
161 * (For code points only, this is like while contains(current)==FALSE).
162 *
163 * When span() returns, the substring between where it started and the position
164 * it returned consists only of characters that are not in the set,
165 * and none of its strings overlap with the span.
166 *
729e4ab9 167 * @stable ICU 3.8
46f4442e
A
168 */
169 USET_SPAN_NOT_CONTAINED = 0,
170 /**
b331163b 171 * Spans the longest substring that is a concatenation of set elements (characters or strings).
46f4442e
A
172 * (For characters only, this is like while contains(current)==TRUE).
173 *
174 * When span() returns, the substring between where it started and the position
175 * it returned consists only of set elements (characters or strings) that are in the set.
176 *
b331163b
A
177 * If a set contains strings, then the span will be the longest substring for which there
178 * exists at least one non-overlapping concatenation of set elements (characters or strings).
179 * This is equivalent to a POSIX regular expression for <code>(OR of each set element)*</code>.
180 * (Java/ICU/Perl regex stops at the first match of an OR.)
46f4442e 181 *
729e4ab9 182 * @stable ICU 3.8
46f4442e
A
183 */
184 USET_SPAN_CONTAINED = 1,
185 /**
b331163b
A
186 * Continues a span() while there is a set element at the current position.
187 * Increments by the longest matching element at each position.
46f4442e
A
188 * (For characters only, this is like while contains(current)==TRUE).
189 *
190 * When span() returns, the substring between where it started and the position
191 * it returned consists only of set elements (characters or strings) that are in the set.
192 *
193 * If a set only contains single characters, then this is the same
194 * as USET_SPAN_CONTAINED.
195 *
196 * If a set contains strings, then the span will be the longest substring
197 * with a match at each position with the longest single set element (character or string).
198 *
199 * Use this span condition together with other longest-match algorithms,
200 * such as ICU converters (ucnv_getUnicodeSet()).
201 *
729e4ab9 202 * @stable ICU 3.8
46f4442e
A
203 */
204 USET_SPAN_SIMPLE = 2,
f3c0d7a5 205#ifndef U_HIDE_DEPRECATED_API
46f4442e
A
206 /**
207 * One more than the last span condition.
f3c0d7a5 208 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
46f4442e
A
209 */
210 USET_SPAN_CONDITION_COUNT
f3c0d7a5 211#endif // U_HIDE_DEPRECATED_API
46f4442e
A
212} USetSpanCondition;
213
4388f060
A
214enum {
215 /**
216 * Capacity of USerializedSet::staticArray.
217 * Enough for any single-code point set.
218 * Also provides padding for nice sizeof(USerializedSet).
219 * @stable ICU 2.4
220 */
221 USET_SERIALIZED_STATIC_ARRAY_CAPACITY=8
222};
223
b75a7d8f
A
224/**
225 * A serialized form of a Unicode set. Limited manipulations are
226 * possible directly on a serialized set. See below.
374ca955 227 * @stable ICU 2.4
b75a7d8f
A
228 */
229typedef struct USerializedSet {
230 /**
231 * The serialized Unicode Set.
374ca955 232 * @stable ICU 2.4
b75a7d8f
A
233 */
234 const uint16_t *array;
235 /**
236 * The length of the array that contains BMP characters.
374ca955 237 * @stable ICU 2.4
b75a7d8f
A
238 */
239 int32_t bmpLength;
240 /**
241 * The total length of the array.
374ca955 242 * @stable ICU 2.4
b75a7d8f
A
243 */
244 int32_t length;
245 /**
246 * A small buffer for the array to reduce memory allocations.
374ca955 247 * @stable ICU 2.4
b75a7d8f
A
248 */
249 uint16_t staticArray[USET_SERIALIZED_STATIC_ARRAY_CAPACITY];
250} USerializedSet;
251
252/*********************************************************************
253 * USet API
254 *********************************************************************/
255
729e4ab9
A
256/**
257 * Create an empty USet object.
258 * Equivalent to uset_open(1, 0).
259 * @return a newly created USet. The caller must call uset_close() on
260 * it when done.
261 * @stable ICU 4.2
262 */
263U_STABLE USet* U_EXPORT2
51004dcb 264uset_openEmpty(void);
729e4ab9 265
b75a7d8f
A
266/**
267 * Creates a USet object that contains the range of characters
46f4442e 268 * start..end, inclusive. If <code>start > end</code>
729e4ab9 269 * then an empty set is created (same as using uset_openEmpty()).
b75a7d8f
A
270 * @param start first character of the range, inclusive
271 * @param end last character of the range, inclusive
272 * @return a newly created USet. The caller must call uset_close() on
273 * it when done.
374ca955 274 * @stable ICU 2.4
b75a7d8f 275 */
374ca955 276U_STABLE USet* U_EXPORT2
b75a7d8f
A
277uset_open(UChar32 start, UChar32 end);
278
279/**
280 * Creates a set from the given pattern. See the UnicodeSet class
281 * description for the syntax of the pattern language.
282 * @param pattern a string specifying what characters are in the set
283 * @param patternLength the length of the pattern, or -1 if null
284 * terminated
285 * @param ec the error code
374ca955 286 * @stable ICU 2.4
b75a7d8f 287 */
374ca955 288U_STABLE USet* U_EXPORT2
b75a7d8f
A
289uset_openPattern(const UChar* pattern, int32_t patternLength,
290 UErrorCode* ec);
291
292/**
293 * Creates a set from the given pattern. See the UnicodeSet class
294 * description for the syntax of the pattern language.
295 * @param pattern a string specifying what characters are in the set
296 * @param patternLength the length of the pattern, or -1 if null
297 * terminated
298 * @param options bitmask for options to apply to the pattern.
299 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
300 * @param ec the error code
374ca955 301 * @stable ICU 2.4
b75a7d8f 302 */
374ca955 303U_STABLE USet* U_EXPORT2
b75a7d8f
A
304uset_openPatternOptions(const UChar* pattern, int32_t patternLength,
305 uint32_t options,
306 UErrorCode* ec);
307
308/**
309 * Disposes of the storage used by a USet object. This function should
310 * be called exactly once for objects returned by uset_open().
311 * @param set the object to dispose of
374ca955 312 * @stable ICU 2.4
b75a7d8f 313 */
374ca955 314U_STABLE void U_EXPORT2
b75a7d8f
A
315uset_close(USet* set);
316
729e4ab9
A
317#if U_SHOW_CPLUSPLUS_API
318
319U_NAMESPACE_BEGIN
320
321/**
322 * \class LocalUSetPointer
323 * "Smart pointer" class, closes a USet via uset_close().
324 * For most methods see the LocalPointerBase base class.
325 *
326 * @see LocalPointerBase
327 * @see LocalPointer
328 * @stable ICU 4.4
329 */
330U_DEFINE_LOCAL_OPEN_POINTER(LocalUSetPointer, USet, uset_close);
331
332U_NAMESPACE_END
333
340931cb 334#endif
729e4ab9 335
46f4442e
A
336/**
337 * Returns a copy of this object.
338 * If this set is frozen, then the clone will be frozen as well.
339 * Use uset_cloneAsThawed() for a mutable clone of a frozen set.
340 * @param set the original set
341 * @return the newly allocated copy of the set
342 * @see uset_cloneAsThawed
729e4ab9 343 * @stable ICU 3.8
46f4442e 344 */
729e4ab9 345U_STABLE USet * U_EXPORT2
46f4442e
A
346uset_clone(const USet *set);
347
348/**
349 * Determines whether the set has been frozen (made immutable) or not.
350 * See the ICU4J Freezable interface for details.
351 * @param set the set
352 * @return TRUE/FALSE for whether the set has been frozen
353 * @see uset_freeze
354 * @see uset_cloneAsThawed
729e4ab9 355 * @stable ICU 3.8
46f4442e 356 */
729e4ab9 357U_STABLE UBool U_EXPORT2
46f4442e
A
358uset_isFrozen(const USet *set);
359
360/**
361 * Freeze the set (make it immutable).
362 * Once frozen, it cannot be unfrozen and is therefore thread-safe
363 * until it is deleted.
364 * See the ICU4J Freezable interface for details.
365 * Freezing the set may also make some operations faster, for example
366 * uset_contains() and uset_span().
367 * A frozen set will not be modified. (It remains frozen.)
368 * @param set the set
369 * @return the same set, now frozen
370 * @see uset_isFrozen
371 * @see uset_cloneAsThawed
729e4ab9 372 * @stable ICU 3.8
46f4442e 373 */
729e4ab9 374U_STABLE void U_EXPORT2
46f4442e
A
375uset_freeze(USet *set);
376
377/**
378 * Clone the set and make the clone mutable.
379 * See the ICU4J Freezable interface for details.
380 * @param set the set
381 * @return the mutable clone
382 * @see uset_freeze
383 * @see uset_isFrozen
384 * @see uset_clone
729e4ab9 385 * @stable ICU 3.8
46f4442e 386 */
729e4ab9 387U_STABLE USet * U_EXPORT2
46f4442e
A
388uset_cloneAsThawed(const USet *set);
389
374ca955
A
390/**
391 * Causes the USet object to represent the range <code>start - end</code>.
392 * If <code>start > end</code> then this USet is set to an empty range.
46f4442e 393 * A frozen set will not be modified.
374ca955
A
394 * @param set the object to set to the given range
395 * @param start first character in the set, inclusive
396 * @param end last character in the set, inclusive
73c04bcf 397 * @stable ICU 3.2
374ca955 398 */
73c04bcf 399U_STABLE void U_EXPORT2
374ca955
A
400uset_set(USet* set,
401 UChar32 start, UChar32 end);
402
403/**
404 * Modifies the set to represent the set specified by the given
405 * pattern. See the UnicodeSet class description for the syntax of
406 * the pattern language. See also the User Guide chapter about UnicodeSet.
407 * <em>Empties the set passed before applying the pattern.</em>
46f4442e 408 * A frozen set will not be modified.
374ca955
A
409 * @param set The set to which the pattern is to be applied.
410 * @param pattern A pointer to UChar string specifying what characters are in the set.
411 * The character at pattern[0] must be a '['.
412 * @param patternLength The length of the UChar string. -1 if NUL terminated.
413 * @param options A bitmask for options to apply to the pattern.
414 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
415 * @param status Returns an error if the pattern cannot be parsed.
416 * @return Upon successful parse, the value is either
417 * the index of the character after the closing ']'
418 * of the parsed pattern.
419 * If the status code indicates failure, then the return value
420 * is the index of the error in the source.
46f4442e 421 *
73c04bcf 422 * @stable ICU 2.8
374ca955 423 */
73c04bcf 424U_STABLE int32_t U_EXPORT2
374ca955
A
425uset_applyPattern(USet *set,
426 const UChar *pattern, int32_t patternLength,
427 uint32_t options,
428 UErrorCode *status);
429
430/**
431 * Modifies the set to contain those code points which have the given value
432 * for the given binary or enumerated property, as returned by
433 * u_getIntPropertyValue. Prior contents of this set are lost.
46f4442e 434 * A frozen set will not be modified.
374ca955
A
435 *
436 * @param set the object to contain the code points defined by the property
437 *
438 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
439 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
440 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
441 *
442 * @param value a value in the range u_getIntPropertyMinValue(prop)..
443 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
444 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
445 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
446 * categories such as [:L:] to be represented.
447 *
448 * @param ec error code input/output parameter
449 *
73c04bcf 450 * @stable ICU 3.2
374ca955 451 */
73c04bcf 452U_STABLE void U_EXPORT2
374ca955
A
453uset_applyIntPropertyValue(USet* set,
454 UProperty prop, int32_t value, UErrorCode* ec);
455
456/**
457 * Modifies the set to contain those code points which have the
458 * given value for the given property. Prior contents of this
459 * set are lost.
46f4442e 460 * A frozen set will not be modified.
374ca955
A
461 *
462 * @param set the object to contain the code points defined by the given
463 * property and value alias
464 *
465 * @param prop a string specifying a property alias, either short or long.
466 * The name is matched loosely. See PropertyAliases.txt for names and a
467 * description of loose matching. If the value string is empty, then this
468 * string is interpreted as either a General_Category value alias, a Script
469 * value alias, a binary property alias, or a special ID. Special IDs are
470 * matched loosely and correspond to the following sets:
471 *
472 * "ANY" = [\\u0000-\\U0010FFFF],
73c04bcf
A
473 * "ASCII" = [\\u0000-\\u007F],
474 * "Assigned" = [:^Cn:].
374ca955
A
475 *
476 * @param propLength the length of the prop, or -1 if NULL
477 *
478 * @param value a string specifying a value alias, either short or long.
479 * The name is matched loosely. See PropertyValueAliases.txt for names
480 * and a description of loose matching. In addition to aliases listed,
481 * numeric values and canonical combining classes may be expressed
482 * numerically, e.g., ("nv", "0.5") or ("ccc", "220"). The value string
483 * may also be empty.
484 *
485 * @param valueLength the length of the value, or -1 if NULL
486 *
487 * @param ec error code input/output parameter
488 *
73c04bcf 489 * @stable ICU 3.2
374ca955 490 */
73c04bcf 491U_STABLE void U_EXPORT2
374ca955
A
492uset_applyPropertyAlias(USet* set,
493 const UChar *prop, int32_t propLength,
494 const UChar *value, int32_t valueLength,
495 UErrorCode* ec);
496
497/**
498 * Return true if the given position, in the given pattern, appears
499 * to be the start of a UnicodeSet pattern.
500 *
501 * @param pattern a string specifying the pattern
502 * @param patternLength the length of the pattern, or -1 if NULL
503 * @param pos the given position
73c04bcf 504 * @stable ICU 3.2
374ca955 505 */
73c04bcf 506U_STABLE UBool U_EXPORT2
374ca955
A
507uset_resemblesPattern(const UChar *pattern, int32_t patternLength,
508 int32_t pos);
509
b75a7d8f
A
510/**
511 * Returns a string representation of this set. If the result of
512 * calling this function is passed to a uset_openPattern(), it
513 * will produce another set that is equal to this one.
514 * @param set the set
515 * @param result the string to receive the rules, may be NULL
516 * @param resultCapacity the capacity of result, may be 0 if result is NULL
517 * @param escapeUnprintable if TRUE then convert unprintable
374ca955
A
518 * character to their hex escape representations, \\uxxxx or
519 * \\Uxxxxxxxx. Unprintable characters are those other than
b75a7d8f
A
520 * U+000A, U+0020..U+007E.
521 * @param ec error code.
522 * @return length of string, possibly larger than resultCapacity
374ca955 523 * @stable ICU 2.4
b75a7d8f 524 */
374ca955 525U_STABLE int32_t U_EXPORT2
b75a7d8f
A
526uset_toPattern(const USet* set,
527 UChar* result, int32_t resultCapacity,
528 UBool escapeUnprintable,
529 UErrorCode* ec);
530
531/**
532 * Adds the given character to the given USet. After this call,
533 * uset_contains(set, c) will return TRUE.
46f4442e 534 * A frozen set will not be modified.
b75a7d8f
A
535 * @param set the object to which to add the character
536 * @param c the character to add
374ca955 537 * @stable ICU 2.4
b75a7d8f 538 */
374ca955 539U_STABLE void U_EXPORT2
b75a7d8f
A
540uset_add(USet* set, UChar32 c);
541
542/**
543 * Adds all of the elements in the specified set to this set if
544 * they're not already present. This operation effectively
545 * modifies this set so that its value is the <i>union</i> of the two
546 * sets. The behavior of this operation is unspecified if the specified
547 * collection is modified while the operation is in progress.
46f4442e 548 * A frozen set will not be modified.
b75a7d8f
A
549 *
550 * @param set the object to which to add the set
551 * @param additionalSet the source set whose elements are to be added to this set.
374ca955 552 * @stable ICU 2.6
b75a7d8f 553 */
374ca955 554U_STABLE void U_EXPORT2
b75a7d8f
A
555uset_addAll(USet* set, const USet *additionalSet);
556
557/**
558 * Adds the given range of characters to the given USet. After this call,
559 * uset_contains(set, start, end) will return TRUE.
46f4442e 560 * A frozen set will not be modified.
b75a7d8f
A
561 * @param set the object to which to add the character
562 * @param start the first character of the range to add, inclusive
563 * @param end the last character of the range to add, inclusive
374ca955 564 * @stable ICU 2.2
b75a7d8f 565 */
374ca955 566U_STABLE void U_EXPORT2
b75a7d8f
A
567uset_addRange(USet* set, UChar32 start, UChar32 end);
568
569/**
570 * Adds the given string to the given USet. After this call,
571 * uset_containsString(set, str, strLen) will return TRUE.
46f4442e 572 * A frozen set will not be modified.
b75a7d8f
A
573 * @param set the object to which to add the character
574 * @param str the string to add
575 * @param strLen the length of the string or -1 if null terminated.
374ca955 576 * @stable ICU 2.4
b75a7d8f 577 */
374ca955 578U_STABLE void U_EXPORT2
b75a7d8f
A
579uset_addString(USet* set, const UChar* str, int32_t strLen);
580
73c04bcf
A
581/**
582 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
583 * If this set already any particular character, it has no effect on that character.
46f4442e 584 * A frozen set will not be modified.
73c04bcf
A
585 * @param set the object to which to add the character
586 * @param str the source string
587 * @param strLen the length of the string or -1 if null terminated.
46f4442e 588 * @stable ICU 3.4
73c04bcf 589 */
46f4442e 590U_STABLE void U_EXPORT2
73c04bcf
A
591uset_addAllCodePoints(USet* set, const UChar *str, int32_t strLen);
592
b75a7d8f
A
593/**
594 * Removes the given character from the given USet. After this call,
595 * uset_contains(set, c) will return FALSE.
46f4442e 596 * A frozen set will not be modified.
b75a7d8f
A
597 * @param set the object from which to remove the character
598 * @param c the character to remove
374ca955 599 * @stable ICU 2.4
b75a7d8f 600 */
374ca955 601U_STABLE void U_EXPORT2
b75a7d8f
A
602uset_remove(USet* set, UChar32 c);
603
604/**
605 * Removes the given range of characters from the given USet. After this call,
606 * uset_contains(set, start, end) will return FALSE.
46f4442e 607 * A frozen set will not be modified.
b75a7d8f
A
608 * @param set the object to which to add the character
609 * @param start the first character of the range to remove, inclusive
610 * @param end the last character of the range to remove, inclusive
374ca955 611 * @stable ICU 2.2
b75a7d8f 612 */
374ca955 613U_STABLE void U_EXPORT2
b75a7d8f
A
614uset_removeRange(USet* set, UChar32 start, UChar32 end);
615
616/**
617 * Removes the given string to the given USet. After this call,
618 * uset_containsString(set, str, strLen) will return FALSE.
46f4442e 619 * A frozen set will not be modified.
b75a7d8f
A
620 * @param set the object to which to add the character
621 * @param str the string to remove
622 * @param strLen the length of the string or -1 if null terminated.
374ca955 623 * @stable ICU 2.4
b75a7d8f 624 */
374ca955 625U_STABLE void U_EXPORT2
b75a7d8f
A
626uset_removeString(USet* set, const UChar* str, int32_t strLen);
627
374ca955
A
628/**
629 * Removes from this set all of its elements that are contained in the
630 * specified set. This operation effectively modifies this
631 * set so that its value is the <i>asymmetric set difference</i> of
632 * the two sets.
46f4442e 633 * A frozen set will not be modified.
374ca955
A
634 * @param set the object from which the elements are to be removed
635 * @param removeSet the object that defines which elements will be
636 * removed from this set
73c04bcf 637 * @stable ICU 3.2
374ca955 638 */
73c04bcf 639U_STABLE void U_EXPORT2
374ca955
A
640uset_removeAll(USet* set, const USet* removeSet);
641
642/**
643 * Retain only the elements in this set that are contained in the
644 * specified range. If <code>start > end</code> then an empty range is
645 * retained, leaving the set empty. This is equivalent to
646 * a boolean logic AND, or a set INTERSECTION.
46f4442e 647 * A frozen set will not be modified.
374ca955
A
648 *
649 * @param set the object for which to retain only the specified range
650 * @param start first character, inclusive, of range to be retained
651 * to this set.
652 * @param end last character, inclusive, of range to be retained
653 * to this set.
73c04bcf 654 * @stable ICU 3.2
374ca955 655 */
73c04bcf 656U_STABLE void U_EXPORT2
374ca955
A
657uset_retain(USet* set, UChar32 start, UChar32 end);
658
659/**
660 * Retains only the elements in this set that are contained in the
661 * specified set. In other words, removes from this set all of
662 * its elements that are not contained in the specified set. This
663 * operation effectively modifies this set so that its value is
664 * the <i>intersection</i> of the two sets.
46f4442e 665 * A frozen set will not be modified.
374ca955
A
666 *
667 * @param set the object on which to perform the retain
668 * @param retain set that defines which elements this set will retain
73c04bcf 669 * @stable ICU 3.2
374ca955 670 */
73c04bcf 671U_STABLE void U_EXPORT2
374ca955
A
672uset_retainAll(USet* set, const USet* retain);
673
674/**
675 * Reallocate this objects internal structures to take up the least
676 * possible space, without changing this object's value.
46f4442e 677 * A frozen set will not be modified.
374ca955
A
678 *
679 * @param set the object on which to perfrom the compact
73c04bcf 680 * @stable ICU 3.2
374ca955 681 */
73c04bcf 682U_STABLE void U_EXPORT2
374ca955
A
683uset_compact(USet* set);
684
b75a7d8f
A
685/**
686 * Inverts this set. This operation modifies this set so that
687 * its value is its complement. This operation does not affect
688 * the multicharacter strings, if any.
46f4442e 689 * A frozen set will not be modified.
b75a7d8f 690 * @param set the set
374ca955 691 * @stable ICU 2.4
b75a7d8f 692 */
374ca955 693U_STABLE void U_EXPORT2
b75a7d8f
A
694uset_complement(USet* set);
695
374ca955
A
696/**
697 * Complements in this set all elements contained in the specified
698 * set. Any character in the other set will be removed if it is
699 * in this set, or will be added if it is not in this set.
46f4442e 700 * A frozen set will not be modified.
374ca955
A
701 *
702 * @param set the set with which to complement
703 * @param complement set that defines which elements will be xor'ed
704 * from this set.
73c04bcf 705 * @stable ICU 3.2
374ca955 706 */
73c04bcf 707U_STABLE void U_EXPORT2
374ca955
A
708uset_complementAll(USet* set, const USet* complement);
709
b75a7d8f
A
710/**
711 * Removes all of the elements from this set. This set will be
712 * empty after this call returns.
46f4442e 713 * A frozen set will not be modified.
b75a7d8f 714 * @param set the set
374ca955 715 * @stable ICU 2.4
b75a7d8f 716 */
374ca955 717U_STABLE void U_EXPORT2
b75a7d8f
A
718uset_clear(USet* set);
719
729e4ab9
A
720/**
721 * Close this set over the given attribute. For the attribute
722 * USET_CASE, the result is to modify this set so that:
723 *
724 * 1. For each character or string 'a' in this set, all strings or
725 * characters 'b' such that foldCase(a) == foldCase(b) are added
726 * to this set.
727 *
728 * 2. For each string 'e' in the resulting set, if e !=
729 * foldCase(e), 'e' will be removed.
730 *
731 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
732 *
733 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
734 * == b denotes that the contents are the same, not pointer
735 * comparison.)
736 *
737 * A frozen set will not be modified.
738 *
739 * @param set the set
740 *
741 * @param attributes bitmask for attributes to close over.
742 * Currently only the USET_CASE bit is supported. Any undefined bits
743 * are ignored.
744 * @stable ICU 4.2
745 */
746U_STABLE void U_EXPORT2
747uset_closeOver(USet* set, int32_t attributes);
748
749/**
750 * Remove all strings from this set.
751 *
752 * @param set the set
753 * @stable ICU 4.2
754 */
755U_STABLE void U_EXPORT2
756uset_removeAllStrings(USet* set);
757
b75a7d8f
A
758/**
759 * Returns TRUE if the given USet contains no characters and no
760 * strings.
761 * @param set the set
762 * @return true if set is empty
374ca955 763 * @stable ICU 2.4
b75a7d8f 764 */
374ca955 765U_STABLE UBool U_EXPORT2
b75a7d8f
A
766uset_isEmpty(const USet* set);
767
768/**
769 * Returns TRUE if the given USet contains the given character.
46f4442e 770 * This function works faster with a frozen set.
b75a7d8f
A
771 * @param set the set
772 * @param c The codepoint to check for within the set
773 * @return true if set contains c
374ca955 774 * @stable ICU 2.4
b75a7d8f 775 */
374ca955 776U_STABLE UBool U_EXPORT2
b75a7d8f
A
777uset_contains(const USet* set, UChar32 c);
778
779/**
780 * Returns TRUE if the given USet contains all characters c
781 * where start <= c && c <= end.
782 * @param set the set
783 * @param start the first character of the range to test, inclusive
784 * @param end the last character of the range to test, inclusive
785 * @return TRUE if set contains the range
374ca955 786 * @stable ICU 2.2
b75a7d8f 787 */
374ca955 788U_STABLE UBool U_EXPORT2
b75a7d8f
A
789uset_containsRange(const USet* set, UChar32 start, UChar32 end);
790
791/**
792 * Returns TRUE if the given USet contains the given string.
793 * @param set the set
794 * @param str the string
795 * @param strLen the length of the string or -1 if null terminated.
796 * @return true if set contains str
374ca955 797 * @stable ICU 2.4
b75a7d8f 798 */
374ca955 799U_STABLE UBool U_EXPORT2
b75a7d8f
A
800uset_containsString(const USet* set, const UChar* str, int32_t strLen);
801
374ca955
A
802/**
803 * Returns the index of the given character within this set, where
804 * the set is ordered by ascending code point. If the character
805 * is not in this set, return -1. The inverse of this method is
806 * <code>charAt()</code>.
807 * @param set the set
808 * @param c the character to obtain the index for
809 * @return an index from 0..size()-1, or -1
73c04bcf 810 * @stable ICU 3.2
374ca955 811 */
73c04bcf 812U_STABLE int32_t U_EXPORT2
374ca955
A
813uset_indexOf(const USet* set, UChar32 c);
814
815/**
816 * Returns the character at the given index within this set, where
817 * the set is ordered by ascending code point. If the index is
818 * out of range, return (UChar32)-1. The inverse of this method is
819 * <code>indexOf()</code>.
820 * @param set the set
729e4ab9 821 * @param charIndex an index from 0..size()-1 to obtain the char for
374ca955 822 * @return the character at the given index, or (UChar32)-1.
73c04bcf 823 * @stable ICU 3.2
374ca955 824 */
73c04bcf 825U_STABLE UChar32 U_EXPORT2
729e4ab9 826uset_charAt(const USet* set, int32_t charIndex);
374ca955 827
b75a7d8f
A
828/**
829 * Returns the number of characters and strings contained in the given
830 * USet.
831 * @param set the set
832 * @return a non-negative integer counting the characters and strings
833 * contained in set
374ca955 834 * @stable ICU 2.4
b75a7d8f 835 */
374ca955 836U_STABLE int32_t U_EXPORT2
b75a7d8f
A
837uset_size(const USet* set);
838
839/**
840 * Returns the number of items in this set. An item is either a range
841 * of characters or a single multicharacter string.
842 * @param set the set
843 * @return a non-negative integer counting the character ranges
844 * and/or strings contained in set
374ca955 845 * @stable ICU 2.4
b75a7d8f 846 */
374ca955 847U_STABLE int32_t U_EXPORT2
b75a7d8f
A
848uset_getItemCount(const USet* set);
849
850/**
851 * Returns an item of this set. An item is either a range of
852 * characters or a single multicharacter string.
853 * @param set the set
854 * @param itemIndex a non-negative integer in the range 0..
855 * uset_getItemCount(set)-1
856 * @param start pointer to variable to receive first character
857 * in range, inclusive
858 * @param end pointer to variable to receive last character in range,
859 * inclusive
860 * @param str buffer to receive the string, may be NULL
861 * @param strCapacity capacity of str, or 0 if str is NULL
862 * @param ec error code
863 * @return the length of the string (>= 2), or 0 if the item is a
864 * range, in which case it is the range *start..*end, or -1 if
865 * itemIndex is out of range
374ca955 866 * @stable ICU 2.4
b75a7d8f 867 */
374ca955 868U_STABLE int32_t U_EXPORT2
b75a7d8f
A
869uset_getItem(const USet* set, int32_t itemIndex,
870 UChar32* start, UChar32* end,
871 UChar* str, int32_t strCapacity,
872 UErrorCode* ec);
873
374ca955
A
874/**
875 * Returns true if set1 contains all the characters and strings
73c04bcf 876 * of set2. It answers the question, 'Is set1 a superset of set2?'
374ca955
A
877 * @param set1 set to be checked for containment
878 * @param set2 set to be checked for containment
879 * @return true if the test condition is met
73c04bcf 880 * @stable ICU 3.2
374ca955 881 */
73c04bcf 882U_STABLE UBool U_EXPORT2
374ca955
A
883uset_containsAll(const USet* set1, const USet* set2);
884
73c04bcf
A
885/**
886 * Returns true if this set contains all the characters
887 * of the given string. This is does not check containment of grapheme
888 * clusters, like uset_containsString.
889 * @param set set of characters to be checked for containment
890 * @param str string containing codepoints to be checked for containment
891 * @param strLen the length of the string or -1 if null terminated.
892 * @return true if the test condition is met
46f4442e 893 * @stable ICU 3.4
73c04bcf 894 */
46f4442e 895U_STABLE UBool U_EXPORT2
73c04bcf
A
896uset_containsAllCodePoints(const USet* set, const UChar *str, int32_t strLen);
897
374ca955
A
898/**
899 * Returns true if set1 contains none of the characters and strings
900 * of set2. It answers the question, 'Is set1 a disjoint set of set2?'
901 * @param set1 set to be checked for containment
902 * @param set2 set to be checked for containment
903 * @return true if the test condition is met
73c04bcf 904 * @stable ICU 3.2
374ca955 905 */
73c04bcf 906U_STABLE UBool U_EXPORT2
374ca955
A
907uset_containsNone(const USet* set1, const USet* set2);
908
909/**
910 * Returns true if set1 contains some of the characters and strings
911 * of set2. It answers the question, 'Does set1 and set2 have an intersection?'
912 * @param set1 set to be checked for containment
913 * @param set2 set to be checked for containment
914 * @return true if the test condition is met
73c04bcf 915 * @stable ICU 3.2
374ca955 916 */
73c04bcf 917U_STABLE UBool U_EXPORT2
374ca955
A
918uset_containsSome(const USet* set1, const USet* set2);
919
46f4442e
A
920/**
921 * Returns the length of the initial substring of the input string which
922 * consists only of characters and strings that are contained in this set
923 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
924 * or only of characters and strings that are not contained
925 * in this set (USET_SPAN_NOT_CONTAINED).
926 * See USetSpanCondition for details.
927 * Similar to the strspn() C library function.
928 * Unpaired surrogates are treated according to contains() of their surrogate code points.
929 * This function works faster with a frozen set and with a non-negative string length argument.
930 * @param set the set
931 * @param s start of the string
932 * @param length of the string; can be -1 for NUL-terminated
933 * @param spanCondition specifies the containment condition
934 * @return the length of the initial substring according to the spanCondition;
935 * 0 if the start of the string does not fit the spanCondition
729e4ab9 936 * @stable ICU 3.8
46f4442e
A
937 * @see USetSpanCondition
938 */
729e4ab9 939U_STABLE int32_t U_EXPORT2
46f4442e
A
940uset_span(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition);
941
942/**
943 * Returns the start of the trailing substring of the input string which
944 * consists only of characters and strings that are contained in this set
945 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
946 * or only of characters and strings that are not contained
947 * in this set (USET_SPAN_NOT_CONTAINED).
948 * See USetSpanCondition for details.
949 * Unpaired surrogates are treated according to contains() of their surrogate code points.
950 * This function works faster with a frozen set and with a non-negative string length argument.
951 * @param set the set
952 * @param s start of the string
953 * @param length of the string; can be -1 for NUL-terminated
954 * @param spanCondition specifies the containment condition
955 * @return the start of the trailing substring according to the spanCondition;
956 * the string length if the end of the string does not fit the spanCondition
729e4ab9 957 * @stable ICU 3.8
46f4442e
A
958 * @see USetSpanCondition
959 */
729e4ab9 960U_STABLE int32_t U_EXPORT2
46f4442e
A
961uset_spanBack(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition);
962
963/**
964 * Returns the length of the initial substring of the input string which
965 * consists only of characters and strings that are contained in this set
966 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
967 * or only of characters and strings that are not contained
968 * in this set (USET_SPAN_NOT_CONTAINED).
969 * See USetSpanCondition for details.
970 * Similar to the strspn() C library function.
971 * Malformed byte sequences are treated according to contains(0xfffd).
972 * This function works faster with a frozen set and with a non-negative string length argument.
973 * @param set the set
974 * @param s start of the string (UTF-8)
975 * @param length of the string; can be -1 for NUL-terminated
976 * @param spanCondition specifies the containment condition
977 * @return the length of the initial substring according to the spanCondition;
978 * 0 if the start of the string does not fit the spanCondition
729e4ab9 979 * @stable ICU 3.8
46f4442e
A
980 * @see USetSpanCondition
981 */
729e4ab9 982U_STABLE int32_t U_EXPORT2
46f4442e
A
983uset_spanUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition);
984
985/**
986 * Returns the start of the trailing substring of the input string which
987 * consists only of characters and strings that are contained in this set
988 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
989 * or only of characters and strings that are not contained
990 * in this set (USET_SPAN_NOT_CONTAINED).
991 * See USetSpanCondition for details.
992 * Malformed byte sequences are treated according to contains(0xfffd).
993 * This function works faster with a frozen set and with a non-negative string length argument.
994 * @param set the set
995 * @param s start of the string (UTF-8)
996 * @param length of the string; can be -1 for NUL-terminated
997 * @param spanCondition specifies the containment condition
998 * @return the start of the trailing substring according to the spanCondition;
999 * the string length if the end of the string does not fit the spanCondition
729e4ab9 1000 * @stable ICU 3.8
46f4442e
A
1001 * @see USetSpanCondition
1002 */
729e4ab9 1003U_STABLE int32_t U_EXPORT2
46f4442e
A
1004uset_spanBackUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition);
1005
374ca955
A
1006/**
1007 * Returns true if set1 contains all of the characters and strings
1008 * of set2, and vis versa. It answers the question, 'Is set1 equal to set2?'
1009 * @param set1 set to be checked for containment
1010 * @param set2 set to be checked for containment
1011 * @return true if the test condition is met
73c04bcf 1012 * @stable ICU 3.2
374ca955 1013 */
73c04bcf 1014U_STABLE UBool U_EXPORT2
374ca955
A
1015uset_equals(const USet* set1, const USet* set2);
1016
b75a7d8f
A
1017/*********************************************************************
1018 * Serialized set API
1019 *********************************************************************/
1020
1021/**
1022 * Serializes this set into an array of 16-bit integers. Serialization
1023 * (currently) only records the characters in the set; multicharacter
1024 * strings are ignored.
1025 *
1026 * The array
1027 * has following format (each line is one 16-bit integer):
1028 *
1029 * length = (n+2*m) | (m!=0?0x8000:0)
1030 * bmpLength = n; present if m!=0
1031 * bmp[0]
1032 * bmp[1]
1033 * ...
1034 * bmp[n-1]
1035 * supp-high[0]
1036 * supp-low[0]
1037 * supp-high[1]
1038 * supp-low[1]
1039 * ...
1040 * supp-high[m-1]
1041 * supp-low[m-1]
1042 *
1043 * The array starts with a header. After the header are n bmp
1044 * code points, then m supplementary code points. Either n or m
1045 * or both may be zero. n+2*m is always <= 0x7FFF.
1046 *
1047 * If there are no supplementary characters (if m==0) then the
1048 * header is one 16-bit integer, 'length', with value n.
1049 *
1050 * If there are supplementary characters (if m!=0) then the header
1051 * is two 16-bit integers. The first, 'length', has value
1052 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
1053 *
1054 * After the header the code points are stored in ascending order.
1055 * Supplementary code points are stored as most significant 16
1056 * bits followed by least significant 16 bits.
1057 *
1058 * @param set the set
1059 * @param dest pointer to buffer of destCapacity 16-bit integers.
1060 * May be NULL only if destCapacity is zero.
1061 * @param destCapacity size of dest, or zero. Must not be negative.
1062 * @param pErrorCode pointer to the error code. Will be set to
1063 * U_INDEX_OUTOFBOUNDS_ERROR if n+2*m > 0x7FFF. Will be set to
1064 * U_BUFFER_OVERFLOW_ERROR if n+2*m+(m!=0?2:1) > destCapacity.
1065 * @return the total length of the serialized format, including
1066 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1067 * than U_BUFFER_OVERFLOW_ERROR.
374ca955 1068 * @stable ICU 2.4
b75a7d8f 1069 */
374ca955 1070U_STABLE int32_t U_EXPORT2
b75a7d8f
A
1071uset_serialize(const USet* set, uint16_t* dest, int32_t destCapacity, UErrorCode* pErrorCode);
1072
1073/**
1074 * Given a serialized array, fill in the given serialized set object.
1075 * @param fillSet pointer to result
1076 * @param src pointer to start of array
1077 * @param srcLength length of array
1078 * @return true if the given array is valid, otherwise false
374ca955 1079 * @stable ICU 2.4
b75a7d8f 1080 */
374ca955 1081U_STABLE UBool U_EXPORT2
b75a7d8f
A
1082uset_getSerializedSet(USerializedSet* fillSet, const uint16_t* src, int32_t srcLength);
1083
1084/**
1085 * Set the USerializedSet to contain the given character (and nothing
1086 * else).
1087 * @param fillSet pointer to result
1088 * @param c The codepoint to set
374ca955 1089 * @stable ICU 2.4
b75a7d8f 1090 */
374ca955 1091U_STABLE void U_EXPORT2
b75a7d8f
A
1092uset_setSerializedToOne(USerializedSet* fillSet, UChar32 c);
1093
1094/**
1095 * Returns TRUE if the given USerializedSet contains the given
1096 * character.
1097 * @param set the serialized set
1098 * @param c The codepoint to check for within the set
1099 * @return true if set contains c
374ca955 1100 * @stable ICU 2.4
b75a7d8f 1101 */
374ca955 1102U_STABLE UBool U_EXPORT2
b75a7d8f
A
1103uset_serializedContains(const USerializedSet* set, UChar32 c);
1104
1105/**
1106 * Returns the number of disjoint ranges of characters contained in
1107 * the given serialized set. Ignores any strings contained in the
1108 * set.
1109 * @param set the serialized set
1110 * @return a non-negative integer counting the character ranges
1111 * contained in set
374ca955 1112 * @stable ICU 2.4
b75a7d8f 1113 */
374ca955 1114U_STABLE int32_t U_EXPORT2
b75a7d8f
A
1115uset_getSerializedRangeCount(const USerializedSet* set);
1116
1117/**
1118 * Returns a range of characters contained in the given serialized
1119 * set.
1120 * @param set the serialized set
1121 * @param rangeIndex a non-negative integer in the range 0..
1122 * uset_getSerializedRangeCount(set)-1
1123 * @param pStart pointer to variable to receive first character
1124 * in range, inclusive
1125 * @param pEnd pointer to variable to receive last character in range,
1126 * inclusive
1127 * @return true if rangeIndex is valid, otherwise false
374ca955 1128 * @stable ICU 2.4
b75a7d8f 1129 */
374ca955 1130U_STABLE UBool U_EXPORT2
b75a7d8f
A
1131uset_getSerializedRange(const USerializedSet* set, int32_t rangeIndex,
1132 UChar32* pStart, UChar32* pEnd);
1133
1134#endif