penguin/golifehk

@golifehk bot in Telegram

datasources/cjlookup/searchables.go

raw ยท 762 bytes

package cjlookup

import (
	"strings"

	query "github.com/tgckpg/golifehk/query"
)

func getSearchables() (*[]query.ISearchable, error) {
	searchables := []query.ISearchable{}

	cjRepl, err := ReadCangJieKeys()
	if err != nil {
		return nil, err
	}

	chars := map[string]*CChar{}
	ReadCangJieTable(chars, cjRepl)
	jpMap, err := ReadJyutPingTable(chars)
	if err != nil {
		return nil, err
	}

	for jyutping, chars := range jpMap {
		for _, c := range *chars {
			cjp := CJyutPing{}
			cjp.Ref = c
			cjp.SKey = strings.ToUpper(jyutping)
			cjp.Key = &cjp.SKey
			searchables = append(searchables, &cjp)
		}
	}

	for _, c := range chars {
		ccj := CFace{}
		ccj.Ref = c
		ccj.Key = &c.Face
		searchables = append(searchables, &ccj)
	}

	return &searchables, nil
}