Documentation
¶
Overview ¶
Package encoding converts text files between UTF-8 and the encodings ZPad edits. The editor itself works on UTF-8.
Index ¶
- Variables
- func Decode(data []byte, kind Kind) (string, error)
- func DecodeOwned(data []byte, kind Kind) (string, error)
- func Encode(text string, kind Kind) ([]byte, error)
- func EncodeStream(dst io.Writer, kind Kind, writeUTF8 func(io.Writer) error) (int64, error)
- func IsUTF16(head []byte) bool
- func Label(k Kind) string
- type Kind
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownEncoding reports that no supported encoding could decode a // file's bytes. ErrUnknownEncoding = errors.New("unknown encoding") // ErrInvalidEncoding reports that text could not be encoded in the // target encoding. ErrInvalidEncoding = errors.New("invalid encoding") )
All lists the encodings the status bar offers.
Functions ¶
func DecodeOwned ¶ added in v0.7.1
DecodeOwned decodes data in kind, reusing data without copying when it is already UTF-8. Callers must own data and never mutate it afterward.
func EncodeStream ¶ added in v0.7.1
EncodeStream encodes the UTF-8 text written by writeUTF8 into dst in kind, returning the number of encoded bytes written to dst. Any invalid UTF-8 or unencodable sequence returns ErrInvalidEncoding.
Types ¶
type Kind ¶
type Kind string
Kind is a text encoding.
func Detect ¶
Detect reads the encoding of data from its BOM, its UTF-16 byte pattern or its UTF-8 validity, falling back to GB18030.
func DetectAndDecodeOwned ¶ added in v0.7.1
DetectAndDecodeOwned detects the encoding of data and decodes it in one pass. Callers must own data and never mutate it afterward, allowing UTF-8 text to be handed to the rope builder without a second validation pass or a full-file string copy, and GB18030 to be decoded once instead of twice.