7091601: Arabic Locale: can not set type of digit in application level
authornaoto
Wed, 03 Apr 2013 10:32:38 -0700
changeset 16733 9267ec7004a1
parent 16732 c96397eeca72
child 16734 da1901d79073
7091601: Arabic Locale: can not set type of digit in application level Reviewed-by: okutsu
jdk/src/macosx/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c
jdk/src/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java
--- a/jdk/src/macosx/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c	Wed Apr 03 12:47:15 2013 -0400
+++ b/jdk/src/macosx/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c	Wed Apr 03 10:32:38 2013 -0700
@@ -32,8 +32,8 @@
 static CFDateFormatterStyle convertDateFormatterStyle(jint javaStyle);
 static CFNumberFormatterStyle convertNumberFormatterStyle(jint javaStyle);
 static void copyArrayElements(JNIEnv *env, CFArrayRef cfarray, jobjectArray jarray, CFIndex sindex, int dindex, int count);
-static jstring getNumberSymbolString(JNIEnv *env, jstring jdefault, CFStringRef type);
-static jchar getNumberSymbolChar(jchar jdefault, CFStringRef type);
+static jstring getNumberSymbolString(JNIEnv *env, jstring jlangtag, jstring jdefault, CFStringRef type);
+static jchar getNumberSymbolChar(JNIEnv *env, jstring jlangtag, jchar jdefault, CFStringRef type);
 
 // from java_props_macosx.c
 extern char * getMacOSXLocale(int cat);
