]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/ualoc.cpp
ICU-62135.0.1.tar.gz
[apple/icu.git] / icuSources / common / ualoc.cpp
index 1458531ad26763bdde0361dfd1cab4bf6d9a8bd4..5bb1a52e97c3e6a5ae8505aa1e1e7e24b2170591 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *****************************************************************************************
-* Copyright (C) 2014-2016 Apple Inc. All Rights Reserved.
+* Copyright (C) 2014-2017 Apple Inc. All Rights Reserved.
 *****************************************************************************************
 */
 
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #endif
 #include <string.h>
+#include <ctype.h>
 #include "unicode/utypes.h"
 #include "unicode/ualoc.h"
 #include "unicode/uloc.h"
@@ -747,8 +748,8 @@ static void ualoc_normalize(const char *locale, char *normalized, int32_t normal
     // 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;
@@ -766,8 +767,8 @@ static void ualoc_getParent(const char *locale, char *parent, int32_t parentCapa
     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
@@ -792,8 +793,8 @@ static const char * getLocParent(const char *locale, int32_t* distance)
             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;
@@ -833,8 +834,8 @@ ualoc_localizationsToUse( const char* const *preferredLanguages,
         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;
@@ -1015,9 +1016,11 @@ ualoc_localizationsToUse( const char* const *preferredLanguages,
                 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
@@ -1032,11 +1035,12 @@ ualoc_localizationsToUse( const char* const *preferredLanguages,
 #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) {