Skip to content

Commit f8806c8

Browse files
authored
Merge pull request #240 from zh-lx/fix-surname-head
fix: 修复 surname:head 对于复姓开头不生效的问题
2 parents d7b4e10 + 818642a commit f8806c8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/common/segmentit/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class AC {
176176
if (surname === "off") {
177177
return item.priority !== Priority.Surname;
178178
} else if (surname === "head") {
179-
return i === 0;
179+
return item.length - 1 - i === 0;
180180
} else {
181181
return true;
182182
}
@@ -193,7 +193,7 @@ export class AC {
193193
if (surname === "off") {
194194
return item.priority !== Priority.Surname;
195195
} else if (surname === "head") {
196-
return i === 0;
196+
return item.length - 1 - i === 0;
197197
} else {
198198
return true;
199199
}

test/surname.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ describe("surname", () => {
4646
"zēng jīng cāng hǎi nán wèi shuǐ hǎo hǎo xué xí lè"
4747
);
4848
});
49+
50+
it("[surname]surname head double", () => {
51+
const result = pinyin("令狐冲", { surname: "head" });
52+
expect(result).to.be.equal("líng hú chōng");
53+
54+
const result1 = pinyin("万俟英", { surname: "head" });
55+
expect(result1).to.be.equal("mò qí yīng");
56+
});
4957
});

0 commit comments

Comments
 (0)