gencode

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePinyinCode added in v1.0.4

func GeneratePinyinCode(input string, checker DuplicateChecker, config *PinyinConfig) (string, error)

GeneratePinyinCode 根据传入的中文文本生成唯一的拼音编码。 如果回调函数判断重复,则自动追加递增序号。 input: 输入的中文字符串 checker: 查重回调函数 config: 可选配置,传入 nil 时将使用默认配置(全拼、全小写、无分隔符)

Types

type CaseStyle added in v1.0.4

type CaseStyle int

CaseStyle 定义拼音的大小写样式

const (
	CaseLower CaseStyle = iota // 全小写(例如: "zhangsan")
	CaseUpper                  // 全大写(例如: "ZHANGSAN")
	CaseCamel                  // 首字母大写驼峰(例如: "ZhangSan")
)

type DuplicateChecker added in v1.0.4

type DuplicateChecker func(code string) (bool, error)

DuplicateChecker 是用于判断编码是否重复的回调函数。 传入生成的拼音编码,返回 true 表示已重复,返回 false 表示可用。 如果返回 error,生成方法将中断并返回该错误。

type PinyinConfig added in v1.0.4

type PinyinConfig struct {
	Style     PinyinStyle // 拼音样式(全拼/首字母)
	Case      CaseStyle   // 大小写样式(小写/大写/驼峰)
	Separator string      // 拼音字与字之间的分隔符(例如 "-" 得到 "zhang-san")
}

PinyinConfig 定义拼音编码生成的配置项

type PinyinStyle added in v1.0.4

type PinyinStyle int

PinyinStyle 定义拼音编码的生成样式

const (
	StyleFull  PinyinStyle = iota // 全拼(例如: "zhangsan")
	StyleFirst                    // 首字母缩写(例如: "zs")
)

type SimpleGenerator

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

func NewSimpleGenerator

func NewSimpleGenerator() *SimpleGenerator

func (*SimpleGenerator) Generate

func (g *SimpleGenerator) Generate(prefix string) string

Jump to

Keyboard shortcuts

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