diff options
Diffstat (limited to 'compiler/ucd.go')
-rw-r--r-- | compiler/ucd.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler/ucd.go b/compiler/ucd.go new file mode 100644 index 0000000..7432ba6 --- /dev/null +++ b/compiler/ucd.go @@ -0,0 +1,36 @@ +//go:generate go run ../generator/main.go +//go:generate gofmt -w ucd_table.go + +package compiler + +import ( + "fmt" + + "github.com/nihei9/maleeni/ucd" +) + +func findCodePointRanges(propName, propVal string) ([]*ucd.CodePointRange, error) { + name := ucd.NormalizeSymbolicValue(propName) + val := ucd.NormalizeSymbolicValue(propVal) + name, ok := propertyNameAbbs[name] + if !ok { + return nil, fmt.Errorf("unsupported character property: %v", propName) + } + val, ok = generalCategoryValueAbbs[val] + if !ok { + return nil, fmt.Errorf("unsupported character property value: %v", val) + } + vals, ok := compositGeneralCategories[val] + if !ok { + vals = []string{val} + } + var ranges []*ucd.CodePointRange + for _, v := range vals { + rs, ok := generalCategoryCodePoints[v] + if !ok { + return nil, fmt.Errorf("invalie value of the General_Category property: %v", v) + } + ranges = append(ranges, rs...) + } + return ranges, nil +} |