mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-10638 Add factory method to create a UStringEnumeration from UEnumeration.
X-SVN-Rev: 36841
This commit is contained in:
parent
22ec77242f
commit
8addf97f7d
3 changed files with 24 additions and 20 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue