|
@@ -1,5 +1,11 @@
|
|
|
package com.mrxu.framework.common.util;
|
|
package com.mrxu.framework.common.util;
|
|
|
|
|
|
|
|
|
|
+import net.sourceforge.pinyin4j.PinyinHelper;
|
|
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
|
|
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
|
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
|
|
|
|
+import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
|
|
|
|
+
|
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
|
@@ -121,4 +127,32 @@ public class StrFunc {
|
|
|
return new String(randBuffer);
|
|
return new String(randBuffer);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private static HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
|
|
|
|
|
+ static {
|
|
|
|
|
+ defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
|
|
|
|
|
+ defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
|
|
|
|
+ }
|
|
|
|
|
+ public static String converterToSpell(String chines){
|
|
|
|
|
+ if(chines == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ StringBuffer pinyinName = new StringBuffer();
|
|
|
|
|
+ char[] nameChar = chines.toCharArray();
|
|
|
|
|
+ for (int i = 0; i < nameChar.length; i++) {
|
|
|
|
|
+ if (nameChar[i] > 128) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ pinyinName.append(PinyinHelper.toHanyuPinyinStringArray(nameChar[i], defaultFormat)[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (BadHanyuPinyinOutputFormatCombination e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ pinyinName.append(nameChar[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return pinyinName.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|