Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-csf
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-csf
Commits
22e39b42
Commit
22e39b42
authored
Apr 03, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
3fcb1e98
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
4 deletions
+51
-4
yd-csf-api/src/main/java/com/yd/csf/api/service/impl/ApiCsfCommonServiceImpl.java
+51
-4
No files found.
yd-csf-api/src/main/java/com/yd/csf/api/service/impl/ApiCsfCommonServiceImpl.java
View file @
22e39b42
...
@@ -282,6 +282,47 @@ public class ApiCsfCommonServiceImpl implements ApiCsfCommonService {
...
@@ -282,6 +282,47 @@ public class ApiCsfCommonServiceImpl implements ApiCsfCommonService {
}
}
}
}
// /**
// * 中文转拼音辅助方法
// * @param chinese
// * @return
// */
// private String convertChineseToPinyin(String chinese) {
// HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
// format.setCaseType(HanyuPinyinCaseType.UPPERCASE);
// format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
//
// StringBuilder pinyin = new StringBuilder();
// boolean lastIsChinese = false; // 标记上一个字符是否为汉字,用于控制空格添加
//
// for (char c : chinese.toCharArray()) {
// if (Character.toString(c).matches("[\\u4E00-\\u9FA5]")) {
// try {
// String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
// if (pinyinArray != null && pinyinArray.length > 0) {
// // 如果上一个字符是汉字且当前也是汉字,则先加空格(避免开头空格)
// if (lastIsChinese) {
// pinyin.append(' ');
// }
// pinyin.append(pinyinArray[0]);
// lastIsChinese = true;
// } else {
// // 如果没有拼音,原样追加
// pinyin.append(c);
// lastIsChinese = false;
// }
// } catch (BadHanyuPinyinOutputFormatCombination e) {
// pinyin.append(c);
// lastIsChinese = false;
// }
// } else {
// pinyin.append(c);
// lastIsChinese = false;
// }
// }
// return pinyin.toString();
// }
/**
/**
* 中文转拼音辅助方法
* 中文转拼音辅助方法
* @param chinese
* @param chinese
...
@@ -293,21 +334,27 @@ public class ApiCsfCommonServiceImpl implements ApiCsfCommonService {
...
@@ -293,21 +334,27 @@ public class ApiCsfCommonServiceImpl implements ApiCsfCommonService {
format
.
setToneType
(
HanyuPinyinToneType
.
WITHOUT_TONE
);
format
.
setToneType
(
HanyuPinyinToneType
.
WITHOUT_TONE
);
StringBuilder
pinyin
=
new
StringBuilder
();
StringBuilder
pinyin
=
new
StringBuilder
();
boolean
lastIsChinese
=
false
;
// 标记上一个字符是否为汉字,用于控制空格添加
boolean
lastIsChinese
=
false
;
for
(
char
c
:
chinese
.
toCharArray
())
{
for
(
char
c
:
chinese
.
toCharArray
())
{
if
(
Character
.
toString
(
c
).
matches
(
"[\\u4E00-\\u9FA5]"
))
{
if
(
Character
.
toString
(
c
).
matches
(
"[\\u4E00-\\u9FA5]"
))
{
try
{
try
{
String
[]
pinyinArray
=
PinyinHelper
.
toHanyuPinyinStringArray
(
c
,
format
);
String
[]
pinyinArray
=
PinyinHelper
.
toHanyuPinyinStringArray
(
c
,
format
);
if
(
pinyinArray
!=
null
&&
pinyinArray
.
length
>
0
)
{
if
(
pinyinArray
!=
null
&&
pinyinArray
.
length
>
0
)
{
// 如果上一个字符是汉字且当前也是汉字,则先加空格(避免开头空格)
String
py
=
pinyinArray
[
0
];
// 将 ü / Ü 替换为 v / V
py
=
py
.
replace
(
"ü"
,
"v"
).
replace
(
"Ü"
,
"V"
);
// 移除可能出现的冒号或其他非字母字符(仅保留字母和空格)
py
=
py
.
replaceAll
(
"[^A-Z]"
,
""
);
if
(
StringUtils
.
isBlank
(
py
))
{
py
=
String
.
valueOf
(
c
);
}
if
(
lastIsChinese
)
{
if
(
lastIsChinese
)
{
pinyin
.
append
(
' '
);
pinyin
.
append
(
' '
);
}
}
pinyin
.
append
(
p
inyinArray
[
0
]
);
pinyin
.
append
(
p
y
);
lastIsChinese
=
true
;
lastIsChinese
=
true
;
}
else
{
}
else
{
// 如果没有拼音,原样追加
pinyin
.
append
(
c
);
pinyin
.
append
(
c
);
lastIsChinese
=
false
;
lastIsChinese
=
false
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment