J2ME 無系統級拼音輸入/轉換 API。HGB2PINYIN 以 **300 字 175ms (Nokia 5300 實測)** 的性能,提供 GB2312/GBK 漢字轉全拼/首字母功能,單文件、零依賴、含完整拼音映射表。
public class HGB2PINYIN {
// 單字符
public static String getFirstPY(char ch); // 首字母 (大寫)
public static String getAllPY(char ch); // 全拼 (小寫, 帶聲調數字可選)
// 字符串
public static String getFirstPY(String str); // 每字首字母拼接
public static String getAllPY(String str); // 每字全拼空格分隔
// 批量 (性能最優)
public static String[] getFirstPYArray(String str);
public static String[] getAllPYArray(String str);
}
q = high - 0xA0, w = low - 0xA0 (GB2312 區位)。String[] PY_TABLE (6763 字),索引 = (q-1)*94 + (w-1) 直接定位拼音字符串。char[]、StringBuilder (J2ME 用 StringBuffer) 復用緩衝區。
// 聯繫人排序索引
String name = "趙雲";
String index = HGB2PINYIN.getFirstPY(name); // "ZY"
String full = HGB2PINYIN.getAllPY(name); // "zhao yun"
// 搜索提示
String query = "zg";
String[] pyArray = HGB2PINYIN.getFirstPYArray(contactName);
if (matchesPrefix(pyArray, query)) showContact(contactName);
new String(bytes, "GBK") 解碼。HGB2PINYIN.java (含映射表、自測 main) 可從項目倉庫下載。已在 Nokia S40/S60、SonyEricsson、Motorola、Samsung 多款真機驗證正確性與性能。
**拼音轉換是中文 J2ME 應用的基礎設施**。HGB2PINYIN 以極致精簡的映射表 + O(1) 查找,在 200KB Heap 環境下實現毫秒級響應。直接拷入項目,即刻獲得專業級中文索引/搜索/排序能力。