Skip to content

Commit

Permalink
Merge "Allow soft hyphens in languages without patterns" into mnc-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
raphlinus authored and Android (Google) Code Review committed Jul 27, 2015
2 parents 2e606d7 + a008961 commit e827c25
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions core/java/android/text/Hyphenator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -53,19 +55,19 @@ private Hyphenator(long nativePtr) {

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
Expand All @@ -75,16 +77,16 @@ public static long get(@Nullable Locale locale) {
.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) {
Expand Down

0 comments on commit e827c25

Please sign in to comment.