Skip to content

Commit

Permalink
Merge pull request #240 from zh-lx/fix-surname-head
Browse files Browse the repository at this point in the history
fix: 修复 surname:head 对于复姓开头不生效的问题
  • Loading branch information
zh-lx authored May 30, 2024
2 parents d7b4e10 + 818642a commit f8806c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/common/segmentit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class AC {
if (surname === "off") {
return item.priority !== Priority.Surname;
} else if (surname === "head") {
return i === 0;
return item.length - 1 - i === 0;
} else {
return true;
}
Expand All @@ -193,7 +193,7 @@ export class AC {
if (surname === "off") {
return item.priority !== Priority.Surname;
} else if (surname === "head") {
return i === 0;
return item.length - 1 - i === 0;
} else {
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions test/surname.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ describe("surname", () => {
"zēng jīng cāng hǎi nán wèi shuǐ hǎo hǎo xué xí lè"
);
});

it("[surname]surname head double", () => {
const result = pinyin("令狐冲", { surname: "head" });
expect(result).to.be.equal("líng hú chōng");

const result1 = pinyin("万俟英", { surname: "head" });
expect(result1).to.be.equal("mò qí yīng");
});
});

0 comments on commit f8806c8

Please sign in to comment.