dictgen

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMultiCharsAndMultiCodes = errors.New("multi chars and multi codes at the same time")
	ErrMissCharOrCode          = errors.New("miss char or code")
)
View Source
var (
	ErrLinerInvalidPattern = errors.New("invalid pattern")
)

Functions

This section is empty.

Types

type Dict

type Dict struct {
	// contains filtered or unexported fields
}

Dict 字典结构

func NewDict

func NewDict() Dict

func (Dict) AddCharWithCodes

func (d Dict) AddCharWithCodes(char string, codes []string)

AddCharWithCodes 添加单字多码数据

func (Dict) AddCodeWithChars

func (d Dict) AddCodeWithChars(code string, chars []string)

AddCodeWithChars 添加单码多字数据

func (Dict) GetCodes

func (d Dict) GetCodes(char string) []string

GetCodes 查询字符对应的code列表

func (Dict) Write

func (d Dict) Write(varName, pkgName string, w io.Writer) error

Write 把Dict序列化后写入Writer中

type Generator

type Generator interface {
	// ParseSingle 解析单个数据,根据不同情况,单个数据可能为单字多码或多码单字,但不能同时存在多码多字的情况
	ParseSingle(raw []byte) (codes []string, chars []string, err error)
	// ParseAll 解析完成的字典数据
	ParseAll(raw io.Reader) (dict Dict, err error)
}

Generator 字典生成器

type Liner

type Liner struct {
	// contains filtered or unexported fields
}

Liner 逐行扫描生成器

func NewLiner

func NewLiner(pattern string, debug bool) (Liner, error)

NewLiner 生成一个按行解析器 pattern: 解析器使用得正则表达式,此表达式至少有2个命名分组。

分组命名格式:
	char: 表示汉字
	code: 表示五笔码

func (Liner) ParseAll

func (l Liner) ParseAll(raw io.Reader) (Dict, error)

ParseAll 解析全量数据

func (Liner) ParseSingle

func (l Liner) ParseSingle(raw []byte) (codes []string, chars []string, err error)

ParseSingle 解析单行数据

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL