com.whaleal.icefrog.extra.pinyin.engine.tinypinyin.TinyPinyinEngine Maven / Gradle / Ivy
The newest version!
package com.whaleal.icefrog.extra.pinyin.engine.tinypinyin;
import com.whaleal.icefrog.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
* @author wh
*/
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) {
return Pinyin.toPinyin(str, separator).toLowerCase();
}
}