mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add Houbb support
This commit is contained in:
parent
b6178794c5
commit
155dce6f3a
@ -19,6 +19,7 @@
|
||||
* 【http 】 SoapClient增加针对不同协议的头信息(pr#305@Gitee)
|
||||
* 【http 】 HttpRequest支持307、308状态码识别(issue#1504@Github)
|
||||
* 【core 】 CharUtil.isBlankChar增加\u0000判断(pr#1505@Github)
|
||||
* 【extra 】 添加Houbb Pinyin支持(pr#1506@Github)
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 修复Validator.isUrl()传空返回true(issue#I3ETTY@Gitee)
|
||||
|
@ -327,6 +327,7 @@
|
||||
<groupId>com.github.houbb</groupId>
|
||||
<artifactId>pinyin</artifactId>
|
||||
<version>0.2.0</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user