diff --git a/icu4c/source/common/unicode/uniset.h b/icu4c/source/common/unicode/uniset.h index cfc86f9e13f..52583b89673 100644 --- a/icu4c/source/common/unicode/uniset.h +++ b/icu4c/source/common/unicode/uniset.h @@ -14,6 +14,7 @@ #include "unicode/utypes.h" #include "unicode/unistr.h" #include "unicode/uchar.h" +#include "unicode/uset.h" U_NAMESPACE_BEGIN @@ -26,33 +27,6 @@ class TransliteratorParser; class UVector; class CaseEquivClass; -/** - * Bitmask values to be passed to the UnicodeSet constructor or - * applyPattern() taking an option parameter. - * @internal - */ -enum { - /** - * Ignore white space within patterns unless quoted or escaped. - * @internal - */ - 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'. - * @internal - */ - USET_CASE_INSENSITIVE = 2, - - /** - * Bitmask for UnicodeSet::closeOver() indicating letter case. - * This may be ORed together with other selectors. - * @internal - */ - USET_CASE = 2 -}; /** * A mutable set of Unicode characters and multicharacter strings. Objects of this class diff --git a/icu4c/source/common/unicode/uset.h b/icu4c/source/common/unicode/uset.h index 0084959eed2..2cbbabe37ca 100644 --- a/icu4c/source/common/unicode/uset.h +++ b/icu4c/source/common/unicode/uset.h @@ -29,6 +29,7 @@ #include "unicode/utypes.h" +#ifndef UCNV_H struct USet; /** * A UnicodeSet. Use the uset_* API to manipulate. Create with @@ -36,9 +37,39 @@ struct USet; * @draft ICU 2.4 */ typedef struct USet USet; +#endif +/** + * Bitmask values to be passed to the UnicodeSet constructor or + * applyPattern() taking an option parameter. + * @draft + */ enum { - USET_SERIALIZED_STATIC_ARRAY_CAPACITY=8 /**< enough for any single-code point set */ + /** + * Ignore white space within patterns unless quoted or escaped. + * @draft + */ + 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 + */ + USET_CASE_INSENSITIVE = 2, + + /** + * Bitmask for UnicodeSet::closeOver() indicating letter case. + * This may be ORed together with other selectors. + * @internal + */ + USET_CASE = 2, + /** + * Enough for any single-code point set + * @internal + */ + USET_SERIALIZED_STATIC_ARRAY_CAPACITY=8 }; /** @@ -98,6 +129,20 @@ U_CAPI USet* U_EXPORT2 uset_openPattern(const UChar* pattern, int32_t patternLength, UErrorCode* ec); +/** + * Creates a set from the given pattern. See the UnicodeSet class + * description for the syntax of the pattern language. + * @param pattern a string specifying what characters are in the set + * @param patternLength the length of the pattern, or -1 if null + * terminated + * @param ec the error code + * @draft ICU 2.4 + */ +U_CAPI 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(). diff --git a/icu4c/source/common/uset.cpp b/icu4c/source/common/uset.cpp index 445bc92e637..8efc5313ac6 100644 --- a/icu4c/source/common/uset.cpp +++ b/icu4c/source/common/uset.cpp @@ -35,7 +35,8 @@ uset_open(UChar32 start, UChar32 end) { U_CAPI USet* U_EXPORT2 uset_openPattern(const UChar* pattern, int32_t patternLength, - UErrorCode* ec) { + UErrorCode* ec) +{ UnicodeString pat(patternLength==-1, pattern, patternLength); UnicodeSet* set = new UnicodeSet(pat, *ec); /* test for NULL */ @@ -51,6 +52,27 @@ uset_openPattern(const UChar* pattern, int32_t patternLength, return (USet*) set; } +U_CAPI USet* U_EXPORT2 +uset_openPatternOptions(const UChar* pattern, int32_t patternLength, + uint32_t options, + UErrorCode* ec) +{ + UnicodeString pat(patternLength==-1, pattern, patternLength); + UnicodeSet* set = new UnicodeSet(pat, options, *ec); + /* test for NULL */ + if(set == 0) { + *ec = U_MEMORY_ALLOCATION_ERROR; + return 0; + } + + if (U_FAILURE(*ec)) { + delete set; + set = NULL; + } + return (USet*) set; +} + + U_CAPI void U_EXPORT2 uset_close(USet* set) { delete (UnicodeSet*) set;