【Go】高性能的简繁体转换
Github链接地址
高性能的简繁体转换
入口
sat.go
// 实现该接口,以提供字体转换
type Dicter interface {
Init(opts ...Option) error //执行初始化操作
Read(string) string //繁体转简体
ReadReverse(string) string //简体转繁体
}
options.go
// 自定义初始化参数内容
type Option func(*Options)
type Options struct {
Path string `json:"path"`
}
func SetPath(path string) Option {
return func(args *Options) {
args.Path = path
}
}
default.go
// 实现 Dicter 接口
func (d *defaultDict) Init(opts ...Option) error
func (d *defaultDict) Read(s string) string
func (d *defaultDict) ReadReverse(s string) string
测试
测试代码
dicter := DefaultDict()
dicter.ReadReverse("么")
or
InitDefaultDict(SetPath("/users/go/xxxx.dict")) //使用自定义词库
dicter := DefaultDict()
dicter.ReadReverse("么")
指标
goos: darwin
goarch: amd64
pkg: github.com/go-creed/sat
BenchmarkNewDict
BenchmarkNewDict-12 14721091 71.2 ns/op
PASS
还没有评论,来说两句吧...