Skip to content

Commit

Permalink
gwidth: special case Variation Selectors
Browse files Browse the repository at this point in the history
go-runewidth reports Variation Selectors as width 1, when they should be
width 0. Special case these. Issue reported in go-runewidth #76

Reference: mattn/go-runewidth#76
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
  • Loading branch information
rockorager committed Feb 8, 2024
1 parent 084d5f8 commit 066bbc5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gwidth.go
Expand Up @@ -11,9 +11,12 @@ func gwidth(s string, unicode bool) int {
}
total := 0
for _, r := range s {
if r == 0xFE0F {
// runewidth incorrectly thinks a VS16 selector is 1
// wide
if r >= 0xFE00 && r <= 0xFE0F {
// Variation Selectors 1 - 16
continue
}
if r >= 0xE0100 && r <= 0xE01EF {
// Variation Selectors 17-256
continue
}
total += runewidth.RuneWidth(r)
Expand Down

0 comments on commit 066bbc5

Please sign in to comment.