mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
Feat (hutool-extra): 汉字转拼音增加使用 pinyin.jar 进行转换的实现
# 修改 1. 发现一个新的进行拼音转换的第三方工具 jar ,增加对这个工具的使用
This commit is contained in:
parent
1edbc0de80
commit
035b716b88
@ -323,6 +323,11 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.houbb</groupId>
|
||||||
|
<artifactId>pinyin</artifactId>
|
||||||
|
<version>0.2.0</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cglib</groupId>
|
<groupId>cglib</groupId>
|
||||||
<artifactId>cglib</artifactId>
|
<artifactId>cglib</artifactId>
|
||||||
|
@ -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>
|
||||||
|
* <dependency>
|
||||||
|
* <groupId>com.github.houbb</groupId>
|
||||||
|
* <artifactId>pinyin</artifactId>
|
||||||
|
* <version>0.2.0</version>
|
||||||
|
* </dependency>
|
||||||
|
* </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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* 封装了 Pinyin 的引擎。
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* pinyin(https://github.com/houbb/pinyin)封装。
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 引入:
|
||||||
|
* <pre>
|
||||||
|
* <dependency>
|
||||||
|
* <groupId>com.github.houbb</groupId>
|
||||||
|
* <artifactId>pinyin</artifactId>
|
||||||
|
* <version>0.2.0</version>
|
||||||
|
* </dependency>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author looly
|
||||||
|
*/
|
||||||
|
package cn.hutool.extra.pinyin.engine.pinyin;
|
Loading…
Reference in New Issue
Block a user