dict

package
v0.0.0-...-221d52c Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package dict implements reading .dict files.

Index

Constants

View Source
const (
	// UTFTextType is utf-8 text.
	UTFTextType = DataType('m')

	// LocaleTextType is text in a locale encoding.
	LocaleTextType = DataType('l')

	// PangoTextType is utf-8 text in the Pango text format.
	PangoTextType = DataType('g')

	// PhoneticType is utf-8 text representing an English phonetic string.
	PhoneticType = DataType('t')

	// XDXFType is utf-8 encoded xml in XDXF format.
	XDXFType = DataType('x')

	// YinBiaoOrKataType is utf-8 encoded Yin Biao or Kana phonetic string.
	YinBiaoOrKataType = DataType('y')

	// PowerWordType is a utf-8 encoded KingSoft PowerWord XML format.
	PowerWordType = DataType('p')

	// MediaWikiType is utf-8 encoded text in MediaWiki format.
	MediaWikiType = DataType('w')

	// HTMLType is utf-8 encoded HTML text.
	HTMLType = DataType('h')

	// WordNetType is WordNet data.
	WordNetType = DataType('n')

	// ResourceFileListType is a list of files in resource storage.
	ResourceFileListType = DataType('r')

	// WavType is .wav sound file data.
	WavType = DataType('W')

	// PictureType is image file data. This was used by the
	// stardict-advertisement-plugin. Images are better stored in a resource
	// file list.
	PictureType = DataType('P')

	// ExperimentalType is reserved for experimental features.
	ExperimentalType = DataType('X')
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Type DataType
	Data []byte
}

Data is a data entry in a Word.

func (*Data) String

func (d *Data) String() string

String returns a string representation of the data.

type DataType

type DataType byte

DataType is a type of data in a word. Data types are specified by a single byte at the beginning of a word. Lower case characters represent string-like data that is terminated by a null terminator ('\0'). Upper case characters represent file-like data that starts with a 32-bit size followed by file data.

type Dict

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

Dict represents a Stardict dictionary's dictionary data.

func New

func New(r ReaderAtCloser, options *Options) (*Dict, error)

New returns a new Dict from the given reader. Dict takes ownership of the reader. The reader can be closed via the Dict's Close method.

func NewFromIfoPath

func NewFromIfoPath(ifoPath string, options *Options) (*Dict, error)

NewFromIfoPath opens the dict file given the path to the .ifo file.

func (*Dict) Close

func (d *Dict) Close() error

Close closes the underlying reader for the .dict file.

func (*Dict) Word

func (d *Dict) Word(e *idx.Word) (*Word, error)

Word retrieves the word for the given index entry from the dictionary.

type Options

type Options struct {
	// SameTypeSequence is an option that indicates that each word in the .dict
	// file will have the same sequence of data types. This is equivalent to
	// the sametypesequence option from the .ifo file..
	//
	// See: https://github.com/huzheng001/stardict-3/blob/master/dict/doc/StarDictFileFormat
	SameTypeSequence []DataType
}

Options are options for the dict data.

type ReaderAtCloser

type ReaderAtCloser interface {
	io.ReaderAt
	io.Closer
}

ReaderAtCloser is an interface that wraps the io.ReaderAt and io.Closer interfaces.

type Word

type Word struct {
	Data []*Data
}

Word is a full dictionary entry.

Jump to

Keyboard shortcuts

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