1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 2002-2014, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
12 * tab size: 8 (not used)
15 * created on: 2002mar07
16 * created by: Markus W. Scherer
18 * C version of UnicodeSet.
24 * \brief C API: Unicode Set
26 * <p>This is a C wrapper around the C++ UnicodeSet class.</p>
32 #include "unicode/utypes.h"
33 #include "unicode/uchar.h"
34 #include "unicode/localpointer.h"
42 * USet is the C API type corresponding to C++ class UnicodeSet.
43 * Use the uset_* API to manipulate. Create with
44 * uset_open*, and destroy with uset_close.
47 typedef struct USet USet
;
51 * Bitmask values to be passed to uset_openPatternOptions() or
52 * uset_applyPattern() taking an option parameter.
57 * Ignore white space within patterns unless quoted or escaped.
60 USET_IGNORE_SPACE
= 1,
63 * Enable case insensitive matching. E.g., "[ab]" with this flag
64 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
65 * match all except 'a', 'A', 'b', and 'B'. This performs a full
66 * closure over case mappings, e.g. U+017F for s.
68 * The resulting set is a superset of the input for the code points but
69 * not for the strings.
70 * It performs a case mapping closure of the code points and adds
71 * full case folding strings for the code points, and reduces strings of
72 * the original set to their full case folding equivalents.
74 * This is designed for case-insensitive matches, for example
75 * in regular expressions. The full code point case closure allows checking of
76 * an input character directly against the closure set.
77 * Strings are matched by comparing the case-folded form from the closure
78 * set with an incremental case folding of the string in question.
80 * The closure set will also contain single code points if the original
81 * set contained case-equivalent strings (like U+00DF for "ss" or "Ss" etc.).
82 * This is not necessary (that is, redundant) for the above matching method
83 * but results in the same closure sets regardless of whether the original
84 * set contained the code point or a string.
88 USET_CASE_INSENSITIVE
= 2,
91 * Enable case insensitive matching. E.g., "[ab]" with this flag
92 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
93 * match all except 'a', 'A', 'b', and 'B'. This adds the lower-,
94 * title-, and uppercase mappings as well as the case folding
95 * of each existing element in the set.
98 USET_ADD_CASE_MAPPINGS
= 4
102 * Argument values for whether span() and similar functions continue while
103 * the current character is contained vs. not contained in the set.
105 * The functionality is straightforward for sets with only single code points,
106 * without strings (which is the common case):
107 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE work the same.
108 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE are inverses of USET_SPAN_NOT_CONTAINED.
109 * - span() and spanBack() partition any string the same way when
110 * alternating between span(USET_SPAN_NOT_CONTAINED) and
111 * span(either "contained" condition).
112 * - Using a complemented (inverted) set and the opposite span conditions
113 * yields the same results.
115 * When a set contains multi-code point strings, then these statements may not
116 * be true, depending on the strings in the set (for example, whether they
117 * overlap with each other) and the string that is processed.
118 * For a set with strings:
119 * - The complement of the set contains the opposite set of code points,
120 * but the same set of strings.
121 * Therefore, complementing both the set and the span conditions
122 * may yield different results.
123 * - When starting spans at different positions in a string
124 * (span(s, ...) vs. span(s+1, ...)) the ends of the spans may be different
125 * because a set string may start before the later position.
126 * - span(USET_SPAN_SIMPLE) may be shorter than
127 * span(USET_SPAN_CONTAINED) because it will not recursively try
128 * all possible paths.
129 * For example, with a set which contains the three strings "xy", "xya" and "ax",
130 * span("xyax", USET_SPAN_CONTAINED) will return 4 but
131 * span("xyax", USET_SPAN_SIMPLE) will return 3.
132 * span(USET_SPAN_SIMPLE) will never be longer than
133 * span(USET_SPAN_CONTAINED).
134 * - With either "contained" condition, span() and spanBack() may partition
135 * a string in different ways.
136 * For example, with a set which contains the two strings "ab" and "ba",
137 * and when processing the string "aba",
138 * span() will yield contained/not-contained boundaries of { 0, 2, 3 }
139 * while spanBack() will yield boundaries of { 0, 1, 3 }.
141 * Note: If it is important to get the same boundaries whether iterating forward
142 * or backward through a string, then either only span() should be used and
143 * the boundaries cached for backward operation, or an ICU BreakIterator
146 * Note: Unpaired surrogates are treated like surrogate code points.
147 * Similarly, set strings match only on code point boundaries,
148 * never in the middle of a surrogate pair.
149 * Illegal UTF-8 sequences are treated like U+FFFD.
150 * When processing UTF-8 strings, malformed set strings
151 * (strings with unpaired surrogates which cannot be converted to UTF-8)
156 typedef enum USetSpanCondition
{
158 * Continues a span() while there is no set element at the current position.
159 * Increments by one code point at a time.
160 * Stops before the first set element (character or string).
161 * (For code points only, this is like while contains(current)==FALSE).
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.
169 USET_SPAN_NOT_CONTAINED
= 0,
171 * Spans the longest substring that is a concatenation of set elements (characters or strings).
172 * (For characters only, this is like while contains(current)==TRUE).
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.
177 * If a set contains strings, then the span will be the longest substring for which there
178 * exists at least one non-overlapping concatenation of set elements (characters or strings).
179 * This is equivalent to a POSIX regular expression for <code>(OR of each set element)*</code>.
180 * (Java/ICU/Perl regex stops at the first match of an OR.)
184 USET_SPAN_CONTAINED
= 1,
186 * Continues a span() while there is a set element at the current position.
187 * Increments by the longest matching element at each position.
188 * (For characters only, this is like while contains(current)==TRUE).
190 * When span() returns, the substring between where it started and the position
191 * it returned consists only of set elements (characters or strings) that are in the set.
193 * If a set only contains single characters, then this is the same
194 * as USET_SPAN_CONTAINED.
196 * If a set contains strings, then the span will be the longest substring
197 * with a match at each position with the longest single set element (character or string).
199 * Use this span condition together with other longest-match algorithms,
200 * such as ICU converters (ucnv_getUnicodeSet()).
204 USET_SPAN_SIMPLE
= 2,
205 #ifndef U_HIDE_DEPRECATED_API
207 * One more than the last span condition.
208 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
210 USET_SPAN_CONDITION_COUNT
211 #endif // U_HIDE_DEPRECATED_API
216 * Capacity of USerializedSet::staticArray.
217 * Enough for any single-code point set.
218 * Also provides padding for nice sizeof(USerializedSet).
221 USET_SERIALIZED_STATIC_ARRAY_CAPACITY
=8
225 * A serialized form of a Unicode set. Limited manipulations are
226 * possible directly on a serialized set. See below.
229 typedef struct USerializedSet
{
231 * The serialized Unicode Set.
234 const uint16_t *array
;
236 * The length of the array that contains BMP characters.
241 * The total length of the array.
246 * A small buffer for the array to reduce memory allocations.
249 uint16_t staticArray
[USET_SERIALIZED_STATIC_ARRAY_CAPACITY
];
252 /*********************************************************************
254 *********************************************************************/
257 * Create an empty USet object.
258 * Equivalent to uset_open(1, 0).
259 * @return a newly created USet. The caller must call uset_close() on
263 U_STABLE USet
* U_EXPORT2
264 uset_openEmpty(void);
267 * Creates a USet object that contains the range of characters
268 * start..end, inclusive. If <code>start > end</code>
269 * then an empty set is created (same as using uset_openEmpty()).
270 * @param start first character of the range, inclusive
271 * @param end last character of the range, inclusive
272 * @return a newly created USet. The caller must call uset_close() on
276 U_STABLE USet
* U_EXPORT2
277 uset_open(UChar32 start
, UChar32 end
);
280 * Creates a set from the given pattern. See the UnicodeSet class
281 * description for the syntax of the pattern language.
282 * @param pattern a string specifying what characters are in the set
283 * @param patternLength the length of the pattern, or -1 if null
285 * @param ec the error code
288 U_STABLE USet
* U_EXPORT2
289 uset_openPattern(const UChar
* pattern
, int32_t patternLength
,
293 * Creates a set from the given pattern. See the UnicodeSet class
294 * description for the syntax of the pattern language.
295 * @param pattern a string specifying what characters are in the set
296 * @param patternLength the length of the pattern, or -1 if null
298 * @param options bitmask for options to apply to the pattern.
299 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
300 * @param ec the error code
303 U_STABLE USet
* U_EXPORT2
304 uset_openPatternOptions(const UChar
* pattern
, int32_t patternLength
,
309 * Disposes of the storage used by a USet object. This function should
310 * be called exactly once for objects returned by uset_open().
311 * @param set the object to dispose of
314 U_STABLE
void U_EXPORT2
315 uset_close(USet
* set
);
317 #if U_SHOW_CPLUSPLUS_API
322 * \class LocalUSetPointer
323 * "Smart pointer" class, closes a USet via uset_close().
324 * For most methods see the LocalPointerBase base class.
326 * @see LocalPointerBase
330 U_DEFINE_LOCAL_OPEN_POINTER(LocalUSetPointer
, USet
, uset_close
);
334 #endif // U_SHOW_CPLUSPLUS_API
337 * Returns a copy of this object.
338 * If this set is frozen, then the clone will be frozen as well.
339 * Use uset_cloneAsThawed() for a mutable clone of a frozen set.
340 * @param set the original set
341 * @return the newly allocated copy of the set
342 * @see uset_cloneAsThawed
345 U_STABLE USet
* U_EXPORT2
346 uset_clone(const USet
*set
);
349 * Determines whether the set has been frozen (made immutable) or not.
350 * See the ICU4J Freezable interface for details.
352 * @return TRUE/FALSE for whether the set has been frozen
354 * @see uset_cloneAsThawed
357 U_STABLE UBool U_EXPORT2
358 uset_isFrozen(const USet
*set
);
361 * Freeze the set (make it immutable).
362 * Once frozen, it cannot be unfrozen and is therefore thread-safe
363 * until it is deleted.
364 * See the ICU4J Freezable interface for details.
365 * Freezing the set may also make some operations faster, for example
366 * uset_contains() and uset_span().
367 * A frozen set will not be modified. (It remains frozen.)
369 * @return the same set, now frozen
371 * @see uset_cloneAsThawed
374 U_STABLE
void U_EXPORT2
375 uset_freeze(USet
*set
);
378 * Clone the set and make the clone mutable.
379 * See the ICU4J Freezable interface for details.
381 * @return the mutable clone
387 U_STABLE USet
* U_EXPORT2
388 uset_cloneAsThawed(const USet
*set
);
391 * Causes the USet object to represent the range <code>start - end</code>.
392 * If <code>start > end</code> then this USet is set to an empty range.
393 * A frozen set will not be modified.
394 * @param set the object to set to the given range
395 * @param start first character in the set, inclusive
396 * @param end last character in the set, inclusive
399 U_STABLE
void U_EXPORT2
401 UChar32 start
, UChar32 end
);
404 * Modifies the set to represent the set specified by the given
405 * pattern. See the UnicodeSet class description for the syntax of
406 * the pattern language. See also the User Guide chapter about UnicodeSet.
407 * <em>Empties the set passed before applying the pattern.</em>
408 * A frozen set will not be modified.
409 * @param set The set to which the pattern is to be applied.
410 * @param pattern A pointer to UChar string specifying what characters are in the set.
411 * The character at pattern[0] must be a '['.
412 * @param patternLength The length of the UChar string. -1 if NUL terminated.
413 * @param options A bitmask for options to apply to the pattern.
414 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
415 * @param status Returns an error if the pattern cannot be parsed.
416 * @return Upon successful parse, the value is either
417 * the index of the character after the closing ']'
418 * of the parsed pattern.
419 * If the status code indicates failure, then the return value
420 * is the index of the error in the source.
424 U_STABLE
int32_t U_EXPORT2
425 uset_applyPattern(USet
*set
,
426 const UChar
*pattern
, int32_t patternLength
,
431 * Modifies the set to contain those code points which have the given value
432 * for the given binary or enumerated property, as returned by
433 * u_getIntPropertyValue. Prior contents of this set are lost.
434 * A frozen set will not be modified.
436 * @param set the object to contain the code points defined by the property
438 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
439 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
440 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
442 * @param value a value in the range u_getIntPropertyMinValue(prop)..
443 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
444 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
445 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
446 * categories such as [:L:] to be represented.
448 * @param ec error code input/output parameter
452 U_STABLE
void U_EXPORT2
453 uset_applyIntPropertyValue(USet
* set
,
454 UProperty prop
, int32_t value
, UErrorCode
* ec
);
457 * Modifies the set to contain those code points which have the
458 * given value for the given property. Prior contents of this
460 * A frozen set will not be modified.
462 * @param set the object to contain the code points defined by the given
463 * property and value alias
465 * @param prop a string specifying a property alias, either short or long.
466 * The name is matched loosely. See PropertyAliases.txt for names and a
467 * description of loose matching. If the value string is empty, then this
468 * string is interpreted as either a General_Category value alias, a Script
469 * value alias, a binary property alias, or a special ID. Special IDs are
470 * matched loosely and correspond to the following sets:
472 * "ANY" = [\\u0000-\\U0010FFFF],
473 * "ASCII" = [\\u0000-\\u007F],
474 * "Assigned" = [:^Cn:].
476 * @param propLength the length of the prop, or -1 if NULL
478 * @param value a string specifying a value alias, either short or long.
479 * The name is matched loosely. See PropertyValueAliases.txt for names
480 * and a description of loose matching. In addition to aliases listed,
481 * numeric values and canonical combining classes may be expressed
482 * numerically, e.g., ("nv", "0.5") or ("ccc", "220"). The value string
485 * @param valueLength the length of the value, or -1 if NULL
487 * @param ec error code input/output parameter
491 U_STABLE
void U_EXPORT2
492 uset_applyPropertyAlias(USet
* set
,
493 const UChar
*prop
, int32_t propLength
,
494 const UChar
*value
, int32_t valueLength
,
498 * Return true if the given position, in the given pattern, appears
499 * to be the start of a UnicodeSet pattern.
501 * @param pattern a string specifying the pattern
502 * @param patternLength the length of the pattern, or -1 if NULL
503 * @param pos the given position
506 U_STABLE UBool U_EXPORT2
507 uset_resemblesPattern(const UChar
*pattern
, int32_t patternLength
,
511 * Returns a string representation of this set. If the result of
512 * calling this function is passed to a uset_openPattern(), it
513 * will produce another set that is equal to this one.
515 * @param result the string to receive the rules, may be NULL
516 * @param resultCapacity the capacity of result, may be 0 if result is NULL
517 * @param escapeUnprintable if TRUE then convert unprintable
518 * character to their hex escape representations, \\uxxxx or
519 * \\Uxxxxxxxx. Unprintable characters are those other than
520 * U+000A, U+0020..U+007E.
521 * @param ec error code.
522 * @return length of string, possibly larger than resultCapacity
525 U_STABLE
int32_t U_EXPORT2
526 uset_toPattern(const USet
* set
,
527 UChar
* result
, int32_t resultCapacity
,
528 UBool escapeUnprintable
,
532 * Adds the given character to the given USet. After this call,
533 * uset_contains(set, c) will return TRUE.
534 * A frozen set will not be modified.
535 * @param set the object to which to add the character
536 * @param c the character to add
539 U_STABLE
void U_EXPORT2
540 uset_add(USet
* set
, UChar32 c
);
543 * Adds all of the elements in the specified set to this set if
544 * they're not already present. This operation effectively
545 * modifies this set so that its value is the <i>union</i> of the two
546 * sets. The behavior of this operation is unspecified if the specified
547 * collection is modified while the operation is in progress.
548 * A frozen set will not be modified.
550 * @param set the object to which to add the set
551 * @param additionalSet the source set whose elements are to be added to this set.
554 U_STABLE
void U_EXPORT2
555 uset_addAll(USet
* set
, const USet
*additionalSet
);
558 * Adds the given range of characters to the given USet. After this call,
559 * uset_contains(set, start, end) will return TRUE.
560 * A frozen set will not be modified.
561 * @param set the object to which to add the character
562 * @param start the first character of the range to add, inclusive
563 * @param end the last character of the range to add, inclusive
566 U_STABLE
void U_EXPORT2
567 uset_addRange(USet
* set
, UChar32 start
, UChar32 end
);
570 * Adds the given string to the given USet. After this call,
571 * uset_containsString(set, str, strLen) will return TRUE.
572 * A frozen set will not be modified.
573 * @param set the object to which to add the character
574 * @param str the string to add
575 * @param strLen the length of the string or -1 if null terminated.
578 U_STABLE
void U_EXPORT2
579 uset_addString(USet
* set
, const UChar
* str
, int32_t strLen
);
582 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
583 * If this set already any particular character, it has no effect on that character.
584 * A frozen set will not be modified.
585 * @param set the object to which to add the character
586 * @param str the source string
587 * @param strLen the length of the string or -1 if null terminated.
590 U_STABLE
void U_EXPORT2
591 uset_addAllCodePoints(USet
* set
, const UChar
*str
, int32_t strLen
);
594 * Removes the given character from the given USet. After this call,
595 * uset_contains(set, c) will return FALSE.
596 * A frozen set will not be modified.
597 * @param set the object from which to remove the character
598 * @param c the character to remove
601 U_STABLE
void U_EXPORT2
602 uset_remove(USet
* set
, UChar32 c
);
605 * Removes the given range of characters from the given USet. After this call,
606 * uset_contains(set, start, end) will return FALSE.
607 * A frozen set will not be modified.
608 * @param set the object to which to add the character
609 * @param start the first character of the range to remove, inclusive
610 * @param end the last character of the range to remove, inclusive
613 U_STABLE
void U_EXPORT2
614 uset_removeRange(USet
* set
, UChar32 start
, UChar32 end
);
617 * Removes the given string to the given USet. After this call,
618 * uset_containsString(set, str, strLen) will return FALSE.
619 * A frozen set will not be modified.
620 * @param set the object to which to add the character
621 * @param str the string to remove
622 * @param strLen the length of the string or -1 if null terminated.
625 U_STABLE
void U_EXPORT2
626 uset_removeString(USet
* set
, const UChar
* str
, int32_t strLen
);
629 * Removes from this set all of its elements that are contained in the
630 * specified set. This operation effectively modifies this
631 * set so that its value is the <i>asymmetric set difference</i> of
633 * A frozen set will not be modified.
634 * @param set the object from which the elements are to be removed
635 * @param removeSet the object that defines which elements will be
636 * removed from this set
639 U_STABLE
void U_EXPORT2
640 uset_removeAll(USet
* set
, const USet
* removeSet
);
643 * Retain only the elements in this set that are contained in the
644 * specified range. If <code>start > end</code> then an empty range is
645 * retained, leaving the set empty. This is equivalent to
646 * a boolean logic AND, or a set INTERSECTION.
647 * A frozen set will not be modified.
649 * @param set the object for which to retain only the specified range
650 * @param start first character, inclusive, of range to be retained
652 * @param end last character, inclusive, of range to be retained
656 U_STABLE
void U_EXPORT2
657 uset_retain(USet
* set
, UChar32 start
, UChar32 end
);
660 * Retains only the elements in this set that are contained in the
661 * specified set. In other words, removes from this set all of
662 * its elements that are not contained in the specified set. This
663 * operation effectively modifies this set so that its value is
664 * the <i>intersection</i> of the two sets.
665 * A frozen set will not be modified.
667 * @param set the object on which to perform the retain
668 * @param retain set that defines which elements this set will retain
671 U_STABLE
void U_EXPORT2
672 uset_retainAll(USet
* set
, const USet
* retain
);
675 * Reallocate this objects internal structures to take up the least
676 * possible space, without changing this object's value.
677 * A frozen set will not be modified.
679 * @param set the object on which to perfrom the compact
682 U_STABLE
void U_EXPORT2
683 uset_compact(USet
* set
);
686 * Inverts this set. This operation modifies this set so that
687 * its value is its complement. This operation does not affect
688 * the multicharacter strings, if any.
689 * A frozen set will not be modified.
693 U_STABLE
void U_EXPORT2
694 uset_complement(USet
* set
);
697 * Complements in this set all elements contained in the specified
698 * set. Any character in the other set will be removed if it is
699 * in this set, or will be added if it is not in this set.
700 * A frozen set will not be modified.
702 * @param set the set with which to complement
703 * @param complement set that defines which elements will be xor'ed
707 U_STABLE
void U_EXPORT2
708 uset_complementAll(USet
* set
, const USet
* complement
);
711 * Removes all of the elements from this set. This set will be
712 * empty after this call returns.
713 * A frozen set will not be modified.
717 U_STABLE
void U_EXPORT2
718 uset_clear(USet
* set
);
721 * Close this set over the given attribute. For the attribute
722 * USET_CASE, the result is to modify this set so that:
724 * 1. For each character or string 'a' in this set, all strings or
725 * characters 'b' such that foldCase(a) == foldCase(b) are added
728 * 2. For each string 'e' in the resulting set, if e !=
729 * foldCase(e), 'e' will be removed.
731 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
733 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
734 * == b denotes that the contents are the same, not pointer
737 * A frozen set will not be modified.
741 * @param attributes bitmask for attributes to close over.
742 * Currently only the USET_CASE bit is supported. Any undefined bits
746 U_STABLE
void U_EXPORT2
747 uset_closeOver(USet
* set
, int32_t attributes
);
750 * Remove all strings from this set.
755 U_STABLE
void U_EXPORT2
756 uset_removeAllStrings(USet
* set
);
759 * Returns TRUE if the given USet contains no characters and no
762 * @return true if set is empty
765 U_STABLE UBool U_EXPORT2
766 uset_isEmpty(const USet
* set
);
769 * Returns TRUE if the given USet contains the given character.
770 * This function works faster with a frozen set.
772 * @param c The codepoint to check for within the set
773 * @return true if set contains c
776 U_STABLE UBool U_EXPORT2
777 uset_contains(const USet
* set
, UChar32 c
);
780 * Returns TRUE if the given USet contains all characters c
781 * where start <= c && c <= end.
783 * @param start the first character of the range to test, inclusive
784 * @param end the last character of the range to test, inclusive
785 * @return TRUE if set contains the range
788 U_STABLE UBool U_EXPORT2
789 uset_containsRange(const USet
* set
, UChar32 start
, UChar32 end
);
792 * Returns TRUE if the given USet contains the given string.
794 * @param str the string
795 * @param strLen the length of the string or -1 if null terminated.
796 * @return true if set contains str
799 U_STABLE UBool U_EXPORT2
800 uset_containsString(const USet
* set
, const UChar
* str
, int32_t strLen
);
803 * Returns the index of the given character within this set, where
804 * the set is ordered by ascending code point. If the character
805 * is not in this set, return -1. The inverse of this method is
806 * <code>charAt()</code>.
808 * @param c the character to obtain the index for
809 * @return an index from 0..size()-1, or -1
812 U_STABLE
int32_t U_EXPORT2
813 uset_indexOf(const USet
* set
, UChar32 c
);
816 * Returns the character at the given index within this set, where
817 * the set is ordered by ascending code point. If the index is
818 * out of range, return (UChar32)-1. The inverse of this method is
819 * <code>indexOf()</code>.
821 * @param charIndex an index from 0..size()-1 to obtain the char for
822 * @return the character at the given index, or (UChar32)-1.
825 U_STABLE UChar32 U_EXPORT2
826 uset_charAt(const USet
* set
, int32_t charIndex
);
829 * Returns the number of characters and strings contained in the given
832 * @return a non-negative integer counting the characters and strings
836 U_STABLE
int32_t U_EXPORT2
837 uset_size(const USet
* set
);
840 * Returns the number of items in this set. An item is either a range
841 * of characters or a single multicharacter string.
843 * @return a non-negative integer counting the character ranges
844 * and/or strings contained in set
847 U_STABLE
int32_t U_EXPORT2
848 uset_getItemCount(const USet
* set
);
851 * Returns an item of this set. An item is either a range of
852 * characters or a single multicharacter string.
854 * @param itemIndex a non-negative integer in the range 0..
855 * uset_getItemCount(set)-1
856 * @param start pointer to variable to receive first character
857 * in range, inclusive
858 * @param end pointer to variable to receive last character in range,
860 * @param str buffer to receive the string, may be NULL
861 * @param strCapacity capacity of str, or 0 if str is NULL
862 * @param ec error code
863 * @return the length of the string (>= 2), or 0 if the item is a
864 * range, in which case it is the range *start..*end, or -1 if
865 * itemIndex is out of range
868 U_STABLE
int32_t U_EXPORT2
869 uset_getItem(const USet
* set
, int32_t itemIndex
,
870 UChar32
* start
, UChar32
* end
,
871 UChar
* str
, int32_t strCapacity
,
875 * Returns true if set1 contains all the characters and strings
876 * of set2. It answers the question, 'Is set1 a superset of set2?'
877 * @param set1 set to be checked for containment
878 * @param set2 set to be checked for containment
879 * @return true if the test condition is met
882 U_STABLE UBool U_EXPORT2
883 uset_containsAll(const USet
* set1
, const USet
* set2
);
886 * Returns true if this set contains all the characters
887 * of the given string. This is does not check containment of grapheme
888 * clusters, like uset_containsString.
889 * @param set set of characters to be checked for containment
890 * @param str string containing codepoints to be checked for containment
891 * @param strLen the length of the string or -1 if null terminated.
892 * @return true if the test condition is met
895 U_STABLE UBool U_EXPORT2
896 uset_containsAllCodePoints(const USet
* set
, const UChar
*str
, int32_t strLen
);
899 * Returns true if set1 contains none of the characters and strings
900 * of set2. It answers the question, 'Is set1 a disjoint set of set2?'
901 * @param set1 set to be checked for containment
902 * @param set2 set to be checked for containment
903 * @return true if the test condition is met
906 U_STABLE UBool U_EXPORT2
907 uset_containsNone(const USet
* set1
, const USet
* set2
);
910 * Returns true if set1 contains some of the characters and strings
911 * of set2. It answers the question, 'Does set1 and set2 have an intersection?'
912 * @param set1 set to be checked for containment
913 * @param set2 set to be checked for containment
914 * @return true if the test condition is met
917 U_STABLE UBool U_EXPORT2
918 uset_containsSome(const USet
* set1
, const USet
* set2
);
921 * Returns the length of the initial substring of the input string which
922 * consists only of characters and strings that are contained in this set
923 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
924 * or only of characters and strings that are not contained
925 * in this set (USET_SPAN_NOT_CONTAINED).
926 * See USetSpanCondition for details.
927 * Similar to the strspn() C library function.
928 * Unpaired surrogates are treated according to contains() of their surrogate code points.
929 * This function works faster with a frozen set and with a non-negative string length argument.
931 * @param s start of the string
932 * @param length of the string; can be -1 for NUL-terminated
933 * @param spanCondition specifies the containment condition
934 * @return the length of the initial substring according to the spanCondition;
935 * 0 if the start of the string does not fit the spanCondition
937 * @see USetSpanCondition
939 U_STABLE
int32_t U_EXPORT2
940 uset_span(const USet
*set
, const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
);
943 * Returns the start of the trailing substring of the input string which
944 * consists only of characters and strings that are contained in this set
945 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
946 * or only of characters and strings that are not contained
947 * in this set (USET_SPAN_NOT_CONTAINED).
948 * See USetSpanCondition for details.
949 * Unpaired surrogates are treated according to contains() of their surrogate code points.
950 * This function works faster with a frozen set and with a non-negative string length argument.
952 * @param s start of the string
953 * @param length of the string; can be -1 for NUL-terminated
954 * @param spanCondition specifies the containment condition
955 * @return the start of the trailing substring according to the spanCondition;
956 * the string length if the end of the string does not fit the spanCondition
958 * @see USetSpanCondition
960 U_STABLE
int32_t U_EXPORT2
961 uset_spanBack(const USet
*set
, const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
);
964 * Returns the length of the initial substring of the input string which
965 * consists only of characters and strings that are contained in this set
966 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
967 * or only of characters and strings that are not contained
968 * in this set (USET_SPAN_NOT_CONTAINED).
969 * See USetSpanCondition for details.
970 * Similar to the strspn() C library function.
971 * Malformed byte sequences are treated according to contains(0xfffd).
972 * This function works faster with a frozen set and with a non-negative string length argument.
974 * @param s start of the string (UTF-8)
975 * @param length of the string; can be -1 for NUL-terminated
976 * @param spanCondition specifies the containment condition
977 * @return the length of the initial substring according to the spanCondition;
978 * 0 if the start of the string does not fit the spanCondition
980 * @see USetSpanCondition
982 U_STABLE
int32_t U_EXPORT2
983 uset_spanUTF8(const USet
*set
, const char *s
, int32_t length
, USetSpanCondition spanCondition
);
986 * Returns the start of the trailing substring of the input string which
987 * consists only of characters and strings that are contained in this set
988 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
989 * or only of characters and strings that are not contained
990 * in this set (USET_SPAN_NOT_CONTAINED).
991 * See USetSpanCondition for details.
992 * Malformed byte sequences are treated according to contains(0xfffd).
993 * This function works faster with a frozen set and with a non-negative string length argument.
995 * @param s start of the string (UTF-8)
996 * @param length of the string; can be -1 for NUL-terminated
997 * @param spanCondition specifies the containment condition
998 * @return the start of the trailing substring according to the spanCondition;
999 * the string length if the end of the string does not fit the spanCondition
1001 * @see USetSpanCondition
1003 U_STABLE
int32_t U_EXPORT2
1004 uset_spanBackUTF8(const USet
*set
, const char *s
, int32_t length
, USetSpanCondition spanCondition
);
1007 * Returns true if set1 contains all of the characters and strings
1008 * of set2, and vis versa. It answers the question, 'Is set1 equal to set2?'
1009 * @param set1 set to be checked for containment
1010 * @param set2 set to be checked for containment
1011 * @return true if the test condition is met
1014 U_STABLE UBool U_EXPORT2
1015 uset_equals(const USet
* set1
, const USet
* set2
);
1017 /*********************************************************************
1018 * Serialized set API
1019 *********************************************************************/
1022 * Serializes this set into an array of 16-bit integers. Serialization
1023 * (currently) only records the characters in the set; multicharacter
1024 * strings are ignored.
1027 * has following format (each line is one 16-bit integer):
1029 * length = (n+2*m) | (m!=0?0x8000:0)
1030 * bmpLength = n; present if m!=0
1043 * The array starts with a header. After the header are n bmp
1044 * code points, then m supplementary code points. Either n or m
1045 * or both may be zero. n+2*m is always <= 0x7FFF.
1047 * If there are no supplementary characters (if m==0) then the
1048 * header is one 16-bit integer, 'length', with value n.
1050 * If there are supplementary characters (if m!=0) then the header
1051 * is two 16-bit integers. The first, 'length', has value
1052 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
1054 * After the header the code points are stored in ascending order.
1055 * Supplementary code points are stored as most significant 16
1056 * bits followed by least significant 16 bits.
1058 * @param set the set
1059 * @param dest pointer to buffer of destCapacity 16-bit integers.
1060 * May be NULL only if destCapacity is zero.
1061 * @param destCapacity size of dest, or zero. Must not be negative.
1062 * @param pErrorCode pointer to the error code. Will be set to
1063 * U_INDEX_OUTOFBOUNDS_ERROR if n+2*m > 0x7FFF. Will be set to
1064 * U_BUFFER_OVERFLOW_ERROR if n+2*m+(m!=0?2:1) > destCapacity.
1065 * @return the total length of the serialized format, including
1066 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1067 * than U_BUFFER_OVERFLOW_ERROR.
1070 U_STABLE
int32_t U_EXPORT2
1071 uset_serialize(const USet
* set
, uint16_t* dest
, int32_t destCapacity
, UErrorCode
* pErrorCode
);
1074 * Given a serialized array, fill in the given serialized set object.
1075 * @param fillSet pointer to result
1076 * @param src pointer to start of array
1077 * @param srcLength length of array
1078 * @return true if the given array is valid, otherwise false
1081 U_STABLE UBool U_EXPORT2
1082 uset_getSerializedSet(USerializedSet
* fillSet
, const uint16_t* src
, int32_t srcLength
);
1085 * Set the USerializedSet to contain the given character (and nothing
1087 * @param fillSet pointer to result
1088 * @param c The codepoint to set
1091 U_STABLE
void U_EXPORT2
1092 uset_setSerializedToOne(USerializedSet
* fillSet
, UChar32 c
);
1095 * Returns TRUE if the given USerializedSet contains the given
1097 * @param set the serialized set
1098 * @param c The codepoint to check for within the set
1099 * @return true if set contains c
1102 U_STABLE UBool U_EXPORT2
1103 uset_serializedContains(const USerializedSet
* set
, UChar32 c
);
1106 * Returns the number of disjoint ranges of characters contained in
1107 * the given serialized set. Ignores any strings contained in the
1109 * @param set the serialized set
1110 * @return a non-negative integer counting the character ranges
1114 U_STABLE
int32_t U_EXPORT2
1115 uset_getSerializedRangeCount(const USerializedSet
* set
);
1118 * Returns a range of characters contained in the given serialized
1120 * @param set the serialized set
1121 * @param rangeIndex a non-negative integer in the range 0..
1122 * uset_getSerializedRangeCount(set)-1
1123 * @param pStart pointer to variable to receive first character
1124 * in range, inclusive
1125 * @param pEnd pointer to variable to receive last character in range,
1127 * @return true if rangeIndex is valid, otherwise false
1130 U_STABLE UBool U_EXPORT2
1131 uset_getSerializedRange(const USerializedSet
* set
, int32_t rangeIndex
,
1132 UChar32
* pStart
, UChar32
* pEnd
);