Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpret "na" as narrow #44

Merged
merged 3 commits into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmark_test.go
Expand Up @@ -37,8 +37,8 @@ func BenchmarkTableAmbiguous(b *testing.B) {
func BenchmarkTableEmoji(b *testing.B) {
benchSink = benchTable(b, emoji)
}
func BenchmarkTableNotassigned(b *testing.B) {
benchSink = benchTable(b, notassigned)
func BenchmarkTableNarrow(b *testing.B) {
benchSink = benchTable(b, narrow)
}
func BenchmarkTableNeutral(b *testing.B) {
benchSink = benchTable(b, neutral)
Expand Down
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, notassigned):
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
6 changes: 4 additions & 2 deletions runewidth_table.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion runewidth_test.go
Expand Up @@ -44,7 +44,7 @@ var tables = []tableInfo{
{doublewidth, "doublewidth", 182440, "3d16eda8650dc2c92d6318d32f0b4a74fda5a278db2d4544b1dd65863394823c"},
{ambiguous, "ambiguous", 138739, "d05e339a10f296de6547ff3d6c5aee32f627f6555477afebd4a3b7e3cf74c9e3"},
{emoji, "emoji", 3535, "9ec17351601d49c535658de8d129c1d0ccda2e620669fc39a2faaee7dedcef6d"},
{notassigned, "notassigned", 10, "68441e98eca1450efbe857ac051fcc872eed347054dfd0bc662d1c4ee021d69f"},
{narrow, "narrow", 111, "fa897699c5e3cd9141c638d539331b0bdd508b874e22996c5e929767d455fc5a"},
{neutral, "neutral", 27333, "5455f5e75c307f70b4e9b2384dc5a8bcd91a4c5e2b24b2b185dfad4d860ee5c2"},
}

Expand Down Expand Up @@ -164,6 +164,8 @@ var runewidthtests = []struct {
{'\u0300', 0, 0},
{'\u2028', 0, 0},
{'\u2029', 0, 0},
{'a', 1, 1}, // ASCII classified as "na" (narrow)
{'⟦', 1, 1}, // non-ASCII classified as "na" (narrow)
}

func TestRuneWidth(t *testing.T) {
Expand Down
12 changes: 5 additions & 7 deletions script/generate.go
Expand Up @@ -92,12 +92,10 @@ func eastasian(out io.Writer, in io.Reader) error {
hi: r2,
})
case "Na":
if r1 > 0xFF {
na = append(na, rrange{
lo: r1,
hi: r2,
})
}
na = append(na, rrange{
lo: r1,
hi: r2,
})
case "N":
nu = append(nu, rrange{
lo: r1,
Expand All @@ -119,7 +117,7 @@ func eastasian(out io.Writer, in io.Reader) error {
fmt.Fprint(out)

shapeup(&na)
generate(out, "notassigned", na)
generate(out, "narrow", na)
fmt.Fprintln(out)

shapeup(&nu)
Expand Down