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"
39 * A UnicodeSet. Use the uset_* API to manipulate. Create with
40 * uset_open*, and destroy with uset_close.
43 typedef struct USet USet
;
47 * Bitmask values to be passed to uset_openPatternOptions() or
48 * uset_applyPattern() taking an option parameter.
53 * Ignore white space within patterns unless quoted or escaped.
56 USET_IGNORE_SPACE
= 1,
59 * Enable case insensitive matching. E.g., "[ab]" with this flag
60 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
61 * match all except 'a', 'A', 'b', and 'B'. This performs a full
62 * closure over case mappings, e.g. U+017F for s.
64 * The resulting set is a superset of the input for the code points but
65 * not for the strings.
66 * It performs a case mapping closure of the code points and adds
67 * full case folding strings for the code points, and reduces strings of
68 * the original set to their full case folding equivalents.
70 * This is designed for case-insensitive matches, for example
71 * in regular expressions. The full code point case closure allows checking of
72 * an input character directly against the closure set.
73 * Strings are matched by comparing the case-folded form from the closure
74 * set with an incremental case folding of the string in question.
76 * The closure set will also contain single code points if the original
77 * set contained case-equivalent strings (like U+00DF for "ss" or "Ss" etc.).
78 * This is not necessary (that is, redundant) for the above matching method
79 * but results in the same closure sets regardless of whether the original
80 * set contained the code point or a string.
84 USET_CASE_INSENSITIVE
= 2,
87 * Enable case insensitive matching. E.g., "[ab]" with this flag
88 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
89 * match all except 'a', 'A', 'b', and 'B'. This adds the lower-,
90 * title-, and uppercase mappings as well as the case folding
91 * of each existing element in the set.
94 USET_ADD_CASE_MAPPINGS
= 4
98 * Argument values for whether span() and similar functions continue while
99 * the current character is contained vs. not contained in the set.
101 * The functionality is straightforward for sets with only single code points,
102 * without strings (which is the common case):
103 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE work the same.
104 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE are inverses of USET_SPAN_NOT_CONTAINED.
105 * - span() and spanBack() partition any string the same way when
106 * alternating between span(USET_SPAN_NOT_CONTAINED) and
107 * span(either "contained" condition).
108 * - Using a complemented (inverted) set and the opposite span conditions
109 * yields the same results.
111 * When a set contains multi-code point strings, then these statements may not
112 * be true, depending on the strings in the set (for example, whether they
113 * overlap with each other) and the string that is processed.
114 * For a set with strings:
115 * - The complement of the set contains the opposite set of code points,
116 * but the same set of strings.
117 * Therefore, complementing both the set and the span conditions
118 * may yield different results.
119 * - When starting spans at different positions in a string
120 * (span(s, ...) vs. span(s+1, ...)) the ends of the spans may be different
121 * because a set string may start before the later position.
122 * - span(USET_SPAN_SIMPLE) may be shorter than
123 * span(USET_SPAN_CONTAINED) because it will not recursively try
124 * all possible paths.
125 * For example, with a set which contains the three strings "xy", "xya" and "ax",
126 * span("xyax", USET_SPAN_CONTAINED) will return 4 but
127 * span("xyax", USET_SPAN_SIMPLE) will return 3.
128 * span(USET_SPAN_SIMPLE) will never be longer than
129 * span(USET_SPAN_CONTAINED).
130 * - With either "contained" condition, span() and spanBack() may partition
131 * a string in different ways.
132 * For example, with a set which contains the two strings "ab" and "ba",
133 * and when processing the string "aba",
134 * span() will yield contained/not-contained boundaries of { 0, 2, 3 }
135 * while spanBack() will yield boundaries of { 0, 1, 3 }.
137 * Note: If it is important to get the same boundaries whether iterating forward
138 * or backward through a string, then either only span() should be used and
139 * the boundaries cached for backward operation, or an ICU BreakIterator
142 * Note: Unpaired surrogates are treated like surrogate code points.
143 * Similarly, set strings match only on code point boundaries,
144 * never in the middle of a surrogate pair.
145 * Illegal UTF-8 sequences are treated like U+FFFD.
146 * When processing UTF-8 strings, malformed set strings
147 * (strings with unpaired surrogates which cannot be converted to UTF-8)
152 typedef enum USetSpanCondition
{
154 * Continues a span() while there is no set element at the current position.
155 * Increments by one code point at a time.
156 * Stops before the first set element (character or string).
157 * (For code points only, this is like while contains(current)==FALSE).
159 * When span() returns, the substring between where it started and the position
160 * it returned consists only of characters that are not in the set,
161 * and none of its strings overlap with the span.
165 USET_SPAN_NOT_CONTAINED
= 0,
167 * Spans the longest substring that is a concatenation of set elements (characters or strings).
168 * (For characters only, this is like while contains(current)==TRUE).
170 * When span() returns, the substring between where it started and the position
171 * it returned consists only of set elements (characters or strings) that are in the set.
173 * If a set contains strings, then the span will be the longest substring for which there
174 * exists at least one non-overlapping concatenation of set elements (characters or strings).
175 * This is equivalent to a POSIX regular expression for <code>(OR of each set element)*</code>.
176 * (Java/ICU/Perl regex stops at the first match of an OR.)
180 USET_SPAN_CONTAINED
= 1,
182 * Continues a span() while there is a set element at the current position.
183 * Increments by the longest matching element at each position.
184 * (For characters only, this is like while contains(current)==TRUE).
186 * When span() returns, the substring between where it started and the position
187 * it returned consists only of set elements (characters or strings) that are in the set.
189 * If a set only contains single characters, then this is the same
190 * as USET_SPAN_CONTAINED.
192 * If a set contains strings, then the span will be the longest substring
193 * with a match at each position with the longest single set element (character or string).
195 * Use this span condition together with other longest-match algorithms,
196 * such as ICU converters (ucnv_getUnicodeSet()).
200 USET_SPAN_SIMPLE
= 2,
201 #ifndef U_HIDE_DEPRECATED_API
203 * One more than the last span condition.
204 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
206 USET_SPAN_CONDITION_COUNT
207 #endif // U_HIDE_DEPRECATED_API
212 * Capacity of USerializedSet::staticArray.
213 * Enough for any single-code point set.
214 * Also provides padding for nice sizeof(USerializedSet).
217 USET_SERIALIZED_STATIC_ARRAY_CAPACITY
=8
221 * A serialized form of a Unicode set. Limited manipulations are
222 * possible directly on a serialized set. See below.
225 typedef struct USerializedSet
{
227 * The serialized Unicode Set.
230 const uint16_t *array
;
232 * The length of the array that contains BMP characters.
237 * The total length of the array.
242 * A small buffer for the array to reduce memory allocations.
245 uint16_t staticArray
[USET_SERIALIZED_STATIC_ARRAY_CAPACITY
];
248 /*********************************************************************
250 *********************************************************************/
253 * Create an empty USet object.
254 * Equivalent to uset_open(1, 0).
255 * @return a newly created USet. The caller must call uset_close() on
259 U_STABLE USet
* U_EXPORT2
260 uset_openEmpty(void);
263 * Creates a USet object that contains the range of characters
264 * start..end, inclusive. If <code>start > end</code>
265 * then an empty set is created (same as using uset_openEmpty()).
266 * @param start first character of the range, inclusive
267 * @param end last character of the range, inclusive
268 * @return a newly created USet. The caller must call uset_close() on
272 U_STABLE USet
* U_EXPORT2
273 uset_open(UChar32 start
, UChar32 end
);
276 * Creates a set from the given pattern. See the UnicodeSet class
277 * description for the syntax of the pattern language.
278 * @param pattern a string specifying what characters are in the set
279 * @param patternLength the length of the pattern, or -1 if null
281 * @param ec the error code
284 U_STABLE USet
* U_EXPORT2
285 uset_openPattern(const UChar
* pattern
, int32_t patternLength
,
289 * Creates a set from the given pattern. See the UnicodeSet class
290 * description for the syntax of the pattern language.
291 * @param pattern a string specifying what characters are in the set
292 * @param patternLength the length of the pattern, or -1 if null
294 * @param options bitmask for options to apply to the pattern.
295 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
296 * @param ec the error code
299 U_STABLE USet
* U_EXPORT2
300 uset_openPatternOptions(const UChar
* pattern
, int32_t patternLength
,
305 * Disposes of the storage used by a USet object. This function should
306 * be called exactly once for objects returned by uset_open().
307 * @param set the object to dispose of
310 U_STABLE
void U_EXPORT2
311 uset_close(USet
* set
);
313 #if U_SHOW_CPLUSPLUS_API
318 * \class LocalUSetPointer
319 * "Smart pointer" class, closes a USet via uset_close().
320 * For most methods see the LocalPointerBase base class.
322 * @see LocalPointerBase
326 U_DEFINE_LOCAL_OPEN_POINTER(LocalUSetPointer
, USet
, uset_close
);
330 #endif // U_SHOW_CPLUSPLUS_API
333 * Returns a copy of this object.
334 * If this set is frozen, then the clone will be frozen as well.
335 * Use uset_cloneAsThawed() for a mutable clone of a frozen set.
336 * @param set the original set
337 * @return the newly allocated copy of the set
338 * @see uset_cloneAsThawed
341 U_STABLE USet
* U_EXPORT2
342 uset_clone(const USet
*set
);
345 * Determines whether the set has been frozen (made immutable) or not.
346 * See the ICU4J Freezable interface for details.
348 * @return TRUE/FALSE for whether the set has been frozen
350 * @see uset_cloneAsThawed
353 U_STABLE UBool U_EXPORT2
354 uset_isFrozen(const USet
*set
);
357 * Freeze the set (make it immutable).
358 * Once frozen, it cannot be unfrozen and is therefore thread-safe
359 * until it is deleted.
360 * See the ICU4J Freezable interface for details.
361 * Freezing the set may also make some operations faster, for example
362 * uset_contains() and uset_span().
363 * A frozen set will not be modified. (It remains frozen.)
365 * @return the same set, now frozen
367 * @see uset_cloneAsThawed
370 U_STABLE
void U_EXPORT2
371 uset_freeze(USet
*set
);
374 * Clone the set and make the clone mutable.
375 * See the ICU4J Freezable interface for details.
377 * @return the mutable clone
383 U_STABLE USet
* U_EXPORT2
384 uset_cloneAsThawed(const USet
*set
);
387 * Causes the USet object to represent the range <code>start - end</code>.
388 * If <code>start > end</code> then this USet is set to an empty range.
389 * A frozen set will not be modified.
390 * @param set the object to set to the given range
391 * @param start first character in the set, inclusive
392 * @param end last character in the set, inclusive
395 U_STABLE
void U_EXPORT2
397 UChar32 start
, UChar32 end
);
400 * Modifies the set to represent the set specified by the given
401 * pattern. See the UnicodeSet class description for the syntax of
402 * the pattern language. See also the User Guide chapter about UnicodeSet.
403 * <em>Empties the set passed before applying the pattern.</em>
404 * A frozen set will not be modified.
405 * @param set The set to which the pattern is to be applied.
406 * @param pattern A pointer to UChar string specifying what characters are in the set.
407 * The character at pattern[0] must be a '['.
408 * @param patternLength The length of the UChar string. -1 if NUL terminated.
409 * @param options A bitmask for options to apply to the pattern.
410 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
411 * @param status Returns an error if the pattern cannot be parsed.
412 * @return Upon successful parse, the value is either
413 * the index of the character after the closing ']'
414 * of the parsed pattern.
415 * If the status code indicates failure, then the return value
416 * is the index of the error in the source.
420 U_STABLE
int32_t U_EXPORT2
421 uset_applyPattern(USet
*set
,
422 const UChar
*pattern
, int32_t patternLength
,
427 * Modifies the set to contain those code points which have the given value
428 * for the given binary or enumerated property, as returned by
429 * u_getIntPropertyValue. Prior contents of this set are lost.
430 * A frozen set will not be modified.
432 * @param set the object to contain the code points defined by the property
434 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
435 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
436 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
438 * @param value a value in the range u_getIntPropertyMinValue(prop)..
439 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
440 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
441 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
442 * categories such as [:L:] to be represented.
444 * @param ec error code input/output parameter
448 U_STABLE
void U_EXPORT2
449 uset_applyIntPropertyValue(USet
* set
,
450 UProperty prop
, int32_t value
, UErrorCode
* ec
);
453 * Modifies the set to contain those code points which have the
454 * given value for the given property. Prior contents of this
456 * A frozen set will not be modified.
458 * @param set the object to contain the code points defined by the given
459 * property and value alias
461 * @param prop a string specifying a property alias, either short or long.
462 * The name is matched loosely. See PropertyAliases.txt for names and a
463 * description of loose matching. If the value string is empty, then this
464 * string is interpreted as either a General_Category value alias, a Script
465 * value alias, a binary property alias, or a special ID. Special IDs are
466 * matched loosely and correspond to the following sets:
468 * "ANY" = [\\u0000-\\U0010FFFF],
469 * "ASCII" = [\\u0000-\\u007F],
470 * "Assigned" = [:^Cn:].
472 * @param propLength the length of the prop, or -1 if NULL
474 * @param value a string specifying a value alias, either short or long.
475 * The name is matched loosely. See PropertyValueAliases.txt for names
476 * and a description of loose matching. In addition to aliases listed,
477 * numeric values and canonical combining classes may be expressed
478 * numerically, e.g., ("nv", "0.5") or ("ccc", "220"). The value string
481 * @param valueLength the length of the value, or -1 if NULL
483 * @param ec error code input/output parameter
487 U_STABLE
void U_EXPORT2
488 uset_applyPropertyAlias(USet
* set
,
489 const UChar
*prop
, int32_t propLength
,
490 const UChar
*value
, int32_t valueLength
,
494 * Return true if the given position, in the given pattern, appears
495 * to be the start of a UnicodeSet pattern.
497 * @param pattern a string specifying the pattern
498 * @param patternLength the length of the pattern, or -1 if NULL
499 * @param pos the given position
502 U_STABLE UBool U_EXPORT2
503 uset_resemblesPattern(const UChar
*pattern
, int32_t patternLength
,
507 * Returns a string representation of this set. If the result of
508 * calling this function is passed to a uset_openPattern(), it
509 * will produce another set that is equal to this one.
511 * @param result the string to receive the rules, may be NULL
512 * @param resultCapacity the capacity of result, may be 0 if result is NULL
513 * @param escapeUnprintable if TRUE then convert unprintable
514 * character to their hex escape representations, \\uxxxx or
515 * \\Uxxxxxxxx. Unprintable characters are those other than
516 * U+000A, U+0020..U+007E.
517 * @param ec error code.
518 * @return length of string, possibly larger than resultCapacity
521 U_STABLE
int32_t U_EXPORT2
522 uset_toPattern(const USet
* set
,
523 UChar
* result
, int32_t resultCapacity
,
524 UBool escapeUnprintable
,
528 * Adds the given character to the given USet. After this call,
529 * uset_contains(set, c) will return TRUE.
530 * A frozen set will not be modified.
531 * @param set the object to which to add the character
532 * @param c the character to add
535 U_STABLE
void U_EXPORT2
536 uset_add(USet
* set
, UChar32 c
);
539 * Adds all of the elements in the specified set to this set if
540 * they're not already present. This operation effectively
541 * modifies this set so that its value is the <i>union</i> of the two
542 * sets. The behavior of this operation is unspecified if the specified
543 * collection is modified while the operation is in progress.
544 * A frozen set will not be modified.
546 * @param set the object to which to add the set
547 * @param additionalSet the source set whose elements are to be added to this set.
550 U_STABLE
void U_EXPORT2
551 uset_addAll(USet
* set
, const USet
*additionalSet
);
554 * Adds the given range of characters to the given USet. After this call,
555 * uset_contains(set, start, end) will return TRUE.
556 * A frozen set will not be modified.
557 * @param set the object to which to add the character
558 * @param start the first character of the range to add, inclusive
559 * @param end the last character of the range to add, inclusive
562 U_STABLE
void U_EXPORT2
563 uset_addRange(USet
* set
, UChar32 start
, UChar32 end
);
566 * Adds the given string to the given USet. After this call,
567 * uset_containsString(set, str, strLen) will return TRUE.
568 * A frozen set will not be modified.
569 * @param set the object to which to add the character
570 * @param str the string to add
571 * @param strLen the length of the string or -1 if null terminated.
574 U_STABLE
void U_EXPORT2
575 uset_addString(USet
* set
, const UChar
* str
, int32_t strLen
);
578 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
579 * If this set already any particular character, it has no effect on that character.
580 * A frozen set will not be modified.
581 * @param set the object to which to add the character
582 * @param str the source string
583 * @param strLen the length of the string or -1 if null terminated.
586 U_STABLE
void U_EXPORT2
587 uset_addAllCodePoints(USet
* set
, const UChar
*str
, int32_t strLen
);
590 * Removes the given character from the given USet. After this call,
591 * uset_contains(set, c) will return FALSE.
592 * A frozen set will not be modified.
593 * @param set the object from which to remove the character
594 * @param c the character to remove
597 U_STABLE
void U_EXPORT2
598 uset_remove(USet
* set
, UChar32 c
);
601 * Removes the given range of characters from the given USet. After this call,
602 * uset_contains(set, start, end) will return FALSE.
603 * A frozen set will not be modified.
604 * @param set the object to which to add the character
605 * @param start the first character of the range to remove, inclusive
606 * @param end the last character of the range to remove, inclusive
609 U_STABLE
void U_EXPORT2
610 uset_removeRange(USet
* set
, UChar32 start
, UChar32 end
);
613 * Removes the given string to the given USet. After this call,
614 * uset_containsString(set, str, strLen) will return FALSE.
615 * A frozen set will not be modified.
616 * @param set the object to which to add the character
617 * @param str the string to remove
618 * @param strLen the length of the string or -1 if null terminated.
621 U_STABLE
void U_EXPORT2
622 uset_removeString(USet
* set
, const UChar
* str
, int32_t strLen
);
625 * Removes from this set all of its elements that are contained in the
626 * specified set. This operation effectively modifies this
627 * set so that its value is the <i>asymmetric set difference</i> of
629 * A frozen set will not be modified.
630 * @param set the object from which the elements are to be removed
631 * @param removeSet the object that defines which elements will be
632 * removed from this set
635 U_STABLE
void U_EXPORT2
636 uset_removeAll(USet
* set
, const USet
* removeSet
);
639 * Retain only the elements in this set that are contained in the
640 * specified range. If <code>start > end</code> then an empty range is
641 * retained, leaving the set empty. This is equivalent to
642 * a boolean logic AND, or a set INTERSECTION.
643 * A frozen set will not be modified.
645 * @param set the object for which to retain only the specified range
646 * @param start first character, inclusive, of range to be retained
648 * @param end last character, inclusive, of range to be retained
652 U_STABLE
void U_EXPORT2
653 uset_retain(USet
* set
, UChar32 start
, UChar32 end
);
656 * Retains only the elements in this set that are contained in the
657 * specified set. In other words, removes from this set all of
658 * its elements that are not contained in the specified set. This
659 * operation effectively modifies this set so that its value is
660 * the <i>intersection</i> of the two sets.
661 * A frozen set will not be modified.
663 * @param set the object on which to perform the retain
664 * @param retain set that defines which elements this set will retain
667 U_STABLE
void U_EXPORT2
668 uset_retainAll(USet
* set
, const USet
* retain
);
671 * Reallocate this objects internal structures to take up the least
672 * possible space, without changing this object's value.
673 * A frozen set will not be modified.
675 * @param set the object on which to perfrom the compact
678 U_STABLE
void U_EXPORT2
679 uset_compact(USet
* set
);
682 * Inverts this set. This operation modifies this set so that
683 * its value is its complement. This operation does not affect
684 * the multicharacter strings, if any.
685 * A frozen set will not be modified.
689 U_STABLE
void U_EXPORT2
690 uset_complement(USet
* set
);
693 * Complements in this set all elements contained in the specified
694 * set. Any character in the other set will be removed if it is
695 * in this set, or will be added if it is not in this set.
696 * A frozen set will not be modified.
698 * @param set the set with which to complement
699 * @param complement set that defines which elements will be xor'ed
703 U_STABLE
void U_EXPORT2
704 uset_complementAll(USet
* set
, const USet
* complement
);
707 * Removes all of the elements from this set. This set will be
708 * empty after this call returns.
709 * A frozen set will not be modified.
713 U_STABLE
void U_EXPORT2
714 uset_clear(USet
* set
);
717 * Close this set over the given attribute. For the attribute
718 * USET_CASE, the result is to modify this set so that:
720 * 1. For each character or string 'a' in this set, all strings or
721 * characters 'b' such that foldCase(a) == foldCase(b) are added
724 * 2. For each string 'e' in the resulting set, if e !=
725 * foldCase(e), 'e' will be removed.
727 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
729 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
730 * == b denotes that the contents are the same, not pointer
733 * A frozen set will not be modified.
737 * @param attributes bitmask for attributes to close over.
738 * Currently only the USET_CASE bit is supported. Any undefined bits
742 U_STABLE
void U_EXPORT2
743 uset_closeOver(USet
* set
, int32_t attributes
);
746 * Remove all strings from this set.
751 U_STABLE
void U_EXPORT2
752 uset_removeAllStrings(USet
* set
);
755 * Returns TRUE if the given USet contains no characters and no
758 * @return true if set is empty
761 U_STABLE UBool U_EXPORT2
762 uset_isEmpty(const USet
* set
);
765 * Returns TRUE if the given USet contains the given character.
766 * This function works faster with a frozen set.
768 * @param c The codepoint to check for within the set
769 * @return true if set contains c
772 U_STABLE UBool U_EXPORT2
773 uset_contains(const USet
* set
, UChar32 c
);
776 * Returns TRUE if the given USet contains all characters c
777 * where start <= c && c <= end.
779 * @param start the first character of the range to test, inclusive
780 * @param end the last character of the range to test, inclusive
781 * @return TRUE if set contains the range
784 U_STABLE UBool U_EXPORT2
785 uset_containsRange(const USet
* set
, UChar32 start
, UChar32 end
);
788 * Returns TRUE if the given USet contains the given string.
790 * @param str the string
791 * @param strLen the length of the string or -1 if null terminated.
792 * @return true if set contains str
795 U_STABLE UBool U_EXPORT2
796 uset_containsString(const USet
* set
, const UChar
* str
, int32_t strLen
);
799 * Returns the index of the given character within this set, where
800 * the set is ordered by ascending code point. If the character
801 * is not in this set, return -1. The inverse of this method is
802 * <code>charAt()</code>.
804 * @param c the character to obtain the index for
805 * @return an index from 0..size()-1, or -1
808 U_STABLE
int32_t U_EXPORT2
809 uset_indexOf(const USet
* set
, UChar32 c
);
812 * Returns the character at the given index within this set, where
813 * the set is ordered by ascending code point. If the index is
814 * out of range, return (UChar32)-1. The inverse of this method is
815 * <code>indexOf()</code>.
817 * @param charIndex an index from 0..size()-1 to obtain the char for
818 * @return the character at the given index, or (UChar32)-1.
821 U_STABLE UChar32 U_EXPORT2
822 uset_charAt(const USet
* set
, int32_t charIndex
);
825 * Returns the number of characters and strings contained in the given
828 * @return a non-negative integer counting the characters and strings
832 U_STABLE
int32_t U_EXPORT2
833 uset_size(const USet
* set
);
836 * Returns the number of items in this set. An item is either a range
837 * of characters or a single multicharacter string.
839 * @return a non-negative integer counting the character ranges
840 * and/or strings contained in set
843 U_STABLE
int32_t U_EXPORT2
844 uset_getItemCount(const USet
* set
);
847 * Returns an item of this set. An item is either a range of
848 * characters or a single multicharacter string.
850 * @param itemIndex a non-negative integer in the range 0..
851 * uset_getItemCount(set)-1
852 * @param start pointer to variable to receive first character
853 * in range, inclusive
854 * @param end pointer to variable to receive last character in range,
856 * @param str buffer to receive the string, may be NULL
857 * @param strCapacity capacity of str, or 0 if str is NULL
858 * @param ec error code
859 * @return the length of the string (>= 2), or 0 if the item is a
860 * range, in which case it is the range *start..*end, or -1 if
861 * itemIndex is out of range
864 U_STABLE
int32_t U_EXPORT2
865 uset_getItem(const USet
* set
, int32_t itemIndex
,
866 UChar32
* start
, UChar32
* end
,
867 UChar
* str
, int32_t strCapacity
,
871 * Returns true if set1 contains all the characters and strings
872 * of set2. It answers the question, 'Is set1 a superset of set2?'
873 * @param set1 set to be checked for containment
874 * @param set2 set to be checked for containment
875 * @return true if the test condition is met
878 U_STABLE UBool U_EXPORT2
879 uset_containsAll(const USet
* set1
, const USet
* set2
);
882 * Returns true if this set contains all the characters
883 * of the given string. This is does not check containment of grapheme
884 * clusters, like uset_containsString.
885 * @param set set of characters to be checked for containment
886 * @param str string containing codepoints to be checked for containment
887 * @param strLen the length of the string or -1 if null terminated.
888 * @return true if the test condition is met
891 U_STABLE UBool U_EXPORT2
892 uset_containsAllCodePoints(const USet
* set
, const UChar
*str
, int32_t strLen
);
895 * Returns true if set1 contains none of the characters and strings
896 * of set2. It answers the question, 'Is set1 a disjoint set of set2?'
897 * @param set1 set to be checked for containment
898 * @param set2 set to be checked for containment
899 * @return true if the test condition is met
902 U_STABLE UBool U_EXPORT2
903 uset_containsNone(const USet
* set1
, const USet
* set2
);
906 * Returns true if set1 contains some of the characters and strings
907 * of set2. It answers the question, 'Does set1 and set2 have an intersection?'
908 * @param set1 set to be checked for containment
909 * @param set2 set to be checked for containment
910 * @return true if the test condition is met
913 U_STABLE UBool U_EXPORT2
914 uset_containsSome(const USet
* set1
, const USet
* set2
);
917 * Returns the length of the initial substring of the input string which
918 * consists only of characters and strings that are contained in this set
919 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
920 * or only of characters and strings that are not contained
921 * in this set (USET_SPAN_NOT_CONTAINED).
922 * See USetSpanCondition for details.
923 * Similar to the strspn() C library function.
924 * Unpaired surrogates are treated according to contains() of their surrogate code points.
925 * This function works faster with a frozen set and with a non-negative string length argument.
927 * @param s start of the string
928 * @param length of the string; can be -1 for NUL-terminated
929 * @param spanCondition specifies the containment condition
930 * @return the length of the initial substring according to the spanCondition;
931 * 0 if the start of the string does not fit the spanCondition
933 * @see USetSpanCondition
935 U_STABLE
int32_t U_EXPORT2
936 uset_span(const USet
*set
, const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
);
939 * Returns the start of the trailing substring of the input string which
940 * consists only of characters and strings that are contained in this set
941 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
942 * or only of characters and strings that are not contained
943 * in this set (USET_SPAN_NOT_CONTAINED).
944 * See USetSpanCondition for details.
945 * Unpaired surrogates are treated according to contains() of their surrogate code points.
946 * This function works faster with a frozen set and with a non-negative string length argument.
948 * @param s start of the string
949 * @param length of the string; can be -1 for NUL-terminated
950 * @param spanCondition specifies the containment condition
951 * @return the start of the trailing substring according to the spanCondition;
952 * the string length if the end of the string does not fit the spanCondition
954 * @see USetSpanCondition
956 U_STABLE
int32_t U_EXPORT2
957 uset_spanBack(const USet
*set
, const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
);
960 * Returns the length of the initial substring of the input string which
961 * consists only of characters and strings that are contained in this set
962 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
963 * or only of characters and strings that are not contained
964 * in this set (USET_SPAN_NOT_CONTAINED).
965 * See USetSpanCondition for details.
966 * Similar to the strspn() C library function.
967 * Malformed byte sequences are treated according to contains(0xfffd).
968 * This function works faster with a frozen set and with a non-negative string length argument.
970 * @param s start of the string (UTF-8)
971 * @param length of the string; can be -1 for NUL-terminated
972 * @param spanCondition specifies the containment condition
973 * @return the length of the initial substring according to the spanCondition;
974 * 0 if the start of the string does not fit the spanCondition
976 * @see USetSpanCondition
978 U_STABLE
int32_t U_EXPORT2
979 uset_spanUTF8(const USet
*set
, const char *s
, int32_t length
, USetSpanCondition spanCondition
);
982 * Returns the start of the trailing substring of the input string which
983 * consists only of characters and strings that are contained in this set
984 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
985 * or only of characters and strings that are not contained
986 * in this set (USET_SPAN_NOT_CONTAINED).
987 * See USetSpanCondition for details.
988 * Malformed byte sequences are treated according to contains(0xfffd).
989 * This function works faster with a frozen set and with a non-negative string length argument.
991 * @param s start of the string (UTF-8)
992 * @param length of the string; can be -1 for NUL-terminated
993 * @param spanCondition specifies the containment condition
994 * @return the start of the trailing substring according to the spanCondition;
995 * the string length if the end of the string does not fit the spanCondition
997 * @see USetSpanCondition
999 U_STABLE
int32_t U_EXPORT2
1000 uset_spanBackUTF8(const USet
*set
, const char *s
, int32_t length
, USetSpanCondition spanCondition
);
1003 * Returns true if set1 contains all of the characters and strings
1004 * of set2, and vis versa. It answers the question, 'Is set1 equal to set2?'
1005 * @param set1 set to be checked for containment
1006 * @param set2 set to be checked for containment
1007 * @return true if the test condition is met
1010 U_STABLE UBool U_EXPORT2
1011 uset_equals(const USet
* set1
, const USet
* set2
);
1013 /*********************************************************************
1014 * Serialized set API
1015 *********************************************************************/
1018 * Serializes this set into an array of 16-bit integers. Serialization
1019 * (currently) only records the characters in the set; multicharacter
1020 * strings are ignored.
1023 * has following format (each line is one 16-bit integer):
1025 * length = (n+2*m) | (m!=0?0x8000:0)
1026 * bmpLength = n; present if m!=0
1039 * The array starts with a header. After the header are n bmp
1040 * code points, then m supplementary code points. Either n or m
1041 * or both may be zero. n+2*m is always <= 0x7FFF.
1043 * If there are no supplementary characters (if m==0) then the
1044 * header is one 16-bit integer, 'length', with value n.
1046 * If there are supplementary characters (if m!=0) then the header
1047 * is two 16-bit integers. The first, 'length', has value
1048 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
1050 * After the header the code points are stored in ascending order.
1051 * Supplementary code points are stored as most significant 16
1052 * bits followed by least significant 16 bits.
1054 * @param set the set
1055 * @param dest pointer to buffer of destCapacity 16-bit integers.
1056 * May be NULL only if destCapacity is zero.
1057 * @param destCapacity size of dest, or zero. Must not be negative.
1058 * @param pErrorCode pointer to the error code. Will be set to
1059 * U_INDEX_OUTOFBOUNDS_ERROR if n+2*m > 0x7FFF. Will be set to
1060 * U_BUFFER_OVERFLOW_ERROR if n+2*m+(m!=0?2:1) > destCapacity.
1061 * @return the total length of the serialized format, including
1062 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
1063 * than U_BUFFER_OVERFLOW_ERROR.
1066 U_STABLE
int32_t U_EXPORT2
1067 uset_serialize(const USet
* set
, uint16_t* dest
, int32_t destCapacity
, UErrorCode
* pErrorCode
);
1070 * Given a serialized array, fill in the given serialized set object.
1071 * @param fillSet pointer to result
1072 * @param src pointer to start of array
1073 * @param srcLength length of array
1074 * @return true if the given array is valid, otherwise false
1077 U_STABLE UBool U_EXPORT2
1078 uset_getSerializedSet(USerializedSet
* fillSet
, const uint16_t* src
, int32_t srcLength
);
1081 * Set the USerializedSet to contain the given character (and nothing
1083 * @param fillSet pointer to result
1084 * @param c The codepoint to set
1087 U_STABLE
void U_EXPORT2
1088 uset_setSerializedToOne(USerializedSet
* fillSet
, UChar32 c
);
1091 * Returns TRUE if the given USerializedSet contains the given
1093 * @param set the serialized set
1094 * @param c The codepoint to check for within the set
1095 * @return true if set contains c
1098 U_STABLE UBool U_EXPORT2
1099 uset_serializedContains(const USerializedSet
* set
, UChar32 c
);
1102 * Returns the number of disjoint ranges of characters contained in
1103 * the given serialized set. Ignores any strings contained in the
1105 * @param set the serialized set
1106 * @return a non-negative integer counting the character ranges
1110 U_STABLE
int32_t U_EXPORT2
1111 uset_getSerializedRangeCount(const USerializedSet
* set
);
1114 * Returns a range of characters contained in the given serialized
1116 * @param set the serialized set
1117 * @param rangeIndex a non-negative integer in the range 0..
1118 * uset_getSerializedRangeCount(set)-1
1119 * @param pStart pointer to variable to receive first character
1120 * in range, inclusive
1121 * @param pEnd pointer to variable to receive last character in range,
1123 * @return true if rangeIndex is valid, otherwise false
1126 U_STABLE UBool U_EXPORT2
1127 uset_getSerializedRange(const USerializedSet
* set
, int32_t rangeIndex
,
1128 UChar32
* pStart
, UChar32
* pEnd
);