|
|
@ -1,5 +1,6 @@ |
|
|
package cc.hiver.core.common.utils; |
|
|
package cc.hiver.core.common.utils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import net.sourceforge.pinyin4j.PinyinHelper; |
|
|
import net.sourceforge.pinyin4j.PinyinHelper; |
|
|
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; |
|
|
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; |
|
|
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; |
|
|
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; |
|
|
@ -15,7 +16,7 @@ public class PinYinUtils { |
|
|
if(chinese == null || chinese.isEmpty()) { |
|
|
if(chinese == null || chinese.isEmpty()) { |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
final StringBuffer pybf = new StringBuffer(); |
|
|
StringBuilder pybf = new StringBuilder(); |
|
|
final char[] arr = chinese.toCharArray(); |
|
|
final char[] arr = chinese.toCharArray(); |
|
|
final HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); |
|
|
final HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); |
|
|
defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE); |
|
|
defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE); |
|
|
@ -23,7 +24,7 @@ public class PinYinUtils { |
|
|
for (char c : arr) { |
|
|
for (char c : arr) { |
|
|
if (c > 128) { |
|
|
if (c > 128) { |
|
|
try { |
|
|
try { |
|
|
final String[] temp = PinyinHelper.toHanyuPinyinStringArray(c); |
|
|
final String[] temp = PinyinHelper.toHanyuPinyinStringArray(c,defaultFormat); |
|
|
if (temp != null) { |
|
|
if (temp != null) { |
|
|
pybf.append(temp[0].charAt(0)); |
|
|
pybf.append(temp[0].charAt(0)); |
|
|
} |
|
|
} |
|
|
|