src/java.base/windows/native/libjava/HostLocaleProviderAdapter_md.c
changeset 54097 9fc262a75638
parent 47216 71c04702a3d5
child 59043 1a79b4bfc85a
equal deleted inserted replaced
54096:acf36e8d61c6 54097:9fc262a75638
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   166             }
   166             }
   167         }
   167         }
   168     }
   168     }
   169 };
   169 };
   170 
   170 
   171 
       
   172 // Localized region name for unknown regions (Windows 10)
       
   173 #define UNKNOWN_REGION  L"Unknown Region ("
       
   174 #define UNKNOWN_REGION_SIZE wcslen(UNKNOWN_REGION)
       
   175 
       
   176 /*
   171 /*
   177  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
   172  * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
   178  * Method:    initialize
   173  * Method:    initialize
   179  * Signature: ()Z
   174  * Signature: ()Z
   180  */
   175  */
   753     CHECK_NULL_RETURN(pjChar, NULL);
   748     CHECK_NULL_RETURN(pjChar, NULL);
   754     got = getLocaleInfoWrapper(pjChar, lcType, buf, BUFLEN);
   749     got = getLocaleInfoWrapper(pjChar, lcType, buf, BUFLEN);
   755     (*env)->ReleaseStringChars(env, jStr, pjChar);
   750     (*env)->ReleaseStringChars(env, jStr, pjChar);
   756 
   751 
   757     if (got) {
   752     if (got) {
   758         // Hack: Windows 10 returns "Unknown Region (XX)" for localized XX region name.
   753         return (*env)->NewString(env, buf, (jsize)wcslen(buf));
   759         // Take that as not known.
   754     } else {
   760         if (type != sun_util_locale_provider_HostLocaleProviderAdapterImpl_DN_LOCALE_REGION ||
   755         return NULL;
   761             wcsncmp(UNKNOWN_REGION, buf, UNKNOWN_REGION_SIZE) != 0) {
   756     }
   762             return (*env)->NewString(env, buf, (jsize)wcslen(buf));
       
   763         }
       
   764     }
       
   765 
       
   766     return NULL;
       
   767 }
   757 }
   768 
   758 
   769 int getLocaleInfoWrapper(const jchar *langtag, LCTYPE type, LPWSTR data, int buflen) {
   759 int getLocaleInfoWrapper(const jchar *langtag, LCTYPE type, LPWSTR data, int buflen) {
   770     if (pGetLocaleInfoEx) {
   760     if (pGetLocaleInfoEx) {
   771         if (wcscmp(L"und", (LPWSTR)langtag) == 0) {
   761         if (wcscmp(L"und", (LPWSTR)langtag) == 0) {