Skip to content

Commit 1afef30

Browse files
committed
ICU-20187 drop support for long-obsolete locale ID variants
1 parent d2e3a88 commit 1afef30

File tree

20 files changed

+297
-722
lines changed

20 files changed

+297
-722
lines changed

icu4c/source/common/putil.cpp

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,50 +1622,37 @@ The variant cannot have dots in it.
16221622
The 'rightmost' variant (@xxx) wins.
16231623
The leftmost codepage (.xxx) wins.
16241624
*/
1625-
char *correctedPOSIXLocale = 0;
16261625
const char* posixID = uprv_getPOSIXIDForDefaultLocale();
1627-
const char *p;
1628-
const char *q;
1629-
int32_t len;
16301626

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

1637-
if (gCorrectedPOSIXLocale != NULL) {
1633+
if (gCorrectedPOSIXLocale != nullptr) {
16381634
return gCorrectedPOSIXLocale;
16391635
}
16401636

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

1651-
/* do not copy after the @ */
1652-
if ((p = uprv_strchr(correctedPOSIXLocale, '@')) != NULL) {
1653-
correctedPOSIXLocale[p-correctedPOSIXLocale] = 0;
1645+
char *limit;
1646+
if ((limit = uprv_strchr(correctedPOSIXLocale, '.')) != nullptr) {
1647+
*limit = 0;
1648+
if ((limit = uprv_strchr(correctedPOSIXLocale, '@')) != nullptr) {
1649+
*limit = 0;
16541650
}
16551651
}
16561652

16571653
/* Note that we scan the *uncorrected* ID. */
1658-
if ((p = uprv_strrchr(posixID, '@')) != NULL) {
1659-
if (correctedPOSIXLocale == NULL) {
1660-
/* new locale can be 1 char longer than old one if @ -> __ */
1661-
correctedPOSIXLocale = static_cast<char *>(uprv_malloc(uprv_strlen(posixID)+2));
1662-
/* Exit on memory allocation error. */
1663-
if (correctedPOSIXLocale == NULL) {
1664-
return NULL;
1665-
}
1666-
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
1667-
correctedPOSIXLocale[p-posixID] = 0;
1668-
}
1654+
const char *p;
1655+
if ((p = uprv_strrchr(posixID, '@')) != nullptr) {
16691656
p++;
16701657

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

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

1684-
if ((q = uprv_strchr(p, '.')) != NULL) {
1671+
const char *q;
1672+
if ((q = uprv_strchr(p, '.')) != nullptr) {
16851673
/* How big will the resulting string be? */
1686-
len = (int32_t)(uprv_strlen(correctedPOSIXLocale) + (q-p));
1674+
int32_t len = (int32_t)(uprv_strlen(correctedPOSIXLocale) + (q-p));
16871675
uprv_strncat(correctedPOSIXLocale, p, q-p);
16881676
correctedPOSIXLocale[len] = 0;
16891677
}
@@ -1699,28 +1687,15 @@ The leftmost codepage (.xxx) wins.
16991687
*/
17001688
}
17011689

1702-
/* Was a correction made? */
1703-
if (correctedPOSIXLocale != NULL) {
1704-
posixID = correctedPOSIXLocale;
1705-
}
1706-
else {
1707-
/* copy it, just in case the original pointer goes away. See j2395 */
1708-
correctedPOSIXLocale = (char *)uprv_malloc(uprv_strlen(posixID) + 1);
1709-
/* Exit on memory allocation error. */
1710-
if (correctedPOSIXLocale == NULL) {
1711-
return NULL;
1712-
}
1713-
posixID = uprv_strcpy(correctedPOSIXLocale, posixID);
1714-
}
1715-
1716-
if (gCorrectedPOSIXLocale == NULL) {
1690+
if (gCorrectedPOSIXLocale == nullptr) {
17171691
gCorrectedPOSIXLocale = correctedPOSIXLocale;
17181692
gCorrectedPOSIXLocaleHeapAllocated = true;
17191693
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
1720-
correctedPOSIXLocale = NULL;
1694+
correctedPOSIXLocale = nullptr;
17211695
}
1696+
posixID = gCorrectedPOSIXLocale;
17221697

1723-
if (correctedPOSIXLocale != NULL) { /* Was already set - clean up. */
1698+
if (correctedPOSIXLocale != nullptr) { /* Was already set - clean up. */
17241699
uprv_free(correctedPOSIXLocale);
17251700
}
17261701

icu4c/source/common/ucurr.cpp

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,14 @@ static const char CURRENCY_MAP[] = "CurrencyMap";
8585
// Tag for default meta-data, in CURRENCY_META
8686
static const char DEFAULT_META[] = "DEFAULT";
8787

88-
// Variant for legacy pre-euro mapping in CurrencyMap
89-
static const char VAR_PRE_EURO[] = "PREEURO";
90-
91-
// Variant for legacy euro mapping in CurrencyMap
92-
static const char VAR_EURO[] = "EURO";
93-
9488
// Variant delimiter
9589
static const char VAR_DELIM = '_';
96-
static const char VAR_DELIM_STR[] = "_";
97-
98-
// Variant for legacy euro mapping in CurrencyMap
99-
//static const char VAR_DELIM_EURO[] = "_EURO";
100-
101-
#define VARIANT_IS_EMPTY 0
102-
#define VARIANT_IS_EURO 0x1
103-
#define VARIANT_IS_PREEURO 0x2
10490

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

110-
static const UChar EUR_STR[] = {0x0045,0x0055,0x0052,0};
111-
11296
// ISO codes mapping table
11397
static const UHashtable* gIsoCodes = NULL;
11498
static icu::UInitOnce gIsoCodesInitOnce = U_INITONCE_INITIALIZER;
@@ -360,30 +344,10 @@ _findMetaData(const UChar* currency, UErrorCode& ec) {
360344

361345
// -------------------------------------
362346

363-
/**
364-
* @see VARIANT_IS_EURO
365-
* @see VARIANT_IS_PREEURO
366-
*/
367-
static uint32_t
347+
static void
368348
idForLocale(const char* locale, char* countryAndVariant, int capacity, UErrorCode* ec)
369349
{
370-
uint32_t variantType = 0;
371-
// !!! this is internal only, assumes buffer is not null and capacity is sufficient
372-
// Extract the country name and variant name. We only
373-
// recognize two variant names, EURO and PREEURO.
374-
char variant[ULOC_FULLNAME_CAPACITY];
375350
ulocimp_getRegionForSupplementalData(locale, FALSE, countryAndVariant, capacity, ec);
376-
uloc_getVariant(locale, variant, sizeof(variant), ec);
377-
if (variant[0] != 0) {
378-
variantType = (uint32_t)(0 == uprv_strcmp(variant, VAR_EURO))
379-
| ((uint32_t)(0 == uprv_strcmp(variant, VAR_PRE_EURO)) << 1);
380-
if (variantType)
381-
{
382-
uprv_strcat(countryAndVariant, VAR_DELIM_STR);
383-
uprv_strcat(countryAndVariant, variant);
384-
}
385-
}
386-
return variantType;
387351
}
388352

389353
// ------------------------------------------
@@ -568,7 +532,7 @@ ucurr_forLocale(const char* locale,
568532

569533
// get country or country_variant in `id'
570534
char id[ULOC_FULLNAME_CAPACITY];
571-
uint32_t variantType = idForLocale(locale, id, UPRV_LENGTHOF(id), ec);
535+
idForLocale(locale, id, UPRV_LENGTHOF(id), ec);
572536
if (U_FAILURE(*ec)) {
573537
return 0;
574538
}
@@ -602,20 +566,6 @@ ucurr_forLocale(const char* locale,
602566
UResourceBundle *countryArray = ures_getByKey(rb, id, cm, &localStatus);
603567
UResourceBundle *currencyReq = ures_getByIndex(countryArray, 0, NULL, &localStatus);
604568
s = ures_getStringByKey(currencyReq, "id", &resLen, &localStatus);
605-
606-
// Get the second item when PREEURO is requested, and this is a known Euro country.
607-
// If the requested variant is PREEURO, and this isn't a Euro country,
608-
// assume that the country changed over to the Euro in the future.
609-
// This is probably an old version of ICU that hasn't been updated yet.
610-
// The latest currency is probably correct.
611-
if (U_SUCCESS(localStatus)) {
612-
if ((variantType & VARIANT_IS_PREEURO) && u_strcmp(s, EUR_STR) == 0) {
613-
currencyReq = ures_getByIndex(countryArray, 1, currencyReq, &localStatus);
614-
s = ures_getStringByKey(currencyReq, "id", &resLen, &localStatus);
615-
} else if ((variantType & VARIANT_IS_EURO)) {
616-
s = EUR_STR;
617-
}
618-
}
619569
ures_close(currencyReq);
620570
ures_close(countryArray);
621571
}
@@ -2305,7 +2255,7 @@ ucurr_countCurrencies(const char* locale,
23052255
uloc_getKeywordValue(locale, "currency", id, ULOC_FULLNAME_CAPACITY, &localStatus);
23062256

23072257
// get country or country_variant in `id'
2308-
/*uint32_t variantType =*/ idForLocale(locale, id, sizeof(id), ec);
2258+
idForLocale(locale, id, sizeof(id), ec);
23092259

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

24232373
// get country or country_variant in `id'
2424-
/*uint32_t variantType =*/ idForLocale(locale, id, sizeof(id), ec);
2374+
idForLocale(locale, id, sizeof(id), ec);
24252375
if (U_FAILURE(*ec))
24262376
{
24272377
return 0;

0 commit comments

Comments
 (0)