Skip to content

Commit

Permalink
🎨 Add RemovePUA siyuan-note/siyuan#13291
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 27, 2024
1 parent c9cf5f7 commit 1ae6a98
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ func (*GuluStr) RemoveCtl(str string) string {
}, str)
}

func (*GuluStr) RemovePUA(str string) string {
return strings.Map(func(r rune) rune {
if (r >= 0xE000 && r <= 0xF8FF) || (r >= 0xF0000 && r <= 0xFFFFD) || (r >= 0x100000 && r <= 0x10FFFD) {
return -1
}
return r
}, str)
}

const (
// ZWSP represents zero-width space.
ZWSP = '\u200B'
Expand Down
24 changes: 24 additions & 0 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ func TestRemoveInvisible(t *testing.T) {
}
}

func TestRemoveCtl(t *testing.T) {
expected := "foo测试barbaz"
got := Str.RemoveCtl("foo\u200b测试\uE004\nbar\tbaz")
if expected != got {
t.Errorf("expected [%s], got [%s]", expected, got)
return
}

got = Str.RemoveCtl("foo\u200e测试\nbar\tbaz")
if expected != got {
t.Errorf("expected [%s], got [%s]", expected, got)
return
}
}

func TestRemovePUA(t *testing.T) {
expected := "foo测​试barbaz"
got := Str.RemovePUA("foo\uE004测​试\uE004barbaz")
if expected != got {
t.Errorf("expected [%s], got [%s]", expected, got)
return
}
}

func TestToBytes(t *testing.T) {
str := "Gulu 你好!"
bytes := Str.ToBytes(str)
Expand Down

0 comments on commit 1ae6a98

Please sign in to comment.