ICU-2438 support for keyword based locales (de@collation=phonebook)

X-SVN-Rev: 13646
This commit is contained in:
Vladimir Weinstein 2003-11-08 08:29:31 +00:00
parent 4c124026b3
commit 204372993d

View file

@ -370,9 +370,37 @@ ucol_open_internal(const char *loc,
/* New version */
if(U_FAILURE(*status)) return 0;
UCollator *result = NULL;
UResourceBundle *b = ures_open(NULL, loc, status);
UResourceBundle *collElem = ures_getByKey(b, "CollationElements", NULL, status);
/* we try to find stuff from keyword */
UResourceBundle *collations = ures_getByKey(b, "collations", NULL, status);
UResourceBundle *collElem = NULL;
if(*status == U_ZERO_ERROR) { // no fallback
char keyBuffer[256];
// if there is a keyword, we pick it up and try to get elements
if(!uloc_getKeywordValue(loc, "collation", keyBuffer, 256, status)) {
// no keyword. we try to find the default setting, which will give us the keyword value
UResourceBundle *defaultColl = ures_getByKeyWithFallback(collations, "default", NULL, status);
if(U_SUCCESS(*status)) {
int32_t defaultKeyLen = 0;
const UChar *defaultKey = ures_getString(defaultColl, &defaultKeyLen, status);
u_UCharsToChars(defaultKey, keyBuffer, defaultKeyLen);
keyBuffer[defaultKeyLen] = 0;
} else {
*status = U_INTERNAL_PROGRAM_ERROR;
return NULL;
}
ures_close(defaultColl);
}
collElem = ures_getByKeyWithFallback(collations, keyBuffer, collElem, status);
} else {
collElem = ures_getByKey(b, "CollationElements", collElem, status);
}
UResourceBundle *binary = NULL;
UErrorCode binaryStatus = U_ZERO_ERROR;
@ -432,6 +460,7 @@ ucol_open_internal(const char *loc,
clean:
ures_close(b);
ures_close(collElem);
ures_close(collations);
ures_close(binary);
return NULL;
}
@ -447,12 +476,14 @@ clean:
*status = U_MEMORY_ALLOCATION_ERROR;
ures_close(b); // ??? appears needed
ures_close(collElem);
ures_close(collations);
ures_close(binary); // ??? appears needed
return NULL;
}
uprv_strcpy(result->requestedLocale, loc);
ures_close(binary);
ures_close(collations); //??? we have to decide on that. Probably affects something :)
return result;
}