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
94026498
Commit
94026498
authored
Mar 18, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
8e18cca6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
yd-csf-api/src/main/java/com/yd/csf/api/service/impl/ApiCsfCommonServiceImpl.java
+13
-0
No files found.
yd-csf-api/src/main/java/com/yd/csf/api/service/impl/ApiCsfCommonServiceImpl.java
View file @
94026498
...
...
@@ -283,18 +283,31 @@ public class ApiCsfCommonServiceImpl implements ApiCsfCommonService {
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
();
...
...
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