mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add Houbb support
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package cn.hutool.extra.pinyin.engine.pinyin;
|
||||
package cn.hutool.extra.pinyin.engine.houbbpinyin;
|
||||
|
||||
import cn.hutool.extra.pinyin.PinyinEngine;
|
||||
import com.github.houbb.pinyin.constant.enums.PinyinStyleEnum;
|
||||
import com.github.houbb.pinyin.util.PinyinHelper;
|
||||
|
||||
/**
|
||||
* 封装了 Pinyin 的引擎。
|
||||
* 封装了 houbb Pinyin 的引擎。
|
||||
*
|
||||
* <p>
|
||||
* pinyin(https://github.com/houbb/pinyin)封装。
|
||||
* houbb pinyin(https://github.com/houbb/pinyin)封装。
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
@@ -22,7 +23,7 @@ import com.github.houbb.pinyin.util.PinyinHelper;
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class PinyinEngine implements cn.hutool.extra.pinyin.PinyinEngine {
|
||||
public class HoubbPinyinEngine implements PinyinEngine {
|
||||
|
||||
/**
|
||||
* 汉字拼音输出的格式
|
||||
@@ -32,7 +33,7 @@ public class PinyinEngine implements cn.hutool.extra.pinyin.PinyinEngine {
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public PinyinEngine() {
|
||||
public HoubbPinyinEngine() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ public class PinyinEngine implements cn.hutool.extra.pinyin.PinyinEngine {
|
||||
*
|
||||
* @param format 格式
|
||||
*/
|
||||
public PinyinEngine(PinyinStyleEnum format) {
|
||||
public HoubbPinyinEngine(PinyinStyleEnum format) {
|
||||
init(format);
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ public class PinyinEngine implements cn.hutool.extra.pinyin.PinyinEngine {
|
||||
@Override
|
||||
public String getPinyin(String str, String separator) {
|
||||
String result;
|
||||
result = PinyinHelper.toPinyin(str, format);
|
||||
result = PinyinHelper.toPinyin(str, format, separator);
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -17,4 +17,4 @@
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
package cn.hutool.extra.pinyin.engine.pinyin;
|
||||
package cn.hutool.extra.pinyin.engine.houbbpinyin;
|
@@ -1,4 +1,5 @@
|
||||
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.bopomofo4j.Bopomofo4jEngine
|
||||
cn.hutool.extra.pinyin.engine.bopomofo4j.Bopomofo4jEngine
|
||||
cn.hutool.extra.pinyin.engine.houbbpinyin.HoubbPinyinEngine
|
||||
|
@@ -0,0 +1,23 @@
|
||||
package cn.hutool.extra.pinyin;
|
||||
|
||||
import cn.hutool.extra.pinyin.engine.bopomofo4j.Bopomofo4jEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Bopomofo4jTest {
|
||||
|
||||
final Bopomofo4jEngine engine = new Bopomofo4jEngine();
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByBopomofo4jTest(){
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByBopomofo4jTest() {
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni haoh", pinyin);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package cn.hutool.extra.pinyin;
|
||||
|
||||
import cn.hutool.extra.pinyin.engine.houbbpinyin.HoubbPinyinEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HoubbPinyinTest {
|
||||
|
||||
final HoubbPinyinEngine engine = new HoubbPinyinEngine();
|
||||
|
||||
@Test
|
||||
public void getFirstLetterTest(){
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinTest() {
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni hao h", pinyin);
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package cn.hutool.extra.pinyin;
|
||||
|
||||
import cn.hutool.extra.pinyin.engine.jpinyin.JPinyinEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JpinyinTest {
|
||||
|
||||
final JPinyinEngine engine = new JPinyinEngine();
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByPinyin4jTest(){
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByPinyin4jTest() {
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni hao h", pinyin);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package cn.hutool.extra.pinyin;
|
||||
|
||||
import cn.hutool.extra.pinyin.engine.pinyin4j.Pinyin4jEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Pinyin4jTest {
|
||||
|
||||
final Pinyin4jEngine engine = new Pinyin4jEngine();
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByPinyin4jTest(){
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByPinyin4jTest() {
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni hao h", pinyin);
|
||||
}
|
||||
}
|
@@ -1,7 +1,5 @@
|
||||
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;
|
||||
|
||||
@@ -9,26 +7,6 @@ public class PinyinUtilTest {
|
||||
|
||||
@Test
|
||||
public void getPinyinTest(){
|
||||
final String pinyin = PinyinUtil.getPinyin("你好", " ");
|
||||
Assert.assertEquals("ni hao", pinyin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByPinyin4jTest() {
|
||||
final Pinyin4jEngine engine = new Pinyin4jEngine();
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
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("你好怡", " ");
|
||||
Assert.assertEquals("ni hao yi", pinyin);
|
||||
}
|
||||
@@ -44,18 +22,4 @@ public class PinyinUtilTest {
|
||||
final String result = PinyinUtil.getFirstLetter("崞阳", ", ");
|
||||
Assert.assertEquals("g, y", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByPinyin4jTest(){
|
||||
final Pinyin4jEngine engine = new Pinyin4jEngine();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,22 @@
|
||||
package cn.hutool.extra.pinyin;
|
||||
|
||||
import cn.hutool.extra.pinyin.engine.tinypinyin.TinyPinyinEngine;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TinyPinyinTest {
|
||||
|
||||
final TinyPinyinEngine engine = new TinyPinyinEngine();
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByPinyin4jTest(){
|
||||
final String result = engine.getFirstLetter("林海", "");
|
||||
Assert.assertEquals("lh", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPinyinByPinyin4jTest() {
|
||||
final String pinyin = engine.getPinyin("你好h", " ");
|
||||
Assert.assertEquals("ni hao h", pinyin);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user