summaryrefslogtreecommitdiffstats
path: root/icu/src/main
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-04-01 13:56:32 -0700
committerElliott Hughes <enh@google.com>2010-04-01 13:56:32 -0700
commitf9157eaea53923d3dbe6a521b29427819052f176 (patch)
tree23d24f5bad0fdaed99ee5e81de7d2f488d4edd19 /icu/src/main
parentf072c0384c0b12f081fb99bc365d284ae6381379 (diff)
downloadlibcore-f9157eaea53923d3dbe6a521b29427819052f176.zip
libcore-f9157eaea53923d3dbe6a521b29427819052f176.tar.gz
libcore-f9157eaea53923d3dbe6a521b29427819052f176.tar.bz2
Tidy up our getAvailableLocales methods to actually ask ICU4C.
These specialized methods are little used, and in several cases ICU itself just returns the list of locales, but that's ICU's business, not ours. As long as ICU is in charge of our locale-specific data, it should be responsible for answering questions about what locale-specific data is available... Change-Id: Idc8a66bbf7fcbc6b06e30929e6a7af3fe30ab7d1
Diffstat (limited to 'icu/src/main')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/Collator.java4
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java5
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java2
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/Resources.java84
-rw-r--r--icu/src/main/native/NativeBreakIterator.cpp16
-rw-r--r--icu/src/main/native/NativeCollation.cpp16
-rw-r--r--icu/src/main/native/Resources.cpp89
7 files changed, 103 insertions, 113 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
index f108737..3673d32 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
@@ -324,8 +324,4 @@ public abstract class Collator implements Cloneable {
* @stable ICU 2.4
*/
public abstract int hashCode();
-
- public static Locale[] getAvailableLocales() {
- return Resources.localesFromStrings(NativeCollation.getAvailableLocalesImpl());
- }
}
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
index 3f67a64..91f2beb 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
@@ -125,10 +125,6 @@ public final class NativeBreakIterator implements Cloneable {
return precedingImpl(this.addr, offset);
}
- public static Locale[] getAvailableLocales() {
- return Resources.localesFromStrings(getAvailableLocalesImpl());
- }
-
public static NativeBreakIterator getCharacterInstance(Locale where) {
return new NativeBreakIterator(getCharacterInstanceImpl(where.toString()), BI_CHAR_INSTANCE);
}
@@ -145,7 +141,6 @@ public final class NativeBreakIterator implements Cloneable {
return new NativeBreakIterator(getWordInstanceImpl(where.toString()), BI_WORD_INSTANCE);
}
- private static native String[] getAvailableLocalesImpl();
private static native int getCharacterInstanceImpl(String locale);
private static native int getWordInstanceImpl(String locale);
private static native int getLineInstanceImpl(String locale);
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
index 7d474ef..fbdcf93 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
@@ -244,6 +244,4 @@ final class NativeCollation
* @internal ICU 2.4
*/
static native void setOffset(int address, int offset);
-
- static native String[] getAvailableLocalesImpl();
}
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
index aae2ff4..874d9be 100644
--- a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
+++ b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
@@ -39,22 +39,17 @@ public final class Resources {
/**
* Cache for ISO language names.
*/
- private static String[] isoLanguages = null;
+ private static String[] isoLanguages;
/**
* Cache for ISO country names.
*/
- private static String[] isoCountries = null;
-
- /**
- * Available locales cache.
- */
- private static String[] availableLocales = null;
+ private static String[] isoCountries;
/**
* Available timezones cache.
*/
- private static String[] availableTimezones = null;
+ private static String[] availableTimezones;
/**
* Returns a shared LocaleData for the given locale.
@@ -102,7 +97,7 @@ public final class Resources {
/**
* Returns an array of ISO language names (two-letter codes), fetched either
* from ICU's database or from our memory cache.
- *
+ *
* @return The array.
*/
public static String[] getISOLanguages() {
@@ -116,7 +111,7 @@ public final class Resources {
/**
* Returns an array of ISO country names (two-letter codes), fetched either
* from ICU's database or from our memory cache.
- *
+ *
* @return The array.
*/
public static String[] getISOCountries() {
@@ -128,23 +123,9 @@ public final class Resources {
}
/**
- * Returns an array of names of locales that are available in the system,
- * fetched either from ICU's database or from our memory cache.
- *
- * @return The array.
- */
- public static String[] getAvailableLocales() {
- if (availableLocales == null) {
- availableLocales = getAvailableLocalesNative();
- }
-
- return availableLocales.clone();
- }
-
- /**
* Returns an array of names of timezones that are available in the system,
* fetched either from the TimeZone class or from our memory cache.
- *
+ *
* @return The array.
*/
public static String[] getKnownTimezones() {
@@ -158,7 +139,7 @@ public final class Resources {
/**
* Returns the display name for the given time zone using the given locale.
- *
+ *
* @param id The time zone ID, for example "Europe/Berlin"
* @param daylight Indicates whether daylight savings is in use
* @param style The style, 0 for long, 1 for short
@@ -261,7 +242,7 @@ public final class Resources {
/**
* Returns the display names for all given timezones using the given locale.
- *
+ *
* @return An array of time zone strings. Each row represents one time zone.
* The first columns holds the ID of the time zone, for example
* "Europe/Berlin". The other columns then hold for each row the
@@ -274,14 +255,14 @@ public final class Resources {
if (locale == null) {
locale = defaultLocale;
}
-
+
// If locale == default and the default locale hasn't changed since
// DefaultTimeZones loaded, return the cached names.
// TODO: We should force a reboot if the default locale changes.
if (defaultLocale.equals(locale) && DefaultTimeZones.locale.equals(defaultLocale)) {
return clone2dStringArray(DefaultTimeZones.names);
}
-
+
return createTimeZoneNamesFor(locale);
}
@@ -322,8 +303,51 @@ public final class Resources {
return result;
}
+ private static Locale[] availableLocalesCache;
+ public static Locale[] getAvailableLocales() {
+ if (availableLocalesCache == null) {
+ availableLocalesCache = localesFromStrings(getAvailableLocalesNative());
+ }
+ return availableLocalesCache.clone();
+ }
+
+ public static Locale[] getAvailableBreakIteratorLocales() {
+ return localesFromStrings(getAvailableBreakIteratorLocalesNative());
+ }
+
+ public static Locale[] getAvailableCalendarLocales() {
+ return localesFromStrings(getAvailableCalendarLocalesNative());
+ }
+
+ public static Locale[] getAvailableCollatorLocales() {
+ return localesFromStrings(getAvailableCollatorLocalesNative());
+ }
+
+ public static Locale[] getAvailableDateFormatLocales() {
+ return localesFromStrings(getAvailableDateFormatLocalesNative());
+ }
+
+ public static Locale[] getAvailableDateFormatSymbolsLocales() {
+ return getAvailableDateFormatLocales();
+ }
+
+ public static Locale[] getAvailableDecimalFormatSymbolsLocales() {
+ return getAvailableNumberFormatLocales();
+ }
+
+ public static Locale[] getAvailableNumberFormatLocales() {
+ return localesFromStrings(getAvailableNumberFormatLocalesNative());
+ }
+
// --- Native methods accessing ICU's database ----------------------------
+ private static native String[] getAvailableBreakIteratorLocalesNative();
+ private static native String[] getAvailableCalendarLocalesNative();
+ private static native String[] getAvailableCollatorLocalesNative();
+ private static native String[] getAvailableDateFormatLocalesNative();
+ private static native String[] getAvailableLocalesNative();
+ private static native String[] getAvailableNumberFormatLocalesNative();
+
public static native String getDisplayCountryNative(String countryCode, String locale);
public static native String getDisplayLanguageNative(String languageCode, String locale);
public static native String getDisplayVariantNative(String variantCode, String locale);
@@ -336,8 +360,6 @@ public final class Resources {
public static native int getCurrencyFractionDigitsNative(String currencyCode);
- private static native String[] getAvailableLocalesNative();
-
private static native String[] getISOLanguagesNative();
private static native String[] getISOCountriesNative();
diff --git a/icu/src/main/native/NativeBreakIterator.cpp b/icu/src/main/native/NativeBreakIterator.cpp
index cd6e712..6cc774b 100644
--- a/icu/src/main/native/NativeBreakIterator.cpp
+++ b/icu/src/main/native/NativeBreakIterator.cpp
@@ -22,21 +22,6 @@
#include "unicode/putil.h"
#include <stdlib.h>
-static jobjectArray getAvailableLocalesImpl(JNIEnv* env, jclass) {
- jclass stringClass = env->FindClass("java/lang/String");
- if (stringClass == NULL) {
- return NULL;
- }
- size_t count = ubrk_countAvailable();
- jobjectArray result = env->NewObjectArray(count, stringClass, NULL);
- for (size_t i = 0; i < count; ++i) {
- jstring s = env->NewStringUTF(ubrk_getAvailable(i));
- env->SetObjectArrayElement(result, i, s);
- env->DeleteLocalRef(s);
- }
- return result;
-}
-
static jint getIterator(JNIEnv* env, jstring locale, UBreakIteratorType type) {
UErrorCode status = U_ZERO_ERROR;
ScopedUtfChars localeChars(env, locale);
@@ -140,7 +125,6 @@ static JNINativeMethod gMethods[] = {
{ "currentImpl", "(I)I", (void*) currentImpl },
{ "firstImpl", "(I)I", (void*) firstImpl },
{ "followingImpl", "(II)I", (void*) followingImpl },
- { "getAvailableLocalesImpl", "()[Ljava/lang/String;", (void*) getAvailableLocalesImpl },
{ "getCharacterInstanceImpl", "(Ljava/lang/String;)I", (void*) getCharacterInstanceImpl },
{ "getLineInstanceImpl", "(Ljava/lang/String;)I", (void*) getLineInstanceImpl },
{ "getSentenceInstanceImpl", "(Ljava/lang/String;)I", (void*) getSentenceInstanceImpl },
diff --git a/icu/src/main/native/NativeCollation.cpp b/icu/src/main/native/NativeCollation.cpp
index 09f192b..148c16e 100644
--- a/icu/src/main/native/NativeCollation.cpp
+++ b/icu/src/main/native/NativeCollation.cpp
@@ -496,24 +496,8 @@ static void setText(JNIEnv *env, jclass obj, jint address,
icu4jni_error(env, status);
}
-static jobjectArray getAvailableLocalesImpl(JNIEnv *env, jclass clazz) {
- jclass stringClass = env->FindClass("java/lang/String");
- if (stringClass == NULL) {
- return NULL;
- }
- size_t count = ucol_countAvailable();
- jobjectArray result = env->NewObjectArray(count, stringClass, NULL);
- for (size_t i = 0; i < count; ++i) {
- jstring s = env->NewStringUTF(ucol_getAvailable(i));
- env->SetObjectArrayElement(result, i, s);
- env->DeleteLocalRef(s);
- }
- return result;
-}
-
static JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
- { "getAvailableLocalesImpl", "()[Ljava/lang/String;", (void*) getAvailableLocalesImpl },
{ "openCollator", "()I", (void*) openCollator__ },
{ "openCollator", "(Ljava/lang/String;)I", (void*) openCollator__Ljava_lang_String_2 },
{ "openCollatorFromRules", "(Ljava/lang/String;II)I", (void*) openCollatorFromRules },
diff --git a/icu/src/main/native/Resources.cpp b/icu/src/main/native/Resources.cpp
index 1dd4bff..e4138b1 100644
--- a/icu/src/main/native/Resources.cpp
+++ b/icu/src/main/native/Resources.cpp
@@ -20,7 +20,10 @@
#include "cutils/log.h"
#include "unicode/numfmt.h"
#include "unicode/locid.h"
+#include "unicode/ubrk.h"
#include "unicode/ucal.h"
+#include "unicode/ucol.h"
+#include "unicode/udat.h"
#include "unicode/gregocal.h"
#include "unicode/ucurr.h"
#include "unicode/calendar.h"
@@ -239,17 +242,42 @@ static jobjectArray getISOLanguagesNative(JNIEnv* env, jclass clazz) {
return toStringArray(env, Locale::getISOLanguages());
}
-static jobjectArray getAvailableLocalesNative(JNIEnv* env, jclass clazz) {
- size_t count = uloc_countAvailable();
+template <typename Counter, typename Getter>
+static jobjectArray getAvailableLocales(JNIEnv* env, Counter* counter, Getter* getter) {
+ size_t count = (*counter)();
jobjectArray result = env->NewObjectArray(count, string_class, NULL);
for (size_t i = 0; i < count; ++i) {
- jstring s = env->NewStringUTF(uloc_getAvailable(i));
+ jstring s = env->NewStringUTF((*getter)(i));
env->SetObjectArrayElement(result, i, s);
env->DeleteLocalRef(s);
}
return result;
}
+static jobjectArray getAvailableLocalesNative(JNIEnv* env, jclass) {
+ return getAvailableLocales(env, uloc_countAvailable, uloc_getAvailable);
+}
+
+static jobjectArray getAvailableBreakIteratorLocalesNative(JNIEnv* env, jclass) {
+ return getAvailableLocales(env, ubrk_countAvailable, ubrk_getAvailable);
+}
+
+static jobjectArray getAvailableCalendarLocalesNative(JNIEnv* env, jclass) {
+ return getAvailableLocales(env, ucal_countAvailable, ucal_getAvailable);
+}
+
+static jobjectArray getAvailableCollatorLocalesNative(JNIEnv* env, jclass) {
+ return getAvailableLocales(env, ucol_countAvailable, ucol_getAvailable);
+}
+
+static jobjectArray getAvailableDateFormatLocalesNative(JNIEnv* env, jclass) {
+ return getAvailableLocales(env, udat_countAvailable, udat_getAvailable);
+}
+
+static jobjectArray getAvailableNumberFormatLocalesNative(JNIEnv* env, jclass) {
+ return getAvailableLocales(env, unum_countAvailable, unum_getAvailable);
+}
+
static TimeZone* timeZoneFromId(JNIEnv* env, jstring id) {
const jchar* chars = env->GetStringChars(id, NULL);
const UnicodeString zoneID(reinterpret_cast<const UChar*>(chars), env->GetStringLength(id));
@@ -690,42 +718,25 @@ static jboolean initLocaleDataImpl(JNIEnv* env, jclass clazz, jstring locale, jo
static JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
- {"getCurrencyFractionDigitsNative", "(Ljava/lang/String;)I",
- (void*) getCurrencyFractionDigitsNative},
- {"getCurrencyCodeNative", "(Ljava/lang/String;)Ljava/lang/String;",
- (void*) getCurrencyCodeNative},
- {"getCurrencySymbolNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
- (void*) getCurrencySymbolNative},
- {"getDisplayCountryNative",
- "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
- (void*) getDisplayCountryNative},
- {"getDisplayLanguageNative",
- "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
- (void*) getDisplayLanguageNative},
- {"getDisplayVariantNative",
- "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
- (void*) getDisplayVariantNative},
- {"getISO3CountryNative",
- "(Ljava/lang/String;)Ljava/lang/String;",
- (void*) getISO3CountryNative},
- {"getISO3LanguageNative",
- "(Ljava/lang/String;)Ljava/lang/String;",
- (void*) getISO3LanguageNative},
- {"getISOCountriesNative", "()[Ljava/lang/String;",
- (void*) getISOCountriesNative},
- {"getISOLanguagesNative", "()[Ljava/lang/String;",
- (void*) getISOLanguagesNative},
- {"getAvailableLocalesNative", "()[Ljava/lang/String;",
- (void*) getAvailableLocalesNative},
- {"getTimeZonesNative",
- "([[Ljava/lang/String;Ljava/lang/String;)V",
- (void*) getTimeZonesNative},
- {"getDisplayTimeZoneNative",
- "(Ljava/lang/String;ZILjava/lang/String;)Ljava/lang/String;",
- (void*) getDisplayTimeZoneNative},
- {"initLocaleDataImpl",
- "(Ljava/lang/String;Lcom/ibm/icu4jni/util/LocaleData;)Z",
- (void*) initLocaleDataImpl},
+ {"getAvailableBreakIteratorLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableBreakIteratorLocalesNative},
+ {"getAvailableCalendarLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableCalendarLocalesNative},
+ {"getAvailableCollatorLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableCollatorLocalesNative},
+ {"getAvailableDateFormatLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableDateFormatLocalesNative},
+ {"getAvailableLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableLocalesNative},
+ {"getAvailableNumberFormatLocalesNative", "()[Ljava/lang/String;", (void*) getAvailableNumberFormatLocalesNative},
+ {"getCurrencyCodeNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getCurrencyCodeNative},
+ {"getCurrencyFractionDigitsNative", "(Ljava/lang/String;)I", (void*) getCurrencyFractionDigitsNative},
+ {"getCurrencySymbolNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getCurrencySymbolNative},
+ {"getDisplayCountryNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getDisplayCountryNative},
+ {"getDisplayLanguageNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getDisplayLanguageNative},
+ {"getDisplayTimeZoneNative", "(Ljava/lang/String;ZILjava/lang/String;)Ljava/lang/String;", (void*) getDisplayTimeZoneNative},
+ {"getDisplayVariantNative", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void*) getDisplayVariantNative},
+ {"getISO3CountryNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getISO3CountryNative},
+ {"getISO3LanguageNative", "(Ljava/lang/String;)Ljava/lang/String;", (void*) getISO3LanguageNative},
+ {"getISOCountriesNative", "()[Ljava/lang/String;", (void*) getISOCountriesNative},
+ {"getISOLanguagesNative", "()[Ljava/lang/String;", (void*) getISOLanguagesNative},
+ {"getTimeZonesNative", "([[Ljava/lang/String;Ljava/lang/String;)V", (void*) getTimeZonesNative},
+ {"initLocaleDataImpl", "(Ljava/lang/String;Lcom/ibm/icu4jni/util/LocaleData;)Z", (void*) initLocaleDataImpl},
};
int register_com_ibm_icu4jni_util_Resources(JNIEnv* env) {