mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add class
This commit is contained in:
Binary file not shown.
@@ -233,6 +233,12 @@
|
||||
<version>1.1.8</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rnkrsoft.bopomofo4j</groupId>
|
||||
<artifactId>bopomofo4j</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib</artifactId>
|
||||
|
@@ -0,0 +1,43 @@
|
||||
package cn.hutool.extra.pinyin.engine.bopomofo4j;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.pinyin.PinyinEngine;
|
||||
import com.rnkrsoft.bopomofo4j.Bopomofo4j;
|
||||
import com.rnkrsoft.bopomofo4j.ToneType;
|
||||
|
||||
/**
|
||||
* 封装了Bopomofo4j的引擎。
|
||||
*
|
||||
* <p>
|
||||
* Bopomofo4j封装,项目:https://gitee.com/rnkrsoft/Bopomofo4j。
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* 引入:
|
||||
* <pre>
|
||||
* <dependency>
|
||||
* <groupId>com.rnkrsoft.bopomofo4j</groupId>
|
||||
* <artifactId>bopomofo4j</artifactId>
|
||||
* <version>1.0.0</version>
|
||||
* </dependency>
|
||||
* </pre>
|
||||
*
|
||||
* @author looly
|
||||
* @since 5.4.5
|
||||
*/
|
||||
public class Bopomofo4jEngine implements PinyinEngine {
|
||||
|
||||
public Bopomofo4jEngine(){
|
||||
Bopomofo4j.local();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPinyin(char c) {
|
||||
return Bopomofo4j.pinyin(String.valueOf(c), ToneType.WITHOUT_TONE, false, false, StrUtil.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPinyin(String str, String separator) {
|
||||
return Bopomofo4j.pinyin(str, ToneType.WITHOUT_TONE, false, false, separator);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 封装了Bopomofo4j的引擎。
|
||||
*
|
||||
* <p>
|
||||
* Bopomofo4j封装,项目:https://gitee.com/rnkrsoft/Bopomofo4j。
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* 引入:
|
||||
* <pre>
|
||||
* <dependency>
|
||||
* <groupId>com.rnkrsoft.bopomofo4j</groupId>
|
||||
* <artifactId>bopomofo4j</artifactId>
|
||||
* <version>1.0.0</version>
|
||||
* </dependency>
|
||||
* </pre>
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
package cn.hutool.extra.pinyin.engine.bopomofo4j;
|
@@ -1,3 +1,4 @@
|
||||
cn.hutool.extra.pinyin.engine.tinypinyin.TinyPinyinEngine
|
||||
cn.hutool.extra.pinyin.engine.jpinyin.JPinyinEngine
|
||||
cn.hutool.extra.pinyin.engine.pinyin4j.Pinyin4jEngine
|
||||
cn.hutool.extra.pinyin.engine.pinyin4j.Pinyin4jEngine
|
||||
cn.hutool.extra.pinyin.engine.bopomofo4j.Bopomofo4jEngine
|
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.extra.pinyin;
|
||||
|
||||
import cn.hutool.extra.pinyin.engine.bopomofo4j.Bopomofo4jEngine;
|
||||
import cn.hutool.extra.pinyin.engine.pinyin4j.Pinyin4jEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -19,6 +20,13 @@ public class PinyinUtilTest {
|
||||
Assert.assertEquals("ni hao h", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByBopomofo4jTest() {
|
||||
final Bopomofo4jEngine engine = new Bopomofo4jEngine();
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni haoh", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinUpperCaseTest(){
|
||||
final String pinyin = PinyinUtil.getPinyin("你好怡", " ");
|
||||
@@ -37,4 +45,11 @@ public class PinyinUtilTest {
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByBopomofo4jTest(){
|
||||
final Bopomofo4jEngine engine = new Bopomofo4jEngine();
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user