ICU-2755 add ucol_open_internal

X-SVN-Rev: 11846
This commit is contained in:
Doug Felt 2003-05-08 22:21:05 +00:00
parent cacf3d2b39
commit 399b051326
6 changed files with 45 additions and 28 deletions

View file

@ -425,19 +425,27 @@ private:
Hashtable* _ids;
public:
CFactory(CollatorFactory* delegate)
CFactory(CollatorFactory* delegate, UErrorCode& status)
: LocaleKeyFactory(delegate->visible() ? VISIBLE : INVISIBLE)
, _delegate(delegate)
, _ids(NULL)
{
UErrorCode status = U_ZERO_ERROR;
int32_t count = 0;
_ids = new Hashtable(status);
if (_ids) {
const UnicodeString * const idlist = _delegate->getSupportedIDs(count, status);
for (int i = 0; i < count; ++i) {
_ids->put(idlist[i], (void*)this, status);
}
if (U_SUCCESS(status)) {
int32_t count = 0;
_ids = new Hashtable(status);
if (_ids) {
const UnicodeString * idlist = _delegate->getSupportedIDs(count, status);
for (int i = 0; i < count; ++i) {
_ids->put(idlist[i], (void*)this, status);
if (U_FAILURE(status)) {
delete _ids;
_ids = NULL;
return;
}
}
} else {
status = U_MEMORY_ALLOCATION_ERROR;
}
}
}
@ -504,7 +512,7 @@ URegistryKey
Collator::registerFactory(CollatorFactory* toAdopt, UErrorCode& status)
{
if (U_SUCCESS(status)) {
CFactory* f = new CFactory(toAdopt);
CFactory* f = new CFactory(toAdopt, status);
if (f) {
return getService()->registerFactory(f, status);
}

View file

@ -665,6 +665,20 @@ RuleBasedCollator::RuleBasedCollator(const Locale& desiredLocale,
return;
}
void
RuleBasedCollator::setUCollator(const char *locale,
UErrorCode &status)
{
if (U_FAILURE(status))
return;
if (ucollator && dataIsOwned)
ucol_close(ucollator);
ucollator = ucol_open_internal(locale, &status);
dataIsOwned = TRUE;
isWriteThroughAlias = FALSE;
}
void
RuleBasedCollator::checkOwned() {
if (!(dataIsOwned || isWriteThroughAlias)) {

View file

@ -336,14 +336,11 @@ tryOpeningFromRules(UResourceBundle *collElem, UErrorCode *status) {
}
U_NAMESPACE_BEGIN
U_CAPI UCollator*
ucol_open(const char *loc,
UErrorCode *status)
{
U_NAMESPACE_USE;
UCollator *result = NULL;
if (status && U_SUCCESS(*status)) {
result = Collator::createUCollator(loc, status);
@ -351,13 +348,21 @@ ucol_open(const char *loc,
return result;
}
}
return ucol_open_internal(loc, status);
}
// API in ucol_imp.h
U_CFUNC UCollator*
ucol_open_internal(const char *loc,
UErrorCode *status)
{
ucol_initUCA(status);
/* 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);
UResourceBundle *binary = NULL;
@ -442,7 +447,6 @@ clean:
ures_close(binary);
return result;
}
U_NAMESPACE_END
U_CAPI void U_EXPORT2
ucol_setReqValidLocales(UCollator *coll, char *requestedLocaleToAdopt, char *validLocaleToAdopt)

View file

@ -815,6 +815,9 @@ UCollator* ucol_initCollator(const UCATableHeader *image, UCollator *fillIn, UEr
U_CFUNC
void ucol_setOptionsFromHeader(UCollator* result, UColOptionSet * opts, UErrorCode *status);
U_CFUNC
UCollator* ucol_open_internal(const char* loc, UErrorCode* status);
#if 0
U_CFUNC
void ucol_putOptionsToHeader(UCollator* result, UColOptionSet * opts, UErrorCode *status);

View file

@ -934,7 +934,7 @@ public:
* Return the locale names directly supported by this factory. The number of names
* is returned in count;
*/
virtual const UnicodeString * const getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
};
// Collator inline methods -----------------------------------------------

View file

@ -813,18 +813,6 @@ inline UBool RuleBasedCollator::operator!=(const Collator& other) const
return !(*this == other);
}
inline void RuleBasedCollator::setUCollator(const char *locale,
UErrorCode &status)
{
if (U_FAILURE(status))
return;
if (ucollator && dataIsOwned)
ucol_close(ucollator);
ucollator = ucol_open(locale, &status);
dataIsOwned = TRUE;
isWriteThroughAlias = FALSE;
}
inline void RuleBasedCollator::setUCollator(const Locale &locale,
UErrorCode &status)
{