Skip to content

Commit

Permalink
ICU-20187 drop support for long-obsolete locale ID variants
Browse files Browse the repository at this point in the history
  • Loading branch information
markusicu committed Feb 14, 2019
1 parent d2e3a88 commit 1afef30
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 722 deletions.
71 changes: 23 additions & 48 deletions icu4c/source/common/putil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1622,50 +1622,37 @@ The variant cannot have dots in it.
The 'rightmost' variant (@xxx) wins.
The leftmost codepage (.xxx) wins.
*/
char *correctedPOSIXLocale = 0;
const char* posixID = uprv_getPOSIXIDForDefaultLocale();
const char *p;
const char *q;
int32_t len;

/* Format: (no spaces)
ll [ _CC ] [ . MM ] [ @ VV]
l = lang, C = ctry, M = charmap, V = variant
*/

if (gCorrectedPOSIXLocale != NULL) {
if (gCorrectedPOSIXLocale != nullptr) {
return gCorrectedPOSIXLocale;
}

if ((p = uprv_strchr(posixID, '.')) != NULL) {
/* assume new locale can't be larger than old one? */
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(uprv_strlen(posixID)+1));
/* Exit on memory allocation error. */
if (correctedPOSIXLocale == NULL) {
return NULL;
}
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
correctedPOSIXLocale[p-posixID] = 0;
// Copy the ID into owned memory.
// Over-allocate in case we replace "@" with "__".
char *correctedPOSIXLocale = static_cast<char *>(uprv_malloc(uprv_strlen(posixID) + 1 + 1));
if (correctedPOSIXLocale == nullptr) {
return nullptr;
}
uprv_strcpy(correctedPOSIXLocale, posixID);

/* do not copy after the @ */
if ((p = uprv_strchr(correctedPOSIXLocale, '@')) != NULL) {
correctedPOSIXLocale[p-correctedPOSIXLocale] = 0;
char *limit;
if ((limit = uprv_strchr(correctedPOSIXLocale, '.')) != nullptr) {
*limit = 0;
if ((limit = uprv_strchr(correctedPOSIXLocale, '@')) != nullptr) {
*limit = 0;
}
}

/* Note that we scan the *uncorrected* ID. */
if ((p = uprv_strrchr(posixID, '@')) != NULL) {
if (correctedPOSIXLocale == NULL) {
/* new locale can be 1 char longer than old one if @ -> __ */
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(uprv_strlen(posixID)+2));
/* Exit on memory allocation error. */
if (correctedPOSIXLocale == NULL) {
return NULL;
}
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
correctedPOSIXLocale[p-posixID] = 0;
}
const char *p;
if ((p = uprv_strrchr(posixID, '@')) != nullptr) {
p++;

/* Take care of any special cases here.. */
Expand All @@ -1674,16 +1661,17 @@ The leftmost codepage (.xxx) wins.
/* Don't worry about no__NY. In practice, it won't appear. */
}

if (uprv_strchr(correctedPOSIXLocale,'_') == NULL) {
if (uprv_strchr(correctedPOSIXLocale,'_') == nullptr) {
uprv_strcat(correctedPOSIXLocale, "__"); /* aa@b -> aa__b (note this can make the new locale 1 char longer) */
}
else {
uprv_strcat(correctedPOSIXLocale, "_"); /* aa_CC@b -> aa_CC_b */
}

if ((q = uprv_strchr(p, '.')) != NULL) {
const char *q;
if ((q = uprv_strchr(p, '.')) != nullptr) {
/* How big will the resulting string be? */
len = (int32_t)(uprv_strlen(correctedPOSIXLocale) + (q-p));
int32_t len = (int32_t)(uprv_strlen(correctedPOSIXLocale) + (q-p));
uprv_strncat(correctedPOSIXLocale, p, q-p);
correctedPOSIXLocale[len] = 0;
}
Expand All @@ -1699,28 +1687,15 @@ The leftmost codepage (.xxx) wins.
*/
}

/* Was a correction made? */
if (correctedPOSIXLocale != NULL) {
posixID = correctedPOSIXLocale;
}
else {
/* copy it, just in case the original pointer goes away. See j2395 */
correctedPOSIXLocale = (char *)uprv_malloc(uprv_strlen(posixID) + 1);
/* Exit on memory allocation error. */
if (correctedPOSIXLocale == NULL) {
return NULL;
}
posixID = uprv_strcpy(correctedPOSIXLocale, posixID);
}

if (gCorrectedPOSIXLocale == NULL) {
if (gCorrectedPOSIXLocale == nullptr) {
gCorrectedPOSIXLocale = correctedPOSIXLocale;
gCorrectedPOSIXLocaleHeapAllocated = true;
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
correctedPOSIXLocale = NULL;
correctedPOSIXLocale = nullptr;
}
posixID = gCorrectedPOSIXLocale;

if (correctedPOSIXLocale != NULL) { /* Was already set - clean up. */
if (correctedPOSIXLocale != nullptr) { /* Was already set - clean up. */
uprv_free(correctedPOSIXLocale);
}

Expand Down
58 changes: 4 additions & 54 deletions icu4c/source/common/ucurr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,14 @@ static const char CURRENCY_MAP[] = "CurrencyMap";
// Tag for default meta-data, in CURRENCY_META
static const char DEFAULT_META[] = "DEFAULT";

// Variant for legacy pre-euro mapping in CurrencyMap
static const char VAR_PRE_EURO[] = "PREEURO";

// Variant for legacy euro mapping in CurrencyMap
static const char VAR_EURO[] = "EURO";

// Variant delimiter
static const char VAR_DELIM = '_';
static const char VAR_DELIM_STR[] = "_";

// Variant for legacy euro mapping in CurrencyMap
//static const char VAR_DELIM_EURO[] = "_EURO";

#define VARIANT_IS_EMPTY 0
#define VARIANT_IS_EURO 0x1
#define VARIANT_IS_PREEURO 0x2

// Tag for localized display names (symbols) of currencies
static const char CURRENCIES[] = "Currencies";
static const char CURRENCIES_NARROW[] = "Currencies%narrow";
static const char CURRENCYPLURALS[] = "CurrencyPlurals";

static const UChar EUR_STR[] = {0x0045,0x0055,0x0052,0};

// ISO codes mapping table
static const UHashtable* gIsoCodes = NULL;
static icu::UInitOnce gIsoCodesInitOnce = U_INITONCE_INITIALIZER;
Expand Down Expand Up @@ -360,30 +344,10 @@ _findMetaData(const UChar* currency, UErrorCode& ec) {

// -------------------------------------

/**
* @see VARIANT_IS_EURO
* @see VARIANT_IS_PREEURO
*/
static uint32_t
static void
idForLocale(const char* locale, char* countryAndVariant, int capacity, UErrorCode* ec)
{
uint32_t variantType = 0;
// !!! this is internal only, assumes buffer is not null and capacity is sufficient
// Extract the country name and variant name. We only
// recognize two variant names, EURO and PREEURO.
char variant[ULOC_FULLNAME_CAPACITY];
ulocimp_getRegionForSupplementalData(locale, FALSE, countryAndVariant, capacity, ec);
uloc_getVariant(locale, variant, sizeof(variant), ec);
if (variant[0] != 0) {
variantType = (uint32_t)(0 == uprv_strcmp(variant, VAR_EURO))
| ((uint32_t)(0 == uprv_strcmp(variant, VAR_PRE_EURO)) << 1);
if (variantType)
{
uprv_strcat(countryAndVariant, VAR_DELIM_STR);
uprv_strcat(countryAndVariant, variant);
}
}
return variantType;
}

// ------------------------------------------
Expand Down Expand Up @@ -568,7 +532,7 @@ ucurr_forLocale(const char* locale,

// get country or country_variant in `id'
char id[ULOC_FULLNAME_CAPACITY];
uint32_t variantType = idForLocale(locale, id, UPRV_LENGTHOF(id), ec);
idForLocale(locale, id, UPRV_LENGTHOF(id), ec);
if (U_FAILURE(*ec)) {
return 0;
}
Expand Down Expand Up @@ -602,20 +566,6 @@ ucurr_forLocale(const char* locale,
UResourceBundle *countryArray = ures_getByKey(rb, id, cm, &localStatus);
UResourceBundle *currencyReq = ures_getByIndex(countryArray, 0, NULL, &localStatus);
s = ures_getStringByKey(currencyReq, "id", &resLen, &localStatus);

// Get the second item when PREEURO is requested, and this is a known Euro country.
// If the requested variant is PREEURO, and this isn't a Euro country,
// assume that the country changed over to the Euro in the future.
// This is probably an old version of ICU that hasn't been updated yet.
// The latest currency is probably correct.
if (U_SUCCESS(localStatus)) {
if ((variantType & VARIANT_IS_PREEURO) && u_strcmp(s, EUR_STR) == 0) {
currencyReq = ures_getByIndex(countryArray, 1, currencyReq, &localStatus);
s = ures_getStringByKey(currencyReq, "id", &resLen, &localStatus);
} else if ((variantType & VARIANT_IS_EURO)) {
s = EUR_STR;
}
}
ures_close(currencyReq);
ures_close(countryArray);
}
Expand Down Expand Up @@ -2305,7 +2255,7 @@ ucurr_countCurrencies(const char* locale,
uloc_getKeywordValue(locale, "currency", id, ULOC_FULLNAME_CAPACITY, &localStatus);

// get country or country_variant in `id'
/*uint32_t variantType =*/ idForLocale(locale, id, sizeof(id), ec);
idForLocale(locale, id, sizeof(id), ec);

if (U_FAILURE(*ec))
{
Expand Down Expand Up @@ -2421,7 +2371,7 @@ ucurr_forLocaleAndDate(const char* locale,
resLen = uloc_getKeywordValue(locale, "currency", id, ULOC_FULLNAME_CAPACITY, &localStatus);

// get country or country_variant in `id'
/*uint32_t variantType =*/ idForLocale(locale, id, sizeof(id), ec);
idForLocale(locale, id, sizeof(id), ec);
if (U_FAILURE(*ec))
{
return 0;
Expand Down
Loading

0 comments on commit 1afef30

Please sign in to comment.