diff --git a/icu4c/source/i18n/ulocdata.c b/icu4c/source/i18n/ulocdata.c index 6288ef4dd5..38ea5f0908 100644 --- a/icu4c/source/i18n/ulocdata.c +++ b/icu4c/source/i18n/ulocdata.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * * -* Copyright (C) 2003, International Business Machines * +* Copyright (C) 2003-2004, International Business Machines * * Corporation and others. All Rights Reserved. * * * ****************************************************************************** @@ -21,13 +21,14 @@ #define PAPER_SIZE "PaperSize" U_CAPI USet* U_EXPORT2 -ulocdata_getExemplarSet(USet *fillIn, const char *localeID, UErrorCode *status){ +ulocdata_getExemplarSet(USet *fillIn, const char *localeID, + uint32_t options, UErrorCode *status){ UResourceBundle *bundle = NULL; const UChar *exemplarChars = NULL; int32_t len = 0; - if(status == NULL || U_FAILURE(*status)){ + if (U_FAILURE(*status)){ return NULL; } @@ -37,9 +38,10 @@ ulocdata_getExemplarSet(USet *fillIn, const char *localeID, UErrorCode *status){ if(fillIn != NULL){ uset_applyPattern(fillIn, exemplarChars, len, - USET_IGNORE_SPACE, status); + USET_IGNORE_SPACE | options, status); }else{ - fillIn = uset_openPattern(exemplarChars, len, status); + fillIn = uset_openPatternOptions(exemplarChars, len, + USET_IGNORE_SPACE | options, status); } ures_close(bundle); diff --git a/icu4c/source/i18n/unicode/ulocdata.h b/icu4c/source/i18n/unicode/ulocdata.h index 1ce9dc0b9c..edcdcb9fa7 100644 --- a/icu4c/source/i18n/unicode/ulocdata.h +++ b/icu4c/source/i18n/unicode/ulocdata.h @@ -1,7 +1,7 @@ /* ****************************************************************************** * * -* Copyright (C) 2003, International Business Machines * +* Copyright (C) 2003-2004, International Business Machines * * Corporation and others. All Rights Reserved. * * * ****************************************************************************** @@ -23,23 +23,32 @@ /** - * Fills the set with the set of exemplar characters for the locale and - * returns the set. + * Returns the set of exemplar characters for a locale. * - * @param fillIn A pointer to USet object to be filled in with the - * exemplar characters set for the locale. - * If NULL is passed, then a new USet will be created and returned. - * The caller owns this object and must dispose it by calling uset_close. - * - * @param localeID The id of the locale for which the exemplar character set - * needs to be retrieved. - * @param status Must be a valid pointer to an error code value, - * which must not indicate a failure before the function call. - * @return USet* The pointer to the fillIn USet object. - * @draft ICU 2.8 + * @param fillIn Pointer to a USet object to receive the + * exemplar character set for the given locale. Previous + * contents of fillIn are lost. If fillIn is NULL, + * then a new USet is created and returned. The caller + * owns the result and must dispose of it by calling + * uset_close. + * @param localeID Locale id for which the exemplar character set + * is to be retrieved. + * @param options Bitmask for options to apply to the exemplar pattern. + * Specify zero to retrieve the exemplar set as it is + * defined in the locale data. Specify + * USET_CASE_INSENSITIVE to retrieve a case-folded + * exemplar set. See uset_applyPattern for a complete + * list of valid options. The USET_IGNORE_SPACE bit is + * always set, regardless of the value of 'options'. + * @param status Pointer to an input-output error code value; + * must not be NULL. + * @return USet* Either fillIn, or if fillIn is NULL, a pointer to + * a newly-allocated USet that the user must close. + * @draft ICU 3.0 */ U_DRAFT USet* U_EXPORT2 -ulocdata_getExemplarSet(USet *fillIn, const char *localeID, UErrorCode *status); +ulocdata_getExemplarSet(USet *fillIn, const char *localeID, + uint32_t options, UErrorCode *status); #ifndef U_HIDE_DRAFT_API /** diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index 8730b9289f..8903c5145d 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -34,11 +34,13 @@ #include "unicode/ustring.h" #include "unicode/utypes.h" #include "unicode/uversion.h" +#include "unicode/ulocdata.h" #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) static void TestNullDefault(void); static void VerifyTranslation(void); +static void TestExemplarSet(void); void PrintDataTable(); /*--------------------------------------------------- @@ -188,34 +190,37 @@ enum { DNAME_EL = 27 }; +#define TESTCASE(name) addTest(root, &name, "tsutil/cloctst/" #name) + void addLocaleTest(TestNode** root); void addLocaleTest(TestNode** root) { - addTest(root, &TestObsoleteNames, "tsutil/cloctst/TestObsoleteNames"); /* srl- move */ - addTest(root, &TestBasicGetters, "tsutil/cloctst/TestBasicGetters"); - addTest(root, &TestNullDefault, "tsutil/cloctst/TestNullDefault"); - addTest(root, &TestPrefixes, "tsutil/cloctst/TestPrefixes"); - addTest(root, &TestSimpleResourceInfo, "tsutil/cloctst/TestSimpleResourceInfo"); - addTest(root, &TestDisplayNames, "tsutil/cloctst/TestDisplayNames"); - addTest(root, &TestGetAvailableLocales, "tsutil/cloctst/TestGetAvailableLocales"); - addTest(root, &TestDataDirectory, "tsutil/cloctst/TestDataDirectory"); - addTest(root, &TestISOFunctions, "tsutil/cloctst/TestISOFunctions"); - addTest(root, &TestISO3Fallback, "tsutil/cloctst/TestISO3Fallback"); - addTest(root, &TestUninstalledISO3Names, "tsutil/cloctst/TestUninstalledISO3Names"); - addTest(root, &TestSimpleDisplayNames, "tsutil/cloctst/TestSimpleDisplayNames"); - addTest(root, &TestVariantParsing, "tsutil/cloctst/TestVariantParsing"); - addTest(root, &TestLocaleStructure, "tsutil/cloctst/TestLocaleStructure"); - addTest(root, &TestConsistentCountryInfo,"tsutil/cloctst/TestConsistentCountryInfo"); - addTest(root, &VerifyTranslation, "tsutil/cloctst/VerifyTranslation"); - /*addTest(root, &MoreVariants, "tsutil/cloctst/MoreVariants");*/ - addTest(root, &TestKeywordVariants, "tsutil/cloctst/TestKeywordVariants"); - addTest(root, &TestKeywordVariantParsing,"tsutil/cloctst/TestKeywordVariantParsing"); - addTest(root, &TestCanonicalization, "tsutil/cloctst/TestCanonicalization"); - addTest(root, &TestDisplayKeywords, "tsutil/cloctst/TestDisplayKeywords"); - addTest(root, &TestDisplayKeywordValues, "tsutil/cloctst/TestDisplayKeywordValues"); - addTest(root, &TestGetBaseName, "tsutil/cloctst/TestGetBaseName"); - addTest(root, &TestGetLocale, "tsutil/cloctst/TestGetLocale"); + TESTCASE(TestObsoleteNames); /* srl- move */ + TESTCASE(TestBasicGetters); + TESTCASE(TestNullDefault); + TESTCASE(TestPrefixes); + TESTCASE(TestSimpleResourceInfo); + TESTCASE(TestDisplayNames); + TESTCASE(TestGetAvailableLocales); + TESTCASE(TestDataDirectory); + TESTCASE(TestISOFunctions); + TESTCASE(TestISO3Fallback); + TESTCASE(TestUninstalledISO3Names); + TESTCASE(TestSimpleDisplayNames); + TESTCASE(TestVariantParsing); + TESTCASE(TestLocaleStructure); + TESTCASE(TestConsistentCountryInfo); + TESTCASE(VerifyTranslation); + /*TESTCASE(MoreVariants);*/ + TESTCASE(TestKeywordVariants); + TESTCASE(TestKeywordVariantParsing); + TESTCASE(TestCanonicalization); + TESTCASE(TestDisplayKeywords); + TESTCASE(TestDisplayKeywordValues); + TESTCASE(TestGetBaseName); + TESTCASE(TestGetLocale); + TESTCASE(TestExemplarSet); } @@ -2224,7 +2229,7 @@ static void VerifyTranslation(void) { /* test that the scripts are a superset of exemplar characters. */ { - USet *exemplarSet = ulocdata_getExemplarSet(NULL,currLoc, &errorCode); + USet *exemplarSet = ulocdata_getExemplarSet(NULL,currLoc, 0, &errorCode); /* test if exemplar characters are part of script code */ findSetMatch(scripts, numScripts, exemplarSet, currLoc); uset_close(exemplarSet); @@ -2949,3 +2954,107 @@ static void TestGetLocale(void) { } #endif } + +/* adjust this limit as appropriate */ +#define MAX_SCRIPTS_PER_LOCALE 8 + +static void TestExemplarSet(void){ + int32_t i, j, k, m, n; + int32_t equalCount = 0; + UErrorCode ec = U_ZERO_ERROR; + UEnumeration* avail; + USet* exemplarSets[2]; + UScriptCode code[MAX_SCRIPTS_PER_LOCALE]; + USet* codeSets[MAX_SCRIPTS_PER_LOCALE]; + int32_t codeLen; + char cbuf[32]; /* 9 should be enough */ + UChar ubuf[64]; /* adjust as needed */ + UBool existsInScript; + int32_t itemCount; + int32_t strLen; + UChar32 start, end; + + exemplarSets[0] = exemplarSets[1] = NULL; + for (i=0; i 0 && equalCount < n); + + END: + uenum_close(avail); + uset_close(exemplarSets[0]); + uset_close(exemplarSets[1]); + for (i=0; i