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