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