Merge "Add KDDI/Softbank to available Shift_Jis mapping."
diff --git a/core/java/android/util/CharsetUtils.java b/core/java/android/util/CharsetUtils.java
index 9d91aca..a763a69 100644
--- a/core/java/android/util/CharsetUtils.java
+++ b/core/java/android/util/CharsetUtils.java
@@ -17,36 +17,58 @@
 package android.util;
 
 import android.os.Build;
+import android.text.TextUtils;
 
 import java.nio.charset.Charset;
 import java.nio.charset.IllegalCharsetNameException;
 import java.nio.charset.UnsupportedCharsetException;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
+ * <p>
  * A class containing utility methods related to character sets. This
  * class is primarily useful for code that wishes to be vendor-aware
- * in its interpretation of Japanese encoding names.
- * 
- * <p>As of this writing, the only vendor that is recognized by this
- * class is Docomo (identified case-insensitively as {@code "docomo"}).</p>
- * 
- * <b>Note:</b> This class is hidden in Cupcake, with a plan to
- * un-hide in Donut. This was done because the first deployment to use
- * this code is based on Cupcake, but the API had to be introduced
- * after the public API freeze for that release. The upshot is that
- * only system applications can safely use this class until Donut is
- * available.
- * 
+ * in its interpretation of Japanese charset names (used in DoCoMo,
+ * KDDI, and SoftBank).
+ * </p>
+ *
+ * <p>
+ * <b>Note:</b> Developers will need to add an appropriate mapping for
+ * each vendor-specific charset. You may need to modify the C libraries
+ * like icu4c in order to let Android support an additional charset.
+ * </p>
+ *
  * @hide
  */
 public final class CharsetUtils {
     /**
-     * name of the vendor "Docomo". <b>Note:</b> This isn't a public
+     * name of the vendor "DoCoMo". <b>Note:</b> This isn't a public
      * constant, in order to keep this class from becoming a de facto
      * reference list of vendor names.
      */
     private static final String VENDOR_DOCOMO = "docomo";
-    
+    /**
+     * Name of the vendor "KDDI".
+     */
+    private static final String VENDOR_KDDI = "kddi";
+    /**
+     * Name of the vendor "SoftBank".
+     */
+    private static final String VENDOR_SOFTBANK = "softbank";
+
+    /**
+     * Represents one-to-one mapping from a vendor name to a charset specific to the vendor.
+     */
+    private static final Map<String, String> sVendorShiftJisMap = new HashMap<String, String>();
+
+    static {
+        // These variants of Shift_JIS come from icu's mapping data (convrtrs.txt)
+        sVendorShiftJisMap.put(VENDOR_DOCOMO, "docomo-shift_jis-2007");
+        sVendorShiftJisMap.put(VENDOR_KDDI, "kddi-shift_jis-2007");
+        sVendorShiftJisMap.put(VENDOR_SOFTBANK, "softbank-shift_jis-2007");
+    }
+
     /**
      * This class is uninstantiable.
      */
@@ -58,20 +80,22 @@
      * Returns the name of the vendor-specific character set
      * corresponding to the given original character set name and
      * vendor. If there is no vendor-specific character set for the
-     * given name/vendor pair, this returns the original character set
-     * name. The vendor name is matched case-insensitively.
-     * 
+     * given name/vendor pair, this returns the original character set name.
+     *
      * @param charsetName the base character set name
-     * @param vendor the vendor to specialize for
+     * @param vendor the vendor to specialize for. All characters should be lower-cased.
      * @return the specialized character set name, or {@code charsetName} if
      * there is no specialized name
      */
     public static String nameForVendor(String charsetName, String vendor) {
-        // TODO: Eventually, this may want to be table-driven.
-
-        if (vendor.equalsIgnoreCase(VENDOR_DOCOMO)
-                && isShiftJis(charsetName)) {
-            return "docomo-shift_jis-2007";
+        if (!TextUtils.isEmpty(charsetName) && !TextUtils.isEmpty(vendor)) {
+            // You can add your own mapping here.
+            if (isShiftJis(charsetName)) {
+                final String vendorShiftJis = sVendorShiftJisMap.get(vendor);
+                if (vendorShiftJis != null) {
+                    return vendorShiftJis;
+                }
+            }
         }
 
         return charsetName;