summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-07-30 16:41:10 +0100
committerNarayan Kamath <narayan@google.com>2014-07-31 12:27:37 +0100
commit9c4462b3d88a36c92d23d4274195e4a7f7a372e5 (patch)
tree9cab3a37f9afc0da4ad8694b5f4a15ac5663a70e /luni
parent1aea503e8f568f9c17c14335783a89d41787e657 (diff)
downloadlibcore-9c4462b3d88a36c92d23d4274195e4a7f7a372e5.zip
libcore-9c4462b3d88a36c92d23d4274195e4a7f7a372e5.tar.gz
libcore-9c4462b3d88a36c92d23d4274195e4a7f7a372e5.tar.bz2
Add ICU.addLikelySubtags(Locale).
We don't need a replacement for ICU.getScript(String), Locale.getScript() can be used instead. The old definition of the function has been left public for the support library to use (though we could remove it if we modify the support lib). Note that addLikelySubtag returns a String that's language tag like, but uses underscores instead of hyphens to separate subtags. bug: 15876704 Change-Id: I6c7d289c4b725a83900e38dd5bbed026afd9ac4e
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/libcore/icu/ICU.java14
-rw-r--r--luni/src/test/java/libcore/icu/ICUTest.java8
2 files changed, 22 insertions, 0 deletions
diff --git a/luni/src/main/java/libcore/icu/ICU.java b/luni/src/main/java/libcore/icu/ICU.java
index 06e2205..0ef3f93 100644
--- a/luni/src/main/java/libcore/icu/ICU.java
+++ b/luni/src/main/java/libcore/icu/ICU.java
@@ -426,7 +426,21 @@ public final class ICU {
public static native String getISO3Language(String languageTag);
+ public static Locale addLikelySubtags(Locale locale) {
+ return Locale.forLanguageTag(addLikelySubtags(locale.toLanguageTag()).replace('_', '-'));
+ }
+
+ /**
+ * @deprecated use {@link #addLikelySubtags(java.util.Locale)} instead.
+ */
+ @Deprecated
public static native String addLikelySubtags(String locale);
+
+ /**
+ * @deprecated use {@link java.util.Locale#getScript()} instead. This has been kept
+ * around only for the support library.
+ */
+ @Deprecated
public static native String getScript(String locale);
private static native String[] getISOLanguagesNative();
diff --git a/luni/src/test/java/libcore/icu/ICUTest.java b/luni/src/test/java/libcore/icu/ICUTest.java
index 525d372..a7cc7a0 100644
--- a/luni/src/test/java/libcore/icu/ICUTest.java
+++ b/luni/src/test/java/libcore/icu/ICUTest.java
@@ -74,6 +74,14 @@ public class ICUTest extends junit.framework.TestCase {
assertEquals("Hebr", ICU.getScript(ICU.addLikelySubtags("iw_IL")));
}
+ public void test_addLikelySubtags() throws Exception {
+ assertEquals("Latn", ICU.addLikelySubtags(new Locale("en", "US")).getScript());
+ assertEquals("Hebr", ICU.addLikelySubtags(new Locale("he")).getScript());
+ assertEquals("Hebr", ICU.addLikelySubtags(new Locale("he", "IL")).getScript());
+ assertEquals("Hebr", ICU.addLikelySubtags(new Locale("iw")).getScript());
+ assertEquals("Hebr", ICU.addLikelySubtags(new Locale("iw", "IL")).getScript());
+ }
+
private String best(Locale l, String skeleton) {
return ICU.getBestDateTimePattern(skeleton, l);
}