michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 2002-2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: uset.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2002mar07 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * C version of UnicodeSet. michael@0: */ michael@0: michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Unicode Set michael@0: * michael@0: *

This is a C wrapper around the C++ UnicodeSet class.

michael@0: */ michael@0: michael@0: #ifndef __USET_H__ michael@0: #define __USET_H__ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uchar.h" michael@0: #include "unicode/localpointer.h" michael@0: michael@0: #ifndef UCNV_H michael@0: struct USet; michael@0: /** michael@0: * A UnicodeSet. Use the uset_* API to manipulate. Create with michael@0: * uset_open*, and destroy with uset_close. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: typedef struct USet USet; michael@0: #endif michael@0: michael@0: /** michael@0: * Bitmask values to be passed to uset_openPatternOptions() or michael@0: * uset_applyPattern() taking an option parameter. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: enum { michael@0: /** michael@0: * Ignore white space within patterns unless quoted or escaped. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: USET_IGNORE_SPACE = 1, michael@0: michael@0: /** michael@0: * Enable case insensitive matching. E.g., "[ab]" with this flag michael@0: * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will michael@0: * match all except 'a', 'A', 'b', and 'B'. This performs a full michael@0: * closure over case mappings, e.g. U+017F for s. michael@0: * michael@0: * The resulting set is a superset of the input for the code points but michael@0: * not for the strings. michael@0: * It performs a case mapping closure of the code points and adds michael@0: * full case folding strings for the code points, and reduces strings of michael@0: * the original set to their full case folding equivalents. michael@0: * michael@0: * This is designed for case-insensitive matches, for example michael@0: * in regular expressions. The full code point case closure allows checking of michael@0: * an input character directly against the closure set. michael@0: * Strings are matched by comparing the case-folded form from the closure michael@0: * set with an incremental case folding of the string in question. michael@0: * michael@0: * The closure set will also contain single code points if the original michael@0: * set contained case-equivalent strings (like U+00DF for "ss" or "Ss" etc.). michael@0: * This is not necessary (that is, redundant) for the above matching method michael@0: * but results in the same closure sets regardless of whether the original michael@0: * set contained the code point or a string. michael@0: * michael@0: * @stable ICU 2.4 michael@0: */ michael@0: USET_CASE_INSENSITIVE = 2, michael@0: michael@0: /** michael@0: * Enable case insensitive matching. E.g., "[ab]" with this flag michael@0: * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will michael@0: * match all except 'a', 'A', 'b', and 'B'. This adds the lower-, michael@0: * title-, and uppercase mappings as well as the case folding michael@0: * of each existing element in the set. michael@0: * @stable ICU 3.2 michael@0: */ michael@0: USET_ADD_CASE_MAPPINGS = 4 michael@0: }; michael@0: michael@0: /** michael@0: * Argument values for whether span() and similar functions continue while michael@0: * the current character is contained vs. not contained in the set. michael@0: * michael@0: * The functionality is straightforward for sets with only single code points, michael@0: * without strings (which is the common case): michael@0: * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE michael@0: * work the same. michael@0: * - span() and spanBack() partition any string the same way when michael@0: * alternating between span(USET_SPAN_NOT_CONTAINED) and michael@0: * span(either "contained" condition). michael@0: * - Using a complemented (inverted) set and the opposite span conditions michael@0: * yields the same results. michael@0: * michael@0: * When a set contains multi-code point strings, then these statements may not michael@0: * be true, depending on the strings in the set (for example, whether they michael@0: * overlap with each other) and the string that is processed. michael@0: * For a set with strings: michael@0: * - The complement of the set contains the opposite set of code points, michael@0: * but the same set of strings. michael@0: * Therefore, complementing both the set and the span conditions michael@0: * may yield different results. michael@0: * - When starting spans at different positions in a string michael@0: * (span(s, ...) vs. span(s+1, ...)) the ends of the spans may be different michael@0: * because a set string may start before the later position. michael@0: * - span(USET_SPAN_SIMPLE) may be shorter than michael@0: * span(USET_SPAN_CONTAINED) because it will not recursively try michael@0: * all possible paths. michael@0: * For example, with a set which contains the three strings "xy", "xya" and "ax", michael@0: * span("xyax", USET_SPAN_CONTAINED) will return 4 but michael@0: * span("xyax", USET_SPAN_SIMPLE) will return 3. michael@0: * span(USET_SPAN_SIMPLE) will never be longer than michael@0: * span(USET_SPAN_CONTAINED). michael@0: * - With either "contained" condition, span() and spanBack() may partition michael@0: * a string in different ways. michael@0: * For example, with a set which contains the two strings "ab" and "ba", michael@0: * and when processing the string "aba", michael@0: * span() will yield contained/not-contained boundaries of { 0, 2, 3 } michael@0: * while spanBack() will yield boundaries of { 0, 1, 3 }. michael@0: * michael@0: * Note: If it is important to get the same boundaries whether iterating forward michael@0: * or backward through a string, then either only span() should be used and michael@0: * the boundaries cached for backward operation, or an ICU BreakIterator michael@0: * could be used. michael@0: * michael@0: * Note: Unpaired surrogates are treated like surrogate code points. michael@0: * Similarly, set strings match only on code point boundaries, michael@0: * never in the middle of a surrogate pair. michael@0: * Illegal UTF-8 sequences are treated like U+FFFD. michael@0: * When processing UTF-8 strings, malformed set strings michael@0: * (strings with unpaired surrogates which cannot be converted to UTF-8) michael@0: * are ignored. michael@0: * michael@0: * @stable ICU 3.8 michael@0: */ michael@0: typedef enum USetSpanCondition { michael@0: /** michael@0: * Continue a span() while there is no set element at the current position. michael@0: * Stops before the first set element (character or string). michael@0: * (For code points only, this is like while contains(current)==FALSE). michael@0: * michael@0: * When span() returns, the substring between where it started and the position michael@0: * it returned consists only of characters that are not in the set, michael@0: * and none of its strings overlap with the span. michael@0: * michael@0: * @stable ICU 3.8 michael@0: */ michael@0: USET_SPAN_NOT_CONTAINED = 0, michael@0: /** michael@0: * Continue a span() while there is a set element at the current position. michael@0: * (For characters only, this is like while contains(current)==TRUE). michael@0: * michael@0: * When span() returns, the substring between where it started and the position michael@0: * it returned consists only of set elements (characters or strings) that are in the set. michael@0: * michael@0: * If a set contains strings, then the span will be the longest substring michael@0: * matching any of the possible concatenations of set elements (characters or strings). michael@0: * (There must be a single, non-overlapping concatenation of characters or strings.) michael@0: * This is equivalent to a POSIX regular expression for (OR of each set element)*. michael@0: * michael@0: * @stable ICU 3.8 michael@0: */ michael@0: USET_SPAN_CONTAINED = 1, michael@0: /** michael@0: * Continue a span() while there is a set element at the current position. michael@0: * (For characters only, this is like while contains(current)==TRUE). michael@0: * michael@0: * When span() returns, the substring between where it started and the position michael@0: * it returned consists only of set elements (characters or strings) that are in the set. michael@0: * michael@0: * If a set only contains single characters, then this is the same michael@0: * as USET_SPAN_CONTAINED. michael@0: * michael@0: * If a set contains strings, then the span will be the longest substring michael@0: * with a match at each position with the longest single set element (character or string). michael@0: * michael@0: * Use this span condition together with other longest-match algorithms, michael@0: * such as ICU converters (ucnv_getUnicodeSet()). michael@0: * michael@0: * @stable ICU 3.8 michael@0: */ michael@0: USET_SPAN_SIMPLE = 2, michael@0: /** michael@0: * One more than the last span condition. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: USET_SPAN_CONDITION_COUNT michael@0: } USetSpanCondition; michael@0: michael@0: enum { michael@0: /** michael@0: * Capacity of USerializedSet::staticArray. michael@0: * Enough for any single-code point set. michael@0: * Also provides padding for nice sizeof(USerializedSet). michael@0: * @stable ICU 2.4 michael@0: */ michael@0: USET_SERIALIZED_STATIC_ARRAY_CAPACITY=8 michael@0: }; michael@0: michael@0: /** michael@0: * A serialized form of a Unicode set. Limited manipulations are michael@0: * possible directly on a serialized set. See below. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: typedef struct USerializedSet { michael@0: /** michael@0: * The serialized Unicode Set. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: const uint16_t *array; michael@0: /** michael@0: * The length of the array that contains BMP characters. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: int32_t bmpLength; michael@0: /** michael@0: * The total length of the array. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: int32_t length; michael@0: /** michael@0: * A small buffer for the array to reduce memory allocations. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: uint16_t staticArray[USET_SERIALIZED_STATIC_ARRAY_CAPACITY]; michael@0: } USerializedSet; michael@0: michael@0: /********************************************************************* michael@0: * USet API michael@0: *********************************************************************/ michael@0: michael@0: /** michael@0: * Create an empty USet object. michael@0: * Equivalent to uset_open(1, 0). michael@0: * @return a newly created USet. The caller must call uset_close() on michael@0: * it when done. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: U_STABLE USet* U_EXPORT2 michael@0: uset_openEmpty(void); michael@0: michael@0: /** michael@0: * Creates a USet object that contains the range of characters michael@0: * start..end, inclusive. If start > end michael@0: * then an empty set is created (same as using uset_openEmpty()). michael@0: * @param start first character of the range, inclusive michael@0: * @param end last character of the range, inclusive michael@0: * @return a newly created USet. The caller must call uset_close() on michael@0: * it when done. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE USet* U_EXPORT2 michael@0: uset_open(UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Creates a set from the given pattern. See the UnicodeSet class michael@0: * description for the syntax of the pattern language. michael@0: * @param pattern a string specifying what characters are in the set michael@0: * @param patternLength the length of the pattern, or -1 if null michael@0: * terminated michael@0: * @param ec the error code michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE USet* U_EXPORT2 michael@0: uset_openPattern(const UChar* pattern, int32_t patternLength, michael@0: UErrorCode* ec); michael@0: michael@0: /** michael@0: * Creates a set from the given pattern. See the UnicodeSet class michael@0: * description for the syntax of the pattern language. michael@0: * @param pattern a string specifying what characters are in the set michael@0: * @param patternLength the length of the pattern, or -1 if null michael@0: * terminated michael@0: * @param options bitmask for options to apply to the pattern. michael@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. michael@0: * @param ec the error code michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE USet* U_EXPORT2 michael@0: uset_openPatternOptions(const UChar* pattern, int32_t patternLength, michael@0: uint32_t options, michael@0: UErrorCode* ec); michael@0: michael@0: /** michael@0: * Disposes of the storage used by a USet object. This function should michael@0: * be called exactly once for objects returned by uset_open(). michael@0: * @param set the object to dispose of michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_close(USet* set); michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * \class LocalUSetPointer michael@0: * "Smart pointer" class, closes a USet via uset_close(). michael@0: * For most methods see the LocalPointerBase base class. michael@0: * michael@0: * @see LocalPointerBase michael@0: * @see LocalPointer michael@0: * @stable ICU 4.4 michael@0: */ michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalUSetPointer, USet, uset_close); michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Returns a copy of this object. michael@0: * If this set is frozen, then the clone will be frozen as well. michael@0: * Use uset_cloneAsThawed() for a mutable clone of a frozen set. michael@0: * @param set the original set michael@0: * @return the newly allocated copy of the set michael@0: * @see uset_cloneAsThawed michael@0: * @stable ICU 3.8 michael@0: */ michael@0: U_STABLE USet * U_EXPORT2 michael@0: uset_clone(const USet *set); michael@0: michael@0: /** michael@0: * Determines whether the set has been frozen (made immutable) or not. michael@0: * See the ICU4J Freezable interface for details. michael@0: * @param set the set michael@0: * @return TRUE/FALSE for whether the set has been frozen michael@0: * @see uset_freeze michael@0: * @see uset_cloneAsThawed michael@0: * @stable ICU 3.8 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_isFrozen(const USet *set); michael@0: michael@0: /** michael@0: * Freeze the set (make it immutable). michael@0: * Once frozen, it cannot be unfrozen and is therefore thread-safe michael@0: * until it is deleted. michael@0: * See the ICU4J Freezable interface for details. michael@0: * Freezing the set may also make some operations faster, for example michael@0: * uset_contains() and uset_span(). michael@0: * A frozen set will not be modified. (It remains frozen.) michael@0: * @param set the set michael@0: * @return the same set, now frozen michael@0: * @see uset_isFrozen michael@0: * @see uset_cloneAsThawed michael@0: * @stable ICU 3.8 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_freeze(USet *set); michael@0: michael@0: /** michael@0: * Clone the set and make the clone mutable. michael@0: * See the ICU4J Freezable interface for details. michael@0: * @param set the set michael@0: * @return the mutable clone michael@0: * @see uset_freeze michael@0: * @see uset_isFrozen michael@0: * @see uset_clone michael@0: * @stable ICU 3.8 michael@0: */ michael@0: U_STABLE USet * U_EXPORT2 michael@0: uset_cloneAsThawed(const USet *set); michael@0: michael@0: /** michael@0: * Causes the USet object to represent the range start - end. michael@0: * If start > end then this USet is set to an empty range. michael@0: * A frozen set will not be modified. michael@0: * @param set the object to set to the given range michael@0: * @param start first character in the set, inclusive michael@0: * @param end last character in the set, inclusive michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_set(USet* set, michael@0: UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Modifies the set to represent the set specified by the given michael@0: * pattern. See the UnicodeSet class description for the syntax of michael@0: * the pattern language. See also the User Guide chapter about UnicodeSet. michael@0: * Empties the set passed before applying the pattern. michael@0: * A frozen set will not be modified. michael@0: * @param set The set to which the pattern is to be applied. michael@0: * @param pattern A pointer to UChar string specifying what characters are in the set. michael@0: * The character at pattern[0] must be a '['. michael@0: * @param patternLength The length of the UChar string. -1 if NUL terminated. michael@0: * @param options A bitmask for options to apply to the pattern. michael@0: * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE. michael@0: * @param status Returns an error if the pattern cannot be parsed. michael@0: * @return Upon successful parse, the value is either michael@0: * the index of the character after the closing ']' michael@0: * of the parsed pattern. michael@0: * If the status code indicates failure, then the return value michael@0: * is the index of the error in the source. michael@0: * michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_applyPattern(USet *set, michael@0: const UChar *pattern, int32_t patternLength, michael@0: uint32_t options, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Modifies the set to contain those code points which have the given value michael@0: * for the given binary or enumerated property, as returned by michael@0: * u_getIntPropertyValue. Prior contents of this set are lost. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param set the object to contain the code points defined by the property michael@0: * michael@0: * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1 michael@0: * or UCHAR_INT_START..UCHAR_INT_LIMIT-1 michael@0: * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1. michael@0: * michael@0: * @param value a value in the range u_getIntPropertyMinValue(prop).. michael@0: * u_getIntPropertyMaxValue(prop), with one exception. If prop is michael@0: * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but michael@0: * rather a mask value produced by U_GET_GC_MASK(). This allows grouped michael@0: * categories such as [:L:] to be represented. michael@0: * michael@0: * @param ec error code input/output parameter michael@0: * michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_applyIntPropertyValue(USet* set, michael@0: UProperty prop, int32_t value, UErrorCode* ec); michael@0: michael@0: /** michael@0: * Modifies the set to contain those code points which have the michael@0: * given value for the given property. Prior contents of this michael@0: * set are lost. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param set the object to contain the code points defined by the given michael@0: * property and value alias michael@0: * michael@0: * @param prop a string specifying a property alias, either short or long. michael@0: * The name is matched loosely. See PropertyAliases.txt for names and a michael@0: * description of loose matching. If the value string is empty, then this michael@0: * string is interpreted as either a General_Category value alias, a Script michael@0: * value alias, a binary property alias, or a special ID. Special IDs are michael@0: * matched loosely and correspond to the following sets: michael@0: * michael@0: * "ANY" = [\\u0000-\\U0010FFFF], michael@0: * "ASCII" = [\\u0000-\\u007F], michael@0: * "Assigned" = [:^Cn:]. michael@0: * michael@0: * @param propLength the length of the prop, or -1 if NULL michael@0: * michael@0: * @param value a string specifying a value alias, either short or long. michael@0: * The name is matched loosely. See PropertyValueAliases.txt for names michael@0: * and a description of loose matching. In addition to aliases listed, michael@0: * numeric values and canonical combining classes may be expressed michael@0: * numerically, e.g., ("nv", "0.5") or ("ccc", "220"). The value string michael@0: * may also be empty. michael@0: * michael@0: * @param valueLength the length of the value, or -1 if NULL michael@0: * michael@0: * @param ec error code input/output parameter michael@0: * michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_applyPropertyAlias(USet* set, michael@0: const UChar *prop, int32_t propLength, michael@0: const UChar *value, int32_t valueLength, michael@0: UErrorCode* ec); michael@0: michael@0: /** michael@0: * Return true if the given position, in the given pattern, appears michael@0: * to be the start of a UnicodeSet pattern. michael@0: * michael@0: * @param pattern a string specifying the pattern michael@0: * @param patternLength the length of the pattern, or -1 if NULL michael@0: * @param pos the given position michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_resemblesPattern(const UChar *pattern, int32_t patternLength, michael@0: int32_t pos); michael@0: michael@0: /** michael@0: * Returns a string representation of this set. If the result of michael@0: * calling this function is passed to a uset_openPattern(), it michael@0: * will produce another set that is equal to this one. michael@0: * @param set the set michael@0: * @param result the string to receive the rules, may be NULL michael@0: * @param resultCapacity the capacity of result, may be 0 if result is NULL michael@0: * @param escapeUnprintable if TRUE then convert unprintable michael@0: * character to their hex escape representations, \\uxxxx or michael@0: * \\Uxxxxxxxx. Unprintable characters are those other than michael@0: * U+000A, U+0020..U+007E. michael@0: * @param ec error code. michael@0: * @return length of string, possibly larger than resultCapacity michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_toPattern(const USet* set, michael@0: UChar* result, int32_t resultCapacity, michael@0: UBool escapeUnprintable, michael@0: UErrorCode* ec); michael@0: michael@0: /** michael@0: * Adds the given character to the given USet. After this call, michael@0: * uset_contains(set, c) will return TRUE. michael@0: * A frozen set will not be modified. michael@0: * @param set the object to which to add the character michael@0: * @param c the character to add michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_add(USet* set, UChar32 c); michael@0: michael@0: /** michael@0: * Adds all of the elements in the specified set to this set if michael@0: * they're not already present. This operation effectively michael@0: * modifies this set so that its value is the union of the two michael@0: * sets. The behavior of this operation is unspecified if the specified michael@0: * collection is modified while the operation is in progress. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param set the object to which to add the set michael@0: * @param additionalSet the source set whose elements are to be added to this set. michael@0: * @stable ICU 2.6 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_addAll(USet* set, const USet *additionalSet); michael@0: michael@0: /** michael@0: * Adds the given range of characters to the given USet. After this call, michael@0: * uset_contains(set, start, end) will return TRUE. michael@0: * A frozen set will not be modified. michael@0: * @param set the object to which to add the character michael@0: * @param start the first character of the range to add, inclusive michael@0: * @param end the last character of the range to add, inclusive michael@0: * @stable ICU 2.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_addRange(USet* set, UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Adds the given string to the given USet. After this call, michael@0: * uset_containsString(set, str, strLen) will return TRUE. michael@0: * A frozen set will not be modified. michael@0: * @param set the object to which to add the character michael@0: * @param str the string to add michael@0: * @param strLen the length of the string or -1 if null terminated. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_addString(USet* set, const UChar* str, int32_t strLen); michael@0: michael@0: /** michael@0: * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"} michael@0: * If this set already any particular character, it has no effect on that character. michael@0: * A frozen set will not be modified. michael@0: * @param set the object to which to add the character michael@0: * @param str the source string michael@0: * @param strLen the length of the string or -1 if null terminated. michael@0: * @stable ICU 3.4 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_addAllCodePoints(USet* set, const UChar *str, int32_t strLen); michael@0: michael@0: /** michael@0: * Removes the given character from the given USet. After this call, michael@0: * uset_contains(set, c) will return FALSE. michael@0: * A frozen set will not be modified. michael@0: * @param set the object from which to remove the character michael@0: * @param c the character to remove michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_remove(USet* set, UChar32 c); michael@0: michael@0: /** michael@0: * Removes the given range of characters from the given USet. After this call, michael@0: * uset_contains(set, start, end) will return FALSE. michael@0: * A frozen set will not be modified. michael@0: * @param set the object to which to add the character michael@0: * @param start the first character of the range to remove, inclusive michael@0: * @param end the last character of the range to remove, inclusive michael@0: * @stable ICU 2.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_removeRange(USet* set, UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Removes the given string to the given USet. After this call, michael@0: * uset_containsString(set, str, strLen) will return FALSE. michael@0: * A frozen set will not be modified. michael@0: * @param set the object to which to add the character michael@0: * @param str the string to remove michael@0: * @param strLen the length of the string or -1 if null terminated. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_removeString(USet* set, const UChar* str, int32_t strLen); michael@0: michael@0: /** michael@0: * Removes from this set all of its elements that are contained in the michael@0: * specified set. This operation effectively modifies this michael@0: * set so that its value is the asymmetric set difference of michael@0: * the two sets. michael@0: * A frozen set will not be modified. michael@0: * @param set the object from which the elements are to be removed michael@0: * @param removeSet the object that defines which elements will be michael@0: * removed from this set michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_removeAll(USet* set, const USet* removeSet); michael@0: michael@0: /** michael@0: * Retain only the elements in this set that are contained in the michael@0: * specified range. If start > end then an empty range is michael@0: * retained, leaving the set empty. This is equivalent to michael@0: * a boolean logic AND, or a set INTERSECTION. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param set the object for which to retain only the specified range michael@0: * @param start first character, inclusive, of range to be retained michael@0: * to this set. michael@0: * @param end last character, inclusive, of range to be retained michael@0: * to this set. michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_retain(USet* set, UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Retains only the elements in this set that are contained in the michael@0: * specified set. In other words, removes from this set all of michael@0: * its elements that are not contained in the specified set. This michael@0: * operation effectively modifies this set so that its value is michael@0: * the intersection of the two sets. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param set the object on which to perform the retain michael@0: * @param retain set that defines which elements this set will retain michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_retainAll(USet* set, const USet* retain); michael@0: michael@0: /** michael@0: * Reallocate this objects internal structures to take up the least michael@0: * possible space, without changing this object's value. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param set the object on which to perfrom the compact michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_compact(USet* set); michael@0: michael@0: /** michael@0: * Inverts this set. This operation modifies this set so that michael@0: * its value is its complement. This operation does not affect michael@0: * the multicharacter strings, if any. michael@0: * A frozen set will not be modified. michael@0: * @param set the set michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_complement(USet* set); michael@0: michael@0: /** michael@0: * Complements in this set all elements contained in the specified michael@0: * set. Any character in the other set will be removed if it is michael@0: * in this set, or will be added if it is not in this set. michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param set the set with which to complement michael@0: * @param complement set that defines which elements will be xor'ed michael@0: * from this set. michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_complementAll(USet* set, const USet* complement); michael@0: michael@0: /** michael@0: * Removes all of the elements from this set. This set will be michael@0: * empty after this call returns. michael@0: * A frozen set will not be modified. michael@0: * @param set the set michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_clear(USet* set); michael@0: michael@0: /** michael@0: * Close this set over the given attribute. For the attribute michael@0: * USET_CASE, the result is to modify this set so that: michael@0: * michael@0: * 1. For each character or string 'a' in this set, all strings or michael@0: * characters 'b' such that foldCase(a) == foldCase(b) are added michael@0: * to this set. michael@0: * michael@0: * 2. For each string 'e' in the resulting set, if e != michael@0: * foldCase(e), 'e' will be removed. michael@0: * michael@0: * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}] michael@0: * michael@0: * (Here foldCase(x) refers to the operation u_strFoldCase, and a michael@0: * == b denotes that the contents are the same, not pointer michael@0: * comparison.) michael@0: * michael@0: * A frozen set will not be modified. michael@0: * michael@0: * @param set the set michael@0: * michael@0: * @param attributes bitmask for attributes to close over. michael@0: * Currently only the USET_CASE bit is supported. Any undefined bits michael@0: * are ignored. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_closeOver(USet* set, int32_t attributes); michael@0: michael@0: /** michael@0: * Remove all strings from this set. michael@0: * michael@0: * @param set the set michael@0: * @stable ICU 4.2 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_removeAllStrings(USet* set); michael@0: michael@0: /** michael@0: * Returns TRUE if the given USet contains no characters and no michael@0: * strings. michael@0: * @param set the set michael@0: * @return true if set is empty michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_isEmpty(const USet* set); michael@0: michael@0: /** michael@0: * Returns TRUE if the given USet contains the given character. michael@0: * This function works faster with a frozen set. michael@0: * @param set the set michael@0: * @param c The codepoint to check for within the set michael@0: * @return true if set contains c michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_contains(const USet* set, UChar32 c); michael@0: michael@0: /** michael@0: * Returns TRUE if the given USet contains all characters c michael@0: * where start <= c && c <= end. michael@0: * @param set the set michael@0: * @param start the first character of the range to test, inclusive michael@0: * @param end the last character of the range to test, inclusive michael@0: * @return TRUE if set contains the range michael@0: * @stable ICU 2.2 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_containsRange(const USet* set, UChar32 start, UChar32 end); michael@0: michael@0: /** michael@0: * Returns TRUE if the given USet contains the given string. michael@0: * @param set the set michael@0: * @param str the string michael@0: * @param strLen the length of the string or -1 if null terminated. michael@0: * @return true if set contains str michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_containsString(const USet* set, const UChar* str, int32_t strLen); michael@0: michael@0: /** michael@0: * Returns the index of the given character within this set, where michael@0: * the set is ordered by ascending code point. If the character michael@0: * is not in this set, return -1. The inverse of this method is michael@0: * charAt(). michael@0: * @param set the set michael@0: * @param c the character to obtain the index for michael@0: * @return an index from 0..size()-1, or -1 michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_indexOf(const USet* set, UChar32 c); michael@0: michael@0: /** michael@0: * Returns the character at the given index within this set, where michael@0: * the set is ordered by ascending code point. If the index is michael@0: * out of range, return (UChar32)-1. The inverse of this method is michael@0: * indexOf(). michael@0: * @param set the set michael@0: * @param charIndex an index from 0..size()-1 to obtain the char for michael@0: * @return the character at the given index, or (UChar32)-1. michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE UChar32 U_EXPORT2 michael@0: uset_charAt(const USet* set, int32_t charIndex); michael@0: michael@0: /** michael@0: * Returns the number of characters and strings contained in the given michael@0: * USet. michael@0: * @param set the set michael@0: * @return a non-negative integer counting the characters and strings michael@0: * contained in set michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_size(const USet* set); michael@0: michael@0: /** michael@0: * Returns the number of items in this set. An item is either a range michael@0: * of characters or a single multicharacter string. michael@0: * @param set the set michael@0: * @return a non-negative integer counting the character ranges michael@0: * and/or strings contained in set michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_getItemCount(const USet* set); michael@0: michael@0: /** michael@0: * Returns an item of this set. An item is either a range of michael@0: * characters or a single multicharacter string. michael@0: * @param set the set michael@0: * @param itemIndex a non-negative integer in the range 0.. michael@0: * uset_getItemCount(set)-1 michael@0: * @param start pointer to variable to receive first character michael@0: * in range, inclusive michael@0: * @param end pointer to variable to receive last character in range, michael@0: * inclusive michael@0: * @param str buffer to receive the string, may be NULL michael@0: * @param strCapacity capacity of str, or 0 if str is NULL michael@0: * @param ec error code michael@0: * @return the length of the string (>= 2), or 0 if the item is a michael@0: * range, in which case it is the range *start..*end, or -1 if michael@0: * itemIndex is out of range michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_getItem(const USet* set, int32_t itemIndex, michael@0: UChar32* start, UChar32* end, michael@0: UChar* str, int32_t strCapacity, michael@0: UErrorCode* ec); michael@0: michael@0: /** michael@0: * Returns true if set1 contains all the characters and strings michael@0: * of set2. It answers the question, 'Is set1 a superset of set2?' michael@0: * @param set1 set to be checked for containment michael@0: * @param set2 set to be checked for containment michael@0: * @return true if the test condition is met michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_containsAll(const USet* set1, const USet* set2); michael@0: michael@0: /** michael@0: * Returns true if this set contains all the characters michael@0: * of the given string. This is does not check containment of grapheme michael@0: * clusters, like uset_containsString. michael@0: * @param set set of characters to be checked for containment michael@0: * @param str string containing codepoints to be checked for containment michael@0: * @param strLen the length of the string or -1 if null terminated. michael@0: * @return true if the test condition is met michael@0: * @stable ICU 3.4 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_containsAllCodePoints(const USet* set, const UChar *str, int32_t strLen); michael@0: michael@0: /** michael@0: * Returns true if set1 contains none of the characters and strings michael@0: * of set2. It answers the question, 'Is set1 a disjoint set of set2?' michael@0: * @param set1 set to be checked for containment michael@0: * @param set2 set to be checked for containment michael@0: * @return true if the test condition is met michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_containsNone(const USet* set1, const USet* set2); michael@0: michael@0: /** michael@0: * Returns true if set1 contains some of the characters and strings michael@0: * of set2. It answers the question, 'Does set1 and set2 have an intersection?' michael@0: * @param set1 set to be checked for containment michael@0: * @param set2 set to be checked for containment michael@0: * @return true if the test condition is met michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_containsSome(const USet* set1, const USet* set2); michael@0: michael@0: /** michael@0: * Returns the length of the initial substring of the input string which michael@0: * consists only of characters and strings that are contained in this set michael@0: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), michael@0: * or only of characters and strings that are not contained michael@0: * in this set (USET_SPAN_NOT_CONTAINED). michael@0: * See USetSpanCondition for details. michael@0: * Similar to the strspn() C library function. michael@0: * Unpaired surrogates are treated according to contains() of their surrogate code points. michael@0: * This function works faster with a frozen set and with a non-negative string length argument. michael@0: * @param set the set michael@0: * @param s start of the string michael@0: * @param length of the string; can be -1 for NUL-terminated michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the length of the initial substring according to the spanCondition; michael@0: * 0 if the start of the string does not fit the spanCondition michael@0: * @stable ICU 3.8 michael@0: * @see USetSpanCondition michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_span(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition); michael@0: michael@0: /** michael@0: * Returns the start of the trailing substring of the input string which michael@0: * consists only of characters and strings that are contained in this set michael@0: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), michael@0: * or only of characters and strings that are not contained michael@0: * in this set (USET_SPAN_NOT_CONTAINED). michael@0: * See USetSpanCondition for details. michael@0: * Unpaired surrogates are treated according to contains() of their surrogate code points. michael@0: * This function works faster with a frozen set and with a non-negative string length argument. michael@0: * @param set the set michael@0: * @param s start of the string michael@0: * @param length of the string; can be -1 for NUL-terminated michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the start of the trailing substring according to the spanCondition; michael@0: * the string length if the end of the string does not fit the spanCondition michael@0: * @stable ICU 3.8 michael@0: * @see USetSpanCondition michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_spanBack(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition); michael@0: michael@0: /** michael@0: * Returns the length of the initial substring of the input string which michael@0: * consists only of characters and strings that are contained in this set michael@0: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), michael@0: * or only of characters and strings that are not contained michael@0: * in this set (USET_SPAN_NOT_CONTAINED). michael@0: * See USetSpanCondition for details. michael@0: * Similar to the strspn() C library function. michael@0: * Malformed byte sequences are treated according to contains(0xfffd). michael@0: * This function works faster with a frozen set and with a non-negative string length argument. michael@0: * @param set the set michael@0: * @param s start of the string (UTF-8) michael@0: * @param length of the string; can be -1 for NUL-terminated michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the length of the initial substring according to the spanCondition; michael@0: * 0 if the start of the string does not fit the spanCondition michael@0: * @stable ICU 3.8 michael@0: * @see USetSpanCondition michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_spanUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition); michael@0: michael@0: /** michael@0: * Returns the start of the trailing substring of the input string which michael@0: * consists only of characters and strings that are contained in this set michael@0: * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE), michael@0: * or only of characters and strings that are not contained michael@0: * in this set (USET_SPAN_NOT_CONTAINED). michael@0: * See USetSpanCondition for details. michael@0: * Malformed byte sequences are treated according to contains(0xfffd). michael@0: * This function works faster with a frozen set and with a non-negative string length argument. michael@0: * @param set the set michael@0: * @param s start of the string (UTF-8) michael@0: * @param length of the string; can be -1 for NUL-terminated michael@0: * @param spanCondition specifies the containment condition michael@0: * @return the start of the trailing substring according to the spanCondition; michael@0: * the string length if the end of the string does not fit the spanCondition michael@0: * @stable ICU 3.8 michael@0: * @see USetSpanCondition michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_spanBackUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition); michael@0: michael@0: /** michael@0: * Returns true if set1 contains all of the characters and strings michael@0: * of set2, and vis versa. It answers the question, 'Is set1 equal to set2?' michael@0: * @param set1 set to be checked for containment michael@0: * @param set2 set to be checked for containment michael@0: * @return true if the test condition is met michael@0: * @stable ICU 3.2 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_equals(const USet* set1, const USet* set2); michael@0: michael@0: /********************************************************************* michael@0: * Serialized set API michael@0: *********************************************************************/ michael@0: michael@0: /** michael@0: * Serializes this set into an array of 16-bit integers. Serialization michael@0: * (currently) only records the characters in the set; multicharacter michael@0: * strings are ignored. michael@0: * michael@0: * The array michael@0: * has following format (each line is one 16-bit integer): michael@0: * michael@0: * length = (n+2*m) | (m!=0?0x8000:0) michael@0: * bmpLength = n; present if m!=0 michael@0: * bmp[0] michael@0: * bmp[1] michael@0: * ... michael@0: * bmp[n-1] michael@0: * supp-high[0] michael@0: * supp-low[0] michael@0: * supp-high[1] michael@0: * supp-low[1] michael@0: * ... michael@0: * supp-high[m-1] michael@0: * supp-low[m-1] michael@0: * michael@0: * The array starts with a header. After the header are n bmp michael@0: * code points, then m supplementary code points. Either n or m michael@0: * or both may be zero. n+2*m is always <= 0x7FFF. michael@0: * michael@0: * If there are no supplementary characters (if m==0) then the michael@0: * header is one 16-bit integer, 'length', with value n. michael@0: * michael@0: * If there are supplementary characters (if m!=0) then the header michael@0: * is two 16-bit integers. The first, 'length', has value michael@0: * (n+2*m)|0x8000. The second, 'bmpLength', has value n. michael@0: * michael@0: * After the header the code points are stored in ascending order. michael@0: * Supplementary code points are stored as most significant 16 michael@0: * bits followed by least significant 16 bits. michael@0: * michael@0: * @param set the set michael@0: * @param dest pointer to buffer of destCapacity 16-bit integers. michael@0: * May be NULL only if destCapacity is zero. michael@0: * @param destCapacity size of dest, or zero. Must not be negative. michael@0: * @param pErrorCode pointer to the error code. Will be set to michael@0: * U_INDEX_OUTOFBOUNDS_ERROR if n+2*m > 0x7FFF. Will be set to michael@0: * U_BUFFER_OVERFLOW_ERROR if n+2*m+(m!=0?2:1) > destCapacity. michael@0: * @return the total length of the serialized format, including michael@0: * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other michael@0: * than U_BUFFER_OVERFLOW_ERROR. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_serialize(const USet* set, uint16_t* dest, int32_t destCapacity, UErrorCode* pErrorCode); michael@0: michael@0: /** michael@0: * Given a serialized array, fill in the given serialized set object. michael@0: * @param fillSet pointer to result michael@0: * @param src pointer to start of array michael@0: * @param srcLength length of array michael@0: * @return true if the given array is valid, otherwise false michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_getSerializedSet(USerializedSet* fillSet, const uint16_t* src, int32_t srcLength); michael@0: michael@0: /** michael@0: * Set the USerializedSet to contain the given character (and nothing michael@0: * else). michael@0: * @param fillSet pointer to result michael@0: * @param c The codepoint to set michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: uset_setSerializedToOne(USerializedSet* fillSet, UChar32 c); michael@0: michael@0: /** michael@0: * Returns TRUE if the given USerializedSet contains the given michael@0: * character. michael@0: * @param set the serialized set michael@0: * @param c The codepoint to check for within the set michael@0: * @return true if set contains c michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_serializedContains(const USerializedSet* set, UChar32 c); michael@0: michael@0: /** michael@0: * Returns the number of disjoint ranges of characters contained in michael@0: * the given serialized set. Ignores any strings contained in the michael@0: * set. michael@0: * @param set the serialized set michael@0: * @return a non-negative integer counting the character ranges michael@0: * contained in set michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: uset_getSerializedRangeCount(const USerializedSet* set); michael@0: michael@0: /** michael@0: * Returns a range of characters contained in the given serialized michael@0: * set. michael@0: * @param set the serialized set michael@0: * @param rangeIndex a non-negative integer in the range 0.. michael@0: * uset_getSerializedRangeCount(set)-1 michael@0: * @param pStart pointer to variable to receive first character michael@0: * in range, inclusive michael@0: * @param pEnd pointer to variable to receive last character in range, michael@0: * inclusive michael@0: * @return true if rangeIndex is valid, otherwise false michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: uset_getSerializedRange(const USerializedSet* set, int32_t rangeIndex, michael@0: UChar32* pStart, UChar32* pEnd); michael@0: michael@0: #endif