Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions segmenter/unicode14_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ func (cr *cursor) ruleLB1() {
case ucd.BreakAI, ucd.BreakSG, ucd.BreakXX:
cr.line = ucd.BreakAL
case ucd.BreakSA:
generalCategory := ucd.LookupType(cr.r)
if generalCategory == unicode.Mn || generalCategory == unicode.Mc {
if unicode.Is(unicode.Mn, cr.r) || unicode.Is(unicode.Mc, cr.r) {
cr.line = ucd.BreakCM
} else {
cr.line = ucd.BreakAL
Expand Down
75 changes: 51 additions & 24 deletions unicodedata/general_category.go

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

13 changes: 2 additions & 11 deletions unicodedata/unicode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@ import (
"github.com/go-text/typesetting/language"
)

var categories []*unicode.RangeTable

func init() {
for cat, table := range unicode.Categories {
if len(cat) == 2 {
categories = append(categories, table)
}
}
}

// LookupType returns the unicode general categorie of the rune,
// or nil if not found.
// The returned table is one of the standard library unicode package.
func LookupType(r rune) *unicode.RangeTable {
for _, table := range categories {
for _, table := range allCategories {
if unicode.Is(table, r) {
return table
}
Expand Down
5 changes: 3 additions & 2 deletions unicodedata/unicode_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package unicodedata

import (
"reflect"
"testing"
"unicode"

Expand Down Expand Up @@ -101,6 +100,8 @@ func TestLookupType(t *testing.T) {
{'.', unicode.Po},
{'カ', unicode.Lo},
{'🦳', unicode.So},
{'\U0001F3FF', unicode.Sk},
{'\U0001F02C', nil},
{-1, nil},
}
for _, tt := range tests {
Expand Down Expand Up @@ -508,7 +509,7 @@ func TestLookupLineBreakClass(t *testing.T) {

}
for _, tt := range tests {
if got := LookupLineBreakClass(tt.args); !reflect.DeepEqual(got, tt.want) {
if got := LookupLineBreakClass(tt.args); got != tt.want {
t.Errorf("LookupLineBreakClass(U+%x) = %p, want %p", tt.args, got, tt.want)
}
}
Expand Down