2 *******************************************************************************
4 * Copyright (C) 2002-2007, 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
100 #ifndef U_HIDE_DRAFT_API
103 * Argument values for whether span() and similar functions continue while
104 * the current character is contained vs. not contained in the set.
106 * The functionality is straightforward for sets with only single code points,
107 * without strings (which is the common case):
108 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE
110 * - span() and spanBack() partition any string the same way when
111 * alternating between span(USET_SPAN_NOT_CONTAINED) and
112 * span(either "contained" condition).
113 * - Using a complemented (inverted) set and the opposite span conditions
114 * yields the same results.
116 * When a set contains multi-code point strings, then these statements may not
117 * be true, depending on the strings in the set (for example, whether they
118 * overlap with each other) and the string that is processed.
119 * For a set with strings:
120 * - The complement of the set contains the opposite set of code points,
121 * but the same set of strings.
122 * Therefore, complementing both the set and the span conditions
123 * may yield different results.
124 * - When starting spans at different positions in a string
125 * (span(s, ...) vs. span(s+1, ...)) the ends of the spans may be different
126 * because a set string may start before the later position.
127 * - span(USET_SPAN_SIMPLE) may be shorter than
128 * span(USET_SPAN_CONTAINED) because it will not recursively try
129 * all possible paths.
130 * For example, with a set which contains the three strings "xy", "xya" and "ax",
131 * span("xyax", USET_SPAN_CONTAINED) will return 4 but
132 * span("xyax", USET_SPAN_SIMPLE) will return 3.
133 * span(USET_SPAN_SIMPLE) will never be longer than
134 * span(USET_SPAN_CONTAINED).
135 * - With either "contained" condition, span() and spanBack() may partition
136 * a string in different ways.
137 * For example, with a set which contains the two strings "ab" and "ba",
138 * and when processing the string "aba",
139 * span() will yield contained/not-contained boundaries of { 0, 2, 3 }
140 * while spanBack() will yield boundaries of { 0, 1, 3 }.
142 * Note: If it is important to get the same boundaries whether iterating forward
143 * or backward through a string, then either only span() should be used and
144 * the boundaries cached for backward operation, or an ICU BreakIterator
147 * Note: Unpaired surrogates are treated like surrogate code points.
148 * Similarly, set strings match only on code point boundaries,
149 * never in the middle of a surrogate pair.
150 * Illegal UTF-8 sequences are treated like U+FFFD.
151 * When processing UTF-8 strings, malformed set strings
152 * (strings with unpaired surrogates which cannot be converted to UTF-8)
157 typedef enum USetSpanCondition
{
159 * Continue a span() while there is no set element at the current position.
160 * Stops before the first set element (character or string).
161 * (For code points only, this is like while contains(current)==FALSE).
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 * Continue a span() while there is a set element at the current position.
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
178 * matching any of the possible concatenations of set elements (characters or strings).
179 * (There must be a single, non-overlapping concatenation of characters or strings.)
180 * This is equivalent to a POSIX regular expression for (OR of each set element)*.
184 USET_SPAN_CONTAINED
= 1,
186 * Continue a span() while there is a set element at the current position.
187 * (For characters only, this is like while contains(current)==TRUE).
189 * When span() returns, the substring between where it started and the position
190 * it returned consists only of set elements (characters or strings) that are in the set.
192 * If a set only contains single characters, then this is the same
193 * as USET_SPAN_CONTAINED.
195 * If a set contains strings, then the span will be the longest substring
196 * with a match at each position with the longest single set element (character or string).
198 * Use this span condition together with other longest-match algorithms,
199 * such as ICU converters (ucnv_getUnicodeSet()).
203 USET_SPAN_SIMPLE
= 2,
205 * One more than the last span condition.
208 USET_SPAN_CONDITION_COUNT
211 #endif /* U_HIDE_DRAFT_API */
214 * A serialized form of a Unicode set. Limited manipulations are
215 * possible directly on a serialized set. See below.
218 typedef struct USerializedSet
{
220 * The serialized Unicode Set.
223 const uint16_t *array
;
225 * The length of the array that contains BMP characters.
230 * The total length of the array.
235 * A small buffer for the array to reduce memory allocations.
238 uint16_t staticArray
[USET_SERIALIZED_STATIC_ARRAY_CAPACITY
];
241 /*********************************************************************
243 *********************************************************************/
246 * Creates a USet object that contains the range of characters
247 * start..end, inclusive.
248 * @param start first character of the range, inclusive
249 * @param end last character of the range, inclusive
250 * @return a newly created USet. The caller must call uset_close() on
254 U_STABLE USet
* U_EXPORT2
255 uset_open(UChar32 start
, UChar32 end
);
258 * Creates a set from the given pattern. See the UnicodeSet class
259 * description for the syntax of the pattern language.
260 * @param pattern a string specifying what characters are in the set
261 * @param patternLength the length of the pattern, or -1 if null
263 * @param ec the error code
266 U_STABLE USet
* U_EXPORT2
267 uset_openPattern(const UChar
* pattern
, int32_t patternLength
,
271 * Creates a set from the given pattern. See the UnicodeSet class
272 * description for the syntax of the pattern language.
273 * @param pattern a string specifying what characters are in the set
274 * @param patternLength the length of the pattern, or -1 if null
276 * @param options bitmask for options to apply to the pattern.
277 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
278 * @param ec the error code
281 U_STABLE USet
* U_EXPORT2
282 uset_openPatternOptions(const UChar
* pattern
, int32_t patternLength
,
287 * Disposes of the storage used by a USet object. This function should
288 * be called exactly once for objects returned by uset_open().
289 * @param set the object to dispose of
292 U_STABLE
void U_EXPORT2
293 uset_close(USet
* set
);
296 * Returns a copy of this object.
297 * If this set is frozen, then the clone will be frozen as well.
298 * Use uset_cloneAsThawed() for a mutable clone of a frozen set.
299 * @param set the original set
300 * @return the newly allocated copy of the set
301 * @see uset_cloneAsThawed
304 U_DRAFT USet
* U_EXPORT2
305 uset_clone(const USet
*set
);
308 * Determines whether the set has been frozen (made immutable) or not.
309 * See the ICU4J Freezable interface for details.
311 * @return TRUE/FALSE for whether the set has been frozen
313 * @see uset_cloneAsThawed
316 U_DRAFT UBool U_EXPORT2
317 uset_isFrozen(const USet
*set
);
320 * Freeze the set (make it immutable).
321 * Once frozen, it cannot be unfrozen and is therefore thread-safe
322 * until it is deleted.
323 * See the ICU4J Freezable interface for details.
324 * Freezing the set may also make some operations faster, for example
325 * uset_contains() and uset_span().
326 * A frozen set will not be modified. (It remains frozen.)
328 * @return the same set, now frozen
330 * @see uset_cloneAsThawed
333 U_DRAFT
void U_EXPORT2
334 uset_freeze(USet
*set
);
337 * Clone the set and make the clone mutable.
338 * See the ICU4J Freezable interface for details.
340 * @return the mutable clone
346 U_DRAFT USet
* U_EXPORT2
347 uset_cloneAsThawed(const USet
*set
);
350 * Causes the USet object to represent the range <code>start - end</code>.
351 * If <code>start > end</code> then this USet is set to an empty range.
352 * A frozen set will not be modified.
353 * @param set the object to set to the given range
354 * @param start first character in the set, inclusive
355 * @param end last character in the set, inclusive
358 U_STABLE
void U_EXPORT2
360 UChar32 start
, UChar32 end
);
363 * Modifies the set to represent the set specified by the given
364 * pattern. See the UnicodeSet class description for the syntax of
365 * the pattern language. See also the User Guide chapter about UnicodeSet.
366 * <em>Empties the set passed before applying the pattern.</em>
367 * A frozen set will not be modified.
368 * @param set The set to which the pattern is to be applied.
369 * @param pattern A pointer to UChar string specifying what characters are in the set.
370 * The character at pattern[0] must be a '['.
371 * @param patternLength The length of the UChar string. -1 if NUL terminated.
372 * @param options A bitmask for options to apply to the pattern.
373 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
374 * @param status Returns an error if the pattern cannot be parsed.
375 * @return Upon successful parse, the value is either
376 * the index of the character after the closing ']'
377 * of the parsed pattern.
378 * If the status code indicates failure, then the return value
379 * is the index of the error in the source.
383 U_STABLE
int32_t U_EXPORT2
384 uset_applyPattern(USet
*set
,
385 const UChar
*pattern
, int32_t patternLength
,
390 * Modifies the set to contain those code points which have the given value
391 * for the given binary or enumerated property, as returned by
392 * u_getIntPropertyValue. Prior contents of this set are lost.
393 * A frozen set will not be modified.
395 * @param set the object to contain the code points defined by the property
397 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
398 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
399 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
401 * @param value a value in the range u_getIntPropertyMinValue(prop)..
402 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
403 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
404 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
405 * categories such as [:L:] to be represented.
407 * @param ec error code input/output parameter
411 U_STABLE
void U_EXPORT2
412 uset_applyIntPropertyValue(USet
* set
,
413 UProperty prop
, int32_t value
, UErrorCode
* ec
);
416 * Modifies the set to contain those code points which have the
417 * given value for the given property. Prior contents of this
419 * A frozen set will not be modified.
421 * @param set the object to contain the code points defined by the given
422 * property and value alias
424 * @param prop a string specifying a property alias, either short or long.
425 * The name is matched loosely. See PropertyAliases.txt for names and a
426 * description of loose matching. If the value string is empty, then this
427 * string is interpreted as either a General_Category value alias, a Script
428 * value alias, a binary property alias, or a special ID. Special IDs are
429 * matched loosely and correspond to the following sets:
431 * "ANY" = [\\u0000-\\U0010FFFF],
432 * "ASCII" = [\\u0000-\\u007F],
433 * "Assigned" = [:^Cn:].
435 * @param propLength the length of the prop, or -1 if NULL
437 * @param value a string specifying a value alias, either short or long.
438 * The name is matched loosely. See PropertyValueAliases.txt for names
439 * and a description of loose matching. In addition to aliases listed,
440 * numeric values and canonical combining classes may be expressed
441 * numerically, e.g., ("nv", "0.5") or ("ccc", "220"). The value string
444 * @param valueLength the length of the value, or -1 if NULL
446 * @param ec error code input/output parameter
450 U_STABLE
void U_EXPORT2
451 uset_applyPropertyAlias(USet
* set
,
452 const UChar
*prop
, int32_t propLength
,
453 const UChar
*value
, int32_t valueLength
,
457 * Return true if the given position, in the given pattern, appears
458 * to be the start of a UnicodeSet pattern.
460 * @param pattern a string specifying the pattern
461 * @param patternLength the length of the pattern, or -1 if NULL
462 * @param pos the given position
465 U_STABLE UBool U_EXPORT2
466 uset_resemblesPattern(const UChar
*pattern
, int32_t patternLength
,
470 * Returns a string representation of this set. If the result of
471 * calling this function is passed to a uset_openPattern(), it
472 * will produce another set that is equal to this one.
474 * @param result the string to receive the rules, may be NULL
475 * @param resultCapacity the capacity of result, may be 0 if result is NULL
476 * @param escapeUnprintable if TRUE then convert unprintable
477 * character to their hex escape representations, \\uxxxx or
478 * \\Uxxxxxxxx. Unprintable characters are those other than
479 * U+000A, U+0020..U+007E.
480 * @param ec error code.
481 * @return length of string, possibly larger than resultCapacity
484 U_STABLE
int32_t U_EXPORT2
485 uset_toPattern(const USet
* set
,
486 UChar
* result
, int32_t resultCapacity
,
487 UBool escapeUnprintable
,
491 * Adds the given character to the given USet. After this call,
492 * uset_contains(set, c) will return TRUE.
493 * A frozen set will not be modified.
494 * @param set the object to which to add the character
495 * @param c the character to add
498 U_STABLE
void U_EXPORT2
499 uset_add(USet
* set
, UChar32 c
);
502 * Adds all of the elements in the specified set to this set if
503 * they're not already present. This operation effectively
504 * modifies this set so that its value is the <i>union</i> of the two
505 * sets. The behavior of this operation is unspecified if the specified
506 * collection is modified while the operation is in progress.
507 * A frozen set will not be modified.
509 * @param set the object to which to add the set
510 * @param additionalSet the source set whose elements are to be added to this set.
513 U_STABLE
void U_EXPORT2
514 uset_addAll(USet
* set
, const USet
*additionalSet
);
517 * Adds the given range of characters to the given USet. After this call,
518 * uset_contains(set, start, end) will return TRUE.
519 * A frozen set will not be modified.
520 * @param set the object to which to add the character
521 * @param start the first character of the range to add, inclusive
522 * @param end the last character of the range to add, inclusive
525 U_STABLE
void U_EXPORT2
526 uset_addRange(USet
* set
, UChar32 start
, UChar32 end
);
529 * Adds the given string to the given USet. After this call,
530 * uset_containsString(set, str, strLen) will return TRUE.
531 * A frozen set will not be modified.
532 * @param set the object to which to add the character
533 * @param str the string to add
534 * @param strLen the length of the string or -1 if null terminated.
537 U_STABLE
void U_EXPORT2
538 uset_addString(USet
* set
, const UChar
* str
, int32_t strLen
);
541 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
542 * If this set already any particular character, it has no effect on that character.
543 * A frozen set will not be modified.
544 * @param set the object to which to add the character
545 * @param str the source string
546 * @param strLen the length of the string or -1 if null terminated.
549 U_STABLE
void U_EXPORT2
550 uset_addAllCodePoints(USet
* set
, const UChar
*str
, int32_t strLen
);
553 * Removes the given character from the given USet. After this call,
554 * uset_contains(set, c) will return FALSE.
555 * A frozen set will not be modified.
556 * @param set the object from which to remove the character
557 * @param c the character to remove
560 U_STABLE
void U_EXPORT2
561 uset_remove(USet
* set
, UChar32 c
);
564 * Removes the given range of characters from the given USet. After this call,
565 * uset_contains(set, start, end) will return FALSE.
566 * A frozen set will not be modified.
567 * @param set the object to which to add the character
568 * @param start the first character of the range to remove, inclusive
569 * @param end the last character of the range to remove, inclusive
572 U_STABLE
void U_EXPORT2
573 uset_removeRange(USet
* set
, UChar32 start
, UChar32 end
);
576 * Removes the given string to the given USet. After this call,
577 * uset_containsString(set, str, strLen) will return FALSE.
578 * A frozen set will not be modified.
579 * @param set the object to which to add the character
580 * @param str the string to remove
581 * @param strLen the length of the string or -1 if null terminated.
584 U_STABLE
void U_EXPORT2
585 uset_removeString(USet
* set
, const UChar
* str
, int32_t strLen
);
588 * Removes from this set all of its elements that are contained in the
589 * specified set. This operation effectively modifies this
590 * set so that its value is the <i>asymmetric set difference</i> of
592 * A frozen set will not be modified.
593 * @param set the object from which the elements are to be removed
594 * @param removeSet the object that defines which elements will be
595 * removed from this set
598 U_STABLE
void U_EXPORT2
599 uset_removeAll(USet
* set
, const USet
* removeSet
);
602 * Retain only the elements in this set that are contained in the
603 * specified range. If <code>start > end</code> then an empty range is
604 * retained, leaving the set empty. This is equivalent to
605 * a boolean logic AND, or a set INTERSECTION.
606 * A frozen set will not be modified.
608 * @param set the object for which to retain only the specified range
609 * @param start first character, inclusive, of range to be retained
611 * @param end last character, inclusive, of range to be retained
615 U_STABLE
void U_EXPORT2
616 uset_retain(USet
* set
, UChar32 start
, UChar32 end
);
619 * Retains only the elements in this set that are contained in the
620 * specified set. In other words, removes from this set all of
621 * its elements that are not contained in the specified set. This
622 * operation effectively modifies this set so that its value is
623 * the <i>intersection</i> of the two sets.
624 * A frozen set will not be modified.
626 * @param set the object on which to perform the retain
627 * @param retain set that defines which elements this set will retain
630 U_STABLE
void U_EXPORT2
631 uset_retainAll(USet
* set
, const USet
* retain
);
634 * Reallocate this objects internal structures to take up the least
635 * possible space, without changing this object's value.
636 * A frozen set will not be modified.
638 * @param set the object on which to perfrom the compact
641 U_STABLE
void U_EXPORT2
642 uset_compact(USet
* set
);
645 * Inverts this set. This operation modifies this set so that
646 * its value is its complement. This operation does not affect
647 * the multicharacter strings, if any.
648 * A frozen set will not be modified.
652 U_STABLE
void U_EXPORT2
653 uset_complement(USet
* set
);
656 * Complements in this set all elements contained in the specified
657 * set. Any character in the other set will be removed if it is
658 * in this set, or will be added if it is not in this set.
659 * A frozen set will not be modified.
661 * @param set the set with which to complement
662 * @param complement set that defines which elements will be xor'ed
666 U_STABLE
void U_EXPORT2
667 uset_complementAll(USet
* set
, const USet
* complement
);
670 * Removes all of the elements from this set. This set will be
671 * empty after this call returns.
672 * A frozen set will not be modified.
676 U_STABLE
void U_EXPORT2
677 uset_clear(USet
* set
);
680 * Returns TRUE if the given USet contains no characters and no
683 * @return true if set is empty
686 U_STABLE UBool U_EXPORT2
687 uset_isEmpty(const USet
* set
);
690 * Returns TRUE if the given USet contains the given character.
691 * This function works faster with a frozen set.
693 * @param c The codepoint to check for within the set
694 * @return true if set contains c
697 U_STABLE UBool U_EXPORT2
698 uset_contains(const USet
* set
, UChar32 c
);
701 * Returns TRUE if the given USet contains all characters c
702 * where start <= c && c <= end.
704 * @param start the first character of the range to test, inclusive
705 * @param end the last character of the range to test, inclusive
706 * @return TRUE if set contains the range
709 U_STABLE UBool U_EXPORT2
710 uset_containsRange(const USet
* set
, UChar32 start
, UChar32 end
);
713 * Returns TRUE if the given USet contains the given string.
715 * @param str the string
716 * @param strLen the length of the string or -1 if null terminated.
717 * @return true if set contains str
720 U_STABLE UBool U_EXPORT2
721 uset_containsString(const USet
* set
, const UChar
* str
, int32_t strLen
);
724 * Returns the index of the given character within this set, where
725 * the set is ordered by ascending code point. If the character
726 * is not in this set, return -1. The inverse of this method is
727 * <code>charAt()</code>.
729 * @param c the character to obtain the index for
730 * @return an index from 0..size()-1, or -1
733 U_STABLE
int32_t U_EXPORT2
734 uset_indexOf(const USet
* set
, UChar32 c
);
737 * Returns the character at the given index within this set, where
738 * the set is ordered by ascending code point. If the index is
739 * out of range, return (UChar32)-1. The inverse of this method is
740 * <code>indexOf()</code>.
742 * @param index an index from 0..size()-1 to obtain the char for
743 * @return the character at the given index, or (UChar32)-1.
746 U_STABLE UChar32 U_EXPORT2
747 uset_charAt(const USet
* set
, int32_t index
);
750 * Returns the number of characters and strings contained in the given
753 * @return a non-negative integer counting the characters and strings
757 U_STABLE
int32_t U_EXPORT2
758 uset_size(const USet
* set
);
761 * Returns the number of items in this set. An item is either a range
762 * of characters or a single multicharacter string.
764 * @return a non-negative integer counting the character ranges
765 * and/or strings contained in set
768 U_STABLE
int32_t U_EXPORT2
769 uset_getItemCount(const USet
* set
);
772 * Returns an item of this set. An item is either a range of
773 * characters or a single multicharacter string.
775 * @param itemIndex a non-negative integer in the range 0..
776 * uset_getItemCount(set)-1
777 * @param start pointer to variable to receive first character
778 * in range, inclusive
779 * @param end pointer to variable to receive last character in range,
781 * @param str buffer to receive the string, may be NULL
782 * @param strCapacity capacity of str, or 0 if str is NULL
783 * @param ec error code
784 * @return the length of the string (>= 2), or 0 if the item is a
785 * range, in which case it is the range *start..*end, or -1 if
786 * itemIndex is out of range
789 U_STABLE
int32_t U_EXPORT2
790 uset_getItem(const USet
* set
, int32_t itemIndex
,
791 UChar32
* start
, UChar32
* end
,
792 UChar
* str
, int32_t strCapacity
,
796 * Returns true if set1 contains all the characters and strings
797 * of set2. It answers the question, 'Is set1 a superset of set2?'
798 * @param set1 set to be checked for containment
799 * @param set2 set to be checked for containment
800 * @return true if the test condition is met
803 U_STABLE UBool U_EXPORT2
804 uset_containsAll(const USet
* set1
, const USet
* set2
);
807 * Returns true if this set contains all the characters
808 * of the given string. This is does not check containment of grapheme
809 * clusters, like uset_containsString.
810 * @param set set of characters to be checked for containment
811 * @param str string containing codepoints to be checked for containment
812 * @param strLen the length of the string or -1 if null terminated.
813 * @return true if the test condition is met
816 U_STABLE UBool U_EXPORT2
817 uset_containsAllCodePoints(const USet
* set
, const UChar
*str
, int32_t strLen
);
820 * Returns true if set1 contains none of the characters and strings
821 * of set2. It answers the question, 'Is set1 a disjoint set of set2?'
822 * @param set1 set to be checked for containment
823 * @param set2 set to be checked for containment
824 * @return true if the test condition is met
827 U_STABLE UBool U_EXPORT2
828 uset_containsNone(const USet
* set1
, const USet
* set2
);
831 * Returns true if set1 contains some of the characters and strings
832 * of set2. It answers the question, 'Does set1 and set2 have an intersection?'
833 * @param set1 set to be checked for containment
834 * @param set2 set to be checked for containment
835 * @return true if the test condition is met
838 U_STABLE UBool U_EXPORT2
839 uset_containsSome(const USet
* set1
, const USet
* set2
);
842 * Returns the length of the initial substring of the input string which
843 * consists only of characters and strings that are contained in this set
844 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
845 * or only of characters and strings that are not contained
846 * in this set (USET_SPAN_NOT_CONTAINED).
847 * See USetSpanCondition for details.
848 * Similar to the strspn() C library function.
849 * Unpaired surrogates are treated according to contains() of their surrogate code points.
850 * This function works faster with a frozen set and with a non-negative string length argument.
852 * @param s start of the string
853 * @param length of the string; can be -1 for NUL-terminated
854 * @param spanCondition specifies the containment condition
855 * @return the length of the initial substring according to the spanCondition;
856 * 0 if the start of the string does not fit the spanCondition
858 * @see USetSpanCondition
860 U_DRAFT
int32_t U_EXPORT2
861 uset_span(const USet
*set
, const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
);
864 * Returns the start of the trailing substring of the input string which
865 * consists only of characters and strings that are contained in this set
866 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
867 * or only of characters and strings that are not contained
868 * in this set (USET_SPAN_NOT_CONTAINED).
869 * See USetSpanCondition for details.
870 * Unpaired surrogates are treated according to contains() of their surrogate code points.
871 * This function works faster with a frozen set and with a non-negative string length argument.
873 * @param s start of the string
874 * @param length of the string; can be -1 for NUL-terminated
875 * @param spanCondition specifies the containment condition
876 * @return the start of the trailing substring according to the spanCondition;
877 * the string length if the end of the string does not fit the spanCondition
879 * @see USetSpanCondition
881 U_DRAFT
int32_t U_EXPORT2
882 uset_spanBack(const USet
*set
, const UChar
*s
, int32_t length
, USetSpanCondition spanCondition
);
885 * Returns the length of the initial substring of the input string which
886 * consists only of characters and strings that are contained in this set
887 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
888 * or only of characters and strings that are not contained
889 * in this set (USET_SPAN_NOT_CONTAINED).
890 * See USetSpanCondition for details.
891 * Similar to the strspn() C library function.
892 * Malformed byte sequences are treated according to contains(0xfffd).
893 * This function works faster with a frozen set and with a non-negative string length argument.
895 * @param s start of the string (UTF-8)
896 * @param length of the string; can be -1 for NUL-terminated
897 * @param spanCondition specifies the containment condition
898 * @return the length of the initial substring according to the spanCondition;
899 * 0 if the start of the string does not fit the spanCondition
901 * @see USetSpanCondition
903 U_DRAFT
int32_t U_EXPORT2
904 uset_spanUTF8(const USet
*set
, const char *s
, int32_t length
, USetSpanCondition spanCondition
);
907 * Returns the start of the trailing substring of the input string which
908 * consists only of characters and strings that are contained in this set
909 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
910 * or only of characters and strings that are not contained
911 * in this set (USET_SPAN_NOT_CONTAINED).
912 * See USetSpanCondition for details.
913 * Malformed byte sequences are treated according to contains(0xfffd).
914 * This function works faster with a frozen set and with a non-negative string length argument.
916 * @param s start of the string (UTF-8)
917 * @param length of the string; can be -1 for NUL-terminated
918 * @param spanCondition specifies the containment condition
919 * @return the start of the trailing substring according to the spanCondition;
920 * the string length if the end of the string does not fit the spanCondition
922 * @see USetSpanCondition
924 U_DRAFT
int32_t U_EXPORT2
925 uset_spanBackUTF8(const USet
*set
, const char *s
, int32_t length
, USetSpanCondition spanCondition
);
928 * Returns true if set1 contains all of the characters and strings
929 * of set2, and vis versa. It answers the question, 'Is set1 equal to set2?'
930 * @param set1 set to be checked for containment
931 * @param set2 set to be checked for containment
932 * @return true if the test condition is met
935 U_STABLE UBool U_EXPORT2
936 uset_equals(const USet
* set1
, const USet
* set2
);
938 /*********************************************************************
940 *********************************************************************/
943 * Serializes this set into an array of 16-bit integers. Serialization
944 * (currently) only records the characters in the set; multicharacter
945 * strings are ignored.
948 * has following format (each line is one 16-bit integer):
950 * length = (n+2*m) | (m!=0?0x8000:0)
951 * bmpLength = n; present if m!=0
964 * The array starts with a header. After the header are n bmp
965 * code points, then m supplementary code points. Either n or m
966 * or both may be zero. n+2*m is always <= 0x7FFF.
968 * If there are no supplementary characters (if m==0) then the
969 * header is one 16-bit integer, 'length', with value n.
971 * If there are supplementary characters (if m!=0) then the header
972 * is two 16-bit integers. The first, 'length', has value
973 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
975 * After the header the code points are stored in ascending order.
976 * Supplementary code points are stored as most significant 16
977 * bits followed by least significant 16 bits.
980 * @param dest pointer to buffer of destCapacity 16-bit integers.
981 * May be NULL only if destCapacity is zero.
982 * @param destCapacity size of dest, or zero. Must not be negative.
983 * @param pErrorCode pointer to the error code. Will be set to
984 * U_INDEX_OUTOFBOUNDS_ERROR if n+2*m > 0x7FFF. Will be set to
985 * U_BUFFER_OVERFLOW_ERROR if n+2*m+(m!=0?2:1) > destCapacity.
986 * @return the total length of the serialized format, including
987 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
988 * than U_BUFFER_OVERFLOW_ERROR.
991 U_STABLE
int32_t U_EXPORT2
992 uset_serialize(const USet
* set
, uint16_t* dest
, int32_t destCapacity
, UErrorCode
* pErrorCode
);
995 * Given a serialized array, fill in the given serialized set object.
996 * @param fillSet pointer to result
997 * @param src pointer to start of array
998 * @param srcLength length of array
999 * @return true if the given array is valid, otherwise false
1002 U_STABLE UBool U_EXPORT2
1003 uset_getSerializedSet(USerializedSet
* fillSet
, const uint16_t* src
, int32_t srcLength
);
1006 * Set the USerializedSet to contain the given character (and nothing
1008 * @param fillSet pointer to result
1009 * @param c The codepoint to set
1012 U_STABLE
void U_EXPORT2
1013 uset_setSerializedToOne(USerializedSet
* fillSet
, UChar32 c
);
1016 * Returns TRUE if the given USerializedSet contains the given
1018 * @param set the serialized set
1019 * @param c The codepoint to check for within the set
1020 * @return true if set contains c
1023 U_STABLE UBool U_EXPORT2
1024 uset_serializedContains(const USerializedSet
* set
, UChar32 c
);
1027 * Returns the number of disjoint ranges of characters contained in
1028 * the given serialized set. Ignores any strings contained in the
1030 * @param set the serialized set
1031 * @return a non-negative integer counting the character ranges
1035 U_STABLE
int32_t U_EXPORT2
1036 uset_getSerializedRangeCount(const USerializedSet
* set
);
1039 * Returns a range of characters contained in the given serialized
1041 * @param set the serialized set
1042 * @param rangeIndex a non-negative integer in the range 0..
1043 * uset_getSerializedRangeCount(set)-1
1044 * @param pStart pointer to variable to receive first character
1045 * in range, inclusive
1046 * @param pEnd pointer to variable to receive last character in range,
1048 * @return true if rangeIndex is valid, otherwise false
1051 U_STABLE UBool U_EXPORT2
1052 uset_getSerializedRange(const USerializedSet
* set
, int32_t rangeIndex
,
1053 UChar32
* pStart
, UChar32
* pEnd
);