Skip to content

Commit

Permalink
Tweak stringsx.Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Nov 13, 2023
1 parent b758ae6 commit 994e239
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion stringsx/confusables.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"regexp"
"strconv"
"strings"
"unicode"

"golang.org/x/text/unicode/norm"
)
Expand Down Expand Up @@ -54,14 +55,19 @@ func Skeleton(s string) string {
var sb strings.Builder

for _, r := range norm.NFD.String(s) {
// TODO this is not the complete set of Default_Ignorable_Code_Point
if unicode.In(r, unicode.Other_Default_Ignorable_Code_Point) {
continue
}

if c, ok := confusables[r]; ok {
sb.WriteString(c)
} else {
sb.WriteRune(r)
}
}

return sb.String()
return norm.NFD.String(sb.String())
}

// Implements https://www.unicode.org/reports/tr39/#def-confusable
Expand Down
1 change: 1 addition & 0 deletions stringsx/confusables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestSkeleton(t *testing.T) {
func TestConfusable(t *testing.T) {
assert.True(t, stringsx.Confusable("", ""))
assert.True(t, stringsx.Confusable("foo", "foo"))
assert.True(t, stringsx.Confusable("\uFFF1foo", "foo"))
assert.True(t, stringsx.Confusable("١", "۱")) // 0x661 vs 0x6f1
assert.True(t, stringsx.Confusable("بلی", "بلى")) // 0x6cc vs 0x649
assert.True(t, stringsx.Confusable("nyaruka", "𝕟𝔂𝛼𝐫ᴜ𝞳𝕒"))
Expand Down

0 comments on commit 994e239

Please sign in to comment.