2 *******************************************************************************
4 * Copyright (C) 2002-2008, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 2002mar07
14 * created by: Markus W. Scherer
16 * C version of UnicodeSet.
22 * \brief C API: Unicode Set
24 * <p>This is a C wrapper around the C++ UnicodeSet class.</p>
30 #include "unicode/utypes.h"
31 #include "unicode/uchar.h"
36 * A UnicodeSet. Use the uset_* API to manipulate. Create with
37 * uset_open*, and destroy with uset_close.
40 typedef struct USet USet
;
44 * Bitmask values to be passed to uset_openPatternOptions() or
45 * uset_applyPattern() taking an option parameter.
50 * Ignore white space within patterns unless quoted or escaped.
53 USET_IGNORE_SPACE
= 1,
56 * Enable case insensitive matching. E.g., "[ab]" with this flag
57 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
58 * match all except 'a', 'A', 'b', and 'B'. This performs a full
59 * closure over case mappings, e.g. U+017F for s.
61 * The resulting set is a superset of the input for the code points but
62 * not for the strings.
63 * It performs a case mapping closure of the code points and adds
64 * full case folding strings for the code points, and reduces strings of
65 * the original set to their full case folding equivalents.
67 * This is designed for case-insensitive matches, for example
68 * in regular expressions. The full code point case closure allows checking of
69 * an input character directly against the closure set.
70 * Strings are matched by comparing the case-folded form from the closure
71 * set with an incremental case folding of the string in question.
73 * The closure set will also contain single code points if the original
74 * set contained case-equivalent strings (like U+00DF for "ss" or "Ss" etc.).
75 * This is not necessary (that is, redundant) for the above matching method
76 * but results in the same closure sets regardless of whether the original
77 * set contained the code point or a string.
81 USET_CASE_INSENSITIVE
= 2,
84 * Enable case insensitive matching. E.g., "[ab]" with this flag
85 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
86 * match all except 'a', 'A', 'b', and 'B'. This adds the lower-,
87 * title-, and uppercase mappings as well as the case folding
88 * of each existing element in the set.
91 USET_ADD_CASE_MAPPINGS
= 4,
94 * Enough for any single-code point set
97 USET_SERIALIZED_STATIC_ARRAY_CAPACITY
=8
101 * Argument values for whether span() and similar functions continue while
102 * the current character is contained vs. not contained in the set.
104 * The functionality is straightforward for sets with only single code points,
105 * without strings (which is the common case):
106 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE
108 * - span() and spanBack() partition any string the same way when
109 * alternating between span(USET_SPAN_NOT_CONTAINED) and
110 * span(either "contained" condition).
111 * - Using a complemented (inverted) set and the opposite span conditions
112 * yields the same results.
114 * When a set contains multi-code point strings, then these statements may not
115 * be true, depending on the strings in the set (for example, whether they
116 * overlap with each other) and the string that is processed.
117 * For a set with strings:
118 * - The complement of the set contains the opposite set of code points,
119 * but the same set of strings.
120 * Therefore, complementing both the set and the span conditions
121 * may yield different results.
122 * - When starting spans at different positions in a string
123 * (span(s, ...) vs. span(s+1, ...)) the ends of the spans may be different
124 * because a set string may start before the later position.
125 * - span(USET_SPAN_SIMPLE) may be shorter than
126 * span(USET_SPAN_CONTAINED) because it will not recursively try
127 * all possible paths.
128 * For example, with a set which contains the three strings "xy", "xya" and "ax",
129 * span("xyax", USET_SPAN_CONTAINED) will return 4 but
130 * span("xyax", USET_SPAN_SIMPLE) will return 3.
131 * span(USET_SPAN_SIMPLE) will never be longer than
132 * span(USET_SPAN_CONTAINED).
133 * - With either "contained" condition, span() and spanBack() may partition
134 * a string in different ways.
135 * For example, with a set which contains the two strings "ab" and "ba",
136 * and when processing the string "aba",
137 * span() will yield contained/not-contained boundaries of { 0, 2, 3 }
138 * while spanBack() will yield boundaries of { 0, 1, 3 }.
140 * Note: If it is important to get the same boundaries whether iterating forward
141 * or backward through a string, then either only span() should be used and
142 * the boundaries cached for backward operation, or an ICU BreakIterator
145 * Note: Unpaired surrogates are treated like surrogate code points.
146 * Similarly, set strings match only on code point boundaries,
147 * never in the middle of a surrogate pair.
148 * Illegal UTF-8 sequences are treated like U+FFFD.
149 * When processing UTF-8 strings, malformed set strings
150 * (strings with unpaired surrogates which cannot be converted to UTF-8)
155 typedef enum USetSpanCondition
{
157 * Continue a span() while there is no set element at the current position.
158 * Stops before the first set element (character or string).
159 * (For code points only, this is like while contains(current)==FALSE).
161 * When span() returns, the substring between where it started and the position
162 * it returned consists only of characters that are not in the set,
163 * and none of its strings overlap with the span.
167 USET_SPAN_NOT_CONTAINED
= 0,
169 * Continue a span() while there is a set element at the current position.
170 * (For characters only, this is like while contains(current)==TRUE).
172 * When span() returns, the substring between where it started and the position
173 * it returned consists only of set elements (characters or strings) that are in the set.
175 * If a set contains strings, then the span will be the longest substring
176 * matching any of the possible concatenations of set elements (characters or strings).
177 * (There must be a single, non-overlapping concatenation of characters or strings.)
178 * This is equivalent to a POSIX regular expression for (OR of each set element)*.
182 USET_SPAN_CONTAINED
= 1,
184 * Continue a span() while there is a set element at the current position.
185 * (For characters only, this is like while contains(current)==TRUE).
187 * When span() returns, the substring between where it started and the position
188 * it returned consists only of set elements (characters or strings) that are in the set.
190 * If a set only contains single characters, then this is the same
191 * as USET_SPAN_CONTAINED.
193 * If a set contains strings, then the span will be the longest substring
194 * with a match at each position with the longest single set element (character or string).
196 * Use this span condition together with other longest-match algorithms,
197 * such as ICU converters (ucnv_getUnicodeSet()).
201 USET_SPAN_SIMPLE
= 2,
203 * One more than the last span condition.
206 USET_SPAN_CONDITION_COUNT
210 * A serialized form of a Unicode set. Limited manipulations are
211 * possible directly on a serialized set. See below.
214 typedef struct USerializedSet
{
216 * The serialized Unicode Set.
219 const uint16_t *array
;
221 * The length of the array that contains BMP characters.
226 * The total length of the array.
231 * A small buffer for the array to reduce memory allocations.
234 uint16_t staticArray
[USET_SERIALIZED_STATIC_ARRAY_CAPACITY
];
237 /*********************************************************************
239 *********************************************************************/
242 * Creates a USet object that contains the range of characters
243 * start..end, inclusive. If <code>start > end</code>
244 * then an empty set is created.
245 * @param start first character of the range, inclusive
246 * @param end last character of the range, inclusive
247 * @return a newly created USet. The caller must call uset_close() on
251 U_STABLE USet
* U_EXPORT2
252 uset_open(UChar32 start
, UChar32 end
);
255 * Creates a set from the given pattern. See the UnicodeSet class
256 * description for the syntax of the pattern language.
257 * @param pattern a string specifying what characters are in the set
258 * @param patternLength the length of the pattern, or -1 if null
260 * @param ec the error code
263 U_STABLE USet
* U_EXPORT2
264 uset_openPattern(const UChar
* pattern
, int32_t patternLength
,
268 * Creates a set from the given pattern. See the UnicodeSet class
269 * description for the syntax of the pattern language.
270 * @param pattern a string specifying what characters are in the set
271 * @param patternLength the length of the pattern, or -1 if null
273 * @param options bitmask for options to apply to the pattern.
274 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
275 * @param ec the error code
278 U_STABLE USet
* U_EXPORT2
279 uset_openPatternOptions(const UChar
* pattern
, int32_t patternLength
,
284 * Disposes of the storage used by a USet object. This function should
285 * be called exactly once for objects returned by uset_open().
286 * @param set the object to dispose of
289 U_STABLE
void U_EXPORT2
290 uset_close(USet
* set
);
293 * Returns a copy of this object.
294 * If this set is frozen, then the clone will be frozen as well.
295 * Use uset_cloneAsThawed() for a mutable clone of a frozen set.
296 * @param set the original set
297 * @return the newly allocated copy of the set
298 * @see uset_cloneAsThawed
301 U_DRAFT USet
* U_EXPORT2
302 uset_clone(const USet
*set
);
305 * Determines whether the set has been frozen (made immutable) or not.
306 * See the ICU4J Freezable interface for details.
308 * @return TRUE/FALSE for whether the set has been frozen
310 * @see uset_cloneAsThawed
313 U_DRAFT UBool U_EXPORT2
314 uset_isFrozen(const USet
*set
);
317 * Freeze the set (make it immutable).
318 * Once frozen, it cannot be unfrozen and is therefore thread-safe
319 * until it is deleted.
320 * See the ICU4J Freezable interface for details.
321 * Freezing the set may also make some operations faster, for example
322 * uset_contains() and uset_span().
323 * A frozen set will not be modified. (It remains frozen.)
325 * @return the same set, now frozen
327 * @see uset_cloneAsThawed
330 U_DRAFT
void U_EXPORT2
331 uset_freeze(USet
*set
);
334 * Clone the set and make the clone mutable.
335 * See the ICU4J Freezable interface for details.
337 * @return the mutable clone
343 U_DRAFT USet
* U_EXPORT2
344 uset_cloneAsThawed(const USet
*set
);
347 * Causes the USet object to represent the range <code>start - end</code>.
348 * If <code>start > end</code> then this USet is set to an empty range.
349 * A frozen set will not be modified.
350 * @param set the object to set to the given range
351 * @param start first character in the set, inclusive
352 * @param end last character in the set, inclusive
355 U_STABLE
void U_EXPORT2
357 UChar32 start
, UChar32 end
);
360 * Modifies the set to represent the set specified by the given
361 * pattern. See the UnicodeSet class description for the syntax of
362 * the pattern language. See also the User Guide chapter about UnicodeSet.
363 * <em>Empties the set passed before applying the pattern.</em>
364 * A frozen set will not be modified.
365 * @param set The set to which the pattern is to be applied.
366 * @param pattern A pointer to UChar string specifying what characters are in the set.
367 * The character at pattern[0] must be a '['.
368 * @param patternLength The length of the UChar string. -1 if NUL terminated.
369 * @param options A bitmask for options to apply to the pattern.
370 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
371 * @param status Returns an error if the pattern cannot be parsed.
372 * @return Upon successful parse, the value is either
373 * the index of the character after the closing ']'
374 * of the parsed pattern.
375 * If the status code indicates failure, then the return value
376 * is the index of the error in the source.
380 U_STABLE
int32_t U_EXPORT2
381 uset_applyPattern(USet
*set
,
382 const UChar
*pattern
, int32_t patternLength
,
387 * Modifies the set to contain those code points which have the given value
388 * for the given binary or enumerated property, as returned by
389 * u_getIntPropertyValue. Prior contents of this set are lost.
390 * A frozen set will not be modified.
392 * @param set the object to contain the code points defined by the property
394 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
395 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
396 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
398 * @param value a value in the range u_getIntPropertyMinValue(prop)..
399 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
400 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
401 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
402 * categories such as [:L:] to be represented.
404 * @param ec error code input/output parameter
408 U_STABLE
void U_EXPORT2
409 uset_applyIntPropertyValue(USet
* set
,
410 UProperty prop
, int32_t value
, UErrorCode
* ec
);
413 * Modifies the set to contain those code points which have the
414 * given value for the given property. Prior contents of this
416 * A frozen set will not be modified.
418 * @param set the object to contain the code points defined by the given
419 * property and value alias
421 * @param prop a string specifying a property alias, either short or long.
422 * The name is matched loosely. See PropertyAliases.txt for names and a
423 * description of loose matching. If the value string is empty, then this
424 * string is interpreted as either a General_Category value alias, a Script
425 * value alias, a binary property alias, or a special ID. Special IDs are
426 * matched loosely and correspond to the following sets:
428 * "ANY" = [\\u0000-\\U0010FFFF],
429 * "ASCII" = [\\u0000-\\u007F],
430 * "Assigned" = [:^Cn:].
432 * @param propLength the length of the prop, or -1 if NULL
434 * @param value a string specifying a value alias, either short or long.
435 * The name is matched loosely. See PropertyValueAliases.txt for names
436 * and a description of loose matching. In addition to aliases listed,
437 * numeric values and canonical combining classes may be expressed
438 * numerically, e.g., ("nv", "0.5") or ("ccc", "220"). The value string
441 * @param valueLength the length of the value, or -1 if NULL
443 * @param ec error code input/output parameter
447 U_STABLE
void U_EXPORT2
448 uset_applyPropertyAlias(USet
* set
,
449 const UChar
*prop
, int32_t propLength
,
450 const UChar
*value
, int32_t valueLength
,
454 * Return true if the given position, in the given pattern, appears
455 * to be the start of a UnicodeSet pattern.
457 * @param pattern a string specifying the pattern
458 * @param patternLength the length of the pattern, or -1 if NULL
459 * @param pos the given position
462 U_STABLE UBool U_EXPORT2
463 uset_resemblesPattern(const UChar
*pattern
, int32_t patternLength
,
467 * Returns a string representation of this set. If the result of
468 * calling this function is passed to a uset_openPattern(), it
469 * will produce another set that is equal to this one.
471 * @param result the string to receive the rules, may be NULL
472 * @param resultCapacity the capacity of result, may be 0 if result is NULL
473 * @param escapeUnprintable if TRUE then convert unprintable
474 * character to their hex escape representations, \\uxxxx or
475 * \\Uxxxxxxxx. Unprintable characters are those other than
476 * U+000A, U+0020..U+007E.
477 * @param ec error code.
478 * @return length of string, possibly larger than resultCapacity
481 U_STABLE
int32_t U_EXPORT2
482 uset_toPattern(const USet
* set
,
483 UChar
* result
, int32_t resultCapacity
,
484 UBool escapeUnprintable
,
488 * Adds the given character to the given USet. After this call,
489 * uset_contains(set, c) will return TRUE.
490 * A frozen set will not be modified.
491 * @param set the object to which to add the character
492 * @param c the character to add
495 U_STABLE
void U_EXPORT2
496 uset_add(USet
* set
, UChar32 c
);
499 * Adds all of the elements in the specified set to this set if
500 * they're not already present. This operation effectively
501 * modifies this set so that its value is the <i>union</i> of the two
502 * sets. The behavior of this operation is unspecified if the specified
503 * collection is modified while the operation is in progress.
504 * A frozen set will not be modified.
506 * @param set the object to which to add the set
507 * @param additionalSet the source set whose elements are to be added to this set.
510 U_STABLE
void U_EXPORT2
511 uset_addAll(USet
* set
, const USet
*additionalSet
);
514 * Adds the given range of characters to the given USet. After this call,
515 * uset_contains(set, start, end) will return TRUE.
516 * A frozen set will not be modified.
517 * @param set the object to which to add the character
518 * @param start the first character of the range to add, inclusive
519 * @param end the last character of the range to add, inclusive
522 U_STABLE
void U_EXPORT2
523 uset_addRange(USet
* set
, UChar32 start
, UChar32 end
);
526 * Adds the given string to the given USet. After this call,
527 * uset_containsString(set, str, strLen) will return TRUE.
528 * A frozen set will not be modified.
529 * @param set the object to which to add the character
530 * @param str the string to add
531 * @param strLen the length of the string or -1 if null terminated.
534 U_STABLE
void U_EXPORT2
535 uset_addString(USet
* set
, const UChar
* str
, int32_t strLen
);
538 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
539 * If this set already any particular character, it has no effect on that character.
540 * A frozen set will not be modified.
541 * @param set the object to which to add the character
542 * @param str the source string
543 * @param strLen the length of the string or -1 if null terminated.
546 U_STABLE
void U_EXPORT2
547 uset_addAllCodePoints(USet
* set
, const UChar
*str
, int32_t strLen
);
550 * Removes the given character from the given USet. After this call,
551 * uset_contains(set, c) will return FALSE.
552 * A frozen set will not be modified.
553 * @param set the object from which to remove the character
554 * @param c the character to remove
557 U_STABLE
void U_EXPORT2
558 uset_remove(USet
* set
, UChar32 c
);
561 * Removes the given range of characters from the given USet. After this call,
562 * uset_contains(set, start, end) will return FALSE.
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 remove, inclusive
566 * @param end the last character of the range to remove, inclusive
569 U_STABLE
void U_EXPORT2
570 uset_removeRange(USet
* set
, UChar32 start
, UChar32 end
);
573 * Removes the given string to the given USet. After this call,
574 * uset_containsString(set, str, strLen) will return FALSE.
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 remove
578 * @param strLen the length of the string or -1 if null terminated.
581 U_STABLE
void U_EXPORT2
582 uset_removeString(USet
* set
, const UChar
* str
, int32_t strLen
);
585 * Removes from this set all of its elements that are contained in the
586 * specified set. This operation effectively modifies this
587 * set so that its value is the <i>asymmetric set difference</i> of
589 * A frozen set will not be modified.
590 * @param set the object from which the elements are to be removed
591 * @param removeSet the object that defines which elements will be
592 * removed from this set
595 U_STABLE
void U_EXPORT2
596 uset_removeAll(USet
* set
, const USet
* removeSet
);
599 * Retain only the elements in this set that are contained in the
600 * specified range. If <code>start > end</code> then an empty range is
601 * retained, leaving the set empty. This is equivalent to
602 * a boolean logic AND, or a set INTERSECTION.
603 * A frozen set will not be modified.
605 * @param set the object for which to retain only the specified range
606 * @param start first character, inclusive, of range to be retained
608 * @param end last character, inclusive, of range to be retained
612 U_STABLE
void U_EXPORT2
613 uset_retain(USet
* set
, UChar32 start
, UChar32 end
);
616 * Retains only the elements in this set that are contained in the
617 * specified set. In other words, removes from this set all of
618 * its elements that are not contained in the specified set. This
619 * operation effectively modifies this set so that its value is
620 * the <i>intersection</i> of the two sets.
621 * A frozen set will not be modified.
623 * @param set the object on which to perform the retain
624 * @param retain set that defines which elements this set will retain
627 U_STABLE
void U_EXPORT2
628 uset_retainAll(USet
* set
, const USet
* retain
);
631 * Reallocate this objects internal structures to take up the least
632 * possible space, without changing this object's value.
633 * A frozen set will not be modified.
635 * @param set the object on which to perfrom the compact
638 U_STABLE
void U_EXPORT2
639 uset_compact(USet
* set
);
642 * Inverts this set. This operation modifies this set so that
643 * its value is its complement. This operation does not affect
644 * the multicharacter strings, if any.
645 * A frozen set will not be modified.
649 U_STABLE
void U_EXPORT2
650 uset_complement(USet
* set
);
653 * Complements in this set all elements contained in the specified
654 * set. Any character in the other set will be removed if it is
655 * in this set, or will be added if it is not in this set.
656 * A frozen set will not be modified.
658 * @param set the set with which to complement
659 * @param complement set that defines which elements will be xor'ed
663 U_STABLE
void U_EXPORT2
664 uset_complementAll(USet
* set
, const USet
* complement
);
667 * Removes all of the elements from this set. This set will be
668 * empty after this call returns.
669 * A frozen set will not be modified.
673 U_STABLE
void U_EXPORT2
674 uset_clear(USet
* set
);
677 * Returns TRUE if the given USet contains no characters and no
680 * @return true if set is empty
683 U_STABLE UBool U_EXPORT2
684 uset_isEmpty(const USet
* set
);
687 * Returns TRUE if the given USet contains the given character.
688 * This function works faster with a frozen set.
690 * @param c The codepoint to check for within the set
691 * @return true if set contains c
694 U_STABLE UBool U_EXPORT2
695 uset_contains(const USet
* set
, UChar32 c
);
698 * Returns TRUE if the given USet contains all characters c
699 * where start <= c && c <= end.
701 * @param start the first character of the range to test, inclusive
702 * @param end the last character of the range to test, inclusive
703 * @return TRUE if set contains the range
706 U_STABLE UBool U_EXPORT2
707 uset_containsRange(const USet
* set
, UChar32 start
, UChar32 end
);
710 * Returns TRUE if the given USet contains the given string.
712 * @param str the string
713 * @param strLen the length of the string or -1 if null terminated.
714 * @return true if set contains str
717 U_STABLE UBool U_EXPORT2
718 uset_containsString(const USet
* set
, const UChar
* str
, int32_t strLen
);
721 * Returns the index of the given character within this set, where
722 * the set is ordered by ascending code point. If the character
723 * is not in this set, return -1. The inverse of this method is
724 * <code>charAt()</code>.
726 * @param c the character to obtain the index for
727 * @return an index from 0..size()-1, or -1
730 U_STABLE
int32_t U_EXPORT2
731 uset_indexOf(const USet
* set
, UChar32 c
);
734 * Returns the character at the given index within this set, where
735 * the set is ordered by ascending code point. If the index is
736 * out of range, return (UChar32)-1. The inverse of this method is
737 * <code>indexOf()</code>.
739 * @param index an index from 0..size()-1 to obtain the char for
740 * @return the character at the given index, or (UChar32)-1.
743 U_STABLE UChar32 U_EXPORT2
744 uset_charAt(const USet
* set
, int32_t index
);
747 * Returns the number of characters and strings contained in the given
750 * @return a non-negative integer counting the characters and strings
754 U_STABLE
int32_t U_EXPORT2
755 uset_size(const USet
* set
);
758 * Returns the number of items in this set. An item is either a range
759 * of characters or a single multicharacter string.
761 * @return a non-negative integer counting the character ranges
762 * and/or strings contained in set
765 U_STABLE
int32_t U_EXPORT2
766 uset_getItemCount(const USet
* set
);
769 * Returns an item of this set. An item is either a range of
770 * characters or a single multicharacter string.
772 * @param itemIndex a non-negative integer in the range 0..
773 * uset_getItemCount(set)-1
774 * @param start pointer to variable to receive first character
775 * in range, inclusive
776 * @param end pointer to variable to receive last character in range,
778 * @param str buffer to receive the string, may be NULL
779 * @param strCapacity capacity of str, or 0 if str is NULL
780 * @param ec error code
781 * @return the length of the string (>= 2), or 0 if the item is a
782 * range, in which case it is the range *start..*end, or -1 if
783 * itemIndex is out of range
786 U_STABLE
int32_t U_EXPORT2
787 uset_getItem(const USet
* set
, int32_t itemIndex
,
788 UChar32
* start
, UChar32
* end
,
789 UChar
* str
, int32_t strCapacity
,
793 * Returns true if set1 contains all the characters and strings
794 * of set2. It answers the question, 'Is set1 a superset of set2?'
795 * @param set1 set to be checked for containment
796 * @param set2 set to be checked for containment
797 * @return true if the test condition is met
800 U_STABLE UBool U_EXPORT2
801 uset_containsAll(const USet
* set1
, const USet
* set2
);
804 * Returns true if this set contains all the characters
805 * of the given string. This is does not check containment of grapheme
806 * clusters, like uset_containsString.
807 * @param set set of characters to be checked for containment
808 * @param str string containing codepoints to be checked for containment
809 * @param strLen the length of the string or -1 if null terminated.
810 * @return true if the test condition is met
813 U_STABLE UBool U_EXPORT2
814 uset_containsAllCodePoints(const USet
* set
, const UChar
*str
, int32_t strLen
);
817 * Returns true if set1 contains none of the characters and strings
818 * of set2. It answers the question, 'Is set1 a disjoint set of set2?'
819 * @param set1 set to be checked for containment
820 * @param set2 set to be checked for containment
821 * @return true if the test condition is met
824 U_STABLE UBool U_EXPORT2
825 uset_containsNone(const USet
* set1
, const USet
* set2
);
828 * Returns true if set1 contains some of the characters and strings
829 * of set2. It answers the question, 'Does set1 and set2 have an intersection?'
830 * @param set1 set to be checked for containment
831 * @param set2 set to be checked for containment
832 * @return true if the test condition is met
835 U_STABLE UBool U_EXPORT2
836 uset_containsSome(const USet
* set1
, const USet
* set2
);
839 * Returns the length of the initial substring of the input string which
840 * consists only of characters and strings that are contained in this set
841 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
842 * or only of characters and strings that are not contained
843 * in this set (USET_SPAN_NOT_CONTAINED).
844 * See USetSpanCondition for details.
845 * Similar to the strspn() C library function.
846 * Unpaired surrogates are treated according to contains() of their surrogate code points.
847 * This function works faster with a frozen set and with a non-negative string length argument.
849 * @param s start of the string
850 * @param length of the string; can be -1 for NUL-terminated
851 * @param spanCondition specifies the containment condition
852 * @return the length of the initial substring according to the spanCondition;
853 * 0 if the start of the string does not fit the spanCondition
855 * @see USetSpanCondition
857 U_DRAFT
int32_t U_EXPORT2
858 uset_span(const USet
*set
, const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
);
861 * Returns the start of the trailing substring of the input string which
862 * consists only of characters and strings that are contained in this set
863 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
864 * or only of characters and strings that are not contained
865 * in this set (USET_SPAN_NOT_CONTAINED).
866 * See USetSpanCondition for details.
867 * Unpaired surrogates are treated according to contains() of their surrogate code points.
868 * This function works faster with a frozen set and with a non-negative string length argument.
870 * @param s start of the string
871 * @param length of the string; can be -1 for NUL-terminated
872 * @param spanCondition specifies the containment condition
873 * @return the start of the trailing substring according to the spanCondition;
874 * the string length if the end of the string does not fit the spanCondition
876 * @see USetSpanCondition
878 U_DRAFT
int32_t U_EXPORT2
879 uset_spanBack(const USet
*set
, const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
);
882 * Returns the length of the initial substring of the input string which
883 * consists only of characters and strings that are contained in this set
884 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
885 * or only of characters and strings that are not contained
886 * in this set (USET_SPAN_NOT_CONTAINED).
887 * See USetSpanCondition for details.
888 * Similar to the strspn() C library function.
889 * Malformed byte sequences are treated according to contains(0xfffd).
890 * This function works faster with a frozen set and with a non-negative string length argument.
892 * @param s start of the string (UTF-8)
893 * @param length of the string; can be -1 for NUL-terminated
894 * @param spanCondition specifies the containment condition
895 * @return the length of the initial substring according to the spanCondition;
896 * 0 if the start of the string does not fit the spanCondition
898 * @see USetSpanCondition
900 U_DRAFT
int32_t U_EXPORT2
901 uset_spanUTF8(const USet
*set
, const char *s
, int32_t length
, USetSpanCondition spanCondition
);
904 * Returns the start of the trailing substring of the input string which
905 * consists only of characters and strings that are contained in this set
906 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
907 * or only of characters and strings that are not contained
908 * in this set (USET_SPAN_NOT_CONTAINED).
909 * See USetSpanCondition for details.
910 * Malformed byte sequences are treated according to contains(0xfffd).
911 * This function works faster with a frozen set and with a non-negative string length argument.
913 * @param s start of the string (UTF-8)
914 * @param length of the string; can be -1 for NUL-terminated
915 * @param spanCondition specifies the containment condition
916 * @return the start of the trailing substring according to the spanCondition;
917 * the string length if the end of the string does not fit the spanCondition
919 * @see USetSpanCondition
921 U_DRAFT
int32_t U_EXPORT2
922 uset_spanBackUTF8(const USet
*set
, const char *s
, int32_t length
, USetSpanCondition spanCondition
);
925 * Returns true if set1 contains all of the characters and strings
926 * of set2, and vis versa. It answers the question, 'Is set1 equal to set2?'
927 * @param set1 set to be checked for containment
928 * @param set2 set to be checked for containment
929 * @return true if the test condition is met
932 U_STABLE UBool U_EXPORT2
933 uset_equals(const USet
* set1
, const USet
* set2
);
935 /*********************************************************************
937 *********************************************************************/
940 * Serializes this set into an array of 16-bit integers. Serialization
941 * (currently) only records the characters in the set; multicharacter
942 * strings are ignored.
945 * has following format (each line is one 16-bit integer):
947 * length = (n+2*m) | (m!=0?0x8000:0)
948 * bmpLength = n; present if m!=0
961 * The array starts with a header. After the header are n bmp
962 * code points, then m supplementary code points. Either n or m
963 * or both may be zero. n+2*m is always <= 0x7FFF.
965 * If there are no supplementary characters (if m==0) then the
966 * header is one 16-bit integer, 'length', with value n.
968 * If there are supplementary characters (if m!=0) then the header
969 * is two 16-bit integers. The first, 'length', has value
970 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
972 * After the header the code points are stored in ascending order.
973 * Supplementary code points are stored as most significant 16
974 * bits followed by least significant 16 bits.
977 * @param dest pointer to buffer of destCapacity 16-bit integers.
978 * May be NULL only if destCapacity is zero.
979 * @param destCapacity size of dest, or zero. Must not be negative.
980 * @param pErrorCode pointer to the error code. Will be set to
981 * U_INDEX_OUTOFBOUNDS_ERROR if n+2*m > 0x7FFF. Will be set to
982 * U_BUFFER_OVERFLOW_ERROR if n+2*m+(m!=0?2:1) > destCapacity.
983 * @return the total length of the serialized format, including
984 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
985 * than U_BUFFER_OVERFLOW_ERROR.
988 U_STABLE
int32_t U_EXPORT2
989 uset_serialize(const USet
* set
, uint16_t* dest
, int32_t destCapacity
, UErrorCode
* pErrorCode
);
992 * Given a serialized array, fill in the given serialized set object.
993 * @param fillSet pointer to result
994 * @param src pointer to start of array
995 * @param srcLength length of array
996 * @return true if the given array is valid, otherwise false
999 U_STABLE UBool U_EXPORT2
1000 uset_getSerializedSet(USerializedSet
* fillSet
, const uint16_t* src
, int32_t srcLength
);
1003 * Set the USerializedSet to contain the given character (and nothing
1005 * @param fillSet pointer to result
1006 * @param c The codepoint to set
1009 U_STABLE
void U_EXPORT2
1010 uset_setSerializedToOne(USerializedSet
* fillSet
, UChar32 c
);
1013 * Returns TRUE if the given USerializedSet contains the given
1015 * @param set the serialized set
1016 * @param c The codepoint to check for within the set
1017 * @return true if set contains c
1020 U_STABLE UBool U_EXPORT2
1021 uset_serializedContains(const USerializedSet
* set
, UChar32 c
);
1024 * Returns the number of disjoint ranges of characters contained in
1025 * the given serialized set. Ignores any strings contained in the
1027 * @param set the serialized set
1028 * @return a non-negative integer counting the character ranges
1032 U_STABLE
int32_t U_EXPORT2
1033 uset_getSerializedRangeCount(const USerializedSet
* set
);
1036 * Returns a range of characters contained in the given serialized
1038 * @param set the serialized set
1039 * @param rangeIndex a non-negative integer in the range 0..
1040 * uset_getSerializedRangeCount(set)-1
1041 * @param pStart pointer to variable to receive first character
1042 * in range, inclusive
1043 * @param pEnd pointer to variable to receive last character in range,
1045 * @return true if rangeIndex is valid, otherwise false
1048 U_STABLE UBool U_EXPORT2
1049 uset_getSerializedRange(const USerializedSet
* set
, int32_t rangeIndex
,
1050 UChar32
* pStart
, UChar32
* pEnd
);