X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..2ca993e82fb37b597a3c73ecd1586a139a6579c5:/icuSources/common/unicode/uset.h diff --git a/icuSources/common/unicode/uset.h b/icuSources/common/unicode/uset.h index b82ceb8f..eb3c9e6a 100644 --- a/icuSources/common/unicode/uset.h +++ b/icuSources/common/unicode/uset.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2002-2004, International Business Machines +* Copyright (C) 2002-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -29,6 +29,7 @@ #include "unicode/utypes.h" #include "unicode/uchar.h" +#include "unicode/localpointer.h" #ifndef UCNV_H struct USet; @@ -57,30 +58,157 @@ enum { * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will * match all except 'a', 'A', 'b', and 'B'. This performs a full * closure over case mappings, e.g. U+017F for s. + * + * The resulting set is a superset of the input for the code points but + * not for the strings. + * It performs a case mapping closure of the code points and adds + * full case folding strings for the code points, and reduces strings of + * the original set to their full case folding equivalents. + * + * This is designed for case-insensitive matches, for example + * in regular expressions. The full code point case closure allows checking of + * an input character directly against the closure set. + * Strings are matched by comparing the case-folded form from the closure + * set with an incremental case folding of the string in question. + * + * The closure set will also contain single code points if the original + * set contained case-equivalent strings (like U+00DF for "ss" or "Ss" etc.). + * This is not necessary (that is, redundant) for the above matching method + * but results in the same closure sets regardless of whether the original + * set contained the code point or a string. + * * @stable ICU 2.4 */ USET_CASE_INSENSITIVE = 2, - /** - * Bitmask for UnicodeSet::closeOver() indicating letter case. - * This may be ORed together with other selectors. - * @internal - */ - USET_CASE = 2, - /** * Enable case insensitive matching. E.g., "[ab]" with this flag * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will * match all except 'a', 'A', 'b', and 'B'. This adds the lower-, * title-, and uppercase mappings as well as the case folding * of each existing element in the set. - * @draft ICU 3.2 + * @stable ICU 3.2 + */ + USET_ADD_CASE_MAPPINGS = 4 +}; + +/** + * Argument values for whether span() and similar functions continue while + * the current character is contained vs. not contained in the set. + * + * The functionality is straightforward for sets with only single code points, + * without strings (which is the common case): + * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE work the same. + * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE are inverses of USET_SPAN_NOT_CONTAINED. + * - span() and spanBack() partition any string the same way when + * alternating between span(USET_SPAN_NOT_CONTAINED) and + * span(either "contained" condition). + * - Using a complemented (inverted) set and the opposite span conditions + * yields the same results. + * + * When a set contains multi-code point strings, then these statements may not + * be true, depending on the strings in the set (for example, whether they + * overlap with each other) and the string that is processed. + * For a set with strings: + * - The complement of the set contains the opposite set of code points, + * but the same set of strings. + * Therefore, complementing both the set and the span conditions + * may yield different results. + * - When starting spans at different positions in a string + * (span(s, ...) vs. span(s+1, ...)) the ends of the spans may be different + * because a set string may start before the later position. + * - span(USET_SPAN_SIMPLE) may be shorter than + * span(USET_SPAN_CONTAINED) because it will not recursively try + * all possible paths. + * For example, with a set which contains the three strings "xy", "xya" and "ax", + * span("xyax", USET_SPAN_CONTAINED) will return 4 but + * span("xyax", USET_SPAN_SIMPLE) will return 3. + * span(USET_SPAN_SIMPLE) will never be longer than + * span(USET_SPAN_CONTAINED). + * - With either "contained" condition, span() and spanBack() may partition + * a string in different ways. + * For example, with a set which contains the two strings "ab" and "ba", + * and when processing the string "aba", + * span() will yield contained/not-contained boundaries of { 0, 2, 3 } + * while spanBack() will yield boundaries of { 0, 1, 3 }. + * + * Note: If it is important to get the same boundaries whether iterating forward + * or backward through a string, then either only span() should be used and + * the boundaries cached for backward operation, or an ICU BreakIterator + * could be used. + * + * Note: Unpaired surrogates are treated like surrogate code points. + * Similarly, set strings match only on code point boundaries, + * never in the middle of a surrogate pair. + * Illegal UTF-8 sequences are treated like U+FFFD. + * When processing UTF-8 strings, malformed set strings + * (strings with unpaired surrogates which cannot be converted to UTF-8) + * are ignored. + * + * @stable ICU 3.8 + */ +typedef enum USetSpanCondition { + /** + * Continues a span() while there is no set element at the current position. + * Increments by one code point at a time. + * Stops before the first set element (character or string). + * (For code points only, this is like while contains(current)==FALSE). + * + * When span() returns, the substring between where it started and the position + * it returned consists only of characters that are not in the set, + * and none of its strings overlap with the span. + * + * @stable ICU 3.8 + */ + USET_SPAN_NOT_CONTAINED = 0, + /** + * Spans the longest substring that is a concatenation of set elements (characters or strings). + * (For characters only, this is like while contains(current)==TRUE). + * + * When span() returns, the substring between where it started and the position + * it returned consists only of set elements (characters or strings) that are in the set. + * + * If a set contains strings, then the span will be the longest substring for which there + * exists at least one non-overlapping concatenation of set elements (characters or strings). + * This is equivalent to a POSIX regular expression for (OR of each set element)*. + * (Java/ICU/Perl regex stops at the first match of an OR.) + * + * @stable ICU 3.8 + */ + USET_SPAN_CONTAINED = 1, + /** + * Continues a span() while there is a set element at the current position. + * Increments by the longest matching element at each position. + * (For characters only, this is like while contains(current)==TRUE). + * + * When span() returns, the substring between where it started and the position + * it returned consists only of set elements (characters or strings) that are in the set. + * + * If a set only contains single characters, then this is the same + * as USET_SPAN_CONTAINED. + * + * If a set contains strings, then the span will be the longest substring + * with a match at each position with the longest single set element (character or string). + * + * Use this span condition together with other longest-match algorithms, + * such as ICU converters (ucnv_getUnicodeSet()). + * + * @stable ICU 3.8 + */ + USET_SPAN_SIMPLE = 2, + /** + * One more than the last span condition. + * @stable ICU 3.8 */ - USET_ADD_CASE_MAPPINGS = 4, + USET_SPAN_CONDITION_COUNT +} USetSpanCondition; +enum { /** - * Enough for any single-code point set - * @internal + * Capacity of USerializedSet::staticArray. + * Enough for any single-code point set. + * Also provides padding for nice sizeof(USerializedSet). + * @stable ICU 2.4 */ USET_SERIALIZED_STATIC_ARRAY_CAPACITY=8 }; @@ -117,9 +245,20 @@ typedef struct USerializedSet { * USet API *********************************************************************/ +/** + * Create an empty USet object. + * Equivalent to uset_open(1, 0). + * @return a newly created USet. The caller must call uset_close() on + * it when done. + * @stable ICU 4.2 + */ +U_STABLE USet* U_EXPORT2 +uset_openEmpty(void); + /** * Creates a USet object that contains the range of characters - * start..end, inclusive. + * start..end, inclusive. If start > end + * then an empty set is created (same as using uset_openEmpty()). * @param start first character of the range, inclusive * @param end last character of the range, inclusive * @return a newly created USet. The caller must call uset_close() on @@ -167,15 +306,89 @@ uset_openPatternOptions(const UChar* pattern, int32_t patternLength, U_STABLE void U_EXPORT2 uset_close(USet* set); +#if U_SHOW_CPLUSPLUS_API + +U_NAMESPACE_BEGIN + +/** + * \class LocalUSetPointer + * "Smart pointer" class, closes a USet via uset_close(). + * For most methods see the LocalPointerBase base class. + * + * @see LocalPointerBase + * @see LocalPointer + * @stable ICU 4.4 + */ +U_DEFINE_LOCAL_OPEN_POINTER(LocalUSetPointer, USet, uset_close); + +U_NAMESPACE_END + +#endif + +/** + * Returns a copy of this object. + * If this set is frozen, then the clone will be frozen as well. + * Use uset_cloneAsThawed() for a mutable clone of a frozen set. + * @param set the original set + * @return the newly allocated copy of the set + * @see uset_cloneAsThawed + * @stable ICU 3.8 + */ +U_STABLE USet * U_EXPORT2 +uset_clone(const USet *set); + +/** + * Determines whether the set has been frozen (made immutable) or not. + * See the ICU4J Freezable interface for details. + * @param set the set + * @return TRUE/FALSE for whether the set has been frozen + * @see uset_freeze + * @see uset_cloneAsThawed + * @stable ICU 3.8 + */ +U_STABLE UBool U_EXPORT2 +uset_isFrozen(const USet *set); + +/** + * Freeze the set (make it immutable). + * Once frozen, it cannot be unfrozen and is therefore thread-safe + * until it is deleted. + * See the ICU4J Freezable interface for details. + * Freezing the set may also make some operations faster, for example + * uset_contains() and uset_span(). + * A frozen set will not be modified. (It remains frozen.) + * @param set the set + * @return the same set, now frozen + * @see uset_isFrozen + * @see uset_cloneAsThawed + * @stable ICU 3.8 + */ +U_STABLE void U_EXPORT2 +uset_freeze(USet *set); + +/** + * Clone the set and make the clone mutable. + * See the ICU4J Freezable interface for details. + * @param set the set + * @return the mutable clone + * @see uset_freeze + * @see uset_isFrozen + * @see uset_clone + * @stable ICU 3.8 + */ +U_STABLE USet * U_EXPORT2 +uset_cloneAsThawed(const USet *set); + /** * Causes the USet object to represent the range start - end. * If start > end then this USet is set to an empty range. + * A frozen set will not be modified. * @param set the object to set to the given range * @param start first character in the set, inclusive * @param end last character in the set, inclusive - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT void U_EXPORT2 +U_STABLE void U_EXPORT2 uset_set(USet* set, UChar32 start, UChar32 end); @@ -184,6 +397,7 @@ uset_set(USet* set, * pattern. See the UnicodeSet class description for the syntax of * the pattern language. See also the User Guide chapter about UnicodeSet. * Empties the set passed before applying the pattern. + * A frozen set will not be modified. * @param set The set to which the pattern is to be applied. * @param pattern A pointer to UChar string specifying what characters are in the set. * The character at pattern[0] must be a '['. @@ -196,10 +410,10 @@ uset_set(USet* set, * of the parsed pattern. * If the status code indicates failure, then the return value * is the index of the error in the source. - * - * @draft ICU 2.8 + * + * @stable ICU 2.8 */ -U_DRAFT int32_t U_EXPORT2 +U_STABLE int32_t U_EXPORT2 uset_applyPattern(USet *set, const UChar *pattern, int32_t patternLength, uint32_t options, @@ -209,6 +423,7 @@ uset_applyPattern(USet *set, * Modifies the set to contain those code points which have the given value * for the given binary or enumerated property, as returned by * u_getIntPropertyValue. Prior contents of this set are lost. + * A frozen set will not be modified. * * @param set the object to contain the code points defined by the property * @@ -224,9 +439,9 @@ uset_applyPattern(USet *set, * * @param ec error code input/output parameter * - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT void U_EXPORT2 +U_STABLE void U_EXPORT2 uset_applyIntPropertyValue(USet* set, UProperty prop, int32_t value, UErrorCode* ec); @@ -234,6 +449,7 @@ uset_applyIntPropertyValue(USet* set, * Modifies the set to contain those code points which have the * given value for the given property. Prior contents of this * set are lost. + * A frozen set will not be modified. * * @param set the object to contain the code points defined by the given * property and value alias @@ -246,7 +462,8 @@ uset_applyIntPropertyValue(USet* set, * matched loosely and correspond to the following sets: * * "ANY" = [\\u0000-\\U0010FFFF], - * "ASCII" = [\\u0000-\\u007F]. + * "ASCII" = [\\u0000-\\u007F], + * "Assigned" = [:^Cn:]. * * @param propLength the length of the prop, or -1 if NULL * @@ -261,9 +478,9 @@ uset_applyIntPropertyValue(USet* set, * * @param ec error code input/output parameter * - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT void U_EXPORT2 +U_STABLE void U_EXPORT2 uset_applyPropertyAlias(USet* set, const UChar *prop, int32_t propLength, const UChar *value, int32_t valueLength, @@ -276,9 +493,9 @@ uset_applyPropertyAlias(USet* set, * @param pattern a string specifying the pattern * @param patternLength the length of the pattern, or -1 if NULL * @param pos the given position - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT UBool U_EXPORT2 +U_STABLE UBool U_EXPORT2 uset_resemblesPattern(const UChar *pattern, int32_t patternLength, int32_t pos); @@ -306,6 +523,7 @@ uset_toPattern(const USet* set, /** * Adds the given character to the given USet. After this call, * uset_contains(set, c) will return TRUE. + * A frozen set will not be modified. * @param set the object to which to add the character * @param c the character to add * @stable ICU 2.4 @@ -319,6 +537,7 @@ uset_add(USet* set, UChar32 c); * modifies this set so that its value is the union of the two * sets. The behavior of this operation is unspecified if the specified * collection is modified while the operation is in progress. + * A frozen set will not be modified. * * @param set the object to which to add the set * @param additionalSet the source set whose elements are to be added to this set. @@ -330,6 +549,7 @@ uset_addAll(USet* set, const USet *additionalSet); /** * Adds the given range of characters to the given USet. After this call, * uset_contains(set, start, end) will return TRUE. + * A frozen set will not be modified. * @param set the object to which to add the character * @param start the first character of the range to add, inclusive * @param end the last character of the range to add, inclusive @@ -341,6 +561,7 @@ uset_addRange(USet* set, UChar32 start, UChar32 end); /** * Adds the given string to the given USet. After this call, * uset_containsString(set, str, strLen) will return TRUE. + * A frozen set will not be modified. * @param set the object to which to add the character * @param str the string to add * @param strLen the length of the string or -1 if null terminated. @@ -349,9 +570,22 @@ uset_addRange(USet* set, UChar32 start, UChar32 end); U_STABLE void U_EXPORT2 uset_addString(USet* set, const UChar* str, int32_t strLen); +/** + * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"} + * If this set already any particular character, it has no effect on that character. + * A frozen set will not be modified. + * @param set the object to which to add the character + * @param str the source string + * @param strLen the length of the string or -1 if null terminated. + * @stable ICU 3.4 + */ +U_STABLE void U_EXPORT2 +uset_addAllCodePoints(USet* set, const UChar *str, int32_t strLen); + /** * Removes the given character from the given USet. After this call, * uset_contains(set, c) will return FALSE. + * A frozen set will not be modified. * @param set the object from which to remove the character * @param c the character to remove * @stable ICU 2.4 @@ -362,6 +596,7 @@ uset_remove(USet* set, UChar32 c); /** * Removes the given range of characters from the given USet. After this call, * uset_contains(set, start, end) will return FALSE. + * A frozen set will not be modified. * @param set the object to which to add the character * @param start the first character of the range to remove, inclusive * @param end the last character of the range to remove, inclusive @@ -373,6 +608,7 @@ uset_removeRange(USet* set, UChar32 start, UChar32 end); /** * Removes the given string to the given USet. After this call, * uset_containsString(set, str, strLen) will return FALSE. + * A frozen set will not be modified. * @param set the object to which to add the character * @param str the string to remove * @param strLen the length of the string or -1 if null terminated. @@ -386,12 +622,13 @@ uset_removeString(USet* set, const UChar* str, int32_t strLen); * specified set. This operation effectively modifies this * set so that its value is the asymmetric set difference of * the two sets. + * A frozen set will not be modified. * @param set the object from which the elements are to be removed * @param removeSet the object that defines which elements will be * removed from this set - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT void U_EXPORT2 +U_STABLE void U_EXPORT2 uset_removeAll(USet* set, const USet* removeSet); /** @@ -399,15 +636,16 @@ uset_removeAll(USet* set, const USet* removeSet); * specified range. If start > end then an empty range is * retained, leaving the set empty. This is equivalent to * a boolean logic AND, or a set INTERSECTION. + * A frozen set will not be modified. * * @param set the object for which to retain only the specified range * @param start first character, inclusive, of range to be retained * to this set. * @param end last character, inclusive, of range to be retained * to this set. - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT void U_EXPORT2 +U_STABLE void U_EXPORT2 uset_retain(USet* set, UChar32 start, UChar32 end); /** @@ -416,28 +654,31 @@ uset_retain(USet* set, UChar32 start, UChar32 end); * its elements that are not contained in the specified set. This * operation effectively modifies this set so that its value is * the intersection of the two sets. + * A frozen set will not be modified. * * @param set the object on which to perform the retain * @param retain set that defines which elements this set will retain - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT void U_EXPORT2 +U_STABLE void U_EXPORT2 uset_retainAll(USet* set, const USet* retain); /** * Reallocate this objects internal structures to take up the least * possible space, without changing this object's value. + * A frozen set will not be modified. * * @param set the object on which to perfrom the compact - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT void U_EXPORT2 +U_STABLE void U_EXPORT2 uset_compact(USet* set); /** * Inverts this set. This operation modifies this set so that * its value is its complement. This operation does not affect * the multicharacter strings, if any. + * A frozen set will not be modified. * @param set the set * @stable ICU 2.4 */ @@ -448,24 +689,64 @@ uset_complement(USet* set); * Complements in this set all elements contained in the specified * set. Any character in the other set will be removed if it is * in this set, or will be added if it is not in this set. + * A frozen set will not be modified. * * @param set the set with which to complement * @param complement set that defines which elements will be xor'ed * from this set. - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT void U_EXPORT2 +U_STABLE void U_EXPORT2 uset_complementAll(USet* set, const USet* complement); /** * Removes all of the elements from this set. This set will be * empty after this call returns. + * A frozen set will not be modified. * @param set the set * @stable ICU 2.4 */ U_STABLE void U_EXPORT2 uset_clear(USet* set); +/** + * Close this set over the given attribute. For the attribute + * USET_CASE, the result is to modify this set so that: + * + * 1. For each character or string 'a' in this set, all strings or + * characters 'b' such that foldCase(a) == foldCase(b) are added + * to this set. + * + * 2. For each string 'e' in the resulting set, if e != + * foldCase(e), 'e' will be removed. + * + * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}] + * + * (Here foldCase(x) refers to the operation u_strFoldCase, and a + * == b denotes that the contents are the same, not pointer + * comparison.) + * + * A frozen set will not be modified. + * + * @param set the set + * + * @param attributes bitmask for attributes to close over. + * Currently only the USET_CASE bit is supported. Any undefined bits + * are ignored. + * @stable ICU 4.2 + */ +U_STABLE void U_EXPORT2 +uset_closeOver(USet* set, int32_t attributes); + +/** + * Remove all strings from this set. + * + * @param set the set + * @stable ICU 4.2 + */ +U_STABLE void U_EXPORT2 +uset_removeAllStrings(USet* set); + /** * Returns TRUE if the given USet contains no characters and no * strings. @@ -478,6 +759,7 @@ uset_isEmpty(const USet* set); /** * Returns TRUE if the given USet contains the given character. + * This function works faster with a frozen set. * @param set the set * @param c The codepoint to check for within the set * @return true if set contains c @@ -517,9 +799,9 @@ uset_containsString(const USet* set, const UChar* str, int32_t strLen); * @param set the set * @param c the character to obtain the index for * @return an index from 0..size()-1, or -1 - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT int32_t U_EXPORT2 +U_STABLE int32_t U_EXPORT2 uset_indexOf(const USet* set, UChar32 c); /** @@ -528,12 +810,12 @@ uset_indexOf(const USet* set, UChar32 c); * out of range, return (UChar32)-1. The inverse of this method is * indexOf(). * @param set the set - * @param index an index from 0..size()-1 to obtain the char for + * @param charIndex an index from 0..size()-1 to obtain the char for * @return the character at the given index, or (UChar32)-1. - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT UChar32 U_EXPORT2 -uset_charAt(const USet* set, int32_t index); +U_STABLE UChar32 U_EXPORT2 +uset_charAt(const USet* set, int32_t charIndex); /** * Returns the number of characters and strings contained in the given @@ -583,24 +865,37 @@ uset_getItem(const USet* set, int32_t itemIndex, /** * Returns true if set1 contains all the characters and strings - * of set2. It answers the question, 'Is set1 a subset of set2?' + * of set2. It answers the question, 'Is set1 a superset of set2?' * @param set1 set to be checked for containment * @param set2 set to be checked for containment * @return true if the test condition is met - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT UBool U_EXPORT2 +U_STABLE UBool U_EXPORT2 uset_containsAll(const USet* set1, const USet* set2); +/** + * Returns true if this set contains all the characters + * of the given string. This is does not check containment of grapheme + * clusters, like uset_containsString. + * @param set set of characters to be checked for containment + * @param str string containing codepoints to be checked for containment + * @param strLen the length of the string or -1 if null terminated. + * @return true if the test condition is met + * @stable ICU 3.4 + */ +U_STABLE UBool U_EXPORT2 +uset_containsAllCodePoints(const USet* set, const UChar *str, int32_t strLen); + /** * Returns true if set1 contains none of the characters and strings * of set2. It answers the question, 'Is set1 a disjoint set of set2?' * @param set1 set to be checked for containment * @param set2 set to be checked for containment * @return true if the test condition is met - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT UBool U_EXPORT2 +U_STABLE UBool U_EXPORT2 uset_containsNone(const USet* set1, const USet* set2); /** @@ -609,20 +904,106 @@ uset_containsNone(const USet* set1, const USet* set2); * @param set1 set to be checked for containment * @param set2 set to be checked for containment * @return true if the test condition is met - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT UBool U_EXPORT2 +U_STABLE UBool U_EXPORT2 uset_containsSome(const USet* set1, const USet* set2); +/** + * Returns the length of the initial substring of the input string which + * consists only of characters and strings that are contained in this set + * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), + * or only of characters and strings that are not contained + * in this set (USET_SPAN_NOT_CONTAINED). + * See USetSpanCondition for details. + * Similar to the strspn() C library function. + * Unpaired surrogates are treated according to contains() of their surrogate code points. + * This function works faster with a frozen set and with a non-negative string length argument. + * @param set the set + * @param s start of the string + * @param length of the string; can be -1 for NUL-terminated + * @param spanCondition specifies the containment condition + * @return the length of the initial substring according to the spanCondition; + * 0 if the start of the string does not fit the spanCondition + * @stable ICU 3.8 + * @see USetSpanCondition + */ +U_STABLE int32_t U_EXPORT2 +uset_span(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition); + +/** + * Returns the start of the trailing substring of the input string which + * consists only of characters and strings that are contained in this set + * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), + * or only of characters and strings that are not contained + * in this set (USET_SPAN_NOT_CONTAINED). + * See USetSpanCondition for details. + * Unpaired surrogates are treated according to contains() of their surrogate code points. + * This function works faster with a frozen set and with a non-negative string length argument. + * @param set the set + * @param s start of the string + * @param length of the string; can be -1 for NUL-terminated + * @param spanCondition specifies the containment condition + * @return the start of the trailing substring according to the spanCondition; + * the string length if the end of the string does not fit the spanCondition + * @stable ICU 3.8 + * @see USetSpanCondition + */ +U_STABLE int32_t U_EXPORT2 +uset_spanBack(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition); + +/** + * Returns the length of the initial substring of the input string which + * consists only of characters and strings that are contained in this set + * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), + * or only of characters and strings that are not contained + * in this set (USET_SPAN_NOT_CONTAINED). + * See USetSpanCondition for details. + * Similar to the strspn() C library function. + * Malformed byte sequences are treated according to contains(0xfffd). + * This function works faster with a frozen set and with a non-negative string length argument. + * @param set the set + * @param s start of the string (UTF-8) + * @param length of the string; can be -1 for NUL-terminated + * @param spanCondition specifies the containment condition + * @return the length of the initial substring according to the spanCondition; + * 0 if the start of the string does not fit the spanCondition + * @stable ICU 3.8 + * @see USetSpanCondition + */ +U_STABLE int32_t U_EXPORT2 +uset_spanUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition); + +/** + * Returns the start of the trailing substring of the input string which + * consists only of characters and strings that are contained in this set + * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), + * or only of characters and strings that are not contained + * in this set (USET_SPAN_NOT_CONTAINED). + * See USetSpanCondition for details. + * Malformed byte sequences are treated according to contains(0xfffd). + * This function works faster with a frozen set and with a non-negative string length argument. + * @param set the set + * @param s start of the string (UTF-8) + * @param length of the string; can be -1 for NUL-terminated + * @param spanCondition specifies the containment condition + * @return the start of the trailing substring according to the spanCondition; + * the string length if the end of the string does not fit the spanCondition + * @stable ICU 3.8 + * @see USetSpanCondition + */ +U_STABLE int32_t U_EXPORT2 +uset_spanBackUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition); + /** * Returns true if set1 contains all of the characters and strings * of set2, and vis versa. It answers the question, 'Is set1 equal to set2?' * @param set1 set to be checked for containment * @param set2 set to be checked for containment * @return true if the test condition is met - * @draft ICU 3.2 + * @stable ICU 3.2 */ -U_DRAFT UBool U_EXPORT2 +U_STABLE UBool U_EXPORT2 uset_equals(const USet* set1, const USet* set2); /*********************************************************************