/*
*****************************************************************************************
-* Copyright (C) 2014-2016 Apple Inc. All Rights Reserved.
+* Copyright (C) 2014-2017 Apple Inc. All Rights Reserved.
*****************************************************************************************
*/
#include <stdio.h>
#endif
#include <string.h>
+#include <ctype.h>
#include "unicode/utypes.h"
#include "unicode/ualoc.h"
#include "unicode/uloc.h"
// uloc_minimizeSubtags(locale, normalized, normalizedCapacity, status);
const char *replacement = NULL;
- if (gMapDataState > 0) {
- replacement = (const char *)uhash_get(gAliasMap, locale);
+ if (icu::gMapDataState > 0) {
+ replacement = (const char *)uhash_get(icu::gAliasMap, locale);
}
if (replacement == NULL) {
replacement = locale;
if (U_FAILURE(*status)) {
return;
}
- if (gMapDataState > 0) {
- const char *replacement = (const char *)uhash_get(gParentMap, locale);
+ if (icu::gMapDataState > 0) {
+ const char *replacement = (const char *)uhash_get(icu::gParentMap, locale);
if (replacement) {
int32_t len = uprv_strlen(replacement);
if (len < parentCapacity) { // allow for 0 termination
return locParentMap[locParentIndex].parent;
}
}
- if (gMapDataState > 0) {
- const char *replacement = (const char *)uhash_get(gParentMap, locale);
+ if (icu::gMapDataState > 0) {
+ const char *replacement = (const char *)uhash_get(icu::gParentMap, locale);
if (replacement) {
*distance = 1;
return replacement;
return -1;
}
// get resource data, need to protect with mutex
- if (gMapDataState == 0) {
- umtx_initOnce(gUALocaleCacheInitOnce, initializeMapData);
+ if (icu::gMapDataState == 0) {
+ umtx_initOnce(icu::gUALocaleCacheInitOnce, initializeMapData);
}
int32_t locsToUseCount = 0;
int32_t prefLangIndex, availLocIndex = 0;
for (availLocIndex = 0; availLocIndex < availableLocalizationsCount; availLocIndex++) {
char availLocMinOrParent[kLangScriptRegMaxLen + 1];
int32_t distance;
- // first check for special Apple parents of availLocNorm -
- // - the number of locales with such parents is small -
- // or if not such parent, then try stripping region.
+ // first check for special Apple parents of availLocNorm; the number
+ // of locales with such parents is small.
+ // If no such parent, or if parent has an intermediate numeric region,
+ // then try stripping the original region.
+ int32_t availLocParentLen = 0;
const char *availLocParent = getLocParent(availLocNorm[availLocIndex], &distance);
if (availLocParent) {
#if DEBUG_UALOC
#endif
continue;
}
+ availLocParentLen = uprv_strlen(availLocParent);
}
if (minDistance <= 1) {
continue; // we can't get any closer in the rest of this iteration
}
- if (availLocParent == NULL) {
+ if (availLocParent == NULL || (availLocParentLen >= 6 && isdigit(availLocParent[availLocParentLen-1]))) {
tmpStatus = U_ZERO_ERROR;
int32_t regLen = uloc_getCountry(availLocNorm[availLocIndex], availLocMinOrParent, kLangScriptRegMaxLen, &tmpStatus);
if (U_SUCCESS(tmpStatus) && regLen > 1) {