Feat (hutool-extra): 汉字转拼音增加使用 pinyin.jar 进行转换的实现

# 修改
1. 发现一个新的进行拼音转换的第三方工具 jar ,增加对这个工具的使用
This commit is contained in:
FULaBUla 2021-04-10 22:42:38 +08:00
parent 1edbc0de80
commit 035b716b88
3 changed files with 98 additions and 0 deletions

View File

@ -323,6 +323,11 @@
<version>1.0.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>pinyin</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>

View File

@ -0,0 +1,73 @@
package cn.hutool.extra.pinyin.engine.pinyin;
import com.github.houbb.pinyin.constant.enums.PinyinStyleEnum;
import com.github.houbb.pinyin.util.PinyinHelper;
/**
* 封装了 Pinyin 的引擎
*
* <p>
* pinyin(https://github.com/houbb/pinyin)封装
* </p>
*
* <p>
* 引入
* <pre>
* &lt;dependency&gt;
* &lt;groupId&gt;com.github.houbb&lt;/groupId&gt;
* &lt;artifactId&gt;pinyin&lt;/artifactId&gt;
* &lt;version&gt;0.2.0&lt;/version&gt;
* &lt;/dependency&gt;
* </pre>
*
* @author looly
*/
public class PinyinEngine implements cn.hutool.extra.pinyin.PinyinEngine {
/**
* 汉字拼音输出的格式
*/
PinyinStyleEnum format;
/**
* 构造
*/
public PinyinEngine() {
this(null);
}
/**
* 构造
*
* @param format 格式
*/
public PinyinEngine(PinyinStyleEnum format) {
init(format);
}
/**
* 初始化
*
* @param format 格式
*/
public void init(PinyinStyleEnum format) {
if (null == format) {
format = PinyinStyleEnum.NORMAL;
}
this.format = format;
}
@Override
public String getPinyin(char c) {
String result;
result = PinyinHelper.toPinyin(String.valueOf(c), format);
return result;
}
@Override
public String getPinyin(String str, String separator) {
String result;
result = PinyinHelper.toPinyin(str, format);
return result;
}
}

View File

@ -0,0 +1,20 @@
/**
* 封装了 Pinyin 的引擎
*
* <p>
* pinyin(https://github.com/houbb/pinyin)封装
* </p>
*
* <p>
* 引入
* <pre>
* &lt;dependency&gt;
* &lt;groupId&gt;com.github.houbb&lt;/groupId&gt;
* &lt;artifactId&gt;pinyin&lt;/artifactId&gt;
* &lt;version&gt;0.2.0&lt;/version&gt;
* &lt;/dependency&gt;
* </pre>
*
* @author looly
*/
package cn.hutool.extra.pinyin.engine.pinyin;