Rewrite some struct linkages

This commit is contained in:
2026-02-20 21:06:47 +08:00
parent 1d9407331a
commit d54f106dee
10 changed files with 228 additions and 128 deletions

View File

@@ -2,25 +2,29 @@ package cjlookup
import (
query "github.com/tgckpg/golifehk/query"
"golang.org/x/exp/slices"
"strconv"
)
type CChar struct {
Face string
CangJie string
JyutPing string
TungJamZi *[]*CChar
YiDukJam *[]string
}
type CJyutPing struct {
Ref *CChar
SKey string
JyutPing *CJyutPing
DukJam *[]*DukJam
_JiDukJam *[]*CJyutPing
query.Searchable
}
type CFace struct {
Ref *CChar
type DukJam struct {
Weight int
JyutPing *CJyutPing
}
type CJyutPing struct {
Roman string
SearchKey string // Searchable key
TungJamZi *[]*CChar
tSorted bool
query.Searchable
}
@@ -32,7 +36,7 @@ func (this *CJyutPing) Test(val string) bool {
return false
}
func (this *CFace) Test(val string) bool {
func (this *CChar) Test(val string) bool {
_, err := strconv.Atoi(val)
if err == nil {
return true
@@ -40,6 +44,35 @@ func (this *CFace) Test(val string) bool {
return false
}
func (m *CChar) String() string {
return m.Face
func (this *CChar) JiDukJam() *[]*CJyutPing {
if this._JiDukJam == nil {
jdj := &[]*CJyutPing{}
for _, dj := range *this.DukJam {
if dj.JyutPing != this.JyutPing {
*jdj = append(*jdj, dj.JyutPing)
}
}
this._JiDukJam = jdj
}
return this._JiDukJam
}
func (this *CJyutPing) SortedTungJamZi() *[]*CChar {
if this.tSorted {
return this.TungJamZi
}
slices.SortFunc(*this.TungJamZi, func(a, b *CChar) int {
switch {
case a.Face < b.Face:
return -1
case a.Face > b.Face:
return 1
default:
return 0
}
})
return this.TungJamZi
}