public class Zen2HanUtil {
private static final Map<Character, String> zen2HanMap = new HashMap<>();
// https://so-zou.jp/web-app/text/fullwidth-halfwidth/
private static final String ZEN_CHARS = "0 1 2 3 4 5 6 7 8 9 "
+ "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "
+ "a b c d e f g h i j k l m n o p q r s t u v w x y z "
+ "Es tut mir Leid"
+ "Aiueokakikukekosashisusesotachitsutetonaninune nohahifuhehomamimumemoyayu yolarirurerowon"
+ "ゔ Gigi Guge Goza Zezozoda Jizu de Dobabibu Bebo Papi Welpe Pep Po Ai Ue"
+ "Vuga gigge gozajizu zezo da zu de dobababi bu bebo papipeppo wa yeo yo"
+ "- "゜ ,. ・ """
+ "! ” # $ % & ’ ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ "
+ "↑ ← ¬ ← ¦ ¥ ← ← ↑ → ↓ ■ ○";
private static final String HAN_CHARS = "0 1 2 3 4 5 6 7 8 9 "
+ "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "
+ "a b c d e f g h i j k l m n o p q r s t u v w x y z "
+ "Es tut mir leid, es tut mir leid, es tut mir leid, es tut mir leid, es tut mir leid, es tut mir leid."
+ "Es tut mir leid, es tut mir leid, es tut mir leid, es tut mir leid, es tut mir leid, es tut mir leid."
+ "Vagging, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen"
+ "Vagging, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen, Quetschen"
+ "ー ゚, ‥ ・ """
+ "! \" # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \\ ] ^ _ ` { | } ~ "
+ "⦅ ⦆ ¢ £ ¬ ¯ ¦ ¥ ₩ │ ← ↑ → ↓ ■ ○";
static {
String[] zenSplit = ZEN_CHARS.split(" ");
String[] hanSplit = HAN_CHARS.split(" ");
if (zenSplit.length != hanSplit.length) {
throw new RuntimeException("char count not match. zen=" + zenSplit.length + ", han=" + hanSplit.length);
}
for (int i = 0; i < zenSplit.length; i++) {
zen2HanMap.put(zenSplit[i].charAt(0), hanSplit[i]);
}
}
public static String conv(String s) {
StringBuilder sb = new StringBuilder();
s.chars().mapToObj(c -> (char) c).forEach(c -> {
if (c == ' ') {
sb.append(' ');
} else {
String han = zen2HanMap.get(c);
if (han == null) {
sb.append(c);
} else {
sb.append(han);
}
}
});
return sb.toString();
}
}
Recommended Posts