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