/*
*******************************************************************************
*
-* Copyright (C) 2002-2003, International Business Machines
+* Copyright (C) 2002-2004, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
#define __USET_H__
#include "unicode/utypes.h"
+#include "unicode/uchar.h"
#ifndef UCNV_H
struct USet;
/**
* A UnicodeSet. Use the uset_* API to manipulate. Create with
* uset_open*, and destroy with uset_close.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
typedef struct USet USet;
#endif
/**
- * Bitmask values to be passed to the UnicodeSet constructor or
- * applyPattern() taking an option parameter.
- * @draft
+ * Bitmask values to be passed to uset_openPatternOptions() or
+ * uset_applyPattern() taking an option parameter.
+ * @stable ICU 2.4
*/
enum {
/**
* Ignore white space within patterns unless quoted or escaped.
- * @draft
+ * @stable ICU 2.4
*/
USET_IGNORE_SPACE = 1,
/**
* 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'.
- * @draft
+ * match all except 'a', 'A', 'b', and 'B'. This performs a full
+ * closure over case mappings, e.g. U+017F for s.
+ * @stable ICU 2.4
*/
USET_CASE_INSENSITIVE = 2,
* @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
+ */
+ USET_ADD_CASE_MAPPINGS = 4,
+
/**
* Enough for any single-code point set
* @internal
/**
* A serialized form of a Unicode set. Limited manipulations are
* possible directly on a serialized set. See below.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
typedef struct USerializedSet {
/**
* The serialized Unicode Set.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
const uint16_t *array;
/**
* The length of the array that contains BMP characters.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
int32_t bmpLength;
/**
* The total length of the array.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
int32_t length;
/**
* A small buffer for the array to reduce memory allocations.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
uint16_t staticArray[USET_SERIALIZED_STATIC_ARRAY_CAPACITY];
} USerializedSet;
* @param end last character of the range, inclusive
* @return a newly created USet. The caller must call uset_close() on
* it when done.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI USet* U_EXPORT2
+U_STABLE USet* U_EXPORT2
uset_open(UChar32 start, UChar32 end);
/**
* @param patternLength the length of the pattern, or -1 if null
* terminated
* @param ec the error code
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI USet* U_EXPORT2
+U_STABLE USet* U_EXPORT2
uset_openPattern(const UChar* pattern, int32_t patternLength,
UErrorCode* ec);
* @param options bitmask for options to apply to the pattern.
* Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
* @param ec the error code
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI USet* U_EXPORT2
+U_STABLE USet* U_EXPORT2
uset_openPatternOptions(const UChar* pattern, int32_t patternLength,
uint32_t options,
UErrorCode* ec);
* Disposes of the storage used by a USet object. This function should
* be called exactly once for objects returned by uset_open().
* @param set the object to dispose of
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_close(USet* set);
+/**
+ * Causes the USet object to represent the range <code>start - end</code>.
+ * If <code>start > end</code> then this USet is set to an empty range.
+ * @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
+ */
+U_DRAFT void U_EXPORT2
+uset_set(USet* set,
+ UChar32 start, UChar32 end);
+
+/**
+ * Modifies the set to represent the set specified by the given
+ * pattern. See the UnicodeSet class description for the syntax of
+ * the pattern language. See also the User Guide chapter about UnicodeSet.
+ * <em>Empties the set passed before applying the pattern.</em>
+ * @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 '['.
+ * @param patternLength The length of the UChar string. -1 if NUL terminated.
+ * @param options A bitmask for options to apply to the pattern.
+ * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
+ * @param status Returns an error if the pattern cannot be parsed.
+ * @return Upon successful parse, the value is either
+ * the index of the character after the closing ']'
+ * 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
+ */
+U_DRAFT int32_t U_EXPORT2
+uset_applyPattern(USet *set,
+ const UChar *pattern, int32_t patternLength,
+ uint32_t options,
+ UErrorCode *status);
+
+/**
+ * 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.
+ *
+ * @param set the object to contain the code points defined by the property
+ *
+ * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
+ * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
+ * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
+ *
+ * @param value a value in the range u_getIntPropertyMinValue(prop)..
+ * u_getIntPropertyMaxValue(prop), with one exception. If prop is
+ * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
+ * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
+ * categories such as [:L:] to be represented.
+ *
+ * @param ec error code input/output parameter
+ *
+ * @draft ICU 3.2
+ */
+U_DRAFT void U_EXPORT2
+uset_applyIntPropertyValue(USet* set,
+ UProperty prop, int32_t value, UErrorCode* ec);
+
+/**
+ * Modifies the set to contain those code points which have the
+ * given value for the given property. Prior contents of this
+ * set are lost.
+ *
+ * @param set the object to contain the code points defined by the given
+ * property and value alias
+ *
+ * @param prop a string specifying a property alias, either short or long.
+ * The name is matched loosely. See PropertyAliases.txt for names and a
+ * description of loose matching. If the value string is empty, then this
+ * string is interpreted as either a General_Category value alias, a Script
+ * value alias, a binary property alias, or a special ID. Special IDs are
+ * matched loosely and correspond to the following sets:
+ *
+ * "ANY" = [\\u0000-\\U0010FFFF],
+ * "ASCII" = [\\u0000-\\u007F].
+ *
+ * @param propLength the length of the prop, or -1 if NULL
+ *
+ * @param value a string specifying a value alias, either short or long.
+ * The name is matched loosely. See PropertyValueAliases.txt for names
+ * and a description of loose matching. In addition to aliases listed,
+ * numeric values and canonical combining classes may be expressed
+ * numerically, e.g., ("nv", "0.5") or ("ccc", "220"). The value string
+ * may also be empty.
+ *
+ * @param valueLength the length of the value, or -1 if NULL
+ *
+ * @param ec error code input/output parameter
+ *
+ * @draft ICU 3.2
+ */
+U_DRAFT void U_EXPORT2
+uset_applyPropertyAlias(USet* set,
+ const UChar *prop, int32_t propLength,
+ const UChar *value, int32_t valueLength,
+ UErrorCode* ec);
+
+/**
+ * Return true if the given position, in the given pattern, appears
+ * to be the start of a UnicodeSet pattern.
+ *
+ * @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
+ */
+U_DRAFT UBool U_EXPORT2
+uset_resemblesPattern(const UChar *pattern, int32_t patternLength,
+ int32_t pos);
+
/**
* Returns a string representation of this set. If the result of
* calling this function is passed to a uset_openPattern(), it
* @param result the string to receive the rules, may be NULL
* @param resultCapacity the capacity of result, may be 0 if result is NULL
* @param escapeUnprintable if TRUE then convert unprintable
- * character to their hex escape representations, \uxxxx or
- * \Uxxxxxxxx. Unprintable characters are those other than
+ * character to their hex escape representations, \\uxxxx or
+ * \\Uxxxxxxxx. Unprintable characters are those other than
* U+000A, U+0020..U+007E.
* @param ec error code.
* @return length of string, possibly larger than resultCapacity
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uset_toPattern(const USet* set,
UChar* result, int32_t resultCapacity,
UBool escapeUnprintable,
* uset_contains(set, c) will return TRUE.
* @param set the object to which to add the character
* @param c the character to add
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_add(USet* set, UChar32 c);
/**
*
* @param set the object to which to add the set
* @param additionalSet the source set whose elements are to be added to this set.
- * @draft ICU 2.6
+ * @stable ICU 2.6
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_addAll(USet* set, const USet *additionalSet);
/**
* @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
- * @draft ICU 2.2
+ * @stable ICU 2.2
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_addRange(USet* set, UChar32 start, UChar32 end);
/**
* @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.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_addString(USet* set, const UChar* str, int32_t strLen);
/**
* uset_contains(set, c) will return FALSE.
* @param set the object from which to remove the character
* @param c the character to remove
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_remove(USet* set, UChar32 c);
/**
* @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
- * @draft ICU 2.2
+ * @stable ICU 2.2
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_removeRange(USet* set, UChar32 start, UChar32 end);
/**
* @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.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_removeString(USet* set, const UChar* str, int32_t strLen);
+/**
+ * Removes from this set all of its elements that are contained in the
+ * specified set. This operation effectively modifies this
+ * set so that its value is the <i>asymmetric set difference</i> of
+ * the two sets.
+ * @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
+ */
+U_DRAFT void U_EXPORT2
+uset_removeAll(USet* set, const USet* removeSet);
+
+/**
+ * Retain only the elements in this set that are contained in the
+ * specified range. If <code>start > end</code> then an empty range is
+ * retained, leaving the set empty. This is equivalent to
+ * a boolean logic AND, or a set INTERSECTION.
+ *
+ * @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
+ */
+U_DRAFT void U_EXPORT2
+uset_retain(USet* set, UChar32 start, UChar32 end);
+
+/**
+ * Retains only the elements in this set that are contained in the
+ * specified set. In other words, removes from this set all of
+ * its elements that are not contained in the specified set. This
+ * operation effectively modifies this set so that its value is
+ * the <i>intersection</i> of the two sets.
+ *
+ * @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
+ */
+U_DRAFT 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.
+ *
+ * @param set the object on which to perfrom the compact
+ * @draft ICU 3.2
+ */
+U_DRAFT 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.
* @param set the set
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
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.
+ *
+ * @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
+ */
+U_DRAFT 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.
* @param set the set
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_clear(USet* set);
/**
* strings.
* @param set the set
* @return true if set is empty
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uset_isEmpty(const USet* set);
/**
* @param set the set
* @param c The codepoint to check for within the set
* @return true if set contains c
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uset_contains(const USet* set, UChar32 c);
/**
* @param start the first character of the range to test, inclusive
* @param end the last character of the range to test, inclusive
* @return TRUE if set contains the range
- * @draft ICU 2.2
+ * @stable ICU 2.2
*/
-U_CAPI UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uset_containsRange(const USet* set, UChar32 start, UChar32 end);
/**
* @param str the string
* @param strLen the length of the string or -1 if null terminated.
* @return true if set contains str
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uset_containsString(const USet* set, const UChar* str, int32_t strLen);
+/**
+ * Returns the index of the given character within this set, where
+ * the set is ordered by ascending code point. If the character
+ * is not in this set, return -1. The inverse of this method is
+ * <code>charAt()</code>.
+ * @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
+ */
+U_DRAFT int32_t U_EXPORT2
+uset_indexOf(const USet* set, UChar32 c);
+
+/**
+ * Returns the character at the given index within this set, where
+ * the set is ordered by ascending code point. If the index is
+ * out of range, return (UChar32)-1. The inverse of this method is
+ * <code>indexOf()</code>.
+ * @param set the set
+ * @param index 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
+ */
+U_DRAFT UChar32 U_EXPORT2
+uset_charAt(const USet* set, int32_t index);
+
/**
* Returns the number of characters and strings contained in the given
* USet.
* @param set the set
* @return a non-negative integer counting the characters and strings
* contained in set
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uset_size(const USet* set);
/**
* @param set the set
* @return a non-negative integer counting the character ranges
* and/or strings contained in set
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uset_getItemCount(const USet* set);
/**
* @return the length of the string (>= 2), or 0 if the item is a
* range, in which case it is the range *start..*end, or -1 if
* itemIndex is out of range
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uset_getItem(const USet* set, int32_t itemIndex,
UChar32* start, UChar32* end,
UChar* str, int32_t strCapacity,
UErrorCode* ec);
+/**
+ * Returns true if set1 contains all the characters and strings
+ * of set2. It answers the question, 'Is set1 a subset 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
+ */
+U_DRAFT UBool U_EXPORT2
+uset_containsAll(const USet* set1, const USet* set2);
+
+/**
+ * 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
+ */
+U_DRAFT UBool U_EXPORT2
+uset_containsNone(const USet* set1, const USet* set2);
+
+/**
+ * Returns true if set1 contains some of the characters and strings
+ * of set2. It answers the question, 'Does set1 and set2 have an intersection?'
+ * @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
+ */
+U_DRAFT UBool U_EXPORT2
+uset_containsSome(const USet* set1, const USet* set2);
+
+/**
+ * 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
+ */
+U_DRAFT UBool U_EXPORT2
+uset_equals(const USet* set1, const USet* set2);
+
/*********************************************************************
* Serialized set API
*********************************************************************/
* @return the total length of the serialized format, including
* the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
* than U_BUFFER_OVERFLOW_ERROR.
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uset_serialize(const USet* set, uint16_t* dest, int32_t destCapacity, UErrorCode* pErrorCode);
/**
* @param src pointer to start of array
* @param srcLength length of array
* @return true if the given array is valid, otherwise false
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uset_getSerializedSet(USerializedSet* fillSet, const uint16_t* src, int32_t srcLength);
/**
* else).
* @param fillSet pointer to result
* @param c The codepoint to set
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI void U_EXPORT2
+U_STABLE void U_EXPORT2
uset_setSerializedToOne(USerializedSet* fillSet, UChar32 c);
/**
* @param set the serialized set
* @param c The codepoint to check for within the set
* @return true if set contains c
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uset_serializedContains(const USerializedSet* set, UChar32 c);
/**
* @param set the serialized set
* @return a non-negative integer counting the character ranges
* contained in set
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI int32_t U_EXPORT2
+U_STABLE int32_t U_EXPORT2
uset_getSerializedRangeCount(const USerializedSet* set);
/**
* @param pEnd pointer to variable to receive last character in range,
* inclusive
* @return true if rangeIndex is valid, otherwise false
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
-U_CAPI UBool U_EXPORT2
+U_STABLE UBool U_EXPORT2
uset_getSerializedRange(const USerializedSet* set, int32_t rangeIndex,
UChar32* pStart, UChar32* pEnd);