KanaUtils { public static String half2FullKatakana(String katakanaToken) { final StringBuilder sb = new StringBuilder(katakanaToken); for (int i = 0; i < sb.length(); i++) { final char ch = sb.charAt(i); if (KanaConstants.isHalfwidthKatakana(ch)) { final Character fullwidthChar = MAPPING_HALF_TO_FULL_KATAKANA.get(ch); if (fullwidthChar != null) { sb.setCharAt(i, fullwidthChar); } else if (i > 0 && (ch == HALFWIDTH_VOICED_MARK || ch == HALFWIDTH_ASPIRATED_MARK) && KanaConstants.isHalfwidthKatakana(sb.charAt(i - 1))) { sb.deleteCharAt(i); i--; if (ch == HALFWIDTH_VOICED_MARK) { sb.setCharAt(i, (char) (sb.charAt(i) + 1)); } else if (ch == HALFWIDTH_ASPIRATED_MARK) { sb.setCharAt(i, (char) (sb.charAt(i) + 2)); } } } } return sb.toString(); } private  KanaUtils(); static String half2FullKatakana(String katakanaToken); static String hiragana2FullKatakana(String text); static final int DIFF_FULLKATAKANA_HIRAGANA; }
@Test public void half2FullKatakanaTest() { assertEquals("ツイッター", KanaUtils.half2FullKatakana("ﾂｲｯﾀｰ")); assertEquals("シュワルツェネッガー", KanaUtils.half2FullKatakana("ｼｭﾜﾙﾂｪﾈｯｶﾞｰ")); assertEquals("パパ", KanaUtils.half2FullKatakana("ﾊﾟﾊﾟ")); assertEquals("ピャニッチ", KanaUtils.half2FullKatakana("ﾋﾟｬﾆｯﾁ")); assertEquals("フィジカル", KanaUtils.half2FullKatakana("ﾌｨｼﾞｶﾙ")); }