go_mdict

package
v0.0.0-...-07f7e3c Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: LGPL-2.1 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MdictTypeMdd MdictType = 1
	MdictTypeMdx MdictType = 2

	EncryptNoEnc      = 0
	EncryptRecordEnc  = 1
	EncryptKeyInfoEnc = 2
	NumfmtBe8bytesq   = 0
	NumfmtBe4bytesi   = 1
	EncodingUtf8      = 0
	EncodingUtf16     = 1
	EncodingBig5      = 2
	ENCODING_GBK      = 3
	ENCODING_GB2312   = 4
	EncodingGb18030   = 5
)

Variables

This section is empty.

Functions

func BuildRangeTree

func BuildRangeTree(list []*MdictRecordBlockInfoListItem, root *RecordBlockRangeTreeNode)

Types

type Dictionary

type Dictionary struct {
	GeneratedByEngineVersion string
	RequiredEngineVersion    string
	Encrypted                string
	// NOTE: the real text encoding lives in the "Encoding" attribute; the
	// upstream code mapped this field to "IsUTF16" by mistake, which silently
	// misdetected every non-UTF16 dictionary (e.g. GBK) as UTF-8.
	Encoding             string
	IsUTF16              string
	Format               string
	Stripkey             string
	CreationDate         string
	Compact              string
	Compat               string
	KeyCaseSensitive     string
	Description          string
	Title                string
	DataSourceFormat     string
	StyleSheet           string
	Left2Right           string
	RegisterBy           string
	UUID                 string
	ContentType          string
	DefaultSortingLocale string
}

Dictionary holds the attributes parsed from the MDict header.

v1/v2 headers use the <Dictionary ...> root tag; v3 headers use <ZDB ...>. Rather than fighting encoding/xml's strict root-tag matching, we parse the attributes with a regex (mirroring the reference Python reader's _parse_header) so both root tags work uniformly.

type MDictKeywordEntry

type MDictKeywordEntry struct {
	RecordStartOffset int64
	RecordEndOffset   int64
	KeyWord           string
	KeyBlockIdx       int64
}

type MDictKeywordIndex

type MDictKeywordIndex struct {
	//encoding                            int
	//encryptType                         int
	KeywordEntry MDictKeywordEntry
	RecordBlock  MDictKeywordIndexRecordBlock
}

type MDictKeywordIndexRecordBlock

type MDictKeywordIndexRecordBlock struct {
	DataStartOffset          int64
	CompressSize             int64
	DeCompressSize           int64
	KeyWordPartStartOffset   int64
	KeyWordPartDataEndOffset int64
}

type Mdict

type Mdict struct {
	*MdictBase
	// contains filtered or unexported fields
}

func New

func New(filename string) (*Mdict, error)

func (*Mdict) BuildIndex

func (mdict *Mdict) BuildIndex() error

BuildIndex 构建索引

func (*Mdict) CreationDate

func (mdict *Mdict) CreationDate() string

func (*Mdict) Description

func (mdict *Mdict) Description() string

func (*Mdict) Digest

func (mdict *Mdict) Digest() string

func (*Mdict) Encoding

func (mdict *Mdict) Encoding() int

Encoding returns the dictionary's text encoding as one of the Encoding* / ENCODING_* constants. For non-UTF16 MDX dictionaries LocateByKeywordEntry returns record bytes still in this native encoding (UTF16 is decoded to UTF-8 internally), so callers must transcode accordingly.

func (*Mdict) GeneratedByEngineVersion

func (mdict *Mdict) GeneratedByEngineVersion() string

func (*Mdict) GetKeyWordEntries

func (mdict *Mdict) GetKeyWordEntries() ([]*MDictKeywordEntry, error)

func (*Mdict) GetKeyWordEntriesSize

func (mdict *Mdict) GetKeyWordEntriesSize() int64

func (*Mdict) IsMDD

func (mdict *Mdict) IsMDD() bool

func (*Mdict) IsRecordEncrypted

func (mdict *Mdict) IsRecordEncrypted() bool

func (*Mdict) IsUTF16

func (mdict *Mdict) IsUTF16() bool

func (*Mdict) KeywordEntryToIndex

func (mdict *Mdict) KeywordEntryToIndex(item *MDictKeywordEntry) (*MDictKeywordIndex, error)

func (*Mdict) LocateByKeywordEntry

func (mdict *Mdict) LocateByKeywordEntry(entry *MDictKeywordEntry) ([]byte, error)

func (*Mdict) LocateByKeywordIndex

func (mdict *Mdict) LocateByKeywordIndex(index *MDictKeywordIndex) ([]byte, error)

func (*Mdict) Lookup

func (mdict *Mdict) Lookup(word string) ([]byte, error)

func (*Mdict) Name

func (mdict *Mdict) Name() string

func (*Mdict) StyleSheet

func (mdict *Mdict) StyleSheet() string

StyleSheet returns the raw StyleSheet header attribute (groups of three lines: number, begin, end), empty when the dictionary defines none.

func (*Mdict) Title

func (mdict *Mdict) Title() string

func (*Mdict) Version

func (mdict *Mdict) Version() string

type MdictAccessor

type MdictAccessor struct {
	Filepath          string `json:"filepath"`
	IsRecordEncrypted bool   `json:"is_record_encrypted"`
	IsMDD             bool   `json:"is_mdd"`
	IsUTF16           bool   `json:"is_utf_16"`
}

func NewAccessor

func NewAccessor(mdict *Mdict) *MdictAccessor

func NewAccessorFromJson

func NewAccessorFromJson(data []byte) (*MdictAccessor, error)

func (*MdictAccessor) RetrieveDefByIndex

func (mdi *MdictAccessor) RetrieveDefByIndex(index *MDictKeywordIndex) ([]byte, error)

func (*MdictAccessor) Serialize

func (mdi *MdictAccessor) Serialize() ([]byte, error)

type MdictBase

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

type MdictRecordBlockInfoListItem

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

func QueryRangeData

func QueryRangeData(root *RecordBlockRangeTreeNode, queryRange int64) *MdictRecordBlockInfoListItem

type MdictType

type MdictType int

type RecordBlockRangeTreeNode

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

Jump to

Keyboard shortcuts

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