From 94027c7201a376107a35ec78cd21db1905662601 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 24 May 2013 12:06:02 -0700 Subject: [PATCH] Use Locale.ROOT for locale neutral operations Bug: 9112465 Change-Id: I6cd63007287b5a1a57cfbabff35d53f66fc5620e --- .../inputmethod/dictionarypack/LocaleUtils.java | 2 +- java/src/com/android/inputmethod/keyboard/Key.java | 2 +- .../android/inputmethod/keyboard/KeyboardId.java | 2 +- .../com/android/inputmethod/latin/LocaleUtils.java | 2 +- .../src/com/android/inputmethod/latin/Suggest.java | 3 ++- .../keyboard/internal/KeySpecParserTests.java | 14 +++++++------- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/dictionarypack/LocaleUtils.java b/java/src/com/android/inputmethod/dictionarypack/LocaleUtils.java index d0e8446f5..77f67b8a3 100644 --- a/java/src/com/android/inputmethod/dictionarypack/LocaleUtils.java +++ b/java/src/com/android/inputmethod/dictionarypack/LocaleUtils.java @@ -144,7 +144,7 @@ public final class LocaleUtils { public static String getMatchLevelSortedString(final int matchLevel) { // This works because the match levels are 0~99 (actually 0~30) // Ideally this should use a number of digits equals to the 1og10 of the greater matchLevel - return String.format("%02d", MATCH_LEVEL_MAX - matchLevel); + return String.format(Locale.ROOT, "%02d", MATCH_LEVEL_MAX - matchLevel); } /** diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 1550e77e3..ae72b4a6b 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -453,7 +453,7 @@ public class Key implements Comparable { } else { label = "/" + mLabel; } - return String.format("%s%s %d,%d %dx%d %s/%s/%s", + return String.format(Locale.ROOT, "%s%s %d,%d %dx%d %s/%s/%s", Constants.printableCode(mCode), label, mX, mY, mWidth, mHeight, mHintLabel, KeyboardIconsSet.getIconName(mIconId), backgroundName(mBackgroundType)); } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index aa27067bc..4c5dd25c4 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -187,7 +187,7 @@ public final class KeyboardId { public String toString() { final String orientation = (mOrientation == Configuration.ORIENTATION_PORTRAIT) ? "port" : "land"; - return String.format("[%s %s:%s %s:%dx%d %s %s %s%s%s%s%s%s%s%s%s]", + return String.format(Locale.ROOT, "[%s %s:%s %s:%dx%d %s %s %s%s%s%s%s%s%s%s%s]", elementIdToName(mElementId), mLocale, mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), diff --git a/java/src/com/android/inputmethod/latin/LocaleUtils.java b/java/src/com/android/inputmethod/latin/LocaleUtils.java index 5fde8158a..a1e40502e 100644 --- a/java/src/com/android/inputmethod/latin/LocaleUtils.java +++ b/java/src/com/android/inputmethod/latin/LocaleUtils.java @@ -148,7 +148,7 @@ public final class LocaleUtils { public static String getMatchLevelSortedString(int matchLevel) { // This works because the match levels are 0~99 (actually 0~30) // Ideally this should use a number of digits equals to the 1og10 of the greater matchLevel - return String.format("%02d", MATCH_LEVEL_MAX - matchLevel); + return String.format(Locale.ROOT, "%02d", MATCH_LEVEL_MAX - matchLevel); } /** diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 2d1141bad..1ad040dd3 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -379,7 +379,8 @@ public final class Suggest { typedWord, cur.toString(), cur.mScore); final String scoreInfoString; if (normalizedScore > 0) { - scoreInfoString = String.format("%d (%4.2f)", cur.mScore, normalizedScore); + scoreInfoString = String.format( + Locale.ROOT, "%d (%4.2f)", cur.mScore, normalizedScore); } else { scoreInfoString = Integer.toString(cur.mScore); } diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java index b1ae6f5b7..861abe831 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java @@ -35,8 +35,8 @@ public class KeySpecParserTests extends AndroidTestCase { private static final String CODE_SETTINGS = "!code/key_settings"; private static final String ICON_SETTINGS = "!icon/settings_key"; - private static final String CODE_SETTINGS_UPPERCASE = CODE_SETTINGS.toUpperCase(); - private static final String ICON_SETTINGS_UPPERCASE = ICON_SETTINGS.toUpperCase(); + private static final String CODE_SETTINGS_UPPERCASE = CODE_SETTINGS.toUpperCase(Locale.ROOT); + private static final String ICON_SETTINGS_UPPERCASE = ICON_SETTINGS.toUpperCase(Locale.ROOT); private static final String CODE_NON_EXISTING = "!code/non_existing"; private static final String ICON_NON_EXISTING = "!icon/non_existing"; @@ -587,7 +587,7 @@ public class KeySpecParserTests extends AndroidTestCase { new String[] { null, "a", "b", "c" }, true); // Upper case specification will not work. assertGetBooleanValue("HAS LABEL", HAS_LABEL, - new String[] { HAS_LABEL.toUpperCase(), "a", "b", "c" }, + new String[] { HAS_LABEL.toUpperCase(Locale.ROOT), "a", "b", "c" }, new String[] { "!HASLABEL!", "a", "b", "c" }, false); assertGetBooleanValue("No has label", HAS_LABEL, @@ -600,13 +600,13 @@ public class KeySpecParserTests extends AndroidTestCase { // Upper case specification will not work. assertGetBooleanValue("Multiple has label", HAS_LABEL, new String[] { - "a", HAS_LABEL.toUpperCase(), "b", "c", HAS_LABEL, "d" }, + "a", HAS_LABEL.toUpperCase(Locale.ROOT), "b", "c", HAS_LABEL, "d" }, new String[] { "a", "!HASLABEL!", "b", "c", null, "d" }, true); // Upper case specification will not work. assertGetBooleanValue("Multiple has label with needs dividers", HAS_LABEL, new String[] { - "a", HAS_LABEL, "b", NEEDS_DIVIDER, HAS_LABEL.toUpperCase(), "d" }, + "a", HAS_LABEL, "b", NEEDS_DIVIDER, HAS_LABEL.toUpperCase(Locale.ROOT), "d" }, new String[] { "a", null, "b", NEEDS_DIVIDER, "!HASLABEL!", "d" }, true); } @@ -625,7 +625,7 @@ public class KeySpecParserTests extends AndroidTestCase { new String[] { null, "a", "b", "c" }, 3); // Upper case specification will not work. assertGetIntValue("FIXED COLUMN ORDER 3", FIXED_COLUMN_ORDER, -1, - new String[] { FIXED_COLUMN_ORDER.toUpperCase() + "3", "a", "b", "c" }, + new String[] { FIXED_COLUMN_ORDER.toUpperCase(Locale.ROOT) + "3", "a", "b", "c" }, new String[] { "!FIXEDCOLUMNORDER!3", "a", "b", "c" }, -1); assertGetIntValue("No fixed column order", FIXED_COLUMN_ORDER, -1, @@ -641,7 +641,7 @@ public class KeySpecParserTests extends AndroidTestCase { // Upper case specification will not work. assertGetIntValue("Multiple fixed column order 5,3 with has label", FIXED_COLUMN_ORDER, -1, new String[] { - FIXED_COLUMN_ORDER.toUpperCase() + "5", HAS_LABEL, "a", + FIXED_COLUMN_ORDER.toUpperCase(Locale.ROOT) + "5", HAS_LABEL, "a", FIXED_COLUMN_ORDER + "3", "b" }, new String[] { "!FIXEDCOLUMNORDER!5", HAS_LABEL, "a", null, "b" }, 3); }