Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 '啊-测-试' 转换为 'A -C -S' 的问题,现在转为 'A-C-S' #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pinyinUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,26 @@
{
var py = this.getPinyin(str, ' ', false, polyphone);
py = py instanceof Array ? py : [py];

var result = [];
for(var i=0; i<py.length; i++)
{
result.push(py[i].replace(/(^| )(\w)\w*/g, function(m,$1,$2){return $2.toUpperCase();}));
// result.push(py[i].replace(/(^| )(\w)\w*/g, function(m,$1,$2){return $2.toUpperCase();}));
var temp = [];
var items = py[i].split(' ');
var reg = /^\w/;
for (var j = 0, len = items.length; j < len; j++) {
var item = items[j];
if (reg.test(item)) {
temp.push(item[0].toUpperCase());
} else {
temp.push(item);
}
}

result.push(temp.join(''));
}

if(!polyphone) return result[0];
else return simpleUnique(result);
}
Expand Down