ICU-10638 Add factory method to create a UStringEnumeration from UEnumeration.

X-SVN-Rev: 36841
This commit is contained in:
Travis Keep 2014-12-10 17:02:02 +00:00
parent 22ec77242f
commit 8addf97f7d
3 changed files with 24 additions and 20 deletions

View File

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2002-2012, International Business Machines
* Copyright (c) 2002-2014, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
@ -130,6 +130,22 @@ StringEnumeration::operator!=(const StringEnumeration& that)const {
// UStringEnumeration implementation --------------------------------------- ***
UStringEnumeration * U_EXPORT2
UStringEnumeration::fromUEnumeration(
UEnumeration *uenumToAdopt, UErrorCode &status) {
if (U_FAILURE(status)) {
uenum_close(uenumToAdopt);
return NULL;
}
UStringEnumeration *result = new UStringEnumeration(uenumToAdopt);
if (result == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
uenum_close(uenumToAdopt);
return NULL;
}
return result;
}
UStringEnumeration::UStringEnumeration(UEnumeration* _uenum) :
uenum(_uenum) {
U_ASSERT(_uenum != 0);

View File

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2002-2012, International Business Machines
* Copyright (c) 2002-2014, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
@ -73,6 +73,8 @@ public:
*/
static UClassID U_EXPORT2 getStaticClassID();
static UStringEnumeration * U_EXPORT2 fromUEnumeration(
UEnumeration *enumToAdopt, UErrorCode &status);
private:
UEnumeration *uenum; // owned
};

View File

@ -867,36 +867,22 @@ Collator::getAvailableLocales(void)
return NULL;
}
static StringEnumeration *
newUStringEnumeration(UEnumeration *uenumToAdopt, UErrorCode &status) {
if (U_FAILURE(status)) {
uenum_close(uenumToAdopt);
return NULL;
}
StringEnumeration *result = new UStringEnumeration(uenumToAdopt);
if (result == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
uenum_close(uenumToAdopt);
return NULL;
}
return result;
}
StringEnumeration* U_EXPORT2
Collator::getKeywords(UErrorCode& status) {
return newUStringEnumeration(ucol_getKeywords(&status), status);
return UStringEnumeration::fromUEnumeration(
ucol_getKeywords(&status), status);
}
StringEnumeration* U_EXPORT2
Collator::getKeywordValues(const char *keyword, UErrorCode& status) {
return newUStringEnumeration(
return UStringEnumeration::fromUEnumeration(
ucol_getKeywordValues(keyword, &status), status);
}
StringEnumeration* U_EXPORT2
Collator::getKeywordValuesForLocale(const char* key, const Locale& locale,
UBool commonlyUsed, UErrorCode& status) {
return newUStringEnumeration(
return UStringEnumeration::fromUEnumeration(
ucol_getKeywordValuesForLocale(
key, locale.getName(), commonlyUsed, &status),
status);