@@ -322,7 +322,7 @@
  */
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCurrencySymbol
   (JNIEnv *env, jclass cls, jstring jlangtag, jstring currencySymbol) {
-    return getNumberSymbolString(env, currencySymbol, kCFNumberFormatterCurrencySymbol);
+    return getNumberSymbolString(env, jlangtag, currencySymbol, kCFNumberFormatterCurrencySymbol);
 }
 
 /*
@@ -332,7 +332,7 @@
  */
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDecimalSeparator
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar decimalSeparator) {
-    return getNumberSymbolChar(decimalSeparator, kCFNumberFormatterDecimalSeparator);
+    return getNumberSymbolChar(env, jlangtag, decimalSeparator, kCFNumberFormatterDecimalSeparator);
 }
 
 /*
@@ -342,7 +342,7 @@
  */
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getGroupingSeparator
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar groupingSeparator) {
-    return getNumberSymbolChar(groupingSeparator, kCFNumberFormatterGroupingSeparator);
+    return getNumberSymbolChar(env, jlangtag, groupingSeparator, kCFNumberFormatterGroupingSeparator);
 }
 
 /*
@@ -352,7 +352,7 @@
  */
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInfinity
   (JNIEnv *env, jclass cls, jstring jlangtag, jstring infinity) {
-    return getNumberSymbolString(env, infinity, kCFNumberFormatterInfinitySymbol);
+    return getNumberSymbolString(env, jlangtag, infinity, kCFNumberFormatterInfinitySymbol);
 }
 
 /*
@@ -362,7 +362,7 @@
  */
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInternationalCurrencySymbol
   (JNIEnv *env, jclass cls, jstring jlangtag, jstring internationalCurrencySymbol) {
-    return getNumberSymbolString(env, internationalCurrencySymbol, kCFNumberFormatterInternationalCurrencySymbol);
+    return getNumberSymbolString(env, jlangtag, internationalCurrencySymbol, kCFNumberFormatterInternationalCurrencySymbol);
 }
 
 /*
@@ -372,7 +372,7 @@
  */
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMinusSign
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar minusSign) {
-    return getNumberSymbolChar(minusSign, kCFNumberFormatterMinusSign);
+    return getNumberSymbolChar(env, jlangtag, minusSign, kCFNumberFormatterMinusSign);
 }
 
 /*
@@ -382,7 +382,7 @@
  */
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMonetaryDecimalSeparator
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar monetaryDecimalSeparator) {
-    return getNumberSymbolChar(monetaryDecimalSeparator, kCFNumberFormatterCurrencyDecimalSeparator);
+    return getNumberSymbolChar(env, jlangtag, monetaryDecimalSeparator, kCFNumberFormatterCurrencyDecimalSeparator);
 }
 
 /*
@@ -392,7 +392,7 @@
  */
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getNaN
   (JNIEnv *env, jclass cls, jstring jlangtag, jstring nan) {
-    return getNumberSymbolString(env, nan, kCFNumberFormatterNaNSymbol);
+    return getNumberSymbolString(env, jlangtag, nan, kCFNumberFormatterNaNSymbol);
 }
 
 /*
@@ -402,7 +402,7 @@
  */
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPercent
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar percent) {
-    return getNumberSymbolChar(percent, kCFNumberFormatterPercentSymbol);
+    return getNumberSymbolChar(env, jlangtag, percent, kCFNumberFormatterPercentSymbol);
 }
 
 /*
@@ -412,7 +412,7 @@
  */
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPerMill
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar perMill) {
-    return getNumberSymbolChar(perMill, kCFNumberFormatterPerMillSymbol);
+    return getNumberSymbolChar(env, jlangtag, perMill, kCFNumberFormatterPerMillSymbol);
 }
 
 /*
@@ -422,7 +422,36 @@
  */
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getZeroDigit
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar zeroDigit) {
-    return getNumberSymbolChar(zeroDigit, kCFNumberFormatterZeroSymbol);
+    // The following code *should* work, but not for some reason :o
+    //
+    //return getNumberSymbolChar(env, jlangtag, zeroDigit, kCFNumberFormatterZeroSymbol);
+    //
+    // so here is a workaround.
+    jchar ret = zeroDigit;
+    CFLocaleRef cflocale = CFLocaleCopyCurrent();
+
+    if (cflocale != NULL) {
+        CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
+                                                  cflocale,
+                                                  kCFNumberFormatterNoStyle);
+        if (nf != NULL) {
+            int zero = 0;
+            CFStringRef str = CFNumberFormatterCreateStringWithValue(kCFAllocatorDefault,
+                              nf, kCFNumberIntType, &zero);
+            if (str != NULL) {
+                if (CFStringGetLength(str) > 0) {
+                    ret = CFStringGetCharacterAtIndex(str, 0);
+                }
+                CFRelease(str);
+            }
+
+            CFRelease(nf);
+        }
+
+        CFRelease(cflocale);
+    }
+
+    return ret;
 }
 
 /*
@@ -432,7 +461,7 @@
  */
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getExponentSeparator
   (JNIEnv *env, jclass cls, jstring jlangtag, jstring exponent) {
-    return getNumberSymbolString(env, exponent, kCFNumberFormatterExponentSymbol);
+    return getNumberSymbolString(env, jlangtag, exponent, kCFNumberFormatterExponentSymbol);
 }
 
 /*
@@ -625,7 +654,7 @@
     }
 }
 
-static jstring getNumberSymbolString(JNIEnv *env, jstring jdefault, CFStringRef type) {
+static jstring getNumberSymbolString(JNIEnv *env, jstring jlangtag, jstring jdefault, CFStringRef type) {
     char buf[BUFLEN];
     jstring ret = jdefault;
     CFLocaleRef cflocale = CFLocaleCopyCurrent();
@@ -633,7 +662,7 @@
     if (cflocale != NULL) {
         CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
                                                   cflocale,
-                                                  kCFNumberFormatterDecimalStyle);
+                                                  kCFNumberFormatterNoStyle);
         if (nf != NULL) {
             CFStringRef str = CFNumberFormatterCopyProperty(nf, type);
             if (str != NULL) {
@@ -651,21 +680,21 @@
     return ret;
 }
 
-static jchar getNumberSymbolChar(jchar jdefault, CFStringRef type) {
-    char buf[BUFLEN];
+static jchar getNumberSymbolChar(JNIEnv *env, jstring jlangtag, jchar jdefault, CFStringRef type) {
     jchar ret = jdefault;
     CFLocaleRef cflocale = CFLocaleCopyCurrent();
 
     if (cflocale != NULL) {
         CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorDefault,
                                                   cflocale,
-                                                  kCFNumberFormatterDecimalStyle);
+                                                  kCFNumberFormatterNoStyle);
         if (nf != NULL) {
             CFStringRef str = CFNumberFormatterCopyProperty(nf, type);
             if (str != NULL) {
-                CFStringGetCString(str, buf, BUFLEN, kCFStringEncodingUTF8);
+                if (CFStringGetLength(str) > 0) {
+                    ret = CFStringGetCharacterAtIndex(str, 0);
+                }
                 CFRelease(str);
-                ret = buf[0];
             }
 
             CFRelease(nf);
--- a/jdk/src/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java	Wed Apr 03 12:47:15 2013 -0400
+++ b/jdk/src/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java	Wed Apr 03 10:32:38 2013 -0700
@@ -303,9 +303,7 @@
                     dfs.setNaN(getNaN(langTag, dfs.getNaN()));
                     dfs.setPercent(getPercent(langTag, dfs.getPercent()));
                     dfs.setPerMill(getPerMill(langTag, dfs.getPerMill()));
-                    if (isNativeDigit(langTag)) {
-                        dfs.setZeroDigit(getZeroDigit(langTag, dfs.getZeroDigit()));
-                    }
+                    dfs.setZeroDigit(getZeroDigit(langTag, dfs.getZeroDigit()));
                     ref = new SoftReference<>(dfs);
                     decimalFormatSymbolsCache.put(locale, ref);
                 }
@@ -420,9 +418,13 @@
             return false;
         }
 
+        int calid = getCalendarID(locale.toLanguageTag());
+        if (calid <= 0 || calid >= calIDToLDML.length) {
+            return false;
+        }
+
         String requestedCalType = locale.getUnicodeLocaleType("ca");
-        String nativeCalType =
-                calIDToLDML[getCalendarID(locale.toLanguageTag())]
+        String nativeCalType = calIDToLDML[calid]
                 .replaceFirst("_.*", ""); // remove locale part.
 
         if (requestedCalType == null) {