ICU-21035 Replace backward compatibility locale_getKeywords() function.
By updating the last 3 callers to do dynamic memory allocation instead, the fixed memory buffer function becomes obsolete.
This commit is contained in:
parent
4767be7f4f
commit
05d49fd373
@ -102,12 +102,6 @@ typedef enum ELocalePos {
|
||||
eMAX_LOCALES
|
||||
} ELocalePos;
|
||||
|
||||
U_CFUNC int32_t locale_getKeywords(const char *localeID,
|
||||
char prev,
|
||||
char *keywords, int32_t keywordCapacity,
|
||||
UBool valuesToo,
|
||||
UErrorCode *status);
|
||||
|
||||
U_CDECL_BEGIN
|
||||
//
|
||||
// Deleter function for Locales owned by the default Locale hash table/
|
||||
@ -1416,8 +1410,6 @@ UnicodeKeywordEnumeration::~UnicodeKeywordEnumeration() = default;
|
||||
StringEnumeration *
|
||||
Locale::createKeywords(UErrorCode &status) const
|
||||
{
|
||||
char keywords[256];
|
||||
int32_t keywordCapacity = sizeof keywords;
|
||||
StringEnumeration *result = NULL;
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
@ -1428,9 +1420,11 @@ Locale::createKeywords(UErrorCode &status) const
|
||||
const char* assignment = uprv_strchr(fullName, '=');
|
||||
if(variantStart) {
|
||||
if(assignment > variantStart) {
|
||||
int32_t keyLen = locale_getKeywords(variantStart+1, '@', keywords, keywordCapacity, FALSE, &status);
|
||||
if(U_SUCCESS(status) && keyLen) {
|
||||
result = new KeywordEnumeration(keywords, keyLen, 0, status);
|
||||
CharString keywords;
|
||||
CharStringByteSink sink(&keywords);
|
||||
ulocimp_getKeywords(variantStart+1, '@', sink, FALSE, &status);
|
||||
if (U_SUCCESS(status) && !keywords.isEmpty()) {
|
||||
result = new KeywordEnumeration(keywords.data(), keywords.length(), 0, status);
|
||||
if (!result) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
@ -1445,8 +1439,6 @@ Locale::createKeywords(UErrorCode &status) const
|
||||
StringEnumeration *
|
||||
Locale::createUnicodeKeywords(UErrorCode &status) const
|
||||
{
|
||||
char keywords[256];
|
||||
int32_t keywordCapacity = sizeof keywords;
|
||||
StringEnumeration *result = NULL;
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
@ -1457,9 +1449,11 @@ Locale::createUnicodeKeywords(UErrorCode &status) const
|
||||
const char* assignment = uprv_strchr(fullName, '=');
|
||||
if(variantStart) {
|
||||
if(assignment > variantStart) {
|
||||
int32_t keyLen = locale_getKeywords(variantStart+1, '@', keywords, keywordCapacity, FALSE, &status);
|
||||
if(U_SUCCESS(status) && keyLen) {
|
||||
result = new UnicodeKeywordEnumeration(keywords, keyLen, 0, status);
|
||||
CharString keywords;
|
||||
CharStringByteSink sink(&keywords);
|
||||
ulocimp_getKeywords(variantStart+1, '@', sink, FALSE, &status);
|
||||
if (U_SUCCESS(status) && !keywords.isEmpty()) {
|
||||
result = new UnicodeKeywordEnumeration(keywords.data(), keywords.length(), 0, status);
|
||||
if (!result) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
}
|
||||
|
@ -57,12 +57,6 @@ U_NAMESPACE_USE
|
||||
/* Locale stuff from locid.cpp */
|
||||
U_CFUNC void locale_set_default(const char *id);
|
||||
U_CFUNC const char *locale_get_default(void);
|
||||
U_CFUNC int32_t
|
||||
locale_getKeywords(const char *localeID,
|
||||
char prev,
|
||||
char *keywords, int32_t keywordCapacity,
|
||||
UBool valuesToo,
|
||||
UErrorCode *status);
|
||||
|
||||
/* ### Data tables **************************************************/
|
||||
|
||||
@ -598,12 +592,12 @@ compareKeywordStructs(const void * /*context*/, const void *left, const void *ri
|
||||
return uprv_strcmp(leftString, rightString);
|
||||
}
|
||||
|
||||
static void
|
||||
_getKeywords(const char *localeID,
|
||||
char prev,
|
||||
ByteSink& sink,
|
||||
UBool valuesToo,
|
||||
UErrorCode *status)
|
||||
U_CFUNC void
|
||||
ulocimp_getKeywords(const char *localeID,
|
||||
char prev,
|
||||
ByteSink& sink,
|
||||
UBool valuesToo,
|
||||
UErrorCode *status)
|
||||
{
|
||||
KeywordStruct keywordList[ULOC_MAX_NO_KEYWORDS];
|
||||
|
||||
@ -719,34 +713,6 @@ _getKeywords(const char *localeID,
|
||||
}
|
||||
}
|
||||
|
||||
U_CFUNC int32_t
|
||||
locale_getKeywords(const char *localeID,
|
||||
char prev,
|
||||
char *keywords, int32_t keywordCapacity,
|
||||
UBool valuesToo,
|
||||
UErrorCode *status) {
|
||||
if (U_FAILURE(*status)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CheckedArrayByteSink sink(keywords, keywordCapacity);
|
||||
_getKeywords(localeID, prev, sink, valuesToo, status);
|
||||
|
||||
int32_t reslen = sink.NumberOfBytesAppended();
|
||||
|
||||
if (U_FAILURE(*status)) {
|
||||
return reslen;
|
||||
}
|
||||
|
||||
if (sink.Overflowed()) {
|
||||
*status = U_BUFFER_OVERFLOW_ERROR;
|
||||
} else {
|
||||
u_terminateChars(keywords, keywordCapacity, reslen, status);
|
||||
}
|
||||
|
||||
return reslen;
|
||||
}
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
uloc_getKeywordValue(const char* localeID,
|
||||
const char* keywordName,
|
||||
@ -1412,9 +1378,6 @@ U_CAPI UEnumeration* U_EXPORT2
|
||||
uloc_openKeywords(const char* localeID,
|
||||
UErrorCode* status)
|
||||
{
|
||||
int32_t i=0;
|
||||
char keywords[256];
|
||||
int32_t keywordsCapacity = 256;
|
||||
char tempBuffer[ULOC_FULLNAME_CAPACITY];
|
||||
const char* tmpLocaleID;
|
||||
|
||||
@ -1462,14 +1425,15 @@ uloc_openKeywords(const char* localeID,
|
||||
|
||||
/* keywords are located after '@' */
|
||||
if((tmpLocaleID = locale_getKeywordsStart(tmpLocaleID)) != NULL) {
|
||||
i=locale_getKeywords(tmpLocaleID+1, '@', keywords, keywordsCapacity, FALSE, status);
|
||||
}
|
||||
|
||||
if(i) {
|
||||
return uloc_openKeywordList(keywords, i, status);
|
||||
} else {
|
||||
return NULL;
|
||||
CharString keywords;
|
||||
CharStringByteSink sink(&keywords);
|
||||
ulocimp_getKeywords(tmpLocaleID+1, '@', sink, FALSE, status);
|
||||
if (U_FAILURE(*status)) {
|
||||
return NULL;
|
||||
}
|
||||
return uloc_openKeywordList(keywords.data(), keywords.length(), status);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -1652,7 +1616,7 @@ _canonicalize(const char* localeID,
|
||||
(!separatorIndicator || separatorIndicator > keywordAssign)) {
|
||||
sink.Append("@", 1);
|
||||
++fieldCount;
|
||||
_getKeywords(tmpLocaleID+1, '@', sink, TRUE, err);
|
||||
ulocimp_getKeywords(tmpLocaleID+1, '@', sink, TRUE, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,13 @@ uloc_getCurrentCountryID(const char* oldID);
|
||||
U_CFUNC const char*
|
||||
uloc_getCurrentLanguageID(const char* oldID);
|
||||
|
||||
U_CFUNC void
|
||||
ulocimp_getKeywords(const char *localeID,
|
||||
char prev,
|
||||
icu::ByteSink& sink,
|
||||
UBool valuesToo,
|
||||
UErrorCode *status);
|
||||
|
||||
icu::CharString U_EXPORT2
|
||||
ulocimp_getLanguage(const char *localeID,
|
||||
const char **pEnd,
|
||||
|
@ -130,7 +130,6 @@
|
||||
#define izrule_getStaticClassID U_ICU_ENTRY_POINT_RENAME(izrule_getStaticClassID)
|
||||
#define izrule_isEquivalentTo U_ICU_ENTRY_POINT_RENAME(izrule_isEquivalentTo)
|
||||
#define izrule_open U_ICU_ENTRY_POINT_RENAME(izrule_open)
|
||||
#define locale_getKeywords U_ICU_ENTRY_POINT_RENAME(locale_getKeywords)
|
||||
#define locale_getKeywordsStart U_ICU_ENTRY_POINT_RENAME(locale_getKeywordsStart)
|
||||
#define locale_get_default U_ICU_ENTRY_POINT_RENAME(locale_get_default)
|
||||
#define locale_set_default U_ICU_ENTRY_POINT_RENAME(locale_set_default)
|
||||
|
Loading…
Reference in New Issue
Block a user