From 97ac8e6b51f9b7c7680d199299ec62adea9a8af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=95=E5=8D=95?= Date: Fri, 10 May 2024 16:18:01 +0800 Subject: [PATCH] Fix #11 (#12) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(mspy_udl): 过滤掉含有非汉字的词条 --- .github/workflows/commit.yml | 2 +- pkg/pinyin/mspy_udl.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index 8356984..d1e0cca 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -77,7 +77,7 @@ jobs: # 上传到 Artifact - name: Upload windows - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: rose path: ./bin/ diff --git a/pkg/pinyin/mspy_udl.go b/pkg/pinyin/mspy_udl.go index 3aa5e55..d51da03 100644 --- a/pkg/pinyin/mspy_udl.go +++ b/pkg/pinyin/mspy_udl.go @@ -5,6 +5,7 @@ import ( "fmt" "slices" "time" + "unicode" "github.com/nopdan/rose/pkg/util" ) @@ -488,6 +489,15 @@ func (f *MspyUDL) Unmarshal(r *bytes.Reader) []*Entry { } func (f *MspyUDL) Marshal(di []*Entry) []byte { + di = slices.DeleteFunc(di, func(v *Entry) bool { + for _, r := range v.Word { + if !unicode.Is(unicode.Han, r) { + return true + } + } + return false + }) + var buf bytes.Buffer buf.Grow(0x2400 + 60*len(di))