diff options
author | Raph Levien <raph@google.com> | 2015-07-27 21:50:16 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-27 21:50:16 +0000 |
commit | e827c2525a6b76c130d2b877fbcdcf62b0ce42eb (patch) | |
tree | ad6254c2cf5a35594a18fff66d77570e9dd1e572 | |
parent | 2e606d7be5275f2bff4c5755351bc3191ecb1bf1 (diff) | |
parent | a00896198d4e4049f24e96ce5056a88eb1693616 (diff) | |
download | frameworks_base-e827c2525a6b76c130d2b877fbcdcf62b0ce42eb.zip frameworks_base-e827c2525a6b76c130d2b877fbcdcf62b0ce42eb.tar.gz frameworks_base-e827c2525a6b76c130d2b877fbcdcf62b0ce42eb.tar.bz2 |
Merge "Allow soft hyphens in languages without patterns" into mnc-dev
-rw-r--r-- | core/java/android/text/Hyphenator.java | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/core/java/android/text/Hyphenator.java b/core/java/android/text/Hyphenator.java index 1ee3827..10a994a 100644 --- a/core/java/android/text/Hyphenator.java +++ b/core/java/android/text/Hyphenator.java @@ -45,6 +45,8 @@ public class Hyphenator { @GuardedBy("sLock") final static HashMap<Locale, Hyphenator> sMap = new HashMap<Locale, Hyphenator>(); + final static Hyphenator sEmptyHyphenator = new Hyphenator(StaticLayout.nLoadHyphenator("")); + final private long mNativePtr; private Hyphenator(long nativePtr) { @@ -53,19 +55,19 @@ public class Hyphenator { public static long get(@Nullable Locale locale) { synchronized (sLock) { - if (sMap.containsKey(locale)) { - Hyphenator result = sMap.get(locale); - return (result == null) ? 0 : result.mNativePtr; + Hyphenator result = sMap.get(locale); + if (result != null) { + return result.mNativePtr; } // TODO: Convert this a proper locale-fallback system // Fall back to language-only, if available Locale languageOnlyLocale = new Locale(locale.getLanguage()); - if (sMap.containsKey(languageOnlyLocale)) { - Hyphenator result = sMap.get(languageOnlyLocale); + result = sMap.get(languageOnlyLocale); + if (result != null) { sMap.put(locale, result); - return (result == null) ? 0 : result.mNativePtr; + return result.mNativePtr; } // Fall back to script-only, if available @@ -75,16 +77,16 @@ public class Hyphenator { .setLanguage("und") .setScript(script) .build(); - if (sMap.containsKey(scriptOnlyLocale)) { - Hyphenator result = sMap.get(scriptOnlyLocale); + result = sMap.get(scriptOnlyLocale); + if (result != null) { sMap.put(locale, result); - return (result == null) ? 0 : result.mNativePtr; + return result.mNativePtr; } } - sMap.put(locale, null); // To remember we found nothing. + sMap.put(locale, sEmptyHyphenator); // To remember we found nothing. } - return 0; + return sEmptyHyphenator.mNativePtr; } private static Hyphenator loadHyphenator(String languageTag) { |