Skip to content

Commit

Permalink
Assign narrow characters width 1
Browse files Browse the repository at this point in the history
The narrow category applies to all ASCII characters, as well as
characters such as double angle brackets.  The tr11 annex says
that these characters are "always narrow and have explicit fullwidth
or wide counterparts", which I believe means they should be
assigned width one.

Previously, these characters were being assigned width 0.
I think before v0.0.5 they were being assigned width one,
but somewhere between v0.0.4 and v0.0.7 it changed to width 0
(maybe when introducing the generation script?).
  • Loading branch information
wedaly committed Aug 14, 2020
1 parent 4709655 commit 1e492b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion runewidth.go
Expand Up @@ -101,8 +101,10 @@ func NewCondition() *Condition {
// See http://www.unicode.org/reports/tr11/
func (c *Condition) RuneWidth(r rune) int {
switch {
case r < 0 || r > 0x10FFFF || inTables(r, nonprint, combining, narrow):
case r < 0 || r > 0x10FFFF || inTables(r, nonprint, combining):
return 0
case inTables(r, narrow):
return 1
case (c.EastAsianWidth && IsAmbiguousWidth(r)) || inTables(r, doublewidth):
return 2
default:
Expand Down
1 change: 1 addition & 0 deletions runewidth_test.go
Expand Up @@ -164,6 +164,7 @@ var runewidthtests = []struct {
{'\u0300', 0, 0},
{'\u2028', 0, 0},
{'\u2029', 0, 0},
{'⟦', 1, 1}, // non-ASCII classified as "na" (narrow)
}

func TestRuneWidth(t *testing.T) {
Expand Down

0 comments on commit 1e492b2

Please sign in to comment.