cn.hutool.extra.pinyin.engine.tinypinyin.TinyPinyinEngine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.extra.pinyin.engine.tinypinyin;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.pinyin.PinyinEngine;
import com.github.promeg.pinyinhelper.Pinyin;
/**
* 封装了TinyPinyin的引擎。
*
*
* TinyPinyin(https://github.com/promeG/TinyPinyin)提供者未提交Maven中央库,
* 因此使用
* https://github.com/biezhi/TinyPinyin打包的版本
*
*
*
* 引入:
*
* <dependency>
* <groupId>io.github.biezhi</groupId>
* <artifactId>TinyPinyin</artifactId>
* <version>2.0.3.RELEASE</version>
* </dependency>
*
*
* @author looly
*/
public class TinyPinyinEngine implements PinyinEngine {
/**
* 构造
*/
public TinyPinyinEngine(){
this(null);
}
/**
* 构造
* @param config 配置
*/
public TinyPinyinEngine(Pinyin.Config config){
Pinyin.init(config);
}
@Override
public String getPinyin(char c) {
if(false == Pinyin.isChinese(c)){
return String.valueOf(c);
}
return Pinyin.toPinyin(c).toLowerCase();
}
@Override
public String getPinyin(String str, String separator) {
final String pinyin = Pinyin.toPinyin(str, separator);
return StrUtil.isEmpty(pinyin) ? pinyin : pinyin.toLowerCase();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy