ICU-898 implementation of getLocale function and method. User can now select the type of locale to get back (requested, valid, actual)
X-SVN-Rev: 7973
This commit is contained in:
parent
c37e26720d
commit
376e2e3d13
@ -492,11 +492,11 @@ int32_t RuleBasedCollator::hashCode() const
|
||||
/**
|
||||
* return the locale of this collator
|
||||
*/
|
||||
const Locale RuleBasedCollator::getLocale(UErrorCode &status) const {
|
||||
const char *result = ucol_getLocale(ucollator, &status);
|
||||
const Locale RuleBasedCollator::getLocale(ULocDataLocaleType type, UErrorCode &status) const {
|
||||
const char *result = ucol_getLocale(ucollator, type, &status);
|
||||
if(result == NULL) {
|
||||
Locale res("");
|
||||
res.setBogus(TRUE);
|
||||
res.setToBogus();
|
||||
return res;
|
||||
} else {
|
||||
return Locale(result);
|
||||
|
@ -283,6 +283,7 @@ ucol_open( const char *loc,
|
||||
result = ucol_initCollator(UCA->image, result, status);
|
||||
// if we use UCA, real locale is root
|
||||
result->rb = ures_open(NULL, "", status);
|
||||
result->binary = ures_open(NULL, "", status);
|
||||
if(U_FAILURE(*status)) {
|
||||
goto clean;
|
||||
}
|
||||
@ -309,25 +310,19 @@ ucol_open( const char *loc,
|
||||
}
|
||||
result->hasRealData = FALSE;
|
||||
}
|
||||
const char *realCollationDataLocale = ures_getLocale(binary, status);
|
||||
ures_close(binary);
|
||||
// if the real data came from the fallback, we want to drag around
|
||||
// the real resource bundle
|
||||
if(uprv_strcmp(ures_getLocale(b, status), realCollationDataLocale) != 0) {
|
||||
result->rb = ures_open(NULL, realCollationDataLocale, status);
|
||||
if(U_FAILURE(*status)) {
|
||||
goto clean;
|
||||
}
|
||||
ures_close(b);
|
||||
} else { // otherwise, we'll keep the initial RB around
|
||||
result->rb = b;
|
||||
}
|
||||
result->binary = binary;
|
||||
result->rb = b;
|
||||
} else { /* There is another error, and we're just gonna clean up */
|
||||
clean:
|
||||
ures_close(b);
|
||||
ures_close(binary);
|
||||
return NULL;
|
||||
}
|
||||
if(loc == NULL) {
|
||||
loc = ures_getLocale(result->rb, status);
|
||||
}
|
||||
result->requestedLocale = (char *)uprv_malloc((uprv_strlen(loc)+1)*sizeof(char));
|
||||
uprv_strcpy(result->requestedLocale, loc);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -378,6 +373,12 @@ ucol_close(UCollator *coll)
|
||||
} else if(coll->hasRealData == TRUE) {
|
||||
uprv_free((UCATableHeader *)coll->image);
|
||||
}
|
||||
if(coll->binary != NULL) {
|
||||
ures_close(coll->binary);
|
||||
}
|
||||
if(coll->requestedLocale != NULL) {
|
||||
uprv_free(coll->requestedLocale);
|
||||
}
|
||||
uprv_free(coll);
|
||||
}
|
||||
|
||||
@ -484,7 +485,9 @@ ucol_openRules( const UChar *rules,
|
||||
result->rules = newRules;
|
||||
result->rulesLength = rulesLength;
|
||||
result->freeRulesOnClose = TRUE;
|
||||
result->rb = 0;
|
||||
result->rb = NULL;
|
||||
result->binary = NULL;
|
||||
result->requestedLocale = NULL;
|
||||
ucol_setAttribute(result, UCOL_STRENGTH, strength, status);
|
||||
ucol_setAttribute(result, UCOL_NORMALIZATION_MODE, norm, status);
|
||||
} else {
|
||||
@ -5658,14 +5661,28 @@ ucol_equal( const UCollator *coll,
|
||||
|
||||
/* returns the locale name the collation data comes from */
|
||||
U_CAPI const char * U_EXPORT2
|
||||
ucol_getLocale(const UCollator *coll, UErrorCode *status) {
|
||||
ucol_getLocale(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status) {
|
||||
const char *result = NULL;
|
||||
if(status == NULL || U_FAILURE(*status)) {
|
||||
return NULL;
|
||||
}
|
||||
if(coll->rb != NULL) {
|
||||
return ures_getLocale(coll->rb, status);
|
||||
} else {
|
||||
return NULL;
|
||||
switch(type) {
|
||||
case ULOC_ACTUAL_LOCALE:
|
||||
if(coll->binary != NULL) {
|
||||
result = ures_getLocale(coll->binary, status);
|
||||
}
|
||||
break;
|
||||
case ULOC_VALID_LOCALE:
|
||||
if(coll->rb != NULL) {
|
||||
result = ures_getLocale(coll->rb, status);
|
||||
}
|
||||
break;
|
||||
case ULOC_REQUESTED_LOCALE:
|
||||
result = coll->requestedLocale;
|
||||
break;
|
||||
default:
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1108,6 +1108,8 @@ UCATableHeader *ucol_assembleTailoringTable(UColTokenParser *src, UErrorCode *st
|
||||
|
||||
if(U_SUCCESS(*status)) {
|
||||
tempColl->rb = NULL;
|
||||
tempColl->binary = NULL;
|
||||
tempColl->requestedLocale = NULL;
|
||||
tempColl->hasRealData = TRUE;
|
||||
}
|
||||
uprv_uca_closeTempTable(tempTable);
|
||||
|
@ -632,7 +632,9 @@ struct UCollator {
|
||||
UColOptionSet *options;
|
||||
SortKeyGenerator *sortKeyGen;
|
||||
UBool freeOnClose;
|
||||
char* requestedLocale;
|
||||
UResourceBundle *rb;
|
||||
UResourceBundle *binary;
|
||||
const UCATableHeader *image;
|
||||
/*CompactEIntArray *mapping;*/
|
||||
UTrie *mapping;
|
||||
|
@ -403,7 +403,7 @@ public:
|
||||
* Gets the locale of the Collator
|
||||
* @draft ICU 2.1
|
||||
*/
|
||||
virtual const Locale getLocale(UErrorCode& status) const = 0;
|
||||
virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
|
||||
|
||||
/**
|
||||
* Convenience method for comparing two strings based on the collation rules.
|
||||
|
@ -336,11 +336,14 @@ public:
|
||||
|
||||
/**
|
||||
* Gets the locale of the Collator
|
||||
* @param type can be either requested, valid or actual locale. For more
|
||||
* information see the definition of ULocDataLocaleType in
|
||||
* uloc.h
|
||||
* @return locale where the collation data lives. If the collator
|
||||
* was instantiated from rules, locale is empty.
|
||||
* @draft ICU 2.1
|
||||
*/
|
||||
virtual const Locale getLocale(UErrorCode& status) const;
|
||||
virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Gets the table-based rules for the collation object.
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/unorm.h"
|
||||
#include "unicode/parseerr.h"
|
||||
#include "unicode/uloc.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
@ -748,13 +749,16 @@ ucol_setNormalization( UCollator *coll,
|
||||
* is instantiated from the rules, then this function returns
|
||||
* NULL.
|
||||
* @param coll The UCollator for which the locale is needed
|
||||
* @param type You can choose between requested, valid and actual
|
||||
* locale. For description see the definition of
|
||||
* ULocDataLocaleType in uloc.h
|
||||
* @param status error code of the operation
|
||||
* @return real locale name from which the collation data comes.
|
||||
* If the collator was instantiated from rules, returns
|
||||
* NULL.
|
||||
*/
|
||||
U_CAPI const char * U_EXPORT2
|
||||
ucol_getLocale(const UCollator *coll, UErrorCode *status);
|
||||
ucol_getLocale(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status);
|
||||
|
||||
/**
|
||||
*@deprecated Remove after Aug 2002
|
||||
|
Loading…
Reference in New Issue
Block a user