Skip to content

Commit 103c812

Browse files
author
cmj
committed
see 12/17 log
1 parent 8711ebe commit 103c812

6 files changed

Lines changed: 52 additions & 40 deletions

File tree

README-CN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ ccs2Pinyin : 汉字转拼音
329329
ccs2Pinyin : 汉字转拼音
330330
getPinyinFirstLetter : 获取第一个汉字首字母
331331
getPinyinFirstLetters: 获取所有汉字的首字母
332-
surname2Pinyin : 姓氏转拼音
332+
getSurnamePinyin : 根据名字获取姓氏的拼音
333+
getSurnameFirstLetter: 根据名字获取姓氏的首字母
333334
```
334335

335336
> - **进程相关→[ProcessUtils.java][process.java][Demo][process.demo]**

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ ccs2Pinyin
329329
ccs2Pinyin
330330
getPinyinFirstLetter
331331
getPinyinFirstLetters: 获取所有汉字的首字母
332-
surname2Pinyin
332+
getSurnamePinyin
333+
getSurnameFirstLetter: 根据名字获取姓氏的首字母
333334
```
334335

335336
> - **About Process→[ProcessUtils.java][process.java][Demo][process.demo]**

utilcode/src/main/java/com/blankj/utilcode/utils/LogUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private LogUtils() {
3434

3535
/**
3636
* 初始化函数
37-
* <p>与{@link #getBuilder(Context)}两者选其一</p>
37+
* <p>与{@link #getBuilder()}两者选其一</p>
3838
*
3939
* @param logSwitch 日志总开关
4040
* @param log2FileSwitch 日志写入文件开关

utilcode/src/main/java/com/blankj/utilcode/utils/PinyinUtils.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ public static String getPinyinFirstLetters(CharSequence ccs, CharSequence split)
8888
}
8989

9090
/**
91-
* 姓氏转拼音
91+
* 根据名字获取姓氏的拼音
9292
*
93-
* @param surname 姓氏
93+
* @param name 名字
9494
* @return 拼音
9595
*/
96-
public static String surname2Pinyin(CharSequence surname) {
97-
if (surname == null || surname.length() == 0) return null;
98-
if (surname.length() >= 2) {
99-
CharSequence str = surname.subSequence(0, 2).toString();
96+
public static String getSurnamePinyin(CharSequence name) {
97+
if (name == null || name.length() == 0) return null;
98+
if (name.length() >= 2) {
99+
CharSequence str = name.subSequence(0, 2);
100100
if (str.equals("澹台")) return "tantai";
101101
else if (str.equals("尉迟")) return "yuchi";
102102
else if (str.equals("万俟")) return "moqi";
103103
else if (str.equals("单于")) return "chanyu";
104104
}
105-
char ch = surname.charAt(0);
105+
char ch = name.charAt(0);
106106
if (surnames.containsKey(ch)) {
107107
return surnames.get(ch);
108108
}
@@ -114,6 +114,19 @@ public static String surname2Pinyin(CharSequence surname) {
114114
}
115115
}
116116

117+
/**
118+
* 根据名字获取姓氏的首字母
119+
*
120+
* @param name 名字
121+
* @return 拼音
122+
*/
123+
public static String getSurnameFirstLetter(CharSequence name) {
124+
String surname = getSurnamePinyin(name);
125+
if (surname == null || surname.length() == 0) return null;
126+
return String.valueOf(surname.charAt(0));
127+
128+
}
129+
117130
// 多音字姓氏映射表
118131
private static final SimpleArrayMap<Character, String> surnames;
119132

@@ -196,5 +209,4 @@ public static String surname2Pinyin(CharSequence surname) {
196209
.append("n fu diao ji feng none gan shi feng ming bao yuan zhi hu qian fu fen wen jian shi yu fou yiao ju jue pi huan zhen bao yan ya zheng fang feng wen ou te jia nu ling mie fu tuo wen li bian zhi ge yuan zi qu xiao chi dan ju you gu zhong yu yang rong ya zhi yu none ying zhui wu er gua ai zhi yan heng jiao ji lie zhu ren ti hong luo ru mou ge ren jiao xiu zhou chi luo none none none luan jia ji yu huan tuo bu wu juan yu bo xun xun bi xi jun ju tu jing ti e e kuang hu wu shen la none none lu bing shu fu an zhao peng qin qian bei diao lu que jian ju tu ya yuan qi li ye zhui kong duo kun sheng qi jing ni e jing zi lai dong qi chun geng ju qu none none ji shu none chi miao rou fu qiu ti hu ti e jie mao fu chun tu yan he yuan pian yun mei hu ying dun mu ju none cang fang ge ying yuan xuan weng shi he chu tang xia ruo liu ji gu jian zhun han zi ci yi yao yan ji li tian kou ti ti ni tu ma jiao liu zhen chen li zhuan zhe ao yao yi ou chi zhi liao rong lou bi shuangzhuo yu wu jue yin tan si jiao yi hua bi ying su huang fan jiao liao yan kao jiu xian xian tu mai zun yu ying lu tuan xian xue yi pi shu luo qi yi ji zhe yu zhan ye yang pi ning hu mi ying meng di yue yu lei bo lu he long shuangyue ying guan qu li luan niao jiu ji yuan ming shi ou ya cang bao zhen gu dong lu ya xiao yang ling chi qu yuan xue tuo si zhi er gua xiu heng zhou ge luan hong wu bo li juan hu e yu xian ti wu que miao an kun bei peng qian chun geng yuan su hu he e gu qiu ci mei wu yi yao weng liu ji yi jian he yi ying zhe liu liao jiao jiu yu lu huan zhan ying hu meng guan shuanglu jin ling jian xian cuo jian jian yan cuo lu you cu ji biao cu pao zhu jun zhu jian mi mi wu liu chen jun lin ni qi lu jiu jun jing li xiang yan jia mi li she zhang lin jing qi ling yan cu mai mai ge chao fu mian mian fu pao qu qu mou fu xian lai qu mian chi feng fu qu mian ma ma mo hui none zou nen fen huang huang jin guang tian tou hong xi kuang hong shu li nian chi hei hei yi qian zhen xi tuan mo mo qian dai chu you dian yi xia yan qu mei yan qing yu li dang du can yin an yan tan an zhen dai can yi mei dan yan du lu zhi fen fu fu min min yuan cu qu chao wa zhu zhi mang ao bie tuo bi yuan chao tuo ding mi nai ding zi gu gu dong fen tao yuan pi chang gao qi yuan tang teng shu shu fen fei wen ba diao tuo tong qu sheng shi you shi ting wu nian jing hun ju yan tu si xi xian yan lei bi yao yan han hui wu hou xi ge zha xiu weng zha nong nang qi zhai ji zi ji ji qi ji chi chen chen he ya ken xie bao ze shi zi chi nian ju tiao ling ling chu quan xie yin nie jiu nie chuo kun yu chu yi ni cuo chuo qu nian xian yu e wo yi chi zou dian chu jin ya chi chen he yin ju ling bao tiao zi yin yu chuo qu wo long pang gong pang yan long long gong kan ta ling ta long gong kan gui qiu bie gui yue chui he jue ")
197210
.append("xie yue ").toString();
198211
}
199-
200-
}
212+
}

utilcode/src/test/java/com/blankj/utilcode/utils/DogeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* author: Blankj
1111
* blog : http://blankj.com
1212
* time : 2016/11/23
13-
* desc : 生成Dode的README
13+
* desc : 生成Doge的README
1414
* </pre>
1515
*/
1616
public class DogeTest {
Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.blankj.utilcode.utils;
22

3+
import org.junit.Before;
34
import org.junit.Test;
45

56
/**
@@ -12,51 +13,48 @@
1213
*/
1314
public class PinyinUtilsTest {
1415

16+
@Before
17+
public void setUp() throws Exception {
18+
PinyinUtils.ccs2Pinyin("");
19+
}
20+
1521
@Test
1622
public void getPinyinFirstLetter() throws Exception {
17-
System.out.println(PinyinUtils.getPinyinFirstLetter("单"));
18-
System.out.println(PinyinUtils.getPinyinFirstLetter("元"));
19-
System.out.println(PinyinUtils.getPinyinFirstLetter("測"));
20-
System.out.println(PinyinUtils.getPinyinFirstLetter("試"));
23+
System.out.println("单: " + PinyinUtils.getPinyinFirstLetter("单"));
24+
System.out.println("元: " + PinyinUtils.getPinyinFirstLetter("元"));
25+
System.out.println("測: " + PinyinUtils.getPinyinFirstLetter("測"));
26+
System.out.println("試: " + PinyinUtils.getPinyinFirstLetter("試"));
2127
}
2228

2329
@Test
2430
public void getPinyinFirstLetters() throws Exception {
25-
System.out.println(PinyinUtils.getPinyinFirstLetters("單元測試",","));
31+
System.out.println("單元測試: " + PinyinUtils.getPinyinFirstLetters("單元測試", ","));
2632
}
2733

2834
@Test
2935
public void ccs2Pinyin() throws Exception {
3036
long t = System.currentTimeMillis();
31-
System.out.println(PinyinUtils.ccs2Pinyin("未初始化的汉字转拼音用时测试", " "));
32-
System.out.printf("用时: %dms\n", System.currentTimeMillis() - t);
33-
t = System.currentTimeMillis();
34-
System.out.println(PinyinUtils.ccs2Pinyin("已初始化的汉字转拼音用时测试", " "));
37+
System.out.println("已初始化的汉字转拼音用时测试: " + PinyinUtils.ccs2Pinyin("已初始化的汉字转拼音用时测试", " "));
3538
System.out.printf("用时: %dms\n", System.currentTimeMillis() - t);
3639
}
3740

3841
@Test
39-
public void surname2Pinyin() throws Exception {
40-
System.out.println(PinyinUtils.surname2Pinyin("澹台"));
41-
System.out.println(PinyinUtils.surname2Pinyin("尉迟"));
42-
System.out.println(PinyinUtils.surname2Pinyin("万俟"));
43-
System.out.println(PinyinUtils.surname2Pinyin("单于"));
44-
String str = "乐乘乜仇会便区单参句召员宓弗折曾朴查洗盖祭种秘繁缪能蕃覃解谌适都阿难黑";
45-
int size = str.length();
46-
System.out.println(size);
42+
public void getSurnamePinyin() throws Exception {
43+
System.out.println("澹台: " + PinyinUtils.getSurnamePinyin("澹台"));
44+
System.out.println("尉迟: " + PinyinUtils.getSurnamePinyin("尉迟"));
45+
System.out.println("万俟: " + PinyinUtils.getSurnamePinyin("万俟"));
46+
System.out.println("单于: " + PinyinUtils.getSurnamePinyin("单于"));
47+
String surnames = "乐乘乜仇会便区单参句召员宓弗折曾朴查洗盖祭种秘繁缪能蕃覃解谌适都阿难黑";
48+
int size = surnames.length();
4749
long t = System.currentTimeMillis();
4850
for (int i = 0; i < size; ++i) {
49-
String s = String.valueOf(str.charAt(i));
50-
System.out.println(s + " 正确: "
51-
+ PinyinUtils.surname2Pinyin(s) + " 错误: "
52-
+ PinyinUtils.ccs2Pinyin(s));
51+
String surname = String.valueOf(surnames.charAt(i));
52+
System.out.printf("%s 正确: %-6s 首字母: %-6s 错误: %-6s\n",
53+
surname,
54+
PinyinUtils.getSurnamePinyin(surname),
55+
PinyinUtils.getSurnameFirstLetter(surname),
56+
PinyinUtils.ccs2Pinyin(surname));
5357
}
5458
System.out.printf("用时: %dms\n", System.currentTimeMillis() - t);
5559
}
56-
57-
@Test
58-
public void cn2Pinyin() throws Exception {
59-
System.out.println(PinyinUtils.ccs2Pinyin("测试中文转拼音"));
60-
System.out.println(PinyinUtils.ccs2Pinyin("测试中文转拼音", " "));
61-
}
6260
}

0 commit comments

Comments
 (0)