com.webapp.utils.jpinyin.ChineseHelper Maven / Gradle / Ivy
package com.webapp.utils.jpinyin;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Properties;
public final class ChineseHelper {
private static final Properties CHINESETABLE = PinyinResource.getChineseTable();
/**
* 将单个繁体字转换为简体字
*
* @param c
* 需要转换的繁体字
* @return 转换后的简体字
*/
public static char convertToSimplifiedChinese(char c) {
if (isTraditionalChinese(c)) {
return CHINESETABLE.getProperty(String.valueOf(c)).charAt(0);
}
return c;
}
/**
* 将单个简体字转换为繁体字
*
* @param c
* 需要转换的简体字
* @return 转换后的繁字体
*/
public static char convertToTraditionalChinese(char c) {
String hanzi = String.valueOf(c);
if (CHINESETABLE.containsValue(hanzi)) {
Iterator> itr = CHINESETABLE.entrySet().iterator();
while (itr.hasNext()) {
Entry