Skip to content

Commit e827c25

Browse files
raphlinusAndroid (Google) Code Review
authored andcommitted
Merge "Allow soft hyphens in languages without patterns" into mnc-dev
2 parents 2e606d7 + a008961 commit e827c25

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

core/java/android/text/Hyphenator.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class Hyphenator {
4545
@GuardedBy("sLock")
4646
final static HashMap<Locale, Hyphenator> sMap = new HashMap<Locale, Hyphenator>();
4747

48+
final static Hyphenator sEmptyHyphenator = new Hyphenator(StaticLayout.nLoadHyphenator(""));
49+
4850
final private long mNativePtr;
4951

5052
private Hyphenator(long nativePtr) {
@@ -53,19 +55,19 @@ private Hyphenator(long nativePtr) {
5355

5456
public static long get(@Nullable Locale locale) {
5557
synchronized (sLock) {
56-
if (sMap.containsKey(locale)) {
57-
Hyphenator result = sMap.get(locale);
58-
return (result == null) ? 0 : result.mNativePtr;
58+
Hyphenator result = sMap.get(locale);
59+
if (result != null) {
60+
return result.mNativePtr;
5961
}
6062

6163
// TODO: Convert this a proper locale-fallback system
6264

6365
// Fall back to language-only, if available
6466
Locale languageOnlyLocale = new Locale(locale.getLanguage());
65-
if (sMap.containsKey(languageOnlyLocale)) {
66-
Hyphenator result = sMap.get(languageOnlyLocale);
67+
result = sMap.get(languageOnlyLocale);
68+
if (result != null) {
6769
sMap.put(locale, result);
68-
return (result == null) ? 0 : result.mNativePtr;
70+
return result.mNativePtr;
6971
}
7072

7173
// Fall back to script-only, if available
@@ -75,16 +77,16 @@ public static long get(@Nullable Locale locale) {
7577
.setLanguage("und")
7678
.setScript(script)
7779
.build();
78-
if (sMap.containsKey(scriptOnlyLocale)) {
79-
Hyphenator result = sMap.get(scriptOnlyLocale);
80+
result = sMap.get(scriptOnlyLocale);
81+
if (result != null) {
8082
sMap.put(locale, result);
81-
return (result == null) ? 0 : result.mNativePtr;
83+
return result.mNativePtr;
8284
}
8385
}
8486

85-
sMap.put(locale, null); // To remember we found nothing.
87+
sMap.put(locale, sEmptyHyphenator); // To remember we found nothing.
8688
}
87-
return 0;
89+
return sEmptyHyphenator.mNativePtr;
8890
}
8991

9092
private static Hyphenator loadHyphenator(String languageTag) {

0 commit comments

Comments
 (0